From 55487832c614edb61ebf22d0c153944ba864feaa Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Thu, 2 Feb 2023 11:30:25 -0400 Subject: sdk: Add `mtx` We're slowly getting there. --- src/Dolphin/mtx/mtx44.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/Dolphin/mtx/mtx44.c (limited to 'src/Dolphin/mtx/mtx44.c') diff --git a/src/Dolphin/mtx/mtx44.c b/src/Dolphin/mtx/mtx44.c new file mode 100644 index 0000000..b974888 --- /dev/null +++ b/src/Dolphin/mtx/mtx44.c @@ -0,0 +1,98 @@ +// This file was taken from the Melee decompilation project. +// https://github.com/doldecomp/melee/blob/master/src/dolphin/mtx/mtx44.c +#include +#include + +void C_MTXFrustum(Mtx44 m, f32 t, f32 b, f32 l, f32 r, f32 n, f32 f) +{ + f32 temp_f8; + f32 temp_f6; + f32 temp_f9; + f32 temp_f11; + + temp_f11 = 1.0F / (r - l); + temp_f8 = 2.0F * n; + temp_f9 = 1.0F / (t - b); + temp_f6 = 1.0F / (f - n); + + m[0][0] = temp_f8 * temp_f11; + m[0][1] = 0.0F; + m[0][2] = temp_f11 * (r + l); + m[0][3] = 0.0F; + + m[1][0] = 0.0F; + m[1][1] = temp_f8 * temp_f9; + m[1][2] = temp_f9 * (t + b); + m[1][3] = 0.0F; + + m[2][0] = 0.0F; + m[2][1] = 0.0F; + m[2][2] = -n * temp_f6; + m[2][3] = temp_f6 * -(f * n); + + m[3][0] = 0.0F; + m[3][1] = 0.0F; + m[3][2] = -1.0F; + m[3][3] = 0.0F; +} + +void C_MTXPerspective(Mtx44 m, f32 fovY, f32 aspect, f32 n, f32 f) +{ + f32 temp_f3; + f32 temp_f4; + + fovY = 0.5F * fovY; + + temp_f4 = 1.0F / tanf(0.017453292F * (fovY)); + temp_f3 = 1.0F / (f - n); + + m[0][0] = temp_f4 / aspect; + m[0][1] = 0.0F; + m[0][2] = 0.0F; + m[0][3] = 0.0F; + + m[1][0] = 0.0F; + m[1][1] = temp_f4; + m[1][2] = 0.0F; + m[1][3] = 0.0F; + + m[2][0] = 0.0F; + m[2][1] = 0.0F; + m[2][2] = -n * temp_f3; + m[2][3] = temp_f3 * -(f * n); + + m[3][0] = 0.0F; + m[3][1] = 0.0F; + m[3][2] = -1.0F; + m[3][3] = 0.0F; +} + +void C_MTXOrtho(Mtx44 m, f32 t, f32 b, f32 l, f32 r, f32 n, f32 f) +{ + f32 temp_f8; + f32 temp_f10; + f32 temp_f4; + + temp_f10 = 1.0F / (r - l); + m[0][0] = 2.0F * temp_f10; + m[0][1] = 0.0F; + m[0][2] = 0.0F; + m[0][3] = temp_f10 * -(r + l); + + temp_f8 = 1.0F / (t - b); + m[1][0] = 0.0F; + m[1][1] = 2.0F * temp_f8; + m[1][2] = 0.0F; + m[1][3] = temp_f8 * -(t + b); + + temp_f4 = 1.0F / (f - n); + m[2][0] = 0.0F; + m[2][1] = 0.0F; + m[2][2] = -1.0F * temp_f4; + m[2][3] = -f * temp_f4; + + m[3][0] = 0.0F; + m[3][1] = 0.0F; + m[3][2] = 0.0F; + m[3][3] = 1.0F; +} -- cgit v1.2.3-13-gbd6f