From 958c31ef1c31fb7a63d68c7c01ddc38359df9816 Mon Sep 17 00:00:00 2001 From: TakaRikka Date: Sun, 10 Sep 2023 22:57:00 -0700 Subject: [PATCH] m_Do_hostIO OK, m_Do_mtx work --- configure.py | 4 +- include/MSL_C/math.h | 25 ++- include/m_Do/m_Do_hostIO.h | 25 ++- include/m_Do/m_Do_mtx.h | 335 +++++++++++++++++++++++++++++++++++++ src/m_Do/m_Do_hostIO.cpp | 62 +++---- src/m_Do/m_Do_mtx.cpp | 182 ++++++++++++++------ 6 files changed, 534 insertions(+), 99 deletions(-) create mode 100644 include/m_Do/m_Do_mtx.h diff --git a/configure.py b/configure.py index 6f3cdf734..3588f3763 100644 --- a/configure.py +++ b/configure.py @@ -100,7 +100,7 @@ "-maxerrors 1", "-nosyspath", "-RTTI off", - "-fp_contract on", + # "-fp_contract on", "-str reuse", "-multibyte", "-i include", @@ -315,6 +315,8 @@ def ActorRel(rel_name, status): # machine NonMatching("m_Do/m_Do_main.cpp"), NonMatching("m_Do/m_Do_controller_pad.cpp"), + Matching ("m_Do/m_Do_hostIO.cpp"), + NonMatching("m_Do/m_Do_mtx.cpp"), # dolzel Matching ("d/d_com_lib_game.cpp"), diff --git a/include/MSL_C/math.h b/include/MSL_C/math.h index 3bc06a35e..ac76223e0 100644 --- a/include/MSL_C/math.h +++ b/include/MSL_C/math.h @@ -57,20 +57,19 @@ inline double sqrt_step(double tmpd, float mag) { return tmpd * 0.5 * (3.0 - mag * (tmpd * tmpd)); } -inline float sqrtf(float mag) { - if (mag > 0.0f) { - double tmpd = __frsqrte(mag); - tmpd = sqrt_step(tmpd, mag); - tmpd = sqrt_step(tmpd, mag); - tmpd = sqrt_step(tmpd, mag); - return mag * tmpd; - } else if (mag < 0.0) { - return NAN; - } else if (fpclassify(mag) == 1) { - return NAN; - } else { - return mag; +extern inline float sqrtf(float x) { + static const double _half = .5; + static const double _three = 3.0; + volatile float y; + if (x > 0.0f) { + double guess = __frsqrte((double)x); // returns an approximation to + guess = _half * guess * (_three - guess * guess * x); // now have 12 sig bits + guess = _half * guess * (_three - guess * guess * x); // now have 24 sig bits + guess = _half * guess * (_three - guess * guess * x); // now have 32 sig bits + y = (float)(x * guess); + return y; } + return x; } inline float atan2f(float y, float x) { diff --git a/include/m_Do/m_Do_hostIO.h b/include/m_Do/m_Do_hostIO.h index 714b20637..f06020ff9 100644 --- a/include/m_Do/m_Do_hostIO.h +++ b/include/m_Do/m_Do_hostIO.h @@ -7,27 +7,36 @@ struct JORReflexible; class mDoHIO_child_c { public: - char mName[24]; - u8 field1_0x18; - u8 field2_0x19; - u8 field3_0x1a; - u8 field4_0x1b; - JORReflexible* mReflexible; + mDoHIO_child_c() { + field_0x18 = 0; + mReflexible = NULL; + } + + ~mDoHIO_child_c() {} + + /* 0x00 */ char mName[24]; + /* 0x18 */ u8 field_0x18; + /* 0x1C */ JORReflexible* mReflexible; }; class mDoHIO_subRoot_c { public: virtual ~mDoHIO_subRoot_c() {} + s8 createChild(const char*, JORReflexible*); + void deleteChild(s8); + private: - mDoHIO_child_c mChild[64]; + /* 0x4 */ mDoHIO_child_c mChild[64]; }; -class mDoHIO_root_c : public mDoHIO_subRoot_c { +class mDoHIO_root_c { public: virtual ~mDoHIO_root_c() {} void update(); + + /* 0x0 */ mDoHIO_subRoot_c m_subroot; }; class mDoHIO_entry_c { diff --git a/include/m_Do/m_Do_mtx.h b/include/m_Do/m_Do_mtx.h new file mode 100644 index 000000000..cee5152f5 --- /dev/null +++ b/include/m_Do/m_Do_mtx.h @@ -0,0 +1,335 @@ +#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/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 param_0, Vec const* param_1, Vec const* param_2, s16 param_3); +void mDoMtx_lookAt(Mtx param_0, Vec const* param_1, Vec const* param_2, Vec const* 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); +void mDoMtx_inverseTranspose(f32 const (*param_0)[4], f32 (*param_1)[4]); +void mDoMtx_QuatConcat(Quaternion const* param_0, Quaternion const* param_1, Quaternion* param_2); + +inline void mDoMtx_multVecSR(Mtx m, const Vec* src, Vec* dst) { + MTXMultVecSR(m, src, dst); +} + +inline void cMtx_concat(const Mtx a, const Mtx b, Mtx ab) { + MTXConcat(a, b, ab); +} + +inline void cMtx_scale(Mtx m, f32 x, f32 y, f32 z) { + MTXScale(m, x, y, z); +} + +inline void mDoMtx_multVec(Mtx m, const Vec* src, Vec* dst) { + MTXMultVec(m, src, dst); +} + +inline void mDoMtx_multVecArray(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_lookAt(Mtx param_0, const Vec* param_1, const Vec* param_2, s16 param_3) { + mDoMtx_lookAt(param_0, param_1, param_2, param_3); +} + +inline void cMtx_multVec(Mtx mtx, const Vec* src, Vec* dst) { + mDoMtx_multVec(mtx, src, dst); +} + +inline void cMtx_lookAt(Mtx param_0, const Vec* param_1, const Vec* param_2, const Vec* param_3, s16 param_4) { + mDoMtx_lookAt(param_0,param_1,param_2,param_3,param_4); +} + +inline void cMtx_copy(const Mtx src, Mtx 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(MtxP 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 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_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 cMtx_inverse(const Mtx a, Mtx b) { + mDoMtx_inverse(a, b); +} + +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 + */ + /* 8000CD64 */ static void transS(cXyz const& xyz); + + /** + * Translates a new Matrix by the given cXyz and then concatenates it with the `now` matrix + * @param xyz The xyz translation vector + */ + /* 8000CDD4 */ static void transM(cXyz const& xyz); + + /** + * 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 + */ + /* 8000CD9C */ static void transM(f32 x, f32 y, f32 z); + + /** + * Scales the `now` Matrix by the given cXyz + * @param xyz The xyz scale vector + */ + /* 8000CE00 */ static void scaleS(cXyz const& xyz); + + /** + * Scales a new Matrix by the given cXyz and then concatenates it with the `now` matrix + * @param xyz The xyz scale vector + */ + /* 8000CE70 */ static void scaleM(cXyz const& xyz); + + /** + * 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 + */ + /* 8000CE38 */ static void scaleM(f32 x, f32 y, f32 z); + + /* 8000CE9C */ static void XYZrotS(csXyz const& xyz); + + /** + * Rotates the `now` matrix by the given csXyz in the order Z, Y, X + * @param xyz The xyz rotation vector + */ + /* 8000CED4 */ static void XYZrotM(csXyz const& xyz); + + /* 8000CF0C */ static void ZXYrotS(csXyz const& xyz); + + /** + * Rotates the `now` matrix by the given csXyz in the order X, Y, Z + * @param xyz The xyz rotation vector + */ + /* 8000CF44 */ static void ZXYrotM(csXyz const& xyz); + + /* 8000CF7C */ static void quatM(Quaternion const*); + + /** + * 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 Z, Y, X + * @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 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 ZXYrotM(s16 x, s16 y, s16 z) { mDoMtx_ZXYrotM(now, x, y, z); } + + /** + * 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 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 z-axis then concatenates it with the `now` matrix + * @param z The rotation value + */ + static void ZrotM(s16 z) { mDoMtx_ZrotM(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 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; +} + +class mDoMtx_quatStack_c { +public: + mDoMtx_quatStack_c() { + field_0x0 = &field_0x4; + field_0x114 = field_0x14; + field_0x118 = &field_0x114; + } + + ~mDoMtx_quatStack_c() {} + + /* 0x000 */ Quaternion* field_0x0; + /* 0x004 */ Quaternion field_0x4; + /* 0x014 */ Quaternion field_0x14[16]; + /* 0x114 */ Quaternion* field_0x114; + /* 0x118 */ Quaternion** field_0x118; +}; // Size: 0x11C + +#endif /* M_DO_M_DO_MTX_H */ \ No newline at end of file diff --git a/src/m_Do/m_Do_hostIO.cpp b/src/m_Do/m_Do_hostIO.cpp index c8f82dfad..cdc0feb12 100644 --- a/src/m_Do/m_Do_hostIO.cpp +++ b/src/m_Do/m_Do_hostIO.cpp @@ -4,39 +4,45 @@ // #include "m_Do/m_Do_hostIO.h" -#include "dolphin/types.h" +#include "dolphin/os/OS.h" +#include "MSL_C/string.h" + +mDoHIO_root_c mDoHIO_root; /* 80017A4C-80017A50 .text update__13mDoHIO_root_cFv */ -void mDoHIO_root_c::update() { - /* Nonmatching */ -} +void mDoHIO_root_c::update() {} /* 80017A50-80017B20 .text createChild__16mDoHIO_subRoot_cFPCcP13JORReflexible */ -void mDoHIO_subRoot_c::createChild(const char*, JORReflexible*) { - /* Nonmatching */ +s8 mDoHIO_subRoot_c::createChild(const char* i_name, JORReflexible* i_reflexible) { + for (int i = 0; i < 64; i++) { + if (mChild[i].mReflexible == i_reflexible) { + // "Danger: Trying to register an already registered HostIO<%s>\n" + OSReport_Error("危険:既に登録されているホストIOをふたたび登録しようとしています<%s>\n", i_name); + return -1; + } + } + + for (int i = 0; i < 64; i++) { + if (mChild[i].mReflexible == NULL) { + strncpy(mChild[i].mName, i_name, sizeof(mChild[i].mName)); + mChild[i].mReflexible = i_reflexible; + return i; + } + } + + // "No free HostIO entries. Could not register. \n" + OSReport_Error("ホストIOの空きエントリがありません。登録できませんでした。\n"); + return -1; } /* 80017B20-80017B88 .text deleteChild__16mDoHIO_subRoot_cFSc */ -void mDoHIO_subRoot_c::deleteChild(signed char) { - /* Nonmatching */ -} - -/* 80017C00-80017C84 .text __dt__13mDoHIO_root_cFv */ -mDoHIO_root_c::~mDoHIO_root_c() { - /* Nonmatching */ -} - -/* 80017C84-80017CF4 .text __dt__16mDoHIO_subRoot_cFv */ -mDoHIO_subRoot_c::~mDoHIO_subRoot_c() { - /* Nonmatching */ -} - -/* 80017CF4-80017D30 .text __dt__14mDoHIO_child_cFv */ -mDoHIO_child_c::~mDoHIO_child_c() { - /* Nonmatching */ -} - -/* 80017D30-80017D40 .text __ct__14mDoHIO_child_cFv */ -mDoHIO_child_c::mDoHIO_child_c() { - /* Nonmatching */ +void mDoHIO_subRoot_c::deleteChild(s8 i_childID) { + if (i_childID >= 0) { + if (mChild[i_childID].mReflexible == NULL) { + // "Danger: Trying to delete HostIO that has already been deleted<%s>\n" + OSReport_Error("危険:すでに削除されているホストIOをさらに削除しようとしています<%s>\n", mChild[i_childID].mName); + } else { + mChild[i_childID].mReflexible = NULL; + } + } } diff --git a/src/m_Do/m_Do_mtx.cpp b/src/m_Do/m_Do_mtx.cpp index 3dbeb1502..9f94a6dc3 100644 --- a/src/m_Do/m_Do_mtx.cpp +++ b/src/m_Do/m_Do_mtx.cpp @@ -4,75 +4,122 @@ // #include "m_Do/m_Do_mtx.h" -#include "dolphin/types.h" +#include "dolphin/mtx/mtx.h" +#include "JSystem/JUtility/JUTAssert.h" +#include "JSystem/JMath/JMath.h" +#include "SSystem/SComponent/c_math.h" /* 8000CB48-8000CBEC .text mDoMtx_XYZrotM__FPA4_fsss */ -void mDoMtx_XYZrotM(float(*)[4], short, short, short) { - /* Nonmatching */ +void mDoMtx_XYZrotM(Mtx mtx, s16 x, s16 y, s16 z) { + Mtx tmp; + if (z != 0) { + mDoMtx_ZrotS(tmp, z); + PSMTXConcat(mtx, tmp, mtx); + } + + if (y != 0) { + mDoMtx_YrotS(tmp, y); + PSMTXConcat(mtx, tmp, mtx); + } + + if (x != 0) { + mDoMtx_XrotS(tmp, x); + PSMTXConcat(mtx, tmp, mtx); + } } /* 8000CBEC-8000CC84 .text mDoMtx_ZXYrotS__FPA4_fsss */ -void mDoMtx_ZXYrotS(float(*)[4], short, short, short) { - /* Nonmatching */ +void mDoMtx_ZXYrotS(Mtx mtx, s16 x, s16 y, s16 z) { + Mtx tmp; + if (y != 0) { + mDoMtx_YrotS(mtx, y); + } else { + PSMTXIdentity(mtx); + } + + if (x != 0) { + mDoMtx_XrotS(tmp, x); + PSMTXConcat(mtx, tmp, mtx); + } + + if (z != 0) { + mDoMtx_ZrotS(tmp, z); + PSMTXConcat(mtx, tmp, mtx); + } } /* 8000CC84-8000CD28 .text mDoMtx_ZXYrotM__FPA4_fsss */ -void mDoMtx_ZXYrotM(float(*)[4], short, short, short) { - /* Nonmatching */ +void mDoMtx_ZXYrotM(Mtx mtx, s16 x, s16 y, s16 z) { + Mtx tmp; + if (y != 0) { + mDoMtx_YrotS(tmp, y); + PSMTXConcat(mtx, tmp, mtx); + } + + if (x != 0) { + mDoMtx_XrotS(tmp, x); + PSMTXConcat(mtx, tmp, mtx); + } + + if (z != 0) { + mDoMtx_ZrotS(tmp, z); + PSMTXConcat(mtx, tmp, mtx); + } } /* 8000CD28-8000CD88 .text mDoMtx_XrotS__FPA4_fs */ -void mDoMtx_XrotS(float(*)[4], short) { +void mDoMtx_XrotS(Mtx, s16) { /* Nonmatching */ } /* 8000CD88-8000CDC8 .text mDoMtx_XrotM__FPA4_fs */ -void mDoMtx_XrotM(float(*)[4], short) { - /* Nonmatching */ +void mDoMtx_XrotM(Mtx mtx, s16 x) { + Mtx tmp; + mDoMtx_XrotS(tmp, x); + PSMTXConcat(mtx, tmp, mtx); } /* 8000CDC8-8000CE28 .text mDoMtx_YrotS__FPA4_fs */ -void mDoMtx_YrotS(float(*)[4], short) { +void mDoMtx_YrotS(Mtx, s16) { /* Nonmatching */ } /* 8000CE28-8000CE68 .text mDoMtx_YrotM__FPA4_fs */ -void mDoMtx_YrotM(float(*)[4], short) { - /* Nonmatching */ +void mDoMtx_YrotM(Mtx mtx, s16 y) { + Mtx tmp; + mDoMtx_YrotS(tmp, y); + PSMTXConcat(mtx, tmp, mtx); } /* 8000CE68-8000CEC8 .text mDoMtx_ZrotS__FPA4_fs */ -void mDoMtx_ZrotS(float(*)[4], short) { +void mDoMtx_ZrotS(Mtx, s16) { /* Nonmatching */ } /* 8000CEC8-8000CF08 .text mDoMtx_ZrotM__FPA4_fs */ -void mDoMtx_ZrotM(float(*)[4], short) { - /* Nonmatching */ +void mDoMtx_ZrotM(Mtx mtx, s16 z) { + Mtx tmp; + mDoMtx_ZrotS(tmp, z); + PSMTXConcat(mtx, tmp, mtx); } /* 8000CF08-8000D10C .text mDoMtx_lookAt__FPA4_fPC3VecPC3Vecs */ -void mDoMtx_lookAt(float(*)[4], const Vec*, const Vec*, short) { - /* Nonmatching */ -} - -/* 8000D10C-8000D148 .text __dt__4cXyzFv */ -cXyz::~cXyz() { +void mDoMtx_lookAt(Mtx, const Vec*, const Vec*, s16) { /* Nonmatching */ } /* 8000D148-8000D284 .text mDoMtx_lookAt__FPA4_fPC3VecPC3VecPC3Vecs */ -void mDoMtx_lookAt(float(*)[4], const Vec*, const Vec*, const Vec*, short) { +void mDoMtx_lookAt(Mtx, const Vec*, const Vec*, const Vec*, s16) { /* Nonmatching */ } /* 8000D284-8000D388 .text mDoMtx_concatProjView__FPA4_CfPA4_CfPA4_f */ -void mDoMtx_concatProjView(const float(*)[4], const float(*)[4], float(*)[4]) { +void mDoMtx_concatProjView(const Mtx, const Mtx, Mtx) { /* Nonmatching */ } /* 8000D388-8000D530 .text mDoMtx_inverseTranspose__FPA4_CfPA4_f */ -void mDoMtx_inverseTranspose(const float(*)[4], float(*)[4]) { +void mDoMtx_inverseTranspose(const Mtx, Mtx) { /* Nonmatching */ } @@ -82,51 +129,88 @@ void mDoMtx_QuatConcat(const Quaternion*, const Quaternion*, Quaternion*) { } /* 8000D634-8000D74C .text mDoMtx_MtxToRot__FPA4_CfP5csXyz */ -void mDoMtx_MtxToRot(const float(*)[4], csXyz*) { - /* Nonmatching */ +// NONMATCHING - sqrtf issues +void mDoMtx_MtxToRot(const Mtx m, csXyz* o_rot) { + o_rot->x = cM_atan2s(-m[1][2], sqrtf(m[0][2] * m[0][2] + m[2][2] * m[2][2])); + + if (o_rot->x == 0x4000 || o_rot->x == -0x4000) { + o_rot->z = 0; + o_rot->y = cM_atan2s(-m[2][0], m[0][0]); + } else { + o_rot->y = cM_atan2s(m[0][2], m[2][2]); + o_rot->z = cM_atan2s(m[1][0], m[1][1]); + } } +Mtx mDoMtx_stack_c::now; +Mtx mDoMtx_stack_c::buffer[16]; + +Mtx* mDoMtx_stack_c::next = mDoMtx_stack_c::buffer; +Mtx* mDoMtx_stack_c::end = mDoMtx_stack_c::buffer + 16; + /* 8000D74C-8000D7CC .text push__14mDoMtx_stack_cFv */ -void mDoMtx_stack_c::push() { - /* Nonmatching */ +bool mDoMtx_stack_c::push() { + if (next >= end) { + JUT_ASSERT(723, next < end) + return false; + } + Mtx* old = next++; + PSMTXCopy(now, *old); + return true; } /* 8000D7CC-8000D850 .text pop__14mDoMtx_stack_cFv */ -void mDoMtx_stack_c::pop() { - /* Nonmatching */ +bool mDoMtx_stack_c::pop() { + if (next <= buffer) { + JUT_ASSERT(745, next > buffer) + return false; + } + next--; + PSMTXCopy(*next, now); + return true; } /* 8000D850-8000D888 .text transM__14mDoMtx_stack_cFfff */ -void mDoMtx_stack_c::transM(float, float, float) { - /* Nonmatching */ +void mDoMtx_stack_c::transM(f32 x, f32 y, f32 z) { + Mtx tmp; + PSMTXTrans(tmp, x, y, z); + PSMTXConcat(now, tmp, now); } /* 8000D888-8000D8C0 .text scaleM__14mDoMtx_stack_cFfff */ -void mDoMtx_stack_c::scaleM(float, float, float) { - /* Nonmatching */ +void mDoMtx_stack_c::scaleM(f32 x, f32 y, f32 z) { + Mtx tmp; + PSMTXScale(tmp, x, y, z); + PSMTXConcat(now, tmp, now); } /* 8000D8C0-8000D904 .text lYrotM__14mDoMtx_stack_cFl */ -void mDoMtx_stack_c::lYrotM(long) { - /* Nonmatching */ +void mDoMtx_stack_c::lYrotM(s32 param_0) { + Mtx m; + mDoMtx_YrotS(m, param_0 >> 16); + MTXConcat(now, m, now); } /* 8000D904-8000D940 .text rYrotM__14mDoMtx_stack_cFf */ -void mDoMtx_stack_c::rYrotM(float) { - /* Nonmatching */ +void mDoMtx_stack_c::rYrotM(f32 i_rad) { + Mtx m; + PSMTXRotRad(m, 'Y', i_rad); + MTXConcat(now, m, now); } /* 8000D940-8000D97C .text quatM__14mDoMtx_stack_cFPC10Quaternion */ -void mDoMtx_stack_c::quatM(const Quaternion*) { - /* Nonmatching */ +void mDoMtx_stack_c::quatM(const Quaternion* param_0) { + Mtx tmp; + PSMTXQuat(tmp, param_0); + PSMTXConcat(now, tmp, now); } -/* 8000D9F8-8000DA34 .text __dt__18mDoMtx_quatStack_cFv */ -mDoMtx_quatStack_c::~mDoMtx_quatStack_c() { - /* Nonmatching */ -} +static mDoMtx_stack_c mDoMtx_stack; -/* 8000DA34-8000DA70 .text __dt__14mDoMtx_stack_cFv */ -mDoMtx_stack_c::~mDoMtx_stack_c() { - /* Nonmatching */ -} +static mDoMtx_quatStack_c mDoMtx_quatStack; + +extern Mtx g_mDoMtx_identity = { + {1.0f, 0.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 0.0f, 0.0f}, + {0.0f, 0.0f, 1.0f, 0.0f}, +};