From 0d93e48035c5f0a7f729919d395c6a4f6eb12980 Mon Sep 17 00:00:00 2001 From: KrimtonZ Date: Mon, 23 Mar 2020 16:31:24 -0500 Subject: skelanime WIP, name Matrix_TranslateThanRotateZYX, match Matrix_Translate --- src/code/sys_matrix.c | 168 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 112 insertions(+), 56 deletions(-) (limited to 'src/code/sys_matrix.c') diff --git a/src/code/sys_matrix.c b/src/code/sys_matrix.c index b300f189d..688b21500 100644 --- a/src/code/sys_matrix.c +++ b/src/code/sys_matrix.c @@ -2,13 +2,16 @@ #include // clang-format off -Mtx gMtxClear = { +Mtx gMtxClear = +{ 65536, 0, 1, 0, 0, 65536, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, }; -MtxF gMtxFClear = { + +MtxF gMtxFClear = +{ 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, @@ -19,67 +22,88 @@ MtxF gMtxFClear = { MtxF* sMatrixStack; // "Matrix_stack" MtxF* sCurrentMatrix; // "Matrix_now" -void Matrix_Init(GameState* gameState) { +void Matrix_Init(GameState* gameState) +{ sCurrentMatrix = Game_Alloc(gameState, 20 * sizeof(MtxF), "../sys_matrix.c", 153); sMatrixStack = sCurrentMatrix; } -void Matrix_Push(void) { +void Matrix_Push(void) +{ Matrix_MtxFCopy(sCurrentMatrix + 1, sCurrentMatrix); sCurrentMatrix++; } -void Matrix_Pull(void) { +void Matrix_Pull(void) +{ sCurrentMatrix--; - if (sCurrentMatrix < sMatrixStack) { + if (sCurrentMatrix < sMatrixStack) + { __assert("Matrix_now >= Matrix_stack", "../sys_matrix.c", 176); } } -void Matrix_Get(MtxF* dest) { +void Matrix_Get(MtxF* dest) +{ Matrix_MtxFCopy(dest, sCurrentMatrix); } -void Matrix_Put(MtxF* src) { +void Matrix_Put(MtxF* src) +{ Matrix_MtxFCopy(sCurrentMatrix, src); } -MtxF* Matrix_GetCurrent(void) { +MtxF* Matrix_GetCurrent(void) +{ return sCurrentMatrix; } -void Matrix_Mult(MtxF* mf, u8 mode) { +void Matrix_Mult(MtxF* mf, u8 mode) +{ MtxF* cmf = Matrix_GetCurrent(); - if (mode == MTXMODE_APPLY) { + if (mode == MTXMODE_APPLY) + { func_800A6FA0(cmf, mf, cmf); - } else { + } + else + { Matrix_MtxFCopy(sCurrentMatrix, mf); } } -#ifdef NON_MATCHING -// minor ordering and regalloc differences void Matrix_Translate(f32 x, f32 y, f32 z, u8 mode) { MtxF* cmf = sCurrentMatrix; - - if (mode == MTXMODE_APPLY) { - cmf->wx += cmf->xx * x + cmf->yx * y + cmf->zx * z; - cmf->wy += cmf->xy * x + cmf->yy * y + cmf->zy * z; - cmf->wz += cmf->xz * x + cmf->yz * y + cmf->zz * z; - cmf->ww += cmf->xw * x + cmf->yw * y + cmf->zw * z; - } else { + f32 tx; + f32 ty; + + if (mode == MTXMODE_APPLY) + { + tx = cmf->xx; + ty = cmf->yx; + cmf->wx += tx * x + ty * y + cmf->zx * z; + tx = cmf->xy; + ty = cmf->yy; + cmf->wy += tx * x + ty * y + cmf->zy * z; + tx = cmf->xz; + ty = cmf->yz; + cmf->wz += tx * x + ty * y + cmf->zz * z; + tx = cmf->xw; + ty = cmf->yw; + cmf->ww += tx * x + ty * y + cmf->zw * z; + } + else + { func_800A7A24(cmf, x, y, z); } } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_matrix/Matrix_Translate.s") -#endif -void Matrix_Scale(f32 x, f32 y, f32 z, u8 mode) { +void Matrix_Scale(f32 x, f32 y, f32 z, u8 mode) +{ MtxF* cmf = sCurrentMatrix; - if (mode == MTXMODE_APPLY) { + if (mode == MTXMODE_APPLY) + { cmf->xx *= x; cmf->xy *= x; cmf->xz *= x; @@ -92,20 +116,25 @@ void Matrix_Scale(f32 x, f32 y, f32 z, u8 mode) { cmf->xw *= x; cmf->yw *= y; cmf->zw *= z; - } else { + } + else + { func_800A76A4(cmf, x, y, z); } } -void Matrix_RotateX(f32 x, u8 mode) { +void Matrix_RotateX(f32 x, u8 mode) +{ MtxF* cmf; f32 sin; f32 cos; f32 temp1; f32 temp2; - if (mode == MTXMODE_APPLY) { - if (x != 0) { + if (mode == MTXMODE_APPLY) + { + if (x != 0) + { cmf = sCurrentMatrix; sin = sinf(x); @@ -131,13 +160,18 @@ void Matrix_RotateX(f32 x, u8 mode) { cmf->yw = temp1 * cos + temp2 * sin; cmf->zw = temp2 * cos - temp1 * sin; } - } else { + } + else + { cmf = sCurrentMatrix; - if (x != 0) { + if (x != 0) + { sin = sinf(x); cos = cosf(x); - } else { + } + else + { sin = 0.0f; cos = 1.0f; } @@ -161,15 +195,18 @@ void Matrix_RotateX(f32 x, u8 mode) { } } -void Matrix_RotateY(f32 y, u8 mode) { +void Matrix_RotateY(f32 y, u8 mode) +{ MtxF* cmf; f32 sin; f32 cos; f32 temp1; f32 temp2; - if (mode == MTXMODE_APPLY) { - if (y != 0) { + if (mode == MTXMODE_APPLY) + { + if (y != 0) + { cmf = sCurrentMatrix; sin = sinf(y); @@ -195,13 +232,18 @@ void Matrix_RotateY(f32 y, u8 mode) { cmf->xw = temp1 * cos - temp2 * sin; cmf->zw = temp1 * sin + temp2 * cos; } - } else { + } + else + { cmf = sCurrentMatrix; - if (y != 0) { + if (y != 0) + { sin = sinf(y); cos = cosf(y); - } else { + } + else + { sin = 0.0f; cos = 1.0f; } @@ -225,15 +267,18 @@ void Matrix_RotateY(f32 y, u8 mode) { } } -void Matrix_RotateZ(f32 z, u8 mode) { +void Matrix_RotateZ(f32 z, u8 mode) +{ MtxF* cmf; f32 sin; f32 cos; f32 temp1; f32 temp2; - if (mode == MTXMODE_APPLY) { - if (z != 0) { + if (mode == MTXMODE_APPLY) + { + if (z != 0) + { cmf = sCurrentMatrix; sin = sinf(z); @@ -289,7 +334,13 @@ void Matrix_RotateZ(f32 z, u8 mode) { } } -void Matrix_RotateXYZ(s16 x, s16 y, s16 z, u8 mode) { +/* + * Rotates the top of the matrix stack by `z` degrees, then + * rotates that matrix by `y` degrees, then rotates that matrix + * by `x` degrees. + * Original Name: Matrix_RotateXYZ, changed to reflect rotation order. +*/ +void Matrix_RotateZYX(s16 x, s16 y, s16 z, u8 mode) { MtxF* cmf = sCurrentMatrix; f32 temp1; f32 temp2; @@ -374,43 +425,48 @@ void Matrix_RotateXYZ(s16 x, s16 y, s16 z, u8 mode) { } } -void func_800D1340(Vec3f* arg0, Vec3s* arg1) { +/* + * Translates the top of the matrix stack by `translation` units, + * then rotates that matrix by `rotation` in Z-Y-X order +*/ +void Matrix_TranslateThenRotateZYX(Vec3f* translation, Vec3s* rotation) +{ MtxF* cmf = sCurrentMatrix; f32 sin; f32 cos; f32 temp1; f32 temp2; - sin = Math_Sins(arg1->z); - cos = Math_Coss(arg1->z); + sin = Math_Sins(rotation->z); + cos = Math_Coss(rotation->z); temp1 = cmf->xx; temp2 = cmf->yx; - cmf->wx += temp1 * arg0->x + temp2 * arg0->y + cmf->zx * arg0->z; + cmf->wx += temp1 * translation->x + temp2 * translation->y + cmf->zx * translation->z; cmf->xx = temp1 * cos + temp2 * sin; cmf->yx = temp2 * cos - temp1 * sin; temp1 = cmf->xy; temp2 = cmf->yy; - cmf->wy += temp1 * arg0->x + temp2 * arg0->y + cmf->zy * arg0->z; + cmf->wy += temp1 * translation->x + temp2 * translation->y + cmf->zy * translation->z; cmf->xy = temp1 * cos + temp2 * sin; cmf->yy = temp2 * cos - temp1 * sin; temp1 = cmf->xz; temp2 = cmf->yz; - cmf->wz += temp1 * arg0->x + temp2 * arg0->y + cmf->zz * arg0->z; + cmf->wz += temp1 * translation->x + temp2 * translation->y + cmf->zz * translation->z; cmf->xz = temp1 * cos + temp2 * sin; cmf->yz = temp2 * cos - temp1 * sin; temp1 = cmf->xw; temp2 = cmf->yw; - cmf->ww += temp1 * arg0->x + temp2 * arg0->y + cmf->zw * arg0->z; + cmf->ww += temp1 * translation->x + temp2 * translation->y + cmf->zw * translation->z; cmf->xw = temp1 * cos + temp2 * sin; cmf->yw = temp2 * cos - temp1 * sin; - if (arg1->y != 0) { - sin = Math_Sins(arg1->y); - cos = Math_Coss(arg1->y); + if (rotation->y != 0) { + sin = Math_Sins(rotation->y); + cos = Math_Coss(rotation->y); temp1 = cmf->xx; temp2 = cmf->zx; @@ -433,9 +489,9 @@ void func_800D1340(Vec3f* arg0, Vec3s* arg1) { cmf->zw = temp1 * sin + temp2 * cos; } - if (arg1->x != 0) { - sin = Math_Sins(arg1->x); - cos = Math_Coss(arg1->x); + if (rotation->x != 0) { + sin = Math_Sins(rotation->x); + cos = Math_Coss(rotation->x); temp1 = cmf->yx; temp2 = cmf->zx; -- cgit v1.2.3 From 9a63f1d4d13c39b4f30819489932023e6104d8e4 Mon Sep 17 00:00:00 2001 From: Roman971 Date: Tue, 24 Mar 2020 00:11:21 +0100 Subject: Run formatter with changes --- src/code/sys_matrix.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/code/sys_matrix.c') diff --git a/src/code/sys_matrix.c b/src/code/sys_matrix.c index b300f189d..b0735109a 100644 --- a/src/code/sys_matrix.c +++ b/src/code/sys_matrix.c @@ -738,12 +738,13 @@ void func_800D20CC(MtxF* mf, Vec3s* vec, s32 flag) { vec->y = Math_atan2f(mf->zx, mf->zz) * (32768 / M_PI); - if (!flag) + if (!flag) { vec->z = Math_atan2f(mf->xy, mf->yy) * (32768 / M_PI); - else + } else { vec->z = Math_atan2f(mf->xy / sqrtf(SQ(mf->xx) + SQ(mf->xz) + SQ(mf->xy)), mf->yy / sqrtf(SQ(mf->yx) + SQ(mf->yz) + SQ(mf->yy))) * (32768 / M_PI); + } } #else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_matrix/func_800D20CC.s") @@ -762,12 +763,13 @@ void func_800D2264(MtxF* mf, Vec3s* vec, s32 flag) { vec->z = Math_atan2f(mf->xy, mf->xx) * (32768 / M_PI); - if (!flag) + if (!flag) { vec->x = Math_atan2f(mf->yz, mf->zz) * (32768 / M_PI); - else + } else { vec->x = Math_atan2f(mf->yz / sqrtf(SQ(mf->yx) + SQ(mf->yy) + SQ(mf->yz)), mf->zz / sqrtf(SQ(mf->zx) + SQ(mf->zy) + SQ(mf->zz))) * (32768 / M_PI); + } } #else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_matrix/func_800D2264.s") -- cgit v1.2.3 From db3cfe1b61397a6656f4d92dd0835a589cf72c68 Mon Sep 17 00:00:00 2001 From: KrimtonZ Date: Tue, 24 Mar 2020 12:16:13 -0500 Subject: use clang, modify z64animation.h and z64dma.h to use open braces on newline --- src/code/sys_matrix.c | 104 ++++++++++++++++---------------------------------- 1 file changed, 33 insertions(+), 71 deletions(-) (limited to 'src/code/sys_matrix.c') diff --git a/src/code/sys_matrix.c b/src/code/sys_matrix.c index 0d1ed55e7..fd474f1fc 100644 --- a/src/code/sys_matrix.c +++ b/src/code/sys_matrix.c @@ -22,52 +22,41 @@ MtxF gMtxFClear = MtxF* sMatrixStack; // "Matrix_stack" MtxF* sCurrentMatrix; // "Matrix_now" -void Matrix_Init(GameState* gameState) -{ +void Matrix_Init(GameState* gameState) { sCurrentMatrix = Game_Alloc(gameState, 20 * sizeof(MtxF), "../sys_matrix.c", 153); sMatrixStack = sCurrentMatrix; } -void Matrix_Push(void) -{ +void Matrix_Push(void) { Matrix_MtxFCopy(sCurrentMatrix + 1, sCurrentMatrix); sCurrentMatrix++; } -void Matrix_Pull(void) -{ +void Matrix_Pull(void) { sCurrentMatrix--; - if (sCurrentMatrix < sMatrixStack) - { + if (sCurrentMatrix < sMatrixStack) { __assert("Matrix_now >= Matrix_stack", "../sys_matrix.c", 176); } } -void Matrix_Get(MtxF* dest) -{ +void Matrix_Get(MtxF* dest) { Matrix_MtxFCopy(dest, sCurrentMatrix); } -void Matrix_Put(MtxF* src) -{ +void Matrix_Put(MtxF* src) { Matrix_MtxFCopy(sCurrentMatrix, src); } -MtxF* Matrix_GetCurrent(void) -{ +MtxF* Matrix_GetCurrent(void) { return sCurrentMatrix; } -void Matrix_Mult(MtxF* mf, u8 mode) -{ +void Matrix_Mult(MtxF* mf, u8 mode) { MtxF* cmf = Matrix_GetCurrent(); - if (mode == MTXMODE_APPLY) - { + if (mode == MTXMODE_APPLY) { func_800A6FA0(cmf, mf, cmf); - } - else - { + } else { Matrix_MtxFCopy(sCurrentMatrix, mf); } } @@ -77,8 +66,7 @@ void Matrix_Translate(f32 x, f32 y, f32 z, u8 mode) { f32 tx; f32 ty; - if (mode == MTXMODE_APPLY) - { + if (mode == MTXMODE_APPLY) { tx = cmf->xx; ty = cmf->yx; cmf->wx += tx * x + ty * y + cmf->zx * z; @@ -91,19 +79,15 @@ void Matrix_Translate(f32 x, f32 y, f32 z, u8 mode) { tx = cmf->xw; ty = cmf->yw; cmf->ww += tx * x + ty * y + cmf->zw * z; - } - else - { + } else { func_800A7A24(cmf, x, y, z); } } -void Matrix_Scale(f32 x, f32 y, f32 z, u8 mode) -{ +void Matrix_Scale(f32 x, f32 y, f32 z, u8 mode) { MtxF* cmf = sCurrentMatrix; - if (mode == MTXMODE_APPLY) - { + if (mode == MTXMODE_APPLY) { cmf->xx *= x; cmf->xy *= x; cmf->xz *= x; @@ -116,25 +100,20 @@ void Matrix_Scale(f32 x, f32 y, f32 z, u8 mode) cmf->xw *= x; cmf->yw *= y; cmf->zw *= z; - } - else - { + } else { func_800A76A4(cmf, x, y, z); } } -void Matrix_RotateX(f32 x, u8 mode) -{ +void Matrix_RotateX(f32 x, u8 mode) { MtxF* cmf; f32 sin; f32 cos; f32 temp1; f32 temp2; - if (mode == MTXMODE_APPLY) - { - if (x != 0) - { + if (mode == MTXMODE_APPLY) { + if (x != 0) { cmf = sCurrentMatrix; sin = sinf(x); @@ -160,18 +139,13 @@ void Matrix_RotateX(f32 x, u8 mode) cmf->yw = temp1 * cos + temp2 * sin; cmf->zw = temp2 * cos - temp1 * sin; } - } - else - { + } else { cmf = sCurrentMatrix; - if (x != 0) - { + if (x != 0) { sin = sinf(x); cos = cosf(x); - } - else - { + } else { sin = 0.0f; cos = 1.0f; } @@ -195,18 +169,15 @@ void Matrix_RotateX(f32 x, u8 mode) } } -void Matrix_RotateY(f32 y, u8 mode) -{ +void Matrix_RotateY(f32 y, u8 mode) { MtxF* cmf; f32 sin; f32 cos; f32 temp1; f32 temp2; - if (mode == MTXMODE_APPLY) - { - if (y != 0) - { + if (mode == MTXMODE_APPLY) { + if (y != 0) { cmf = sCurrentMatrix; sin = sinf(y); @@ -232,18 +203,13 @@ void Matrix_RotateY(f32 y, u8 mode) cmf->xw = temp1 * cos - temp2 * sin; cmf->zw = temp1 * sin + temp2 * cos; } - } - else - { + } else { cmf = sCurrentMatrix; - if (y != 0) - { + if (y != 0) { sin = sinf(y); cos = cosf(y); - } - else - { + } else { sin = 0.0f; cos = 1.0f; } @@ -267,18 +233,15 @@ void Matrix_RotateY(f32 y, u8 mode) } } -void Matrix_RotateZ(f32 z, u8 mode) -{ +void Matrix_RotateZ(f32 z, u8 mode) { MtxF* cmf; f32 sin; f32 cos; f32 temp1; f32 temp2; - if (mode == MTXMODE_APPLY) - { - if (z != 0) - { + if (mode == MTXMODE_APPLY) { + if (z != 0) { cmf = sCurrentMatrix; sin = sinf(z); @@ -339,7 +302,7 @@ void Matrix_RotateZ(f32 z, u8 mode) * rotates that matrix by `y` degrees, then rotates that matrix * by `x` degrees. * Original Name: Matrix_RotateXYZ, changed to reflect rotation order. -*/ + */ void Matrix_RotateZYX(s16 x, s16 y, s16 z, u8 mode) { MtxF* cmf = sCurrentMatrix; f32 temp1; @@ -428,9 +391,8 @@ void Matrix_RotateZYX(s16 x, s16 y, s16 z, u8 mode) { /* * Translates the top of the matrix stack by `translation` units, * then rotates that matrix by `rotation` in Z-Y-X order -*/ -void Matrix_TranslateThenRotateZYX(Vec3f* translation, Vec3s* rotation) -{ + */ +void Matrix_TranslateThenRotateZYX(Vec3f* translation, Vec3s* rotation) { MtxF* cmf = sCurrentMatrix; f32 sin; f32 cos; -- cgit v1.2.3 From a99840162b2ab08125bc09fa5ec7aa47a8466e21 Mon Sep 17 00:00:00 2001 From: KrimtonZ Date: Tue, 24 Mar 2020 14:01:00 -0500 Subject: minor formatting updates, match func_800A4A20 --- src/code/sys_matrix.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/code/sys_matrix.c') diff --git a/src/code/sys_matrix.c b/src/code/sys_matrix.c index fd474f1fc..24c5768d0 100644 --- a/src/code/sys_matrix.c +++ b/src/code/sys_matrix.c @@ -2,16 +2,14 @@ #include // clang-format off -Mtx gMtxClear = -{ +Mtx gMtxClear = { 65536, 0, 1, 0, 0, 65536, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, }; -MtxF gMtxFClear = -{ +MtxF gMtxFClear = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, -- cgit v1.2.3