Skip to content

Commit eb0f548

Browse files
authored
Implement C_MTXReorder and C_MTXROMultVecArray (#84)
* Implement C_MTXReorder and C_MTXROMultVecArray * Fixes * Add necessary declarations to the header * Move around and fix declarations
1 parent 845aad4 commit eb0f548

3 files changed

Lines changed: 52 additions & 9 deletions

File tree

include/dolphin/mtx.h

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,48 @@ void C_MTXMultVec(const Mtx m, const Vec* src, Vec* dst);
8181
void C_MTXMultVecArray(const Mtx m, const Vec* srcBase, Vec* dstBase, u32 count);
8282
void C_MTXMultVecSR(const Mtx m, const Vec* src, Vec* dst);
8383
void C_MTXMultVecArraySR(const Mtx m, const Vec* srcBase, Vec* dstBase, u32 count);
84+
void C_MTXROMultVecArray(const ROMtx m, const Vec *srcBase, Vec *dstBase, u32 count);
8485

8586
#ifdef GEKKO
8687
void PSMTXMultVec(const Mtx m, const Vec* src, Vec* dst);
8788
void PSMTXMultVecArray(const Mtx m, const Vec* srcBase, Vec* dstBase, u32 count);
8889
void PSMTXMultVecSR(const Mtx m, const Vec* src, Vec* dst);
8990
void PSMTXMultVecArraySR(const Mtx m, const Vec* srcBase, Vec* dstBase, u32 count);
91+
void PSMTXMultS16VecArray(const Mtx m, const S16Vec* srcBase, Vec* dstBase, u32 count);
92+
93+
void PSMTXROMultVecArray(const ROMtx m, const Vec *srcBase, Vec *dstBase, u32 count);
94+
void PSMTXROSkin2VecArray(const ROMtx m0, const ROMtx m1, const f32* wtBase, const Vec* srcBase,
95+
Vec* dstBase, u32 count);
96+
void PSMTXROMultS16VecArray(const ROMtx m, const S16Vec* srcBase, Vec* dstBase, u32 count);
9097
#else
9198
#define PSMTXMultVec MTXMultVec
9299
#define PSMTXMultVecArray MTXMultVecArray
93100
#define PSMTXMultVecSR MTXMultVecSR
94101
#define PSMTXMultVecArraySR MTXMultVecArraySR
102+
#define PSMTXMultS16VecArray MTXMultS16VecArray
103+
104+
#define PSMTXROMultVecArray MTXROMultVecArray
105+
#define PSMTXROSkin2VecArray MTXROSkin2VecArray
106+
#define PSMTXROMultS16VecArray MTXROMultS16VecArray
95107
#endif
96108

97109
#ifdef MTX_USE_PS
98110
#define MTXMultVec PSMTXMultVec
99111
#define MTXMultVecArray PSMTXMultVecArray
100112
#define MTXMultVecSR PSMTXMultVecSR
101113
#define MTXMultVecArraySR PSMTXMultVecArraySR
114+
#define MTXMultS16VecArray PSMTXMultS16VecArray
115+
116+
#define MTXROMultVecArray PSMTXROMultVecArray
117+
#define MTXROSkin2VecArray PSMTXROSkin2VecArray
118+
#define MTXROMultS16VecArray PSMTXROMultS16VecArray
102119
#else // MTX_USE_C
103120
#define MTXMultVec C_MTXMultVec
104121
#define MTXMultVecArray C_MTXMultVecArray
105122
#define MTXMultVecSR C_MTXMultVecSR
106123
#define MTXMultVecArraySR C_MTXMultVecArraySR
124+
125+
#define MTXROMultVecArray C_MTXROMultVecArray
107126
#endif
108127

109128
void C_MTXQuat(Mtx m, const Quaternion* q);
@@ -118,6 +137,8 @@ void C_MTXRotRad(Mtx m, char axis, f32 rad);
118137
void C_MTXRotTrig(Mtx m, char axis, f32 sinA, f32 cosA);
119138
void C_MTXRotAxisRad(Mtx m, const Vec* axis, f32 rad);
120139

140+
void C_MTXReorder(const Mtx src, ROMtx dst);
141+
121142
#ifdef GEKKO
122143
void PSMTXQuat(Mtx m, const Quaternion* q);
123144
void PSMTXReflect(Mtx m, const Vec* p, const Vec* n);
@@ -130,6 +151,8 @@ void PSMTXScaleApply(const Mtx src, Mtx dst, f32 xS, f32 yS, f32 zS);
130151
void PSMTXRotRad(Mtx m, char axis, f32 rad);
131152
void PSMTXRotTrig(Mtx m, char axis, f32 sinA, f32 cosA);
132153
void PSMTXRotAxisRad(Mtx m, const Vec* axis, f32 rad);
154+
155+
void PSMTXReorder(const Mtx src, ROMtx dest);
133156
#else
134157
#define PSMTXQuat MTXQuat
135158
#define PSMTXReflect MTXReflect
@@ -143,6 +166,8 @@ void PSMTXRotAxisRad(Mtx m, const Vec* axis, f32 rad);
143166

144167
#define PSMTXRotRad MTXRotRad
145168
#define PSMTXRotAxisRad MTXRotAxisRad
169+
170+
#define PSMTXReorder MTXReorder
146171
#endif
147172

148173
#ifdef MTX_USE_PS
@@ -159,6 +184,8 @@ void PSMTXRotAxisRad(Mtx m, const Vec* axis, f32 rad);
159184
#define MTXRotDeg(m, axis, deg) PSMTXRotRad(m, axis, MTXDegToRad(deg))
160185
#define MTXRotAxisDeg(m, axis, deg) PSMTXRotAxisRad(m, axis, MTXDegToRad(deg))
161186

187+
#define MTXReorder PSMTXReorder
188+
162189
#else // MTX_USE_C
163190
#define MTXQuat C_MTXQuat
164191
#define MTXReflect C_MTXReflect
@@ -173,6 +200,8 @@ void PSMTXRotAxisRad(Mtx m, const Vec* axis, f32 rad);
173200
#define MTXRotDeg(m, axis, deg) C_MTXRotRad(m, axis, MTXDegToRad(deg))
174201
#define MTXRotAxisDeg(m, axis, deg) C_MTXRotAxisRad(m, axis, MTXDegToRad(deg))
175202

203+
#define MTXReorder C_MTXReorder
204+
176205
#endif
177206

178207
void C_MTXLookAt(Mtx m, const Point3d* camPos, const Vec* camUp, const Point3d* target);
@@ -336,15 +365,6 @@ void PSQUATInverse(const Quaternion* src, Quaternion* inv);
336365
#define QUATSquad C_QUATSquad
337366
#define QUATCompA C_QUATCompA
338367

339-
#ifdef GEKKO
340-
void PSMTXReorder(const Mtx src, ROMtx dest);
341-
void PSMTXROMultVecArray(const ROMtx m, const Vec* srcBase, Vec* dstBase, u32 count);
342-
void PSMTXROSkin2VecArray(const ROMtx m0, const ROMtx m1, const f32* wtBase, const Vec* srcBase,
343-
Vec* dstBase, u32 count);
344-
void PSMTXMultS16VecArray(const Mtx m, const S16Vec* srcBase, Vec* dstBase, u32 count);
345-
void PSMTXROMultS16VecArray(const ROMtx m, const S16Vec* srcBase, Vec* dstBase, u32 count);
346-
#endif
347-
348368
void MTXInitStack(MtxStack* sPtr, u32 numMtx);
349369
MtxPtr MTXPush(MtxStack* sPtr, const Mtx m);
350370
MtxPtr MTXPushFwd(MtxStack* sPtr, const Mtx m);

lib/dolphin/mtx/mtx.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,17 @@ void C_MTXRotAxisRad(Mtx m, const Vec* axis, f32 rad) {
505505
m[2][3] = 0;
506506
}
507507

508+
void C_MTXReorder(const Mtx src, ROMtx dst)
509+
{
510+
u32 i;
511+
u32 j;
512+
for (i = 0; i < 3; i++) {
513+
for (j = 0; j < 4; j++) {
514+
dst[j][i] = src[i][j];
515+
}
516+
}
517+
}
518+
508519
void C_MTXLookAt(Mtx m, const Point3d* camPos, const Vec* camUp, const Point3d* target) {
509520
Vec vLook;
510521
Vec vRight;

lib/dolphin/mtx/mtxvec.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,15 @@ void C_MTXMultVecArraySR(const Mtx m, const Vec* srcBase, Vec* dstBase, u32 coun
7373
}
7474
}
7575

76+
void C_MTXROMultVecArray(const ROMtx m, const Vec *srcBase, Vec *dstBase, u32 count)
77+
{
78+
u32 i;
79+
for (i = 0; i < count; i++) {
80+
const Vec* src = &srcBase[i];
81+
Vec* dst = &dstBase[i];
82+
83+
dst->x = m[0][0] * src->x + m[0][1] * src->y + m[0][2] * src->z;
84+
dst->y = m[1][0] * src->x + m[1][1] * src->y + m[1][2] * src->z;
85+
dst->z = m[2][0] * src->x + m[2][1] * src->y + m[2][2] * src->z;
86+
}
87+
}

0 commit comments

Comments
 (0)