summaryrefslogtreecommitdiff
path: root/include/m_Do/m_Do_mtx.h
blob: 4bca7e358fae74e9c46daec89a1adbb70b0c5059 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
#ifndef M_DO_M_DO_MTX_H
#define M_DO_M_DO_MTX_H

#include "SSystem/SComponent/c_sxyz.h"
#include "SSystem/SComponent/c_xyz.h"
#include "dolphin/mtx/mtxvec.h"
#include "dolphin/mtx/quat.h"
#include "dolphin/types.h"

void mDoMtx_XYZrotS(Mtx, s16, s16, s16);
void mDoMtx_XYZrotM(Mtx, s16, s16, s16);
void mDoMtx_ZXYrotS(Mtx, s16, s16, s16);
void mDoMtx_ZXYrotM(Mtx, s16, s16, s16);
void mDoMtx_ZrotS(Mtx, s16);
void mDoMtx_YrotS(Mtx, s16);
void mDoMtx_XrotS(Mtx, s16);
void mDoMtx_XrotM(Mtx, s16);
void mDoMtx_YrotM(Mtx, s16);
void mDoMtx_ZrotM(Mtx, s16);
void mDoMtx_MtxToRot(CMtxP, csXyz*);
void mDoMtx_lookAt(Mtx mtx, const Vec* param_1, const Vec* param_2, s16 param_3);
void mDoMtx_lookAt(Mtx mtx, const Vec* param_1, const Vec* param_2, const Vec* param_3,
                   s16 param_4);
void mDoMtx_concatProjView(f32 const (*param_0)[4], f32 const (*param_1)[4], f32 (*param_2)[4]);
void mDoMtx_ZrotM(Mtx mtx, s16 z);
bool mDoMtx_inverseTranspose(f32 const (*param_0)[4], f32 (*param_1)[4]);
void mDoMtx_QuatConcat(const Quaternion* param_0, const Quaternion* param_1, Quaternion* param_2);
void mDoMtx_concat(const Mtx a, const Mtx b, Mtx c);

inline void mDoMtx_multVecSR(const Mtx m, const Vec* src, Vec* dst) {
    MTXMultVecSR(m, src, dst);
}

inline void cMtx_concat(const Mtx a, const Mtx b, Mtx ab) {
    mDoMtx_concat(a, b, ab);
}

inline void cMtx_scale(Mtx m, f32 x, f32 y, f32 z) {
    MTXScale(m, x, y, z);
}

inline void mDoMtx_multVec(const Mtx m, const Vec* src, Vec* dst) {
    MTXMultVec(m, src, dst);
}

inline void mDoMtx_multVecArray(const Mtx m, const Vec* src, Vec* dst, u32 count) {
    MTXMultVecArray(m, src, dst, count);
}

inline void mDoMtx_copy(const Mtx src, Mtx dst) {
    MTXCopy(src, dst);
}

inline void mDoMtx_trans(Mtx m, f32 x, f32 y, f32 z) {
    MTXTrans(m, x, y, z);
}

inline void cMtx_XrotM(Mtx mtx, s16 x) {
    mDoMtx_XrotM(mtx, x);
}

inline void cMtx_YrotM(Mtx mtx, s16 y) {
    mDoMtx_YrotM(mtx, y);
}

inline void cMtx_ZrotM(Mtx mtx, s16 z) {
    mDoMtx_ZrotM(mtx, z);
}

inline void cMtx_XrotS(Mtx mtx, s16 x) {
    mDoMtx_XrotS(mtx, x);
}

inline void cMtx_YrotS(Mtx mtx, s16 y) {
    mDoMtx_YrotS(mtx, y);
}

inline void cMtx_ZrotS(Mtx mtx, s16 z) {
    mDoMtx_ZrotS(mtx, z);
}

inline void cMtx_lookAt(Mtx mtx, const Vec* param_1, const Vec* param_2, s16 param_3) {
    mDoMtx_lookAt(mtx, param_1, param_2, param_3);
}

inline void cMtx_multVec(const Mtx mtx, const Vec* src, Vec* dst) {
    mDoMtx_multVec(mtx, src, dst);
}

inline void cMtx_lookAt(Mtx mtx, const Vec* param_1, const Vec* param_2, const Vec* param_3, s16 param_4) {
    mDoMtx_lookAt(mtx, param_1, param_2, param_3, param_4);
}

inline void cMtx_copy(CMtxP src, MtxP dst) {
    mDoMtx_copy(src, dst);
}

inline void cMtx_multVecArray(Mtx mtx, const Vec* src, Vec* dst, u32 count) {
    mDoMtx_multVecArray(mtx, src, dst, count);
}

inline void mDoMtx_multVecZero(CMtxP param_0, Vec* param_1) {
    param_1->x = param_0[0][3];
    param_1->y = param_0[1][3];
    param_1->z = param_0[2][3];
}

inline void cMtx_multVecSR(const Mtx m, const Vec* src, Vec* dst) {
    mDoMtx_multVecSR(m, src, dst);
}

inline void mDoMtx_quatMultiply(const Quaternion* a, const Quaternion* b, Quaternion* ab) {
    QUATMultiply(a,b,ab);
}

inline void mDoMtx_quatSlerp(const Quaternion* a, const Quaternion* b, Quaternion* ab, f32 param_4) {
    C_QUATSlerp(a,b,ab,param_4);
}

inline void mDoMtx_quatRotAxisRad(Quaternion* q, const Vec* axis, f32 rad) {
    C_QUATRotAxisRad(q, axis, rad);
}

inline void mDoMtx_identity(Mtx m) {
    MTXIdentity(m);
}

inline void mDoMtx_concat(const Mtx a, const Mtx b, Mtx c) {
    MTXConcat(a, b, c);
}

inline void mDoMtx_inverse(const Mtx a, Mtx b) {
    MTXInverse(a, b);
}

inline void mDoMtx_scale(Mtx m, f32 x, f32 y, f32 z) {
    MTXScale(m, x, y, z);
}

inline void mDoMtx_quat(Mtx m, const Quaternion* q) {
    MTXQuat(m, q);
}

inline void cMtx_inverse(const Mtx a, Mtx b) {
    mDoMtx_inverse(a, b);
}

inline void cMtx_inverseTranspose(const Mtx a, Mtx b) {
    mDoMtx_inverseTranspose(a, b);
}

inline void cMtx_concatProjView(const Mtx a, const Mtx b, Mtx c) {
    mDoMtx_concatProjView(a, b, c);
}

class mDoMtx_stack_c {
public:
    mDoMtx_stack_c() {
        next = buffer;
        end = buffer + 16;
    }

    ~mDoMtx_stack_c() {}

    static bool push();
    static bool pop();
    static void lYrotM(s32);
    static void rYrotM(f32);

    /**
     * Translates the `now` Matrix by the given cXyz
     * @param xyz The xyz translation vector
     */
    static inline void transS(const cXyz& xyz) { transS(xyz.x, xyz.y, xyz.z); }

    /**
     * Translates a new Matrix by the given cXyz and then concatenates it with the `now` matrix
     * @param xyz The xyz translation vector
     */
    static inline void transM(const cXyz& xyz) { transM(xyz.x, xyz.y, xyz.z); }

    /**
     * Translates a new Matrix by the given X, Y, and Z values and then concatenates it with the `now` matrix
     * @param x The x-axis translation value
     * @param y The y-axis translation value
     * @param z The z-axis translation value
     */
    static void transM(f32 x, f32 y, f32 z);

    /**
     * Scales the `now` Matrix by the given cXyz
     * @param xyz The xyz scale vector
     */
    static void scaleS(const cXyz& xyz);

    /**
     * Scales a new Matrix by the given cXyz and then concatenates it with the `now` matrix
     * @param xyz The xyz scale vector
     */
    static void scaleM(const cXyz& xyz) { scaleM(xyz.x, xyz.y, xyz.z); }

    /**
     * Scales a new Matrix by the given X, Y, and Z values and then concatenates it with the `now` matrix
     * @param x The x-axis scale value
     * @param y The y-axis scale value
     * @param z The z-axis scale value
     */
    static void scaleM(f32 x, f32 y, f32 z);

    static void XYZrotS(const csXyz& xyz);

    /**
     * Rotates the `now` matrix by the given csXyz in the order X, Y, Z
     * @param xyz The xyz rotation vector
     */
    static void XYZrotM(const csXyz& xyz) { XYZrotM(xyz.x, xyz.y, xyz.z); }

    static void ZXYrotS(const csXyz& xyz) { ZXYrotS(xyz.x, xyz.y, xyz.z); }

    /**
     * Rotates the `now` matrix by the given csXyz in the order Z, X, Y
     * @param xyz The xyz rotation vector
     */
    static void ZXYrotM(const csXyz& xyz) { ZXYrotM(xyz.x, xyz.y, xyz.z); }

    static void quatM(const Quaternion*);

    static void quatS(const Quaternion* quat) { MTXQuat(now, quat); }

    /**
     * Returns the `now` Matrix
     * @return The `now` Matrix
     */
    static MtxP get() { return now; }

    /**
     * Translates the `now` Matrix by the given X, Y, and Z values
     * @param x The x-axis translation value
     * @param y The y-axis translation value
     * @param z The z-axis translation value
     */
    static void transS(f32 x, f32 y, f32 z) { MTXTrans(now, x, y, z); }

    /**
     * Scales the `now` Matrix by the given X, Y, and Z values
     * @param x The x-axis scale value
     * @param y The y-axis scale value
     * @param z The z-axis scale value
     */
    static void scaleS(f32 x, f32 y, f32 z) { MTXScale(now, x, y, z); }

    /**
     * Multiplies a given Vec `a` by the `now` Matrix and places the result into Vec `b`
     * @param a The source Vec
     * @param b The output Vec
     */
    static void multVec(const Vec* a, Vec* b) { MTXMultVec(now, a, b); }

    /**
     * Multiplies a given Vec `a` by the `now` Matrix's "Scale-and-Rotate" component and places the result into Vec `b`
     * @param a The source Vec
     * @param b The output Vec
     */
    static void multVecSR(const Vec* a, Vec* b) { MTXMultVecSR(now, a, b); }

    static void multVecZero(Vec* v) { mDoMtx_multVecZero(now, v); }

    /**
     * Multiplies a given Vec array `src` by the `now` Matrix and places the result into Vec array `dst`
     * @param src The source Vec array
     * @param dst The output Vec array
     * @param count The size of the array
     */
    static void multVecArray(const Vec* src, Vec* dst, u32 count) {
        MTXMultVecArray(now, src, dst, count);
    }

    static void XYZrotS(s16 x, s16 y, s16 z) { mDoMtx_XYZrotS(now, x, y, z); }

    /**
     * Rotates the `now` matrix by the given X, Y, and Z values in the order X, Y, Z
     * @param x The x-axis rotation value
     * @param y The y-axis rotation value
     * @param z The z-axis rotation value
     */
    static void XYZrotM(s16 x, s16 y, s16 z) { mDoMtx_XYZrotM(now, x, y, z); }

    static void ZXYrotS(s16 x, s16 y, s16 z) { mDoMtx_ZXYrotS(now, x, y, z); }

    /**
     * Rotates the `now` matrix by the given X, Y, and Z values in the order Z, X, Y
     * @param x The x-axis rotation value
     * @param y The y-axis rotation value
     * @param z The z-axis rotation value
     */
    static void ZXYrotM(s16 x, s16 y, s16 z) { mDoMtx_ZXYrotM(now, x, y, z); }

    /**
     * Rotates the `now` matrix on the X-axis
     * @param x The rotation value
     */
    static void XrotS(s16 x) { mDoMtx_XrotS(now, x); }

    /**
     * Rotates a new matrix on the X-axis then concatenates it with the `now` matrix
     * @param x The rotation value
     */
    static void XrotM(s16 x) { mDoMtx_XrotM(now, x); }

    /**
     * Rotates a new matrix on the Y-axis then concatenates it with the `now` matrix
     * @param y The rotation value
     */
    static void YrotM(s16 y) { mDoMtx_YrotM(now, y); }

    /**
     * Rotates the `now` matrix on the Y-axis
     * @param y The rotation value
     */
    static void YrotS(s16 y) { mDoMtx_YrotS(now, y); }

    /**
     * Rotates a new matrix on the z-axis then concatenates it with the `now` matrix
     * @param z The rotation value
     */
    static void ZrotM(s16 z) { mDoMtx_ZrotM(now, z); }

    /**
     * Rotates the `now` matrix on the Z-axis
     * @param z The rotation value
     */
    static void ZrotS(s16 z) { mDoMtx_ZrotS(now, z); }

    static void inverse() { MTXInverse(now, now); }

    static void inverseTranspose() { mDoMtx_inverseTranspose(now, now); }

    /**
     * Concatenates the `now` matrix with the given Matrix `m`
     * @param m The matrix to concatenate with `now`
     */
    static void concat(const Mtx m) { MTXConcat(now, m, now); }

    static void revConcat(const Mtx m) { MTXConcat(m, now, now); }

    /**
     * Copies a given matrix `m` to the `now` matrix
     * @param m The source matrix to copy
     */
    static void copy(const Mtx m) { MTXCopy(m, now); }

    static void rotAxisRadS(const Vec* axis, f32 rad) {
        MTXRotAxisRad(now, axis, rad);
    }

    // TODO
    static void rYrotS(f32) {}

    static Mtx now;
    static Mtx buffer[16];
    static Mtx* next;
    static Mtx* end;
};

extern Mtx g_mDoMtx_identity;

inline MtxP mDoMtx_getIdentity() {
    return g_mDoMtx_identity;
}

inline MtxP cMtx_getIdentity() {
    return mDoMtx_getIdentity();
}

class mDoMtx_quatStack_c {
public:
    mDoMtx_quatStack_c() {
        field_0x0 = &field_0x4;
        field_0x114 = field_0x14;
        field_0x118 = &field_0x114;
    }

    ~mDoMtx_quatStack_c() {}

    inline static Quaternion* get();

    static void rotAxisRadS(const Vec* axis, f32 rad) {
        QUATRotAxisRad(get(), axis, rad);
    }

    /* 0x000 */ Quaternion* field_0x0;
    /* 0x004 */ Quaternion field_0x4;
    /* 0x014 */ Quaternion field_0x14[16];
    /* 0x114 */ Quaternion* field_0x114;
    /* 0x118 */ Quaternion** field_0x118;
};  // Size: 0x11C

extern mDoMtx_quatStack_c mDoMtx_quatStack;

Quaternion* mDoMtx_quatStack_c::get() { return mDoMtx_quatStack.field_0x0; }

#endif /* M_DO_M_DO_MTX_H */