2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
// clang-format off
|
2022-10-15 21:14:35 +00:00
|
|
|
Mtx gMtxClear = gdSPDefMtx(
|
|
|
|
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-23 21:31:24 +00:00
|
|
|
|
2020-03-24 19:01:00 +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-24 17:16:13 +00:00
|
|
|
void Matrix_Init(GameState* gameState) {
|
2020-05-26 15:39:27 +00:00
|
|
|
sCurrentMatrix = GameState_Alloc(gameState, 20 * sizeof(MtxF), "../sys_matrix.c", 153);
|
2020-03-17 04:31:30 +00:00
|
|
|
sMatrixStack = sCurrentMatrix;
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
void Matrix_Push(void) {
|
2020-03-17 04:31:30 +00:00
|
|
|
Matrix_MtxFCopy(sCurrentMatrix + 1, sCurrentMatrix);
|
|
|
|
sCurrentMatrix++;
|
|
|
|
}
|
|
|
|
|
2021-02-24 19:28:04 +00:00
|
|
|
void Matrix_Pop(void) {
|
2020-03-17 04:31:30 +00:00
|
|
|
sCurrentMatrix--;
|
2021-04-29 18:39:46 +00:00
|
|
|
ASSERT(sCurrentMatrix >= sMatrixStack, "Matrix_now >= Matrix_stack", "../sys_matrix.c", 176);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
void Matrix_Get(MtxF* dest) {
|
2020-03-17 04:31:30 +00:00
|
|
|
Matrix_MtxFCopy(dest, sCurrentMatrix);
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
void Matrix_Put(MtxF* src) {
|
2020-03-17 04:31:30 +00:00
|
|
|
Matrix_MtxFCopy(sCurrentMatrix, src);
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
MtxF* Matrix_GetCurrent(void) {
|
2020-03-17 04:31:30 +00:00
|
|
|
return sCurrentMatrix;
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
void Matrix_Mult(MtxF* mf, u8 mode) {
|
2020-03-17 04:31:30 +00:00
|
|
|
MtxF* cmf = Matrix_GetCurrent();
|
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
if (mode == MTXMODE_APPLY) {
|
2020-08-08 15:23:16 +00:00
|
|
|
SkinMatrix_MtxFMtxFMult(cmf, mf, cmf);
|
2020-03-24 17:16:13 +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
|
|
|
}
|
|
|
|
|
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-23 21:31:24 +00:00
|
|
|
f32 tx;
|
|
|
|
f32 ty;
|
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
if (mode == MTXMODE_APPLY) {
|
2020-03-23 21:31:24 +00:00
|
|
|
tx = cmf->xx;
|
2021-08-31 18:19:41 +00:00
|
|
|
ty = cmf->xy;
|
|
|
|
cmf->xw += tx * x + ty * y + cmf->xz * z;
|
|
|
|
tx = cmf->yx;
|
2020-03-23 21:31:24 +00:00
|
|
|
ty = cmf->yy;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->yw += tx * x + ty * y + cmf->yz * z;
|
|
|
|
tx = cmf->zx;
|
|
|
|
ty = cmf->zy;
|
|
|
|
cmf->zw += tx * x + ty * y + cmf->zz * z;
|
|
|
|
tx = cmf->wx;
|
|
|
|
ty = cmf->wy;
|
|
|
|
cmf->ww += tx * x + ty * y + cmf->wz * z;
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-08-08 15:23:16 +00:00
|
|
|
SkinMatrix_SetTranslate(cmf, x, y, z);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:16:13 +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-24 17:16:13 +00:00
|
|
|
if (mode == MTXMODE_APPLY) {
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->xx *= x;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->yx *= x;
|
|
|
|
cmf->zx *= x;
|
|
|
|
cmf->xy *= y;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->yy *= y;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->zy *= y;
|
|
|
|
cmf->xz *= z;
|
|
|
|
cmf->yz *= z;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->zz *= z;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->wx *= x;
|
|
|
|
cmf->wy *= y;
|
|
|
|
cmf->wz *= z;
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-08-08 15:23:16 +00:00
|
|
|
SkinMatrix_SetScale(cmf, x, y, z);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:16:13 +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-24 17:16:13 +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);
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->xy;
|
|
|
|
temp2 = cmf->xz;
|
|
|
|
cmf->xy = temp1 * cos + temp2 * sin;
|
|
|
|
cmf->xz = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
temp1 = cmf->yy;
|
2021-08-31 18:19:41 +00:00
|
|
|
temp2 = cmf->yz;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->yy = temp1 * cos + temp2 * sin;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->yz = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->zy;
|
2020-03-17 04:31:30 +00:00
|
|
|
temp2 = cmf->zz;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->zy = temp1 * cos + temp2 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->zz = temp2 * cos - temp1 * sin;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->wy;
|
|
|
|
temp2 = cmf->wz;
|
|
|
|
cmf->wy = temp1 * cos + temp2 * sin;
|
|
|
|
cmf->wz = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf = sCurrentMatrix;
|
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
if (x != 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
sin = sinf(x);
|
|
|
|
cos = cosf(x);
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-03-17 04:31:30 +00:00
|
|
|
sin = 0.0f;
|
|
|
|
cos = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmf->yx = 0.0f;
|
|
|
|
cmf->zx = 0.0f;
|
|
|
|
cmf->wx = 0.0f;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->xy = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->wy = 0.0f;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->xz = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->wz = 0.0f;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->xw = 0.0f;
|
|
|
|
cmf->yw = 0.0f;
|
|
|
|
cmf->zw = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->xx = 1.0f;
|
|
|
|
cmf->ww = 1.0f;
|
|
|
|
cmf->yy = cos;
|
|
|
|
cmf->zz = cos;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->zy = sin;
|
|
|
|
cmf->yz = -sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:16:13 +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-24 17:16:13 +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;
|
2021-08-31 18:19:41 +00:00
|
|
|
temp2 = cmf->xz;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->xx = temp1 * cos - temp2 * sin;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->xz = temp1 * sin + temp2 * cos;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->yx;
|
|
|
|
temp2 = cmf->yz;
|
|
|
|
cmf->yx = temp1 * cos - temp2 * sin;
|
|
|
|
cmf->yz = temp1 * sin + temp2 * cos;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->zx;
|
2020-03-17 04:31:30 +00:00
|
|
|
temp2 = cmf->zz;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->zx = temp1 * cos - temp2 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->zz = temp1 * sin + temp2 * cos;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->wx;
|
|
|
|
temp2 = cmf->wz;
|
|
|
|
cmf->wx = temp1 * cos - temp2 * sin;
|
|
|
|
cmf->wz = temp1 * sin + temp2 * cos;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf = sCurrentMatrix;
|
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
if (y != 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
sin = sinf(y);
|
|
|
|
cos = cosf(y);
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-03-17 04:31:30 +00:00
|
|
|
sin = 0.0f;
|
|
|
|
cos = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmf->yx = 0.0f;
|
|
|
|
cmf->wx = 0.0f;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->xy = 0.0f;
|
|
|
|
cmf->zy = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->wy = 0.0f;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->yz = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->wz = 0.0f;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->xw = 0.0f;
|
|
|
|
cmf->yw = 0.0f;
|
|
|
|
cmf->zw = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->yy = 1.0f;
|
|
|
|
cmf->ww = 1.0f;
|
|
|
|
cmf->xx = cos;
|
|
|
|
cmf->zz = cos;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->zx = -sin;
|
|
|
|
cmf->xz = sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 17:16:13 +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-24 17:16:13 +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;
|
2021-08-31 18:19:41 +00:00
|
|
|
temp2 = cmf->xy;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->xx = temp1 * cos + temp2 * sin;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->xy = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->yx;
|
2020-03-17 04:31:30 +00:00
|
|
|
temp2 = cmf->yy;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->yx = temp1 * cos + temp2 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->yy = temp2 * cos - temp1 * sin;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->zx;
|
|
|
|
temp2 = cmf->zy;
|
|
|
|
cmf->zx = temp1 * cos + temp2 * sin;
|
|
|
|
cmf->zy = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->wx;
|
|
|
|
temp2 = cmf->wy;
|
|
|
|
cmf->wx = temp1 * cos + temp2 * sin;
|
|
|
|
cmf->wy = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
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->zx = 0.0f;
|
|
|
|
cmf->wx = 0.0f;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->zy = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->wy = 0.0f;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->xz = 0.0f;
|
|
|
|
cmf->yz = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->wz = 0.0f;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->xw = 0.0f;
|
|
|
|
cmf->yw = 0.0f;
|
|
|
|
cmf->zw = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->zz = 1.0f;
|
|
|
|
cmf->ww = 1.0f;
|
|
|
|
cmf->xx = cos;
|
|
|
|
cmf->yy = cos;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->yx = sin;
|
|
|
|
cmf->xy = -sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
/**
|
2021-11-17 10:52:26 +00:00
|
|
|
* Rotate using ZYX Tait-Bryan angles.
|
|
|
|
* This means a (column) vector is first rotated around X, then around Y, then around Z, then (if `mode` is
|
|
|
|
* `MTXMODE_APPLY`) gets transformed according to whatever the matrix was before adding the ZYX rotation.
|
2020-03-23 21:31:24 +00:00
|
|
|
* Original Name: Matrix_RotateXYZ, changed to reflect rotation order.
|
2020-03-24 17:16:13 +00:00
|
|
|
*/
|
2021-11-17 10:52:26 +00:00
|
|
|
void Matrix_RotateZYX(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-12-26 10:44:53 +00:00
|
|
|
sin = Math_SinS(z);
|
|
|
|
cos = Math_CosS(z);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
temp1 = cmf->xx;
|
2021-08-31 18:19:41 +00:00
|
|
|
temp2 = cmf->xy;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->xx = temp1 * cos + temp2 * sin;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->xy = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->yx;
|
2020-03-17 04:31:30 +00:00
|
|
|
temp2 = cmf->yy;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->yx = temp1 * cos + temp2 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->yy = temp2 * cos - temp1 * sin;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->zx;
|
|
|
|
temp2 = cmf->zy;
|
|
|
|
cmf->zx = temp1 * cos + temp2 * sin;
|
|
|
|
cmf->zy = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->wx;
|
|
|
|
temp2 = cmf->wy;
|
|
|
|
cmf->wx = temp1 * cos + temp2 * sin;
|
|
|
|
cmf->wy = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (y != 0) {
|
2020-12-26 10:44:53 +00:00
|
|
|
sin = Math_SinS(y);
|
|
|
|
cos = Math_CosS(y);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
temp1 = cmf->xx;
|
2021-08-31 18:19:41 +00:00
|
|
|
temp2 = cmf->xz;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->xx = temp1 * cos - temp2 * sin;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->xz = temp1 * sin + temp2 * cos;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->yx;
|
|
|
|
temp2 = cmf->yz;
|
|
|
|
cmf->yx = temp1 * cos - temp2 * sin;
|
|
|
|
cmf->yz = temp1 * sin + temp2 * cos;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->zx;
|
2020-03-17 04:31:30 +00:00
|
|
|
temp2 = cmf->zz;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->zx = temp1 * cos - temp2 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->zz = temp1 * sin + temp2 * cos;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->wx;
|
|
|
|
temp2 = cmf->wz;
|
|
|
|
cmf->wx = temp1 * cos - temp2 * sin;
|
|
|
|
cmf->wz = temp1 * sin + temp2 * cos;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (x != 0) {
|
2020-12-26 10:44:53 +00:00
|
|
|
sin = Math_SinS(x);
|
|
|
|
cos = Math_CosS(x);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->xy;
|
|
|
|
temp2 = cmf->xz;
|
|
|
|
cmf->xy = temp1 * cos + temp2 * sin;
|
|
|
|
cmf->xz = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
temp1 = cmf->yy;
|
2021-08-31 18:19:41 +00:00
|
|
|
temp2 = cmf->yz;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->yy = temp1 * cos + temp2 * sin;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->yz = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->zy;
|
2020-03-17 04:31:30 +00:00
|
|
|
temp2 = cmf->zz;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->zy = temp1 * cos + temp2 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->zz = temp2 * cos - temp1 * sin;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->wy;
|
|
|
|
temp2 = cmf->wz;
|
|
|
|
cmf->wy = temp1 * cos + temp2 * sin;
|
|
|
|
cmf->wz = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2021-11-17 10:52:26 +00:00
|
|
|
SkinMatrix_SetRotateZYX(cmf, x, y, z);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
/**
|
2021-11-17 10:52:26 +00:00
|
|
|
* Translate and rotate using ZYX Tait-Bryan angles.
|
|
|
|
* This means a (column) vector is first rotated around X, then around Y, then around Z, then translated, then gets
|
|
|
|
* transformed according to whatever the matrix was previously.
|
2020-03-24 17:16:13 +00:00
|
|
|
*/
|
2021-11-17 10:52:26 +00:00
|
|
|
void Matrix_TranslateRotateZYX(Vec3f* translation, Vec3s* rotation) {
|
2020-03-17 04:31:30 +00:00
|
|
|
MtxF* cmf = sCurrentMatrix;
|
2021-02-14 00:49:40 +00:00
|
|
|
f32 sin = Math_SinS(rotation->z);
|
|
|
|
f32 cos = Math_CosS(rotation->z);
|
2020-03-17 04:31:30 +00:00
|
|
|
f32 temp1;
|
|
|
|
f32 temp2;
|
|
|
|
|
|
|
|
temp1 = cmf->xx;
|
2021-08-31 18:19:41 +00:00
|
|
|
temp2 = cmf->xy;
|
2021-11-17 10:52:26 +00:00
|
|
|
cmf->xw += temp1 * translation->x + temp2 * translation->y + cmf->xz * translation->z;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->xx = temp1 * cos + temp2 * sin;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->xy = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->yx;
|
2020-03-17 04:31:30 +00:00
|
|
|
temp2 = cmf->yy;
|
2021-11-17 10:52:26 +00:00
|
|
|
cmf->yw += temp1 * translation->x + temp2 * translation->y + cmf->yz * translation->z;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->yx = temp1 * cos + temp2 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->yy = temp2 * cos - temp1 * sin;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->zx;
|
|
|
|
temp2 = cmf->zy;
|
2021-11-17 10:52:26 +00:00
|
|
|
cmf->zw += temp1 * translation->x + temp2 * translation->y + cmf->zz * translation->z;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->zx = temp1 * cos + temp2 * sin;
|
|
|
|
cmf->zy = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->wx;
|
|
|
|
temp2 = cmf->wy;
|
2021-11-17 10:52:26 +00:00
|
|
|
cmf->ww += temp1 * translation->x + temp2 * translation->y + cmf->wz * translation->z;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->wx = temp1 * cos + temp2 * sin;
|
|
|
|
cmf->wy = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-23 21:31:24 +00:00
|
|
|
if (rotation->y != 0) {
|
2020-12-26 10:44:53 +00:00
|
|
|
sin = Math_SinS(rotation->y);
|
|
|
|
cos = Math_CosS(rotation->y);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
temp1 = cmf->xx;
|
2021-08-31 18:19:41 +00:00
|
|
|
temp2 = cmf->xz;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->xx = temp1 * cos - temp2 * sin;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->xz = temp1 * sin + temp2 * cos;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->yx;
|
|
|
|
temp2 = cmf->yz;
|
|
|
|
cmf->yx = temp1 * cos - temp2 * sin;
|
|
|
|
cmf->yz = temp1 * sin + temp2 * cos;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->zx;
|
2020-03-17 04:31:30 +00:00
|
|
|
temp2 = cmf->zz;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->zx = temp1 * cos - temp2 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->zz = temp1 * sin + temp2 * cos;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->wx;
|
|
|
|
temp2 = cmf->wz;
|
|
|
|
cmf->wx = temp1 * cos - temp2 * sin;
|
|
|
|
cmf->wz = temp1 * sin + temp2 * cos;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 21:31:24 +00:00
|
|
|
if (rotation->x != 0) {
|
2020-12-26 10:44:53 +00:00
|
|
|
sin = Math_SinS(rotation->x);
|
|
|
|
cos = Math_CosS(rotation->x);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->xy;
|
|
|
|
temp2 = cmf->xz;
|
|
|
|
cmf->xy = temp1 * cos + temp2 * sin;
|
|
|
|
cmf->xz = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
|
|
|
temp1 = cmf->yy;
|
2021-08-31 18:19:41 +00:00
|
|
|
temp2 = cmf->yz;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->yy = temp1 * cos + temp2 * sin;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->yz = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->zy;
|
2020-03-17 04:31:30 +00:00
|
|
|
temp2 = cmf->zz;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->zy = temp1 * cos + temp2 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->zz = temp2 * cos - temp1 * sin;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->wy;
|
|
|
|
temp2 = cmf->wz;
|
|
|
|
cmf->wy = temp1 * cos + temp2 * sin;
|
|
|
|
cmf->wz = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
/**
|
|
|
|
* Set the current matrix to translate and rotate using YXZ Tait-Bryan angles.
|
|
|
|
* This means a (column) vector is first rotated around Z, then around X, then around Y, then translated.
|
|
|
|
*/
|
|
|
|
void Matrix_SetTranslateRotateYXZ(f32 translateX, f32 translateY, f32 translateZ, Vec3s* rot) {
|
2020-03-17 04:31:30 +00:00
|
|
|
MtxF* cmf = sCurrentMatrix;
|
2022-01-10 23:28:01 +00:00
|
|
|
f32 temp1 = Math_SinS(rot->y);
|
|
|
|
f32 temp2 = Math_CosS(rot->y);
|
|
|
|
f32 cos;
|
|
|
|
f32 sin;
|
|
|
|
|
|
|
|
cmf->xx = temp2;
|
|
|
|
cmf->zx = -temp1;
|
|
|
|
cmf->xw = translateX;
|
|
|
|
cmf->yw = translateY;
|
|
|
|
cmf->zw = translateZ;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->wx = 0.0f;
|
|
|
|
cmf->wy = 0.0f;
|
|
|
|
cmf->wz = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->ww = 1.0f;
|
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
if (rot->x != 0) {
|
|
|
|
sin = Math_SinS(rot->x);
|
|
|
|
cos = Math_CosS(rot->x);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
cmf->zz = temp2 * cos;
|
|
|
|
cmf->zy = temp2 * sin;
|
|
|
|
cmf->xz = temp1 * cos;
|
|
|
|
cmf->xy = temp1 * sin;
|
|
|
|
cmf->yz = -sin;
|
|
|
|
cmf->yy = cos;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2022-01-10 23:28:01 +00:00
|
|
|
cmf->zz = temp2;
|
|
|
|
cmf->xz = temp1;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->yz = 0.0f;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->zy = 0.0f;
|
|
|
|
cmf->xy = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->yy = 1.0f;
|
|
|
|
}
|
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
if (rot->z != 0) {
|
|
|
|
sin = Math_SinS(rot->z);
|
|
|
|
cos = Math_CosS(rot->z);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
temp1 = cmf->xx;
|
|
|
|
temp2 = cmf->xy;
|
|
|
|
cmf->xx = temp1 * cos + temp2 * sin;
|
|
|
|
cmf->xy = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
temp1 = cmf->zx;
|
|
|
|
temp2 = cmf->zy;
|
|
|
|
cmf->zx = temp1 * cos + temp2 * sin;
|
|
|
|
cmf->zy = temp2 * cos - temp1 * sin;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
temp2 = cmf->yy;
|
|
|
|
cmf->yx = temp2 * sin;
|
|
|
|
cmf->yy = temp2 * cos;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->yx = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
Mtx* Matrix_MtxFToMtx(MtxF* src, Mtx* dest) {
|
2020-08-08 15:23:16 +00:00
|
|
|
s32 temp;
|
2020-03-17 04:31:30 +00:00
|
|
|
u16* m1 = (u16*)&dest->m[0][0];
|
|
|
|
u16* m2 = (u16*)&dest->m[2][0];
|
|
|
|
|
2020-08-08 15:23:16 +00:00
|
|
|
temp = src->xx * 0x10000;
|
|
|
|
m1[0] = (temp >> 0x10);
|
|
|
|
m1[16 + 0] = temp & 0xFFFF;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = src->yx * 0x10000;
|
2020-08-08 15:23:16 +00:00
|
|
|
m1[1] = (temp >> 0x10);
|
|
|
|
m1[16 + 1] = temp & 0xFFFF;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = src->zx * 0x10000;
|
2020-08-08 15:23:16 +00:00
|
|
|
m1[2] = (temp >> 0x10);
|
|
|
|
m1[16 + 2] = temp & 0xFFFF;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = src->wx * 0x10000;
|
2020-08-08 15:23:16 +00:00
|
|
|
m1[3] = (temp >> 0x10);
|
|
|
|
m1[16 + 3] = temp & 0xFFFF;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = src->xy * 0x10000;
|
2020-08-08 15:23:16 +00:00
|
|
|
m1[4] = (temp >> 0x10);
|
|
|
|
m1[16 + 4] = temp & 0xFFFF;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-08-08 15:23:16 +00:00
|
|
|
temp = src->yy * 0x10000;
|
|
|
|
m1[5] = (temp >> 0x10);
|
|
|
|
m1[16 + 5] = temp & 0xFFFF;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = src->zy * 0x10000;
|
2020-08-08 15:23:16 +00:00
|
|
|
m1[6] = (temp >> 0x10);
|
|
|
|
m1[16 + 6] = temp & 0xFFFF;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = src->wy * 0x10000;
|
2020-08-08 15:23:16 +00:00
|
|
|
m1[7] = (temp >> 0x10);
|
|
|
|
m1[16 + 7] = temp & 0xFFFF;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = src->xz * 0x10000;
|
2020-08-08 15:23:16 +00:00
|
|
|
m1[8] = (temp >> 0x10);
|
|
|
|
m1[16 + 8] = temp & 0xFFFF;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = src->yz * 0x10000;
|
2020-08-08 15:23:16 +00:00
|
|
|
m1[9] = (temp >> 0x10);
|
2020-03-17 04:31:30 +00:00
|
|
|
m2[9] = temp & 0xFFFF;
|
|
|
|
|
2020-08-08 15:23:16 +00:00
|
|
|
temp = src->zz * 0x10000;
|
|
|
|
m1[10] = (temp >> 0x10);
|
2020-03-17 04:31:30 +00:00
|
|
|
m2[10] = temp & 0xFFFF;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = src->wz * 0x10000;
|
2020-08-08 15:23:16 +00:00
|
|
|
m1[11] = (temp >> 0x10);
|
2020-03-17 04:31:30 +00:00
|
|
|
m2[11] = temp & 0xFFFF;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = src->xw * 0x10000;
|
2020-08-08 15:23:16 +00:00
|
|
|
m1[12] = (temp >> 0x10);
|
2020-03-17 04:31:30 +00:00
|
|
|
m2[12] = temp & 0xFFFF;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = src->yw * 0x10000;
|
2020-08-08 15:23:16 +00:00
|
|
|
m1[13] = (temp >> 0x10);
|
2020-03-17 04:31:30 +00:00
|
|
|
m2[13] = temp & 0xFFFF;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = src->zw * 0x10000;
|
2020-08-08 15:23:16 +00:00
|
|
|
m1[14] = (temp >> 0x10);
|
2020-03-17 04:31:30 +00:00
|
|
|
m2[14] = temp & 0xFFFF;
|
|
|
|
|
2020-08-08 15:23:16 +00:00
|
|
|
temp = src->ww * 0x10000;
|
|
|
|
m1[15] = (temp >> 0x10);
|
2020-03-17 04:31:30 +00:00
|
|
|
m2[15] = temp & 0xFFFF;
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
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-10-27 00:47: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;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
dest->x = cmf->xw + (cmf->xx * src->x + cmf->xy * src->y + cmf->xz * src->z);
|
|
|
|
dest->y = cmf->yw + (cmf->yx * src->x + cmf->yy * src->y + cmf->yz * src->z);
|
|
|
|
dest->z = cmf->zw + (cmf->zx * src->x + cmf->zy * src->y + cmf->zz * src->z);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
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->yx = src->yx;
|
2021-08-31 18:19:41 +00:00
|
|
|
dest->zx = src->zx;
|
|
|
|
dest->wx = src->wx;
|
|
|
|
dest->xy = src->xy;
|
2020-03-17 04:31:30 +00:00
|
|
|
dest->yy = src->yy;
|
2021-08-31 18:19:41 +00:00
|
|
|
dest->zy = src->zy;
|
|
|
|
dest->wy = src->wy;
|
2020-03-17 04:31:30 +00:00
|
|
|
dest->xx = src->xx;
|
|
|
|
dest->yx = src->yx;
|
|
|
|
dest->zx = src->zx;
|
|
|
|
dest->wx = src->wx;
|
2021-08-31 18:19:41 +00:00
|
|
|
dest->xy = src->xy;
|
|
|
|
dest->yy = src->yy;
|
|
|
|
dest->zy = src->zy;
|
2020-03-17 04:31:30 +00:00
|
|
|
dest->wy = src->wy;
|
2021-08-31 18:19:41 +00:00
|
|
|
dest->xz = src->xz;
|
|
|
|
dest->yz = src->yz;
|
|
|
|
dest->zz = src->zz;
|
2020-03-17 04:31:30 +00:00
|
|
|
dest->wz = src->wz;
|
2021-08-31 18:19:41 +00:00
|
|
|
dest->xw = src->xw;
|
|
|
|
dest->yw = src->yw;
|
|
|
|
dest->zw = src->zw;
|
2020-03-17 04:31:30 +00:00
|
|
|
dest->ww = src->ww;
|
2021-08-31 18:19:41 +00:00
|
|
|
dest->xz = src->xz;
|
|
|
|
dest->yz = src->yz;
|
2020-03-17 04:31:30 +00:00
|
|
|
dest->zz = src->zz;
|
|
|
|
dest->wz = src->wz;
|
2021-08-31 18:19:41 +00:00
|
|
|
dest->xw = src->xw;
|
|
|
|
dest->yw = src->yw;
|
|
|
|
dest->zw = src->zw;
|
2020-03-17 04:31:30 +00:00
|
|
|
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);
|
2021-08-31 18:19:41 +00:00
|
|
|
dest->yx = ((m1[1] << 0x10) | m2[1]) * (1 / 65536.0f);
|
|
|
|
dest->zx = ((m1[2] << 0x10) | m2[2]) * (1 / 65536.0f);
|
|
|
|
dest->wx = ((m1[3] << 0x10) | m2[3]) * (1 / 65536.0f);
|
|
|
|
dest->xy = ((m1[4] << 0x10) | m2[4]) * (1 / 65536.0f);
|
2020-03-17 04:31:30 +00:00
|
|
|
dest->yy = ((m1[5] << 0x10) | m2[5]) * (1 / 65536.0f);
|
2021-08-31 18:19:41 +00:00
|
|
|
dest->zy = ((m1[6] << 0x10) | m2[6]) * (1 / 65536.0f);
|
|
|
|
dest->wy = ((m1[7] << 0x10) | m2[7]) * (1 / 65536.0f);
|
|
|
|
dest->xz = ((m1[8] << 0x10) | m2[8]) * (1 / 65536.0f);
|
|
|
|
dest->yz = ((m1[9] << 0x10) | m2[9]) * (1 / 65536.0f);
|
2020-03-17 04:31:30 +00:00
|
|
|
dest->zz = ((m1[10] << 0x10) | m2[10]) * (1 / 65536.0f);
|
2021-08-31 18:19:41 +00:00
|
|
|
dest->wz = ((m1[11] << 0x10) | m2[11]) * (1 / 65536.0f);
|
|
|
|
dest->xw = ((m1[12] << 0x10) | m2[12]) * (1 / 65536.0f);
|
|
|
|
dest->yw = ((m1[13] << 0x10) | m2[13]) * (1 / 65536.0f);
|
|
|
|
dest->zw = ((m1[14] << 0x10) | m2[14]) * (1 / 65536.0f);
|
2020-03-17 04:31:30 +00:00
|
|
|
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) {
|
2021-08-31 18:19:41 +00:00
|
|
|
dest->x = mf->xw + (mf->xx * src->x + mf->xy * src->y + mf->xz * src->z);
|
|
|
|
dest->y = mf->yw + (mf->yx * src->x + mf->yy * src->y + mf->yz * src->z);
|
|
|
|
dest->z = mf->zw + (mf->zx * src->x + mf->zy * src->y + mf->zz * src->z);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-22 15:25:17 +00:00
|
|
|
void Matrix_Transpose(MtxF* mf) {
|
2020-03-17 04:31:30 +00:00
|
|
|
f32 temp;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = mf->yx;
|
|
|
|
mf->yx = mf->xy;
|
|
|
|
mf->xy = temp;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = mf->zx;
|
|
|
|
mf->zx = mf->xz;
|
|
|
|
mf->xz = temp;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = mf->zy;
|
|
|
|
mf->zy = mf->yz;
|
|
|
|
mf->yz = temp;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
/**
|
|
|
|
* Changes the 3x3 part of the current matrix to `mf` * S, where S is the scale in the current matrix.
|
|
|
|
*
|
|
|
|
* In details, S is a diagonal where each coefficient is the norm of the column in the 3x3 current matrix.
|
|
|
|
* The 3x3 part can then be written as R * S where R has its columns normalized.
|
|
|
|
* Since R is typically a rotation matrix, and the 3x3 part is changed from R * S to `mf` * S, this operation can be
|
|
|
|
* seen as replacing the R rotation with `mf`, hence the function name.
|
|
|
|
*/
|
|
|
|
void Matrix_ReplaceRotation(MtxF* mf) {
|
2020-03-17 04:31:30 +00:00
|
|
|
MtxF* cmf = sCurrentMatrix;
|
2022-01-10 23:28:01 +00:00
|
|
|
f32 acc;
|
2020-03-17 04:31:30 +00:00
|
|
|
f32 temp;
|
2022-01-10 23:28:01 +00:00
|
|
|
f32 curColNorm;
|
|
|
|
|
|
|
|
// compute the Euclidean norm of the first column of the current matrix
|
|
|
|
acc = cmf->xx;
|
|
|
|
acc *= acc;
|
|
|
|
temp = cmf->yx;
|
|
|
|
acc += SQ(temp);
|
|
|
|
temp = cmf->zx;
|
|
|
|
acc += SQ(temp);
|
|
|
|
curColNorm = sqrtf(acc);
|
|
|
|
|
|
|
|
cmf->xx = mf->xx * curColNorm;
|
|
|
|
cmf->yx = mf->yx * curColNorm;
|
|
|
|
cmf->zx = mf->zx * curColNorm;
|
|
|
|
|
|
|
|
// second column
|
|
|
|
acc = cmf->xy;
|
|
|
|
acc *= acc;
|
|
|
|
temp = cmf->yy;
|
|
|
|
acc += SQ(temp);
|
|
|
|
temp = cmf->zy;
|
|
|
|
acc += SQ(temp);
|
|
|
|
curColNorm = sqrtf(acc);
|
|
|
|
|
|
|
|
cmf->xy = mf->xy * curColNorm;
|
|
|
|
cmf->yy = mf->yy * curColNorm;
|
|
|
|
cmf->zy = mf->zy * curColNorm;
|
|
|
|
|
|
|
|
// third column
|
|
|
|
acc = cmf->xz;
|
|
|
|
acc *= acc;
|
|
|
|
temp = cmf->yz;
|
|
|
|
acc += SQ(temp);
|
|
|
|
temp = cmf->zz;
|
|
|
|
acc += SQ(temp);
|
|
|
|
curColNorm = sqrtf(acc);
|
|
|
|
|
|
|
|
cmf->xz = mf->xz * curColNorm;
|
|
|
|
cmf->yz = mf->yz * curColNorm;
|
|
|
|
cmf->zz = mf->zz * curColNorm;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-22 15:25:17 +00:00
|
|
|
/**
|
2021-11-17 10:52:26 +00:00
|
|
|
* Gets the rotation the specified matrix represents, using Tait-Bryan YXZ angles.
|
2021-08-22 15:25:17 +00:00
|
|
|
* The flag value doesn't matter for a rotation matrix. Not 0 does extra calculation.
|
|
|
|
*/
|
|
|
|
void Matrix_MtxFToYXZRotS(MtxF* mf, Vec3s* rotDest, s32 flag) {
|
2020-12-01 19:31:04 +00:00
|
|
|
f32 temp;
|
|
|
|
f32 temp2;
|
|
|
|
f32 temp3;
|
|
|
|
f32 temp4;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = mf->xz;
|
2020-12-01 19:31:04 +00:00
|
|
|
temp *= temp;
|
|
|
|
temp += SQ(mf->zz);
|
2022-04-24 14:23:49 +00:00
|
|
|
rotDest->x = RAD_TO_BINANG(Math_FAtan2F(-mf->yz, sqrtf(temp)));
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-22 15:25:17 +00:00
|
|
|
if ((rotDest->x == 0x4000) || (rotDest->x == -0x4000)) {
|
|
|
|
rotDest->z = 0;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-04-24 14:23:49 +00:00
|
|
|
rotDest->y = RAD_TO_BINANG(Math_FAtan2F(-mf->zx, mf->xx));
|
2020-03-23 23:11:21 +00:00
|
|
|
} else {
|
2022-04-24 14:23:49 +00:00
|
|
|
rotDest->y = RAD_TO_BINANG(Math_FAtan2F(mf->xz, mf->zz));
|
2020-12-01 19:31:04 +00:00
|
|
|
|
|
|
|
if (!flag) {
|
2022-04-24 14:23:49 +00:00
|
|
|
rotDest->z = RAD_TO_BINANG(Math_FAtan2F(mf->yx, mf->yy));
|
2020-12-01 19:31:04 +00:00
|
|
|
} else {
|
|
|
|
temp = mf->xx;
|
2021-08-31 18:19:41 +00:00
|
|
|
temp2 = mf->zx;
|
|
|
|
temp3 = mf->zy;
|
2020-12-01 19:31:04 +00:00
|
|
|
|
|
|
|
temp *= temp;
|
2021-04-06 03:56:52 +00:00
|
|
|
temp += SQ(temp2);
|
2021-08-31 18:19:41 +00:00
|
|
|
temp2 = mf->yx;
|
2020-12-01 19:31:04 +00:00
|
|
|
temp += SQ(temp2);
|
2021-08-31 18:19:41 +00:00
|
|
|
/* temp = xx^2+zx^2+yx^2 == 1 for a rotation matrix */
|
2020-12-01 19:31:04 +00:00
|
|
|
temp = sqrtf(temp);
|
|
|
|
temp = temp2 / temp;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp2 = mf->xy;
|
2020-12-01 19:31:04 +00:00
|
|
|
temp2 *= temp2;
|
|
|
|
temp2 += SQ(temp3);
|
|
|
|
temp3 = mf->yy;
|
|
|
|
temp2 += SQ(temp3);
|
2021-08-31 18:19:41 +00:00
|
|
|
/* temp2 = xy^2+zy^2+yy^2 == 1 for a rotation matrix */
|
2020-12-01 19:31:04 +00:00
|
|
|
temp2 = sqrtf(temp2);
|
|
|
|
temp2 = temp3 / temp2;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
/* for a rotation matrix, temp == yx and temp2 == yy
|
2021-08-22 15:25:17 +00:00
|
|
|
* which is the same as in the !flag branch */
|
2022-04-24 14:23:49 +00:00
|
|
|
rotDest->z = RAD_TO_BINANG(Math_FAtan2F(temp, temp2));
|
2020-12-01 19:31:04 +00:00
|
|
|
}
|
2020-03-23 23:11:21 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-22 15:25:17 +00:00
|
|
|
/**
|
2021-11-17 10:52:26 +00:00
|
|
|
* Gets the rotation the specified matrix represents, using Tait-Bryan ZYX angles.
|
2021-08-22 15:25:17 +00:00
|
|
|
* The flag value doesn't matter for a rotation matrix. Not 0 does extra calculation.
|
|
|
|
*/
|
|
|
|
void Matrix_MtxFToZYXRotS(MtxF* mf, Vec3s* rotDest, s32 flag) {
|
2020-12-01 19:31:04 +00:00
|
|
|
f32 temp;
|
|
|
|
f32 temp2;
|
2021-04-06 03:56:52 +00:00
|
|
|
f32 temp3;
|
|
|
|
f32 temp4;
|
2020-12-01 19:31:04 +00:00
|
|
|
|
|
|
|
temp = mf->xx;
|
|
|
|
temp *= temp;
|
2021-08-31 18:19:41 +00:00
|
|
|
temp += SQ(mf->yx);
|
2022-04-24 14:23:49 +00:00
|
|
|
rotDest->y = RAD_TO_BINANG(Math_FAtan2F(-mf->zx, sqrtf(temp)));
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-22 15:25:17 +00:00
|
|
|
if ((rotDest->y == 0x4000) || (rotDest->y == -0x4000)) {
|
|
|
|
rotDest->x = 0;
|
2022-04-24 14:23:49 +00:00
|
|
|
rotDest->z = RAD_TO_BINANG(Math_FAtan2F(-mf->xy, mf->yy));
|
2021-08-22 15:25:17 +00:00
|
|
|
} else {
|
2022-04-24 14:23:49 +00:00
|
|
|
rotDest->z = RAD_TO_BINANG(Math_FAtan2F(mf->yx, mf->xx));
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-22 15:25:17 +00:00
|
|
|
if (!flag) {
|
2022-04-24 14:23:49 +00:00
|
|
|
rotDest->x = RAD_TO_BINANG(Math_FAtan2F(mf->zy, mf->zz));
|
2021-08-22 15:25:17 +00:00
|
|
|
} else {
|
|
|
|
// see Matrix_MtxFToYXZRotS
|
2021-08-31 18:19:41 +00:00
|
|
|
temp = mf->xy;
|
2021-08-22 15:25:17 +00:00
|
|
|
temp2 = mf->yy;
|
2021-08-31 18:19:41 +00:00
|
|
|
temp3 = mf->yz;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-22 15:25:17 +00:00
|
|
|
temp *= temp;
|
|
|
|
temp += SQ(temp2);
|
2021-08-31 18:19:41 +00:00
|
|
|
temp2 = mf->zy;
|
2021-08-22 15:25:17 +00:00
|
|
|
temp += SQ(temp2);
|
|
|
|
temp = sqrtf(temp);
|
|
|
|
temp = temp2 / temp;
|
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp2 = mf->xz;
|
2021-08-22 15:25:17 +00:00
|
|
|
temp2 *= temp2;
|
|
|
|
temp2 += SQ(temp3);
|
|
|
|
temp3 = mf->zz;
|
|
|
|
temp2 += SQ(temp3);
|
|
|
|
temp2 = sqrtf(temp2);
|
|
|
|
temp2 = temp3 / temp2;
|
|
|
|
|
2022-04-24 14:23:49 +00:00
|
|
|
rotDest->x = RAD_TO_BINANG(Math_FAtan2F(temp, temp2));
|
2021-08-22 15:25:17 +00:00
|
|
|
}
|
2020-03-23 23:11:21 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-22 15:25:17 +00:00
|
|
|
/*
|
2022-01-10 23:28:01 +00:00
|
|
|
* Rotate the matrix by `angle` radians around a unit vector `axis`.
|
|
|
|
* NB: `axis` is assumed to be a unit vector.
|
2021-08-22 15:25:17 +00:00
|
|
|
*/
|
2022-01-10 23:28:01 +00:00
|
|
|
void Matrix_RotateAxis(f32 angle, Vec3f* axis, 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) {
|
2022-01-10 23:28:01 +00:00
|
|
|
if (angle != 0) {
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf = sCurrentMatrix;
|
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
sin = sinf(angle);
|
|
|
|
cos = cosf(angle);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
temp1 = cmf->xx;
|
2021-08-31 18:19:41 +00:00
|
|
|
temp2 = cmf->xy;
|
|
|
|
temp3 = cmf->xz;
|
2022-01-10 23:28:01 +00:00
|
|
|
temp4 = (axis->x * temp1 + axis->y * temp2 + axis->z * temp3) * (1.0f - cos);
|
|
|
|
cmf->xx = temp1 * cos + axis->x * temp4 + sin * (temp2 * axis->z - temp3 * axis->y);
|
|
|
|
cmf->xy = temp2 * cos + axis->y * temp4 + sin * (temp3 * axis->x - temp1 * axis->z);
|
|
|
|
cmf->xz = temp3 * cos + axis->z * temp4 + sin * (temp1 * axis->y - temp2 * axis->x);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->yx;
|
2020-03-17 04:31:30 +00:00
|
|
|
temp2 = cmf->yy;
|
2021-08-31 18:19:41 +00:00
|
|
|
temp3 = cmf->yz;
|
2022-01-10 23:28:01 +00:00
|
|
|
temp4 = (axis->x * temp1 + axis->y * temp2 + axis->z * temp3) * (1.0f - cos);
|
|
|
|
cmf->yx = temp1 * cos + axis->x * temp4 + sin * (temp2 * axis->z - temp3 * axis->y);
|
|
|
|
cmf->yy = temp2 * cos + axis->y * temp4 + sin * (temp3 * axis->x - temp1 * axis->z);
|
|
|
|
cmf->yz = temp3 * cos + axis->z * temp4 + sin * (temp1 * axis->y - temp2 * axis->x);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
temp1 = cmf->zx;
|
|
|
|
temp2 = cmf->zy;
|
2020-03-17 04:31:30 +00:00
|
|
|
temp3 = cmf->zz;
|
2022-01-10 23:28:01 +00:00
|
|
|
temp4 = (axis->x * temp1 + axis->y * temp2 + axis->z * temp3) * (1.0f - cos);
|
|
|
|
cmf->zx = temp1 * cos + axis->x * temp4 + sin * (temp2 * axis->z - temp3 * axis->y);
|
|
|
|
cmf->zy = temp2 * cos + axis->y * temp4 + sin * (temp3 * axis->x - temp1 * axis->z);
|
|
|
|
cmf->zz = temp3 * cos + axis->z * temp4 + sin * (temp1 * axis->y - temp2 * axis->x);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf = sCurrentMatrix;
|
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
if (angle != 0) {
|
|
|
|
sin = sinf(angle);
|
|
|
|
cos = cosf(angle);
|
2020-03-17 04:31:30 +00:00
|
|
|
rCos = 1.0f - cos;
|
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
cmf->xx = axis->x * axis->x * rCos + cos;
|
|
|
|
cmf->yy = axis->y * axis->y * rCos + cos;
|
|
|
|
cmf->zz = axis->z * axis->z * rCos + cos;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-04-06 03:56:52 +00:00
|
|
|
if (0) {}
|
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
temp2 = axis->x * rCos * axis->y;
|
|
|
|
temp3 = axis->z * sin;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->yx = temp2 + temp3;
|
|
|
|
cmf->xy = temp2 - temp3;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
temp2 = axis->x * rCos * axis->z;
|
|
|
|
temp3 = axis->y * sin;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->zx = temp2 - temp3;
|
|
|
|
cmf->xz = temp2 + temp3;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
temp2 = axis->y * rCos * axis->z;
|
|
|
|
temp3 = axis->x * sin;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->zy = temp2 + temp3;
|
|
|
|
cmf->yz = temp2 - temp3;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->wx = cmf->wy = cmf->wz = cmf->xw = cmf->yw = cmf->zw = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->ww = 1.0f;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->yx = 0.0f;
|
|
|
|
cmf->zx = 0.0f;
|
|
|
|
cmf->wx = 0.0f;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->xy = 0.0f;
|
|
|
|
cmf->zy = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->wy = 0.0f;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->xz = 0.0f;
|
|
|
|
cmf->yz = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->wz = 0.0f;
|
2021-08-31 18:19:41 +00:00
|
|
|
cmf->xw = 0.0f;
|
|
|
|
cmf->yw = 0.0f;
|
|
|
|
cmf->zw = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
cmf->xx = 1.0f;
|
|
|
|
cmf->yy = 1.0f;
|
|
|
|
cmf->zz = 1.0f;
|
|
|
|
cmf->ww = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)) {
|
2020-04-16 21:36:12 +00:00
|
|
|
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",
|
2021-08-31 18:19:41 +00:00
|
|
|
file, line, "mf", mf->xx, mf->xy, mf->xz, mf->xw, mf->yx, mf->yy, mf->yz, mf->yw, mf->zx,
|
|
|
|
mf->zy, mf->zz, mf->zw, mf->wx, mf->wy, mf->wz, mf->ww);
|
2020-03-17 04:31:30 +00:00
|
|
|
Fault_AddHungupAndCrash(file, line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mf;
|
|
|
|
}
|
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
void Matrix_SetTranslateUniformScaleMtxF(MtxF* mf, f32 scale, f32 translateX, f32 translateY, f32 translateZ) {
|
2020-03-17 04:31:30 +00:00
|
|
|
mf->yx = 0.0f;
|
|
|
|
mf->zx = 0.0f;
|
2021-08-31 18:19:41 +00:00
|
|
|
mf->wx = 0.0f;
|
|
|
|
mf->xy = 0.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
mf->zy = 0.0f;
|
2021-08-31 18:19:41 +00:00
|
|
|
mf->wy = 0.0f;
|
|
|
|
mf->xz = 0.0f;
|
|
|
|
mf->yz = 0.0f;
|
|
|
|
mf->wz = 0.0f;
|
2022-01-10 23:28:01 +00:00
|
|
|
mf->xx = scale;
|
|
|
|
mf->yy = scale;
|
|
|
|
mf->zz = scale;
|
|
|
|
mf->xw = translateX;
|
|
|
|
mf->yw = translateY;
|
|
|
|
mf->zw = translateZ;
|
2020-03-17 04:31:30 +00:00
|
|
|
mf->ww = 1.0f;
|
|
|
|
}
|
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
void Matrix_SetTranslateUniformScaleMtx(Mtx* mtx, f32 scale, f32 translateX, f32 translateY, f32 translateZ) {
|
2020-03-17 04:31:30 +00:00
|
|
|
MtxF mf;
|
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
Matrix_SetTranslateUniformScaleMtxF(&mf, scale, translateX, translateY, translateZ);
|
2020-05-25 21:18:14 +00:00
|
|
|
guMtxF2L(&mf, mtx);
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
void Matrix_SetTranslateUniformScaleMtx2(Mtx* mtx, f32 scale, f32 translateX, f32 translateY, f32 translateZ) {
|
|
|
|
u16* intPart = (u16*)&mtx->m[0][0];
|
|
|
|
u16* fracPart = (u16*)&mtx->m[2][0];
|
|
|
|
u32 fixedPoint;
|
|
|
|
|
|
|
|
fixedPoint = (s32)(scale * 0x10000);
|
|
|
|
fracPart[0] = fixedPoint & 0xFFFF;
|
|
|
|
intPart[0] = (fixedPoint >> 16) & 0xFFFF;
|
|
|
|
|
|
|
|
fixedPoint = (s32)(scale * 0x10000);
|
|
|
|
intPart[5] = (fixedPoint >> 16) & 0xFFFF;
|
|
|
|
fracPart[5] = fixedPoint & 0xFFFF;
|
|
|
|
|
|
|
|
fixedPoint = (s32)(scale * 0x10000);
|
|
|
|
intPart[10] = (fixedPoint >> 16) & 0xFFFF;
|
|
|
|
fracPart[10] = fixedPoint & 0xFFFF;
|
|
|
|
|
|
|
|
fixedPoint = (s32)(translateX * 0x10000);
|
|
|
|
intPart[12] = (fixedPoint >> 16) & 0xFFFF;
|
|
|
|
fracPart[12] = fixedPoint & 0xFFFF;
|
|
|
|
|
|
|
|
fixedPoint = (s32)(translateY * 0x10000);
|
|
|
|
intPart[13] = (fixedPoint >> 16) & 0xFFFF;
|
|
|
|
fracPart[13] = fixedPoint & 0xFFFF;
|
|
|
|
|
|
|
|
fixedPoint = (s32)(translateZ * 0x10000);
|
|
|
|
intPart[14] = (fixedPoint >> 16) & 0xFFFF;
|
|
|
|
fracPart[14] = fixedPoint & 0xFFFF;
|
|
|
|
|
|
|
|
intPart[1] = 0;
|
|
|
|
intPart[2] = 0;
|
|
|
|
intPart[3] = 0;
|
|
|
|
intPart[4] = 0;
|
|
|
|
intPart[6] = 0;
|
|
|
|
intPart[7] = 0;
|
|
|
|
intPart[8] = 0;
|
|
|
|
intPart[9] = 0;
|
|
|
|
intPart[11] = 0;
|
|
|
|
intPart[15] = 1;
|
|
|
|
|
|
|
|
fracPart[1] = 0;
|
|
|
|
fracPart[2] = 0;
|
|
|
|
fracPart[3] = 0;
|
|
|
|
fracPart[4] = 0;
|
|
|
|
fracPart[6] = 0;
|
|
|
|
fracPart[7] = 0;
|
|
|
|
fracPart[8] = 0;
|
|
|
|
fracPart[9] = 0;
|
|
|
|
fracPart[11] = 0;
|
|
|
|
fracPart[15] = 0;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
void Matrix_SetTranslateScaleMtx1(Mtx* mtx, f32 scaleX, f32 scaleY, f32 scaleZ, f32 translateX, f32 translateY,
|
|
|
|
f32 translateZ) {
|
|
|
|
u16* intPart = (u16*)&mtx->m[0][0];
|
|
|
|
u16* fracPart = (u16*)&mtx->m[2][0];
|
|
|
|
u32 fixedPoint;
|
|
|
|
|
|
|
|
fixedPoint = (s32)(scaleX * 0x10000);
|
|
|
|
intPart[0] = (fixedPoint >> 16) & 0xFFFF;
|
|
|
|
fracPart[0] = fixedPoint & 0xFFFF;
|
|
|
|
|
|
|
|
fixedPoint = (s32)(scaleY * 0x10000);
|
|
|
|
intPart[5] = (fixedPoint >> 16) & 0xFFFF;
|
|
|
|
fracPart[5] = fixedPoint & 0xFFFF;
|
|
|
|
|
|
|
|
fixedPoint = (s32)(scaleZ * 0x10000);
|
|
|
|
intPart[10] = (fixedPoint >> 16) & 0xFFFF;
|
|
|
|
fracPart[10] = fixedPoint & 0xFFFF;
|
|
|
|
|
|
|
|
fixedPoint = (s32)(translateX * 0x10000);
|
|
|
|
intPart[12] = (fixedPoint >> 16) & 0xFFFF;
|
|
|
|
fracPart[12] = fixedPoint & 0xFFFF;
|
|
|
|
|
|
|
|
fixedPoint = (s32)(translateY * 0x10000);
|
|
|
|
intPart[13] = (fixedPoint >> 16) & 0xFFFF;
|
|
|
|
fracPart[13] = fixedPoint & 0xFFFF;
|
|
|
|
|
|
|
|
fixedPoint = (s32)(translateZ * 0x10000);
|
|
|
|
intPart[14] = (fixedPoint >> 16) & 0xFFFF;
|
|
|
|
fracPart[14] = fixedPoint & 0xFFFF;
|
|
|
|
|
|
|
|
intPart[1] = 0;
|
|
|
|
intPart[2] = 0;
|
|
|
|
intPart[3] = 0;
|
|
|
|
intPart[4] = 0;
|
|
|
|
intPart[6] = 0;
|
|
|
|
intPart[7] = 0;
|
|
|
|
intPart[8] = 0;
|
|
|
|
intPart[9] = 0;
|
|
|
|
intPart[11] = 0;
|
|
|
|
intPart[15] = 1;
|
|
|
|
|
|
|
|
fracPart[1] = 0;
|
|
|
|
fracPart[2] = 0;
|
|
|
|
fracPart[3] = 0;
|
|
|
|
fracPart[4] = 0;
|
|
|
|
fracPart[6] = 0;
|
|
|
|
fracPart[7] = 0;
|
|
|
|
fracPart[8] = 0;
|
|
|
|
fracPart[9] = 0;
|
|
|
|
fracPart[11] = 0;
|
|
|
|
fracPart[15] = 0;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
void Matrix_SetTranslateScaleMtx2(Mtx* mtx, f32 scaleX, f32 scaleY, f32 scaleZ, f32 translateX, f32 translateY,
|
|
|
|
f32 translateZ) {
|
2020-12-01 19:31:04 +00:00
|
|
|
Mtx_t* m = &mtx->m;
|
2022-01-10 23:28:01 +00:00
|
|
|
u16* intPart = (u16*)&(*m)[0][0];
|
|
|
|
u16* fracPart = (u16*)&(*m)[2][0];
|
|
|
|
u32 fixedPoint;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-01 19:31:04 +00:00
|
|
|
(*m)[0][1] = 0;
|
|
|
|
(*m)[2][1] = 0;
|
|
|
|
(*m)[0][3] = 0;
|
|
|
|
(*m)[2][3] = 0;
|
2022-02-22 00:01:28 +00:00
|
|
|
(*m)[1][0] = 0;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
fixedPoint = (s32)(scaleX * 0x10000);
|
|
|
|
(*m)[0][0] = fixedPoint;
|
|
|
|
intPart[1] = 0;
|
|
|
|
(*m)[2][0] = fixedPoint << 16;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
fixedPoint = (s32)(scaleY * 0x10000);
|
|
|
|
(*m)[0][2] = fixedPoint >> 16;
|
|
|
|
(*m)[2][2] = fixedPoint & 0xFFFF;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
fixedPoint = (s32)(scaleZ * 0x10000);
|
|
|
|
(*m)[1][1] = fixedPoint;
|
|
|
|
intPart[11] = 0;
|
|
|
|
(*m)[3][1] = fixedPoint << 16;
|
2020-12-01 19:31:04 +00:00
|
|
|
|
2022-02-22 00:01:28 +00:00
|
|
|
(*m)[3][0] = 0;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
fixedPoint = (s32)(translateX * 0x10000);
|
|
|
|
intPart[12] = (fixedPoint >> 16) & 0xFFFF;
|
|
|
|
fracPart[12] = fixedPoint & 0xFFFF;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
fixedPoint = (s32)(translateY * 0x10000);
|
|
|
|
intPart[13] = (fixedPoint >> 16) & 0xFFFF;
|
|
|
|
fracPart[13] = fixedPoint & 0xFFFF;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-01-10 23:28:01 +00:00
|
|
|
fixedPoint = (s32)(translateZ * 0x10000);
|
|
|
|
intPart[14] = (fixedPoint >> 16) & 0xFFFF;
|
|
|
|
intPart[15] = 1;
|
|
|
|
(*m)[3][3] = fixedPoint << 16;
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|