sys_matrix OK, documented, rename some other mathematics functions (#787)

* Import data and bss, add some name options

* Decomp rest of stack functions,
remove RSPMatrix,
split header

* sys_matrix OK (thanks Tharo)

Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com>

* pragma weaks in sinf and cosf, change documentation
change mcros to use 0x8000

* Rename sinf and cosf

* Correct initialisation of sMtxFClear

* More minor cleanup

* Rename stack functions

* Matrix_InsertMatrix -> Matrix_Mult

* The big transpose rename

* Fix MirRay_DrawReflectedBeam

* Matrix_InsertTranslation -> Matrix_Translate

* Matrix_Insert.Rotation_s -> Matrix_Rotate$1S
+ RotateY -> RotateYS

* Matrix_Insert(.)Rotation_f -> Matrix_Rotate$1F

* Matrix_RotateStateAroundXAxis -> Matrix_RotateXFApply
Matrix_SetStateXRotation -> Matrix_RotateXFNew

* Matrix_MultiplyVector3fByState -> Matrix_MultVec3f

* Matrix_MultiplyVector3fXZByCurrentState -> Matrix_MultVec3fXZ

* Matrix_GetStateTranslation -> Matrix_MultZero

* Matrix_GetStateTranslationAndScaled(.) -> Matrix_MultVec$1

* Matrix_FromRSPMatrix -> Matrix_MtxToMtxF

* Matrix_MultiplyVector3fByMatrix -> Matrix_MultVec3fExt

* Matrix_TransposeXYZ -> Matrix_Transpose

* Matrix_ToRSPMatrix -> Matrix_MtxFToMtx

* Matrix_AppendToPolyOpaDisp -> Matrix_MtxFToNewMtx
and document the conversion functions

* Matrix_NormalizeXYZ -> Matrix_ReplaceRotation

* Matrix_InsertRotationAroundUnitVector_f -> Matrix_RotateAxisF and S

* Matrix_InsertRotation -> Matrix_RotateZYX

* Document the last functions

* Small cleanup

* Matrix_JointPosition -> Matrix_TranslateRotateZYX

* Matrix_SetStateRotationAndTranslation -> Matrix_SetTranslateRotateYXZ

* func_8018219C -> Matrix_MtxFToYXZRot

* func_801822C4 -> Matrix_MtxFToZYXRot

* Fix files

* Format

* Review 1

* Renames

* Fix warning in EnDragon

* Format

* Convert `mode` to an actual enum

* Add enums, typedefs, externs to sys_matrix header

* Review

* One more

* More review

* Fix function names

* Format

* Fix names

* Format

* Review

* engineer's review

* Fix build

* Format

* Fix again

Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com>
This commit is contained in:
EllipticEllipsis
2022-05-26 04:24:39 +01:00
committed by GitHub
parent e1477702ca
commit 8049dec339
303 changed files with 5474 additions and 3324 deletions
+317 -48
View File
@@ -1347,60 +1347,329 @@ typedef union {
long int force_structure_alignment[4];
} Hilite;
#define gdSPDefLights0(ar,ag,ab) \
{ {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \
{{{ { 0, 0, 0},0,{ 0, 0, 0},0,{ 0, 0, 0},0}}} }
#define gdSPDefLights1(ar,ag,ab,r1,g1,b1,x1,y1,z1) \
{ {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \
{{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}} }
#define gdSPDefLights2(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2) \
{ {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \
{{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \
{{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}} }
#define gdSPDefLights3(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3) \
{ {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \
{{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \
{{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \
{{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}} }
#define gdSPDefLights4(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3,r4,g4,b4,x4,y4,z4) \
{ {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \
{{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \
{{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \
{{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}, \
{{ {r4,g4,b4},0,{r4,g4,b4},0,{x4,y4,z4},0}}} }
#define gdSPDefLights5(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3,r4,g4,b4,x4,y4,z4,r5,g5,b5,x5,y5,z5) \
{ {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \
{{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \
{{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \
{{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}, \
{{ {r4,g4,b4},0,{r4,g4,b4},0,{x4,y4,z4},0}}, \
{{ {r5,g5,b5},0,{r5,g5,b5},0,{x5,y5,z5},0}}} }
#define gdSPDefLights0(ar,ag,ab) \
{ \
{{ \
{ ar, ag, ab }, 0, \
{ ar, ag, ab }, 0 \
}}, \
{ \
{{ \
{ 0, 0, 0 }, 0, \
{ 0, 0, 0 }, 0, \
{ 0, 0, 0 }, 0 \
}} \
} \
}
#define gdSPDefLights1(ar,ag,ab, \
r1,g1,b1, \
x1,y1,z1) \
{ \
{{ \
{ ar, ag, ab }, 0, \
{ ar, ag, ab }, 0 \
}}, \
{ \
{{ \
{ r1, g1, b1 }, 0, \
{ r1, g1, b1 }, 0, \
{ x1, y1, z1 }, 0 \
}} \
} \
}
#define gdSPDefLights6(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3,r4,g4,b4,x4,y4,z4,r5,g5,b5,x5,y5,z5,r6,g6,b6,x6,y6,z6) \
{ {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \
{{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \
{{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \
{{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}, \
{{ {r4,g4,b4},0,{r4,g4,b4},0,{x4,y4,z4},0}}, \
{{ {r5,g5,b5},0,{r5,g5,b5},0,{x5,y5,z5},0}}, \
{{ {r6,g6,b6},0,{r6,g6,b6},0,{x6,y6,z6},0}}} }
#define gdSPDefLights2(ar,ag,ab, \
r1,g1,b1, \
x1,y1,z1, \
r2,g2,b2, \
x2,y2,z2) \
{ \
{{ \
{ ar, ag, ab }, 0, \
{ ar, ag, ab }, 0 \
}}, \
{ \
{{ \
{ r1, g1, b1 }, 0, \
{ r1, g1, b1 }, 0, \
{ x1, y1, z1 }, 0 \
}}, \
{{ \
{ r2, g2, b2 }, 0, \
{ r2, g2, b2 }, 0, \
{ x2, y2, z2 }, 0 \
}} \
} \
}
#define gdSPDefLights3(ar,ag,ab, \
r1,g1,b1, \
x1,y1,z1, \
r2,g2,b2, \
x2,y2,z2, \
r3,g3,b3, \
x3,y3,z3) \
{ \
{{ \
{ ar, ag, ab }, 0, \
{ ar, ag, ab }, 0 \
}}, \
{ \
{{ \
{ r1, g1, b1 }, 0, \
{ r1, g1, b1 }, 0, \
{ x1, y1, z1 }, 0 \
}}, \
{{ \
{ r2, g2, b2 }, 0, \
{ r2, g2, b2 }, 0, \
{ x2, y2, z2 }, 0 \
}}, \
{{ \
{ r3, g3, b3 }, 0, \
{ r3, g3, b3 }, 0, \
{ x3, y3, z3 }, 0 \
}} \
} \
}
#define gdSPDefLights7(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3,r4,g4,b4,x4,y4,z4,r5,g5,b5,x5,y5,z5,r6,g6,b6,x6,y6,z6,r7,g7,b7,x7,y7,z7) \
{ {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \
{{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \
{{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \
{{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}, \
{{ {r4,g4,b4},0,{r4,g4,b4},0,{x4,y4,z4},0}}, \
{{ {r5,g5,b5},0,{r5,g5,b5},0,{x5,y5,z5},0}}, \
{{ {r6,g6,b6},0,{r6,g6,b6},0,{x6,y6,z6},0}}, \
{{ {r7,g7,b7},0,{r7,g7,b7},0,{x7,y7,z7},0}}} }
#define gdSPDefLights4(ar,ag,ab, \
r1,g1,b1, \
x1,y1,z1, \
r2,g2,b2, \
x2,y2,z2, \
r3,g3,b3, \
x3,y3,z3, \
r4,g4,b4, \
x4,y4,z4) \
{ \
{{ \
{ ar, ag, ab }, 0, \
{ ar, ag, ab }, 0 \
}}, \
{ \
{{ \
{ r1, g1, b1 }, 0, \
{ r1, g1, b1 }, 0, \
{ x1, y1, z1 }, 0 \
}}, \
{{ \
{ r2, g2, b2 }, 0, \
{ r2, g2, b2 }, 0, \
{ x2, y2, z2 }, 0 \
}}, \
{{ \
{ r3, g3, b3 }, 0, \
{ r3, g3, b3 }, 0, \
{ x3, y3, z3 }, 0 \
}}, \
{{ \
{ r4, g4, b4 }, 0, \
{ r4, g4, b4 }, 0, \
{ x4, y4, z4 }, 0 \
}} \
} \
}
#define gdSPDefLights5(ar,ag,ab, \
r1,g1,b1, \
x1,y1,z1, \
r2,g2,b2, \
x2,y2,z2, \
r3,g3,b3, \
x3,y3,z3, \
r4,g4,b4, \
x4,y4,z4, \
r5,g5,b5, \
x5,y5,z5) \
{ \
{{ \
{ ar, ag, ab }, 0, \
{ ar, ag, ab }, 0 \
}}, \
{ \
{{ \
{ r1, g1, b1 }, 0, \
{ r1, g1, b1 }, 0, \
{ x1, y1, z1 }, 0 \
}}, \
{{ \
{ r2, g2, b2 }, 0, \
{ r2, g2, b2 }, 0, \
{ x2, y2, z2 }, 0 \
}}, \
{{ \
{ r3, g3, b3 }, 0, \
{ r3, g3, b3 }, 0, \
{ x3, y3, z3 }, 0 \
}}, \
{{ \
{ r4, g4, b4 }, 0, \
{ r4, g4, b4 }, 0, \
{ x4, y4, z4 }, 0 \
}}, \
{{ \
{ r5, g5, b5 }, 0, \
{ r5, g5, b5 }, 0, \
{ x5, y5, z5 }, 0 \
}} \
} \
}
#define gdSPDefLookAt(rightx,righty,rightz,upx,upy,upz) \
{ {{ {{0,0,0},0,{0,0,0},0,{rightx,righty,rightz},0}}, \
{ {{0,0x80,0},0,{0,0x80,0},0,{upx,upy,upz},0}}} }
#define gdSPDefLights6(ar,ag,ab, \
r1,g1,b1, \
x1,y1,z1, \
r2,g2,b2, \
x2,y2,z2, \
r3,g3,b3, \
x3,y3,z3, \
r4,g4,b4, \
x4,y4,z4, \
r5,g5,b5, \
x5,y5,z5, \
r6,g6,b6, \
x6,y6,z6) \
{ \
{{ \
{ ar, ag, ab }, 0, \
{ ar, ag, ab }, 0 \
}}, \
{ \
{{ \
{ r1, g1, b1 }, 0, \
{ r1, g1, b1 }, 0, \
{ x1, y1, z1 }, 0 \
}}, \
{{ \
{ r2, g2, b2 }, 0, \
{ r2, g2, b2 }, 0, \
{ x2, y2, z2 }, 0 \
}}, \
{{ \
{ r3, g3, b3 }, 0, \
{ r3, g3, b3 }, 0, \
{ x3, y3, z3 }, 0 \
}}, \
{{ \
{ r4, g4, b4 }, 0, \
{ r4, g4, b4 }, 0, \
{ x4, y4, z4 }, 0 \
}}, \
{{ \
{ r5, g5, b5 }, 0, \
{ r5, g5, b5 }, 0, \
{ x5, y5, z5 }, 0 \
}}, \
{{ \
{ r6, g6, b6 }, 0, \
{ r6, g6, b6 }, 0, \
{ x6, y6, z6 }, 0 \
}} \
} \
}
#define gdSPDefLights7(ar,ag,ab, \
r1,g1,b1, \
x1,y1,z1, \
r2,g2,b2, \
x2,y2,z2, \
r3,g3,b3, \
x3,y3,z3, \
r4,g4,b4, \
x4,y4,z4, \
r5,g5,b5, \
x5,y5,z5, \
r6,g6,b6, \
x6,y6,z6, \
r7,g7,b7, \
x7,y7,z7) \
{ \
{{ \
{ ar, ag, ab }, 0, \
{ ar, ag, ab }, 0 \
}}, \
{ \
{{ \
{ r1, g1, b1 }, 0, \
{ r1, g1, b1 }, 0, \
{ x1, y1, z1 }, 0 \
}}, \
{{ \
{ r2, g2, b2 }, 0, \
{ r2, g2, b2 }, 0, \
{ x2, y2, z2 }, 0 \
}}, \
{{ \
{ r3, g3, b3 }, 0, \
{ r3, g3, b3 }, 0, \
{ x3, y3, z3 }, 0 \
}}, \
{{ \
{ r4, g4, b4 }, 0, \
{ r4, g4, b4 }, 0, \
{ x4, y4, z4 }, 0 \
}}, \
{{ \
{ r5, g5, b5 }, 0, \
{ r5, g5, b5 }, 0, \
{ x5, y5, z5 }, 0 \
}}, \
{{ \
{ r6, g6, b6 }, 0, \
{ r6, g6, b6 }, 0, \
{ x6, y6, z6 }, 0 \
}}, \
{{ \
{ r7, g7, b7 }, 0, \
{ r7, g7, b7 }, 0, \
{ x7, y7, z7 }, 0 \
}} \
} \
}
#define gdSPDefLookAt(rightx,righty,rightz,upx,upy,upz) \
{{ \
{{ \
{ 0, 0, 0 }, 0, \
{ 0, 0, 0 }, 0, \
{ rightx, righty, rightz }, 0 \
}}, \
{{ \
{ 0, 0x80, 0 }, 0, \
{ 0, 0x80, 0 }, 0, \
{ upx, upy, upz }, 0 \
}} \
}}
#define qs1616(e) ((s32)((e) * 0x00010000))
#define IPART(x) ((qs1616(x) >> 16) & 0xFFFF)
#define FPART(x) (qs1616(x) & 0xFFFF)
#define gdSPDefMtx( \
xx, yx, zx, wx, \
xy, yy, zy, wy, \
xz, yz, zz, wz, \
xw, yw, zw, ww) \
{{ \
(IPART(xx) << 0x10) | IPART(xy), \
(IPART(xz) << 0x10) | IPART(xw), \
(IPART(yx) << 0x10) | IPART(yy), \
(IPART(yz) << 0x10) | IPART(yw), \
(IPART(zx) << 0x10) | IPART(zy), \
(IPART(zz) << 0x10) | IPART(zw), \
(IPART(wx) << 0x10) | IPART(wy), \
(IPART(wz) << 0x10) | IPART(ww), \
(FPART(xx) << 0x10) | FPART(xy), \
(FPART(xz) << 0x10) | FPART(xw), \
(FPART(yx) << 0x10) | FPART(yy), \
(FPART(yz) << 0x10) | FPART(yw), \
(FPART(zx) << 0x10) | FPART(zy), \
(FPART(zz) << 0x10) | FPART(zw), \
(FPART(wx) << 0x10) | FPART(wy), \
(FPART(wz) << 0x10) | FPART(ww), \
}}
/*
* Graphics DMA Packet
+8 -4
View File
@@ -27,6 +27,10 @@ typedef void* TexturePtr;
typedef long int Mtx_t[4][4];
typedef union {
Mtx_t m;
struct {
u16 intPart[4][4];
u16 fracPart[4][4];
};
long long int forc_structure_alignment;
} Mtx; // size = 0x40
@@ -34,10 +38,10 @@ typedef float MtxF_t[4][4];
typedef union {
MtxF_t mf;
struct {
float xx, xy, xz, xw,
yx, yy, yz, yw,
zx, zy, zz, zw,
wx, wy, wz, ww;
float xx, yx, zx, wx,
xy, yy, zy, wy,
xz, yz, zz, wz,
xw, yw, zw, ww;
};
} MtxF; // size = 0x40