From b45a089e15d79821b07be020db628e01a49b1fd2 Mon Sep 17 00:00:00 2001 From: TakaRikka <38417346+TakaRikka@users.noreply.github.com> Date: Thu, 4 Sep 2025 07:56:59 -0700 Subject: some J3D/misc cleanup (#2628) * some j3d cleanup * begin using uintptr_t * j3dgraphbase cleanup * j3dgraphanimator cleanup --- src/JSystem/J3DGraphBase/J3DTransform.cpp | 85 +++++++++++++------------------ 1 file changed, 36 insertions(+), 49 deletions(-) (limited to 'src/JSystem/J3DGraphBase/J3DTransform.cpp') diff --git a/src/JSystem/J3DGraphBase/J3DTransform.cpp b/src/JSystem/J3DGraphBase/J3DTransform.cpp index 127cfde23f..ee0d58f27f 100644 --- a/src/JSystem/J3DGraphBase/J3DTransform.cpp +++ b/src/JSystem/J3DGraphBase/J3DTransform.cpp @@ -1,12 +1,7 @@ -// -// Generated By: dol2asm -// Translation Unit: J3DTransform -// - #include "JSystem/J3DGraphBase/J3DTransform.h" -#include "JSystem/JMath/JMATrigonometric.h" #include "JSystem/J3DGraphBase/J3DStruct.h" -#include "dolphin/base/PPCArch.h" +#include "JSystem/JMath/JMATrigonometric.h" +#include "JSystem/JMath/JMath.h" /* 80311630-80311638 -00001 0008+00 0/0 0/0 0/0 .text __MTGQR7__FUl */ void __MTGQR7(register u32 v) { @@ -19,12 +14,14 @@ void __MTGQR7(register u32 v) { /* 80311638-80311670 30BF78 0038+00 0/0 2/2 0/0 .text J3DGQRSetup7__FUlUlUlUl */ void J3DGQRSetup7(u32 r0, u32 r1, u32 r2, u32 r3) { - u32 v = (((r0 << 8) + r1) << 16) | ((r2 << 8) + r3); + u32 v = ((r0 << 8) + r1) << 16; + v |= (r2 << 8) + r3; __MTGQR7(v); } /* 80311670-80311760 30BFB0 00F0+00 0/0 2/2 0/0 .text J3DCalcBBoardMtx__FPA4_f */ // this uses a non-standard sqrtf, not sure why or how its supposed to be setup +#if !PLATFORM_SHIELD inline f32 J3D_sqrtf(register f32 x) { register f32 recip; @@ -36,6 +33,9 @@ inline f32 J3D_sqrtf(register f32 x) { } return x; } +#else +#define J3D_sqrtf sqrtf +#endif void J3DCalcBBoardMtx(register Mtx mtx) { f32 x = (mtx[0][0] * mtx[0][0]) + (mtx[1][0] * mtx[1][0]) + (mtx[2][0] * mtx[2][0]); @@ -86,10 +86,10 @@ void J3DCalcYBBoardMtx(Mtx mtx) { f32 z = (mtx[0][2] * mtx[0][2]) + (mtx[1][2] * mtx[1][2]) + (mtx[2][2] * mtx[2][2]); if (x > 0.0f) { - x = J3D_sqrtf(x); + x = JMath::fastSqrt(x); } if (z > 0.0f) { - z = J3D_sqrtf(z); + z = JMath::fastSqrt(z); } Vec vec = { 0.0f, -mtx[2][1], mtx[1][1] }; @@ -165,6 +165,9 @@ lbl_8005F118: /* 80311964-80311A24 30C2A4 00C0+00 0/0 2/2 2/2 .text * J3DGetTranslateRotateMtx__FRC16J3DTransformInfoPA4_f */ void J3DGetTranslateRotateMtx(const J3DTransformInfo& tx, Mtx dst) { + f32 cxsz; + f32 sxcz; + f32 sx = JMASSin(tx.mRotation.x), cx = JMASCos(tx.mRotation.x); f32 sy = JMASSin(tx.mRotation.y), cy = JMASCos(tx.mRotation.y); f32 sz = JMASSin(tx.mRotation.z), cz = JMASCos(tx.mRotation.z); @@ -175,15 +178,15 @@ void J3DGetTranslateRotateMtx(const J3DTransformInfo& tx, Mtx dst) { dst[2][1] = cy * sx; dst[2][2] = cy * cx; - f32 cxsz = cx * sz; - f32 sxcz = sx * cz; + cxsz = cx * sz; + sxcz = sx * cz; dst[0][1] = sxcz * sy - cxsz; dst[1][2] = cxsz * sy - sxcz; - f32 sxsz = sx * sz; - f32 cxcz = cx * cz; - dst[0][2] = cxcz * sy + sxsz; - dst[1][1] = sxsz * sy + cxcz; + cxsz = sx * sz; + sxcz = cx * cz; + dst[0][2] = sxcz * sy + cxsz; + dst[1][1] = cxsz * sy + sxcz; dst[0][3] = tx.mTranslate.x; dst[1][3] = tx.mTranslate.y; @@ -192,6 +195,9 @@ void J3DGetTranslateRotateMtx(const J3DTransformInfo& tx, Mtx dst) { /* 80311A24-80311ACC 30C364 00A8+00 0/0 1/1 0/0 .text J3DGetTranslateRotateMtx__FsssfffPA4_f */ void J3DGetTranslateRotateMtx(s16 rx, s16 ry, s16 rz, f32 tx, f32 ty, f32 tz, Mtx dst) { + f32 cxsz; + f32 sxcz; + f32 sx = JMASSin(rx), cx = JMASCos(rx); f32 sy = JMASSin(ry), cy = JMASCos(ry); f32 sz = JMASSin(rz), cz = JMASCos(rz); @@ -202,15 +208,15 @@ void J3DGetTranslateRotateMtx(s16 rx, s16 ry, s16 rz, f32 tx, f32 ty, f32 tz, Mt dst[2][1] = cy * sx; dst[2][2] = cy * cx; - f32 cxsz = cx * sz; - f32 sxcz = sx * cz; + cxsz = cx * sz; + sxcz = sx * cz; dst[0][1] = sxcz * sy - cxsz; dst[1][2] = cxsz * sy - sxcz; - f32 sxsz = sx * sz; - f32 cxcz = cx * cz; - dst[0][2] = cxcz * sy + sxsz; - dst[1][1] = sxsz * sy + cxcz; + cxsz = sx * sz; + sxcz = cx * cz; + dst[0][2] = sxcz * sy + cxsz; + dst[1][1] = cxsz * sy + sxcz; dst[0][3] = tx; dst[1][3] = ty; @@ -235,15 +241,10 @@ void J3DGetTextureMtx(const J3DTextureSRTInfo& srt, const Vec& center, Mtx dst) dst[1][1] = cy; dst[1][2] = (-sy * center.x - cy * center.y) + center.y + srt.mTranslationY; - dst[2][3] = 0.0f; - dst[2][1] = 0.0f; - dst[2][0] = 0.0f; - dst[1][3] = 0.0f; - dst[0][3] = 0.0f; - dst[2][2] = 1.0f; + dst[0][3] = dst[1][3] = dst[2][0] = dst[2][1] = dst[2][3] = 0.0f; + dst[2][2] = 1.0f; } - /* 80311B80-80311C34 30C4C0 00B4+00 0/0 3/3 0/0 .text * J3DGetTextureMtxOld__FRC17J3DTextureSRTInfoRC3VecPA4_f */ void J3DGetTextureMtxOld(const J3DTextureSRTInfo& srt, const Vec& center, Mtx dst) { @@ -262,12 +263,8 @@ void J3DGetTextureMtxOld(const J3DTextureSRTInfo& srt, const Vec& center, Mtx ds dst[1][1] = cy; dst[1][3] = (-sy * center.x - cy * center.y) + center.y + srt.mTranslationY; - dst[2][3] = 0.0f; - dst[2][1] = 0.0f; - dst[2][0] = 0.0f; - dst[1][2] = 0.0f; - dst[0][2] = 0.0f; - dst[2][2] = 1.0f; + dst[0][2] = dst[1][2] = dst[2][0] = dst[2][1] = dst[2][3] = 0.0f; + dst[2][2] = 1.0f; } /* 80311C34-80311CE4 30C574 00B0+00 0/0 3/3 0/0 .text @@ -285,15 +282,10 @@ void J3DGetTextureMtxMaya(const J3DTextureSRTInfo& srt, Mtx dst) { dst[1][1] = srt.mScaleY * cr; dst[1][2] = -tx * sr - cr * (ty + srt.mScaleY) + 0.5f; - dst[2][3] = 0.0f; - dst[2][1] = 0.0f; - dst[2][0] = 0.0f; - dst[1][3] = 0.0f; - dst[0][3] = 0.0f; - dst[2][2] = 1.0f; + dst[0][3] = dst[1][3] = dst[2][0] = dst[2][1] = dst[2][3] = 0.0f; + dst[2][2] = 1.0f; } - /* 80311CE4-80311D94 30C624 00B0+00 0/0 3/3 0/0 .text * J3DGetTextureMtxMayaOld__FRC17J3DTextureSRTInfoPA4_f */ void J3DGetTextureMtxMayaOld(const J3DTextureSRTInfo& srt, Mtx dst) { @@ -309,15 +301,10 @@ void J3DGetTextureMtxMayaOld(const J3DTextureSRTInfo& srt, Mtx dst) { dst[1][1] = srt.mScaleY * cr; dst[1][3] = -tx * sr - cr * (ty + srt.mScaleY) + 0.5f; - dst[2][3] = 0.0f; - dst[2][1] = 0.0f; - dst[2][0] = 0.0f; - dst[1][2] = 0.0f; - dst[0][2] = 0.0f; - dst[2][2] = 1.0f; + dst[0][2] = dst[1][2] = dst[2][0] = dst[2][1] = dst[2][3] = 0.0f; + dst[2][2] = 1.0f; } - /* 80311D94-80311DF8 30C6D4 0064+00 0/0 2/2 0/0 .text J3DScaleNrmMtx__FPA4_fRC3Vec */ asm void J3DScaleNrmMtx(register Mtx mtx, const register Vec& scl) { #ifdef __MWERKS__ // clang-format off -- cgit v1.2.3