1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-23 05:45:03 +00:00
oot/src/code/sys_matrix.c

1072 lines
27 KiB
C
Raw Normal View History

2020-03-17 04:31:30 +00:00
#include <ultra64.h>
#include <global.h>
2020-03-22 21:19:43 +00:00
// clang-format off
Mtx gMtxClear = {
2020-03-17 04:31:30 +00:00
65536, 0, 1, 0,
0, 65536, 0, 1,
0, 0, 0, 0,
0, 0, 0, 0,
};
2020-03-22 21:19:43 +00:00
MtxF gMtxFClear = {
2020-03-17 04:31:30 +00:00
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f,
};
2020-03-22 21:19:43 +00:00
// clang-format on
2020-03-17 04:31:30 +00:00
2020-03-22 21:19:43 +00:00
MtxF* sMatrixStack; // "Matrix_stack"
2020-03-17 04:31:30 +00:00
MtxF* sCurrentMatrix; // "Matrix_now"
2020-03-22 21:19:43 +00:00
void Matrix_Init(GameState* gameState) {
2020-03-17 04:31:30 +00:00
sCurrentMatrix = Game_Alloc(gameState, 20 * sizeof(MtxF), "../sys_matrix.c", 153);
sMatrixStack = sCurrentMatrix;
}
2020-03-22 21:19:43 +00:00
void Matrix_Push(void) {
2020-03-17 04:31:30 +00:00
Matrix_MtxFCopy(sCurrentMatrix + 1, sCurrentMatrix);
sCurrentMatrix++;
}
2020-03-22 21:19:43 +00:00
void Matrix_Pull(void) {
2020-03-17 04:31:30 +00:00
sCurrentMatrix--;
2020-03-22 21:19:43 +00:00
if (sCurrentMatrix < sMatrixStack) {
2020-03-17 04:31:30 +00:00
__assert("Matrix_now >= Matrix_stack", "../sys_matrix.c", 176);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
2020-03-22 21:19:43 +00:00
void Matrix_Get(MtxF* dest) {
2020-03-17 04:31:30 +00:00
Matrix_MtxFCopy(dest, sCurrentMatrix);
}
2020-03-22 21:19:43 +00:00
void Matrix_Put(MtxF* src) {
2020-03-17 04:31:30 +00:00
Matrix_MtxFCopy(sCurrentMatrix, src);
}
2020-03-22 21:19:43 +00:00
MtxF* Matrix_GetCurrent(void) {
2020-03-17 04:31:30 +00:00
return sCurrentMatrix;
}
2020-03-22 21:19:43 +00:00
void Matrix_Mult(MtxF* mf, u8 mode) {
2020-03-17 04:31:30 +00:00
MtxF* cmf = Matrix_GetCurrent();
2020-03-22 21:19:43 +00:00
if (mode == MTXMODE_APPLY) {
2020-03-17 04:31:30 +00:00
func_800A6FA0(cmf, mf, cmf);
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
Matrix_MtxFCopy(sCurrentMatrix, mf);
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
#ifdef NON_MATCHING
// minor ordering and regalloc differences
2020-03-22 21:19:43 +00:00
void Matrix_Translate(f32 x, f32 y, f32 z, u8 mode) {
2020-03-17 04:31:30 +00:00
MtxF* cmf = sCurrentMatrix;
2020-03-22 21:19:43 +00:00
if (mode == MTXMODE_APPLY) {
2020-03-17 04:31:30 +00:00
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;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
func_800A7A24(cmf, x, y, z);
}
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/sys_matrix/Matrix_Translate.s")
#endif
2020-03-22 21:19:43 +00:00
void Matrix_Scale(f32 x, f32 y, f32 z, u8 mode) {
2020-03-17 04:31:30 +00:00
MtxF* cmf = sCurrentMatrix;
2020-03-22 21:19:43 +00:00
if (mode == MTXMODE_APPLY) {
2020-03-17 04:31:30 +00:00
cmf->xx *= x;
cmf->xy *= x;
cmf->xz *= x;
cmf->yx *= y;
cmf->yy *= y;
cmf->yz *= y;
cmf->zx *= z;
cmf->zy *= z;
cmf->zz *= z;
cmf->xw *= x;
cmf->yw *= y;
cmf->zw *= z;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
func_800A76A4(cmf, x, y, z);
}
}
2020-03-22 21:19:43 +00:00
void Matrix_RotateX(f32 x, u8 mode) {
2020-03-17 04:31:30 +00:00
MtxF* cmf;
f32 sin;
f32 cos;
f32 temp1;
f32 temp2;
2020-03-22 21:19:43 +00:00
if (mode == MTXMODE_APPLY) {
if (x != 0) {
2020-03-17 04:31:30 +00:00
cmf = sCurrentMatrix;
sin = sinf(x);
cos = cosf(x);
temp1 = cmf->yx;
temp2 = cmf->zx;
cmf->yx = temp1 * cos + temp2 * sin;
cmf->zx = temp2 * cos - temp1 * sin;
temp1 = cmf->yy;
temp2 = cmf->zy;
cmf->yy = temp1 * cos + temp2 * sin;
cmf->zy = temp2 * cos - temp1 * sin;
temp1 = cmf->yz;
temp2 = cmf->zz;
cmf->yz = temp1 * cos + temp2 * sin;
cmf->zz = temp2 * cos - temp1 * sin;
temp1 = cmf->yw;
temp2 = cmf->zw;
cmf->yw = temp1 * cos + temp2 * sin;
cmf->zw = temp2 * cos - temp1 * sin;
}
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
cmf = sCurrentMatrix;
2020-03-22 21:19:43 +00:00
if (x != 0) {
2020-03-17 04:31:30 +00:00
sin = sinf(x);
cos = cosf(x);
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
sin = 0.0f;
cos = 1.0f;
}
cmf->xy = 0.0f;
cmf->xz = 0.0f;
cmf->xw = 0.0f;
cmf->yx = 0.0f;
cmf->yw = 0.0f;
cmf->zx = 0.0f;
cmf->zw = 0.0f;
cmf->wx = 0.0f;
cmf->wy = 0.0f;
cmf->wz = 0.0f;
cmf->xx = 1.0f;
cmf->ww = 1.0f;
cmf->yy = cos;
cmf->zz = cos;
cmf->yz = sin;
cmf->zy = -sin;
}
}
2020-03-22 21:19:43 +00:00
void Matrix_RotateY(f32 y, u8 mode) {
2020-03-17 04:31:30 +00:00
MtxF* cmf;
f32 sin;
f32 cos;
f32 temp1;
f32 temp2;
2020-03-22 21:19:43 +00:00
if (mode == MTXMODE_APPLY) {
if (y != 0) {
2020-03-17 04:31:30 +00:00
cmf = sCurrentMatrix;
sin = sinf(y);
cos = cosf(y);
temp1 = cmf->xx;
temp2 = cmf->zx;
cmf->xx = temp1 * cos - temp2 * sin;
cmf->zx = temp1 * sin + temp2 * cos;
temp1 = cmf->xy;
temp2 = cmf->zy;
cmf->xy = temp1 * cos - temp2 * sin;
cmf->zy = temp1 * sin + temp2 * cos;
temp1 = cmf->xz;
temp2 = cmf->zz;
cmf->xz = temp1 * cos - temp2 * sin;
cmf->zz = temp1 * sin + temp2 * cos;
temp1 = cmf->xw;
temp2 = cmf->zw;
cmf->xw = temp1 * cos - temp2 * sin;
cmf->zw = temp1 * sin + temp2 * cos;
}
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
cmf = sCurrentMatrix;
2020-03-22 21:19:43 +00:00
if (y != 0) {
2020-03-17 04:31:30 +00:00
sin = sinf(y);
cos = cosf(y);
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
sin = 0.0f;
cos = 1.0f;
}
cmf->xy = 0.0f;
cmf->xw = 0.0f;
cmf->yx = 0.0f;
cmf->yz = 0.0f;
cmf->yw = 0.0f;
cmf->zy = 0.0f;
cmf->zw = 0.0f;
cmf->wx = 0.0f;
cmf->wy = 0.0f;
cmf->wz = 0.0f;
cmf->yy = 1.0f;
cmf->ww = 1.0f;
cmf->xx = cos;
cmf->zz = cos;
cmf->xz = -sin;
cmf->zx = sin;
}
}
2020-03-22 21:19:43 +00:00
void Matrix_RotateZ(f32 z, u8 mode) {
2020-03-17 04:31:30 +00:00
MtxF* cmf;
f32 sin;
f32 cos;
f32 temp1;
f32 temp2;
2020-03-22 21:19:43 +00:00
if (mode == MTXMODE_APPLY) {
if (z != 0) {
2020-03-17 04:31:30 +00:00
cmf = sCurrentMatrix;
sin = sinf(z);
cos = cosf(z);
temp1 = cmf->xx;
temp2 = cmf->yx;
cmf->xx = temp1 * cos + temp2 * sin;
cmf->yx = temp2 * cos - temp1 * sin;
temp1 = cmf->xy;
temp2 = cmf->yy;
cmf->xy = temp1 * cos + temp2 * sin;
cmf->yy = temp2 * cos - temp1 * sin;
temp1 = cmf->xz;
temp2 = cmf->yz;
cmf->xz = temp1 * cos + temp2 * sin;
cmf->yz = temp2 * cos - temp1 * sin;
temp1 = cmf->xw;
temp2 = cmf->yw;
cmf->xw = temp1 * cos + temp2 * sin;
cmf->yw = temp2 * cos - temp1 * sin;
}
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
cmf = sCurrentMatrix;
2020-03-22 21:19:43 +00:00
if (z != 0) {
2020-03-17 04:31:30 +00:00
sin = sinf(z);
cos = cosf(z);
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
sin = 0.0f;
cos = 1.0f;
}
cmf->xz = 0.0f;
cmf->xw = 0.0f;
cmf->yz = 0.0f;
cmf->yw = 0.0f;
cmf->zx = 0.0f;
cmf->zy = 0.0f;
cmf->zw = 0.0f;
cmf->wx = 0.0f;
cmf->wy = 0.0f;
cmf->wz = 0.0f;
cmf->zz = 1.0f;
cmf->ww = 1.0f;
cmf->xx = cos;
cmf->yy = cos;
cmf->xy = sin;
cmf->yx = -sin;
}
}
2020-03-22 21:19:43 +00:00
void Matrix_RotateXYZ(s16 x, s16 y, s16 z, u8 mode) {
2020-03-17 04:31:30 +00:00
MtxF* cmf = sCurrentMatrix;
f32 temp1;
f32 temp2;
f32 sin;
f32 cos;
2020-03-22 21:19:43 +00:00
if (mode == MTXMODE_APPLY) {
2020-03-17 04:31:30 +00:00
sin = Math_Sins(z);
cos = Math_Coss(z);
temp1 = cmf->xx;
temp2 = cmf->yx;
cmf->xx = temp1 * cos + temp2 * sin;
cmf->yx = temp2 * cos - temp1 * sin;
temp1 = cmf->xy;
temp2 = cmf->yy;
cmf->xy = temp1 * cos + temp2 * sin;
cmf->yy = temp2 * cos - temp1 * sin;
temp1 = cmf->xz;
temp2 = cmf->yz;
cmf->xz = temp1 * cos + temp2 * sin;
cmf->yz = temp2 * cos - temp1 * sin;
temp1 = cmf->xw;
temp2 = cmf->yw;
cmf->xw = temp1 * cos + temp2 * sin;
cmf->yw = temp2 * cos - temp1 * sin;
2020-03-22 21:19:43 +00:00
if (y != 0) {
2020-03-17 04:31:30 +00:00
sin = Math_Sins(y);
cos = Math_Coss(y);
temp1 = cmf->xx;
temp2 = cmf->zx;
cmf->xx = temp1 * cos - temp2 * sin;
cmf->zx = temp1 * sin + temp2 * cos;
temp1 = cmf->xy;
temp2 = cmf->zy;
cmf->xy = temp1 * cos - temp2 * sin;
cmf->zy = temp1 * sin + temp2 * cos;
temp1 = cmf->xz;
temp2 = cmf->zz;
cmf->xz = temp1 * cos - temp2 * sin;
cmf->zz = temp1 * sin + temp2 * cos;
temp1 = cmf->xw;
temp2 = cmf->zw;
cmf->xw = temp1 * cos - temp2 * sin;
cmf->zw = temp1 * sin + temp2 * cos;
}
2020-03-22 21:19:43 +00:00
if (x != 0) {
2020-03-17 04:31:30 +00:00
sin = Math_Sins(x);
cos = Math_Coss(x);
temp1 = cmf->yx;
temp2 = cmf->zx;
cmf->yx = temp1 * cos + temp2 * sin;
cmf->zx = temp2 * cos - temp1 * sin;
temp1 = cmf->yy;
temp2 = cmf->zy;
cmf->yy = temp1 * cos + temp2 * sin;
cmf->zy = temp2 * cos - temp1 * sin;
temp1 = cmf->yz;
temp2 = cmf->zz;
cmf->yz = temp1 * cos + temp2 * sin;
cmf->zz = temp2 * cos - temp1 * sin;
temp1 = cmf->yw;
temp2 = cmf->zw;
cmf->yw = temp1 * cos + temp2 * sin;
cmf->zw = temp2 * cos - temp1 * sin;
}
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
func_800A7704(cmf, x, y, z);
}
}
2020-03-22 21:19:43 +00:00
void func_800D1340(Vec3f* arg0, Vec3s* arg1) {
2020-03-17 04:31:30 +00:00
MtxF* cmf = sCurrentMatrix;
f32 sin;
f32 cos;
f32 temp1;
f32 temp2;
sin = Math_Sins(arg1->z);
cos = Math_Coss(arg1->z);
temp1 = cmf->xx;
temp2 = cmf->yx;
cmf->wx += temp1 * arg0->x + temp2 * arg0->y + cmf->zx * arg0->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->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->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->xw = temp1 * cos + temp2 * sin;
cmf->yw = temp2 * cos - temp1 * sin;
2020-03-22 21:19:43 +00:00
if (arg1->y != 0) {
2020-03-17 04:31:30 +00:00
sin = Math_Sins(arg1->y);
cos = Math_Coss(arg1->y);
temp1 = cmf->xx;
temp2 = cmf->zx;
cmf->xx = temp1 * cos - temp2 * sin;
cmf->zx = temp1 * sin + temp2 * cos;
temp1 = cmf->xy;
temp2 = cmf->zy;
cmf->xy = temp1 * cos - temp2 * sin;
cmf->zy = temp1 * sin + temp2 * cos;
temp1 = cmf->xz;
temp2 = cmf->zz;
cmf->xz = temp1 * cos - temp2 * sin;
cmf->zz = temp1 * sin + temp2 * cos;
temp1 = cmf->xw;
temp2 = cmf->zw;
cmf->xw = temp1 * cos - temp2 * sin;
cmf->zw = temp1 * sin + temp2 * cos;
}
2020-03-22 21:19:43 +00:00
if (arg1->x != 0) {
2020-03-17 04:31:30 +00:00
sin = Math_Sins(arg1->x);
cos = Math_Coss(arg1->x);
temp1 = cmf->yx;
temp2 = cmf->zx;
cmf->yx = temp1 * cos + temp2 * sin;
cmf->zx = temp2 * cos - temp1 * sin;
temp1 = cmf->yy;
temp2 = cmf->zy;
cmf->yy = temp1 * cos + temp2 * sin;
cmf->zy = temp2 * cos - temp1 * sin;
temp1 = cmf->yz;
temp2 = cmf->zz;
cmf->yz = temp1 * cos + temp2 * sin;
cmf->zz = temp2 * cos - temp1 * sin;
temp1 = cmf->yw;
temp2 = cmf->zw;
cmf->yw = temp1 * cos + temp2 * sin;
cmf->zw = temp2 * cos - temp1 * sin;
}
}
#ifdef NON_MATCHING
// regalloc differences
2020-03-22 21:19:43 +00:00
void func_800D1694(f32 x, f32 y, f32 z, Vec3s* vec) {
2020-03-17 04:31:30 +00:00
MtxF* cmf = sCurrentMatrix;
f32 sp30;
f32 sp2C;
f32 sp28;
f32 sp24;
sp30 = Math_Sins(vec->y);
sp2C = Math_Coss(vec->y);
cmf->xx = sp2C;
cmf->xz = -sp30;
cmf->wx = x;
cmf->wy = y;
cmf->wz = z;
cmf->xw = 0.0f;
cmf->yw = 0.0f;
cmf->zw = 0.0f;
cmf->ww = 1.0f;
2020-03-22 21:19:43 +00:00
if (vec->x != 0) {
2020-03-17 04:31:30 +00:00
sp24 = Math_Sins(vec->x);
sp28 = Math_Coss(vec->x);
cmf->zy = -sp24;
cmf->yy = sp28;
cmf->zz = sp2C * sp28;
cmf->yz = sp2C * sp24;
cmf->zx = sp30 * sp28;
cmf->yx = sp30 * sp24;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
cmf->zz = sp2C;
cmf->zx = sp30;
cmf->zy = 0.0f;
cmf->yz = 0.0f;
cmf->yx = 0.0f;
cmf->yy = 1.0f;
}
2020-03-22 21:19:43 +00:00
if (vec->z != 0) {
2020-03-17 04:31:30 +00:00
sp24 = Math_Sins(vec->z);
sp28 = Math_Coss(vec->z);
sp30 = cmf->xx;
sp2C = cmf->yx;
cmf->xx = sp30 * sp28 + sp2C * sp24;
cmf->yx = sp2C * sp28 - sp30 * sp24;
sp30 = cmf->xz;
sp2C = cmf->yz;
cmf->xz = sp30 * sp28 + sp2C * sp24;
cmf->yz = sp2C * sp28 - sp30 * sp24;
sp2C = cmf->yy;
cmf->xy = sp2C * sp24;
cmf->yy = sp2C * sp28;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
cmf->xy = 0.0f;
}
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/sys_matrix/func_800D1694.s")
#endif
#ifdef NON_MATCHING
// mostly regalloc differences
2020-03-22 21:19:43 +00:00
Mtx* Matrix_MtxFToMtx(MtxF* src, Mtx* dest) {
2020-03-17 04:31:30 +00:00
u16* m1 = (u16*)&dest->m[0][0];
u16* m2 = (u16*)&dest->m[2][0];
s32 temp;
temp = src->xx * 65536.0f;
2020-03-22 21:19:43 +00:00
m1[0] = (temp >> 0x10) & 0xFFFF;
2020-03-17 04:31:30 +00:00
m2[0] = temp & 0xFFFF;
temp = src->xy * 65536.0f;
2020-03-22 21:19:43 +00:00
m1[1] = (temp >> 0x10) & 0xFFFF;
2020-03-17 04:31:30 +00:00
m2[1] = temp & 0xFFFF;
temp = src->xz * 65536.0f;
2020-03-22 21:19:43 +00:00
m1[2] = (temp >> 0x10) & 0xFFFF;
2020-03-17 04:31:30 +00:00
m2[2] = temp & 0xFFFF;
temp = src->xw * 65536.0f;
2020-03-22 21:19:43 +00:00
m1[3] = (temp >> 0x10) & 0xFFFF;
2020-03-17 04:31:30 +00:00
m2[3] = temp & 0xFFFF;
temp = src->yx * 65536.0f;
2020-03-22 21:19:43 +00:00
m1[4] = (temp >> 0x10) & 0xFFFF;
2020-03-17 04:31:30 +00:00
m2[4] = temp & 0xFFFF;
temp = src->yy * 65536.0f;
2020-03-22 21:19:43 +00:00
m1[5] = (temp >> 0x10) & 0xFFFF;
2020-03-17 04:31:30 +00:00
m2[5] = temp & 0xFFFF;
temp = src->yz * 65536.0f;
2020-03-22 21:19:43 +00:00
m1[6] = (temp >> 0x10) & 0xFFFF;
2020-03-17 04:31:30 +00:00
m2[6] = temp & 0xFFFF;
temp = src->yw * 65536.0f;
2020-03-22 21:19:43 +00:00
m1[7] = (temp >> 0x10) & 0xFFFF;
2020-03-17 04:31:30 +00:00
m2[7] = temp & 0xFFFF;
temp = src->zx * 65536.0f;
2020-03-22 21:19:43 +00:00
m1[8] = (temp >> 0x10) & 0xFFFF;
2020-03-17 04:31:30 +00:00
m2[8] = temp & 0xFFFF;
temp = src->zy * 65536.0f;
2020-03-22 21:19:43 +00:00
m1[9] = (temp >> 0x10) & 0xFFFF;
2020-03-17 04:31:30 +00:00
m2[9] = temp & 0xFFFF;
temp = src->zz * 65536.0f;
2020-03-22 21:19:43 +00:00
m1[10] = (temp >> 0x10) & 0xFFFF;
2020-03-17 04:31:30 +00:00
m2[10] = temp & 0xFFFF;
temp = src->zw * 65536.0f;
2020-03-22 21:19:43 +00:00
m1[11] = (temp >> 0x10) & 0xFFFF;
2020-03-17 04:31:30 +00:00
m2[11] = temp & 0xFFFF;
temp = src->wx * 65536.0f;
2020-03-22 21:19:43 +00:00
m1[12] = (temp >> 0x10) & 0xFFFF;
2020-03-17 04:31:30 +00:00
m2[12] = temp & 0xFFFF;
temp = src->wy * 65536.0f;
2020-03-22 21:19:43 +00:00
m1[13] = (temp >> 0x10) & 0xFFFF;
2020-03-17 04:31:30 +00:00
m2[13] = temp & 0xFFFF;
temp = src->wz * 65536.0f;
2020-03-22 21:19:43 +00:00
m1[14] = (temp >> 0x10) & 0xFFFF;
2020-03-17 04:31:30 +00:00
m2[14] = temp & 0xFFFF;
temp = src->ww * 65536.0f;
2020-03-22 21:19:43 +00:00
m1[15] = (temp >> 0x10) & 0xFFFF;
2020-03-17 04:31:30 +00:00
m2[15] = temp & 0xFFFF;
return dest;
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/sys_matrix/Matrix_MtxFToMtx.s")
#endif
2020-03-22 21:19:43 +00:00
Mtx* Matrix_ToMtx(Mtx* dest, char* file, s32 line) {
2020-03-17 04:31:30 +00:00
return Matrix_MtxFToMtx(Matrix_CheckFloats(sCurrentMatrix, file, line), dest);
}
2020-03-22 21:19:43 +00:00
Mtx* Matrix_NewMtx(GraphicsContext* gfxCtx, char* file, s32 line) {
2020-03-17 04:31:30 +00:00
return Matrix_ToMtx(Graph_Alloc(gfxCtx, sizeof(Mtx)), file, line);
}
2020-03-22 21:19:43 +00:00
Mtx* Matrix_MtxFToNewMtx(MtxF* src, GraphicsContext* gfxCtx) {
2020-03-17 04:31:30 +00:00
return Matrix_MtxFToMtx(src, Graph_Alloc(gfxCtx, sizeof(Mtx)));
}
2020-03-22 21:19:43 +00:00
void Matrix_MultVec3f(Vec3f* src, Vec3f* dest) {
2020-03-17 04:31:30 +00:00
MtxF* cmf = sCurrentMatrix;
dest->x = cmf->wx + (cmf->xx * src->x + cmf->yx * src->y + cmf->zx * src->z);
dest->y = cmf->wy + (cmf->xy * src->x + cmf->yy * src->y + cmf->zy * src->z);
dest->z = cmf->wz + (cmf->xz * src->x + cmf->yz * src->y + cmf->zz * src->z);
}
2020-03-22 21:19:43 +00:00
void Matrix_MtxFCopy(MtxF* dest, MtxF* src) {
2020-03-17 04:31:30 +00:00
dest->xx = src->xx;
dest->xy = src->xy;
dest->xz = src->xz;
dest->xw = src->xw;
dest->yx = src->yx;
dest->yy = src->yy;
dest->yz = src->yz;
dest->yw = src->yw;
dest->xx = src->xx;
dest->xy = src->xy;
dest->xz = src->xz;
dest->xw = src->xw;
dest->yx = src->yx;
dest->yy = src->yy;
dest->yz = src->yz;
dest->yw = src->yw;
dest->zx = src->zx;
dest->zy = src->zy;
dest->zz = src->zz;
dest->zw = src->zw;
dest->wx = src->wx;
dest->wy = src->wy;
dest->wz = src->wz;
dest->ww = src->ww;
dest->zx = src->zx;
dest->zy = src->zy;
dest->zz = src->zz;
dest->zw = src->zw;
dest->wx = src->wx;
dest->wy = src->wy;
dest->wz = src->wz;
dest->ww = src->ww;
}
2020-03-22 21:19:43 +00:00
void Matrix_MtxToMtxF(Mtx* src, MtxF* dest) {
2020-03-17 04:31:30 +00:00
u16* m1 = (u16*)&src->m[0][0];
u16* m2 = (u16*)&src->m[2][0];
dest->xx = ((m1[0] << 0x10) | m2[0]) * (1 / 65536.0f);
dest->xy = ((m1[1] << 0x10) | m2[1]) * (1 / 65536.0f);
dest->xz = ((m1[2] << 0x10) | m2[2]) * (1 / 65536.0f);
dest->xw = ((m1[3] << 0x10) | m2[3]) * (1 / 65536.0f);
dest->yx = ((m1[4] << 0x10) | m2[4]) * (1 / 65536.0f);
dest->yy = ((m1[5] << 0x10) | m2[5]) * (1 / 65536.0f);
dest->yz = ((m1[6] << 0x10) | m2[6]) * (1 / 65536.0f);
dest->yw = ((m1[7] << 0x10) | m2[7]) * (1 / 65536.0f);
dest->zx = ((m1[8] << 0x10) | m2[8]) * (1 / 65536.0f);
dest->zy = ((m1[9] << 0x10) | m2[9]) * (1 / 65536.0f);
dest->zz = ((m1[10] << 0x10) | m2[10]) * (1 / 65536.0f);
dest->zw = ((m1[11] << 0x10) | m2[11]) * (1 / 65536.0f);
dest->wx = ((m1[12] << 0x10) | m2[12]) * (1 / 65536.0f);
dest->wy = ((m1[13] << 0x10) | m2[13]) * (1 / 65536.0f);
dest->wz = ((m1[14] << 0x10) | m2[14]) * (1 / 65536.0f);
dest->ww = ((m1[15] << 0x10) | m2[15]) * (1 / 65536.0f);
}
2020-03-22 21:19:43 +00:00
void Matrix_MultVec3fExt(Vec3f* src, Vec3f* dest, MtxF* mf) {
2020-03-17 04:31:30 +00:00
dest->x = mf->wx + (mf->xx * src->x + mf->yx * src->y + mf->zx * src->z);
dest->y = mf->wy + (mf->xy * src->x + mf->yy * src->y + mf->zy * src->z);
dest->z = mf->wz + (mf->xz * src->x + mf->yz * src->y + mf->zz * src->z);
}
2020-03-22 21:19:43 +00:00
void Matrix_Reverse(MtxF* mf) {
2020-03-17 04:31:30 +00:00
f32 temp;
temp = mf->xy;
mf->xy = mf->yx;
mf->yx = temp;
temp = mf->xz;
mf->xz = mf->zx;
mf->zx = temp;
temp = mf->yz;
mf->yz = mf->zy;
mf->zy = temp;
}
#ifdef NON_MATCHING
2020-03-22 21:19:43 +00:00
void func_800D1FD4(MtxF* mf) {
2020-03-17 04:31:30 +00:00
MtxF* cmf = sCurrentMatrix;
f32 temp;
temp = sqrtf(SQ(cmf->xx) + SQ(cmf->xy) + SQ(cmf->xz));
cmf->xx = mf->xx * temp;
cmf->xy = mf->xy * temp;
cmf->xz = mf->xz * temp;
temp = sqrtf(SQ(cmf->yx) + SQ(cmf->yy) + SQ(cmf->yz));
cmf->yx = mf->yx * temp;
cmf->yy = mf->yy * temp;
cmf->yz = mf->yz * temp;
temp = sqrtf(SQ(cmf->zx) + SQ(cmf->zy) + SQ(cmf->zz));
cmf->zx = mf->zx * temp;
cmf->zy = mf->zy * temp;
cmf->zz = mf->zz * temp;
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/sys_matrix/func_800D1FD4.s")
#endif
#ifdef NON_MATCHING
// same differences as func_800D2264
2020-03-22 21:19:43 +00:00
void func_800D20CC(MtxF* mf, Vec3s* vec, s32 flag) {
2020-03-21 02:09:42 +00:00
vec->x = Math_atan2f(-mf->zy, sqrtf(SQ(mf->zx) + SQ(mf->zz))) * (32768 / M_PI);
2020-03-17 04:31:30 +00:00
2020-03-22 21:19:43 +00:00
if ((vec->x == 0x4000) || (vec->x == -0x4000)) {
2020-03-17 04:31:30 +00:00
vec->z = 0;
2020-03-21 02:09:42 +00:00
vec->y = Math_atan2f(-mf->xz, mf->xx) * (32768 / M_PI);
2020-03-17 04:31:30 +00:00
return;
}
2020-03-21 02:09:42 +00:00
vec->y = Math_atan2f(mf->zx, mf->zz) * (32768 / M_PI);
2020-03-17 04:31:30 +00:00
if (!flag)
2020-03-21 02:09:42 +00:00
vec->z = Math_atan2f(mf->xy, mf->yy) * (32768 / M_PI);
2020-03-17 04:31:30 +00:00
else
2020-03-22 21:19:43 +00:00
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);
2020-03-17 04:31:30 +00:00
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/sys_matrix/func_800D20CC.s")
#endif
#ifdef NON_MATCHING
// same differences as func_800D20CC
2020-03-22 21:19:43 +00:00
void func_800D2264(MtxF* mf, Vec3s* vec, s32 flag) {
2020-03-21 02:09:42 +00:00
vec->y = Math_atan2f(-mf->xz, sqrtf(SQ(mf->xx) + SQ(mf->xy))) * (32768 / M_PI);
2020-03-17 04:31:30 +00:00
2020-03-22 21:19:43 +00:00
if ((vec->y == 0x4000) || (vec->y == -0x4000)) {
2020-03-17 04:31:30 +00:00
vec->x = 0;
2020-03-21 02:09:42 +00:00
vec->z = Math_atan2f(-mf->yx, mf->yy) * (32768 / M_PI);
2020-03-17 04:31:30 +00:00
return;
}
2020-03-21 02:09:42 +00:00
vec->z = Math_atan2f(mf->xy, mf->xx) * (32768 / M_PI);
2020-03-17 04:31:30 +00:00
if (!flag)
2020-03-21 02:09:42 +00:00
vec->x = Math_atan2f(mf->yz, mf->zz) * (32768 / M_PI);
2020-03-17 04:31:30 +00:00
else
2020-03-22 21:19:43 +00:00
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);
2020-03-17 04:31:30 +00:00
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/sys_matrix/func_800D2264.s")
#endif
#ifdef NON_MATCHING
// regalloc differences
2020-03-22 21:19:43 +00:00
void func_800D23FC(f32 f, Vec3f* vec, u8 mode) {
2020-03-17 04:31:30 +00:00
MtxF* cmf;
f32 sin;
f32 cos;
f32 rCos;
f32 temp1;
f32 temp2;
f32 temp3;
f32 temp4;
2020-03-22 21:19:43 +00:00
if (mode == MTXMODE_APPLY) {
if (f != 0) {
2020-03-17 04:31:30 +00:00
cmf = sCurrentMatrix;
sin = sinf(f);
cos = cosf(f);
temp1 = cmf->xx;
temp2 = cmf->yx;
temp3 = cmf->zx;
temp4 = (vec->x * temp1 + vec->y * temp2 + vec->z * temp3) * (1.0f - cos);
cmf->xx = temp1 * cos + vec->x * temp4 + sin * (temp2 * vec->z - temp3 * vec->y);
cmf->yx = temp2 * cos + vec->y * temp4 + sin * (temp3 * vec->x - temp1 * vec->z);
cmf->zx = temp3 * cos + vec->z * temp4 + sin * (temp1 * vec->y - temp2 * vec->x);
temp1 = cmf->xy;
temp2 = cmf->yy;
temp3 = cmf->zy;
temp4 = (vec->x * temp1 + vec->y * temp2 + vec->z * temp3) * (1.0f - cos);
cmf->xy = temp1 * cos + vec->x * temp4 + sin * (temp2 * vec->z - temp3 * vec->y);
cmf->yy = temp2 * cos + vec->y * temp4 + sin * (temp3 * vec->x - temp1 * vec->z);
cmf->zy = temp3 * cos + vec->z * temp4 + sin * (temp1 * vec->y - temp2 * vec->x);
temp1 = cmf->xz;
temp2 = cmf->yz;
temp3 = cmf->zz;
temp4 = (vec->x * temp1 + vec->y * temp2 + vec->z * temp3) * (1.0f - cos);
cmf->xz = temp1 * cos + vec->x * temp4 + sin * (temp2 * vec->z - temp3 * vec->y);
cmf->yz = temp2 * cos + vec->y * temp4 + sin * (temp3 * vec->x - temp1 * vec->z);
cmf->zz = temp3 * cos + vec->z * temp4 + sin * (temp1 * vec->y - temp2 * vec->x);
}
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
cmf = sCurrentMatrix;
2020-03-22 21:19:43 +00:00
if (f != 0) {
2020-03-17 04:31:30 +00:00
sin = sinf(f);
cos = cosf(f);
rCos = 1.0f - cos;
cmf->xx = vec->x * vec->x * rCos + cos;
cmf->yy = vec->y * vec->y * rCos + cos;
cmf->zz = vec->z * vec->z * rCos + cos;
temp1 = vec->x * rCos * vec->y;
temp2 = vec->z * sin;
cmf->xy = temp1 + temp2;
cmf->yx = temp1 - temp2;
temp1 = vec->x * rCos * vec->z;
temp2 = vec->y * sin;
cmf->xz = temp1 - temp2;
cmf->zx = temp1 + temp2;
temp1 = vec->y * rCos * vec->z;
temp2 = vec->x * sin;
cmf->yz = temp1 + temp2;
cmf->zy = temp1 - temp2;
cmf->xw = 0.0f;
cmf->yw = 0.0f;
cmf->zw = 0.0f;
cmf->wx = 0.0f;
cmf->wy = 0.0f;
cmf->wz = 0.0f;
cmf->ww = 1.0f;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
cmf->xy = 0.0f;
cmf->xz = 0.0f;
cmf->xw = 0.0f;
cmf->yx = 0.0f;
cmf->yz = 0.0f;
cmf->yw = 0.0f;
cmf->zx = 0.0f;
cmf->zy = 0.0f;
cmf->zw = 0.0f;
cmf->wx = 0.0f;
cmf->wy = 0.0f;
cmf->wz = 0.0f;
cmf->xx = 1.0f;
cmf->yy = 1.0f;
cmf->zz = 1.0f;
cmf->ww = 1.0f;
}
}
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/sys_matrix/func_800D23FC.s")
#endif
2020-03-22 21:19:43 +00:00
MtxF* Matrix_CheckFloats(MtxF* mf, char* file, s32 line) {
2020-03-17 04:31:30 +00:00
s32 i, j;
2020-03-22 21:19:43 +00:00
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
if (!(-32768.0f <= mf->mf[i][j]) || !(mf->mf[i][j] < 32768.0f)) {
osSyncPrintf("%s %d: [%s] =\n/ %12.6f %12.6f %12.6f %12.6f \\\n| %12.6f %12.6f %12.6f %12.6f |\n| "
"%12.6f %12.6f %12.6f %12.6f |\n\\ %12.6f %12.6f %12.6f %12.6f /\n",
file, line, "mf", mf->xx, mf->yx, mf->zx, mf->wx, mf->xy, mf->yy, mf->zy, mf->wy, mf->xz,
mf->yz, mf->zz, mf->wz, mf->xw, mf->yw, mf->zw, mf->ww);
2020-03-17 04:31:30 +00:00
Fault_AddHungupAndCrash(file, line);
}
}
}
return mf;
}
2020-03-22 21:19:43 +00:00
void func_800D2A34(MtxF* mf, f32 arg1, f32 arg2, f32 arg3, f32 arg4) {
2020-03-17 04:31:30 +00:00
mf->xy = 0.0f;
mf->xz = 0.0f;
mf->xw = 0.0f;
mf->yx = 0.0f;
mf->yz = 0.0f;
mf->yw = 0.0f;
mf->zx = 0.0f;
mf->zy = 0.0f;
mf->zw = 0.0f;
mf->xx = arg1;
mf->yy = arg1;
mf->zz = arg1;
mf->wx = arg2;
mf->wy = arg3;
mf->wz = arg4;
mf->ww = 1.0f;
}
2020-03-22 21:19:43 +00:00
void func_800D2A98(Mtx* mtx, f32 arg1, f32 arg2, f32 arg3, f32 arg4) {
2020-03-17 04:31:30 +00:00
MtxF mf;
func_800D2A34(&mf, arg1, arg2, arg3, arg4);
func_801064E0(&mf, mtx);
}
2020-03-22 21:19:43 +00:00
void func_800D2AE4(Mtx* mtx, f32 arg1, f32 arg2, f32 arg3, f32 arg4) {
2020-03-17 04:31:30 +00:00
u16* m1 = (u16*)&mtx->m[0][0];
u16* m2 = (u16*)&mtx->m[2][0];
u32 temp;
temp = (s32)(arg1 * 65536.0f);
m2[0] = temp & 0xFFFF;
m1[0] = (temp >> 16) & 0xFFFF;
temp = (s32)(arg1 * 65536.0f);
m1[5] = (temp >> 16) & 0xFFFF;
m2[5] = temp & 0xFFFF;
temp = (s32)(arg1 * 65536.0f);
m1[10] = (temp >> 16) & 0xFFFF;
m2[10] = temp & 0xFFFF;
temp = (s32)(arg2 * 65536.0f);
m1[12] = (temp >> 16) & 0xFFFF;
m2[12] = temp & 0xFFFF;
temp = (s32)(arg3 * 65536.0f);
m1[13] = (temp >> 16) & 0xFFFF;
m2[13] = temp & 0xFFFF;
temp = (s32)(arg4 * 65536.0f);
m1[14] = (temp >> 16) & 0xFFFF;
m2[14] = temp & 0xFFFF;
m1[1] = 0;
m1[2] = 0;
m1[3] = 0;
m1[4] = 0;
m1[6] = 0;
m1[7] = 0;
m1[8] = 0;
m1[9] = 0;
m1[11] = 0;
m1[15] = 1;
m2[1] = 0;
m2[2] = 0;
m2[3] = 0;
m2[4] = 0;
m2[6] = 0;
m2[7] = 0;
m2[8] = 0;
m2[9] = 0;
m2[11] = 0;
m2[15] = 0;
}
2020-03-22 21:19:43 +00:00
void func_800D2BD0(Mtx* mtx, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f32 arg6) {
2020-03-17 04:31:30 +00:00
u16* m1 = (u16*)&mtx->m[0][0];
u16* m2 = (u16*)&mtx->m[2][0];
u32 temp;
temp = (s32)(arg1 * 65536.0f);
m1[0] = (temp >> 16) & 0xFFFF;
m2[0] = temp & 0xFFFF;
temp = (s32)(arg2 * 65536.0f);
m1[5] = (temp >> 16) & 0xFFFF;
m2[5] = temp & 0xFFFF;
temp = (s32)(arg3 * 65536.0f);
m1[10] = (temp >> 16) & 0xFFFF;
m2[10] = temp & 0xFFFF;
temp = (s32)(arg4 * 65536.0f);
m1[12] = (temp >> 16) & 0xFFFF;
m2[12] = temp & 0xFFFF;
temp = (s32)(arg5 * 65536.0f);
m1[13] = (temp >> 16) & 0xFFFF;
m2[13] = temp & 0xFFFF;
temp = (s32)(arg6 * 65536.0f);
m1[14] = (temp >> 16) & 0xFFFF;
m2[14] = temp & 0xFFFF;
m1[1] = 0;
m1[2] = 0;
m1[3] = 0;
m1[4] = 0;
m1[6] = 0;
m1[7] = 0;
m1[8] = 0;
m1[9] = 0;
m1[11] = 0;
m1[15] = 1;
m2[1] = 0;
m2[2] = 0;
m2[3] = 0;
m2[4] = 0;
m2[6] = 0;
m2[7] = 0;
m2[8] = 0;
m2[9] = 0;
m2[11] = 0;
m2[15] = 0;
}
#ifdef NON_MATCHING
// minor ordering and regalloc differences
2020-03-22 21:19:43 +00:00
void func_800D2CEC(Mtx* mtx, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f32 arg6) {
2020-03-17 04:31:30 +00:00
u16* m1 = (u16*)&mtx->m[0][0];
u16* m2 = (u16*)&mtx->m[2][0];
u32 temp;
mtx->m[0][1] = 0;
mtx->m[2][1] = 0;
mtx->m[0][3] = 0;
mtx->m[2][3] = 0;
mtx->m[0][4] = 0;
temp = (s32)(arg1 * 65536.0f);
m1[0] = temp & 0xFFFF;
mtx->m[2][0] = temp << 16;
temp = (s32)(arg2 * 65536.0f);
mtx->m[0][2] = temp >> 16;
mtx->m[2][2] = temp & 0xFFFF;
m1[1] = 0;
mtx->m[2][4] = 0;
temp = (s32)(arg3 * 65536.0f);
mtx->m[1][1] = temp;
m1[11] = 0;
mtx->m[3][1] = temp << 16;
temp = (s32)(arg4 * 65536.0f);
m1[12] = (temp >> 16) & 0xFFFF;
m2[12] = temp & 0xFFFF;
temp = (s32)(arg5 * 65536.0f);
m1[13] = (temp >> 16) & 0xFFFF;
m2[13] = temp & 0xFFFF;
temp = (s32)(arg6 * 65536.0f);
m1[14] = (temp >> 16) & 0xFFFF;
mtx->m[3][3] = temp << 16;
m1[15] = 1;
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/sys_matrix/func_800D2CEC.s")
#endif