diff options
Diffstat (limited to 'libs/JSystem/J3DGraphBase/J3DTransform.cpp')
| -rw-r--r-- | libs/JSystem/J3DGraphBase/J3DTransform.cpp | 272 |
1 files changed, 239 insertions, 33 deletions
diff --git a/libs/JSystem/J3DGraphBase/J3DTransform.cpp b/libs/JSystem/J3DGraphBase/J3DTransform.cpp index 520e90bb05..2d8ddc9977 100644 --- a/libs/JSystem/J3DGraphBase/J3DTransform.cpp +++ b/libs/JSystem/J3DGraphBase/J3DTransform.cpp @@ -4,13 +4,10 @@ // #include "JSystem/J3DGraphBase/J3DTransform.h" +#include "JSystem/J3DGraphBase/J3DStruct.h" +#include "JSystem/JMath/JMATrigonometric.h" #include "dol2asm.h" - -// -// Types: -// - -struct J3DTextureSRTInfo {}; +#include "dolphin/base/PPCArch.h" // // Forward References: @@ -44,23 +41,19 @@ extern "C" u8 sincosTable___5JMath[65536]; // /* 80311630-80311638 -00001 0008+00 0/0 0/0 0/0 .text __MTGQR7__FUl */ -asm void __MTGQR7(u32 param_0) { +void __MTGQR7(register u32 v) { // clang-format off - nofralloc - mtspr 0x397, r3 - blr + asm { + mtspr GQR7, v + } // clang-format on } /* 80311638-80311670 30BF78 0038+00 0/0 2/2 0/0 .text J3DGQRSetup7__FUlUlUlUl */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void J3DGQRSetup7(u32 param_0, u32 param_1, u32 param_2, u32 param_3) { - nofralloc -#include "asm/JSystem/J3DGraphBase/J3DTransform/J3DGQRSetup7__FUlUlUlUl.s" +void J3DGQRSetup7(u32 r0, u32 r1, u32 r2, u32 r3) { + u32 v = (((r0 << 8) + r1) << 16) | ((r2 << 8) + r3); + __MTGQR7(v); } -#pragma pop /* ############################################################################################## */ /* 80456378-8045637C 004978 0004+00 6/6 0/0 0/0 .sdata2 @435 */ @@ -72,6 +65,44 @@ SECTION_SDATA2 static u8 lit_435[4] = { }; /* 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 +#ifdef NONMATCHING +static inline f32 sqrtf2(f32 x) { + if (x > 0.0f) { + f32 guess = (f32)__frsqrte(x); + return (f32)(x * guess); + } + return x; +} + +void J3DCalcBBoardMtx(Mtx mtx) { + f32 x = (mtx[0][0] * mtx[0][0]) + (mtx[1][0] * mtx[1][0]) + (mtx[2][0] * mtx[2][0]); + f32 y = (mtx[0][1] * mtx[0][1]) + (mtx[1][1] * mtx[1][1]) + (mtx[2][1] * mtx[2][1]); + 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 *= sqrtf2(x); + } + if (y > 0.0f) { + y *= sqrtf2(y); + } + if (z > 0.0f) { + z *= sqrtf2(z); + } + + mtx[0][0] = x; + mtx[0][1] = 0.0f; + mtx[0][2] = 0.0f; + + mtx[1][0] = 0.0f; + mtx[1][1] = y; + mtx[1][2] = 0.0f; + + mtx[2][0] = 0.0f; + mtx[2][1] = 0.0f; + mtx[2][2] = z; +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -80,6 +111,7 @@ asm void J3DCalcBBoardMtx(f32 (*param_0)[4]) { #include "asm/JSystem/J3DGraphBase/J3DTransform/J3DCalcBBoardMtx__FPA4_f.s" } #pragma pop +#endif /* ############################################################################################## */ /* 803A1E30-803A1E50 02E490 0020+00 0/0 1/1 0/0 .rodata j3dDefaultTransformInfo */ @@ -121,25 +153,58 @@ asm void J3DPSCalcInverseTranspose(f32 (*param_0)[4], f32 (*param_1)[3]) { /* 80311964-80311A24 30C2A4 00C0+00 0/0 2/2 2/2 .text * J3DGetTranslateRotateMtx__FRC16J3DTransformInfoPA4_f */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void J3DGetTranslateRotateMtx(J3DTransformInfo const& param_0, f32 (*param_1)[4]) { - nofralloc -#include "asm/JSystem/J3DGraphBase/J3DTransform/J3DGetTranslateRotateMtx__FRC16J3DTransformInfoPA4_f.s" +void J3DGetTranslateRotateMtx(const J3DTransformInfo& tx, Mtx dst) { + 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); + + dst[2][0] = -sy; + dst[0][0] = cz * cy; + dst[1][0] = sz * cy; + dst[2][1] = cy * sx; + dst[2][2] = cy * cx; + + f32 cxsz = cx * sz; + f32 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; + + dst[0][3] = tx.mTranslate.x; + dst[1][3] = tx.mTranslate.y; + dst[2][3] = tx.mTranslate.z; } -#pragma pop /* 80311A24-80311ACC 30C364 00A8+00 0/0 1/1 0/0 .text J3DGetTranslateRotateMtx__FsssfffPA4_f */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void J3DGetTranslateRotateMtx(s16 param_0, s16 param_1, s16 param_2, f32 param_3, f32 param_4, - f32 param_5, f32 (*param_6)[4]) { - nofralloc -#include "asm/JSystem/J3DGraphBase/J3DTransform/J3DGetTranslateRotateMtx__FsssfffPA4_f.s" +void J3DGetTranslateRotateMtx(s16 rx, s16 ry, s16 rz, f32 tx, f32 ty, f32 tz, Mtx dst) { + f32 sx = JMASSin(rx), cx = JMASCos(rx); + f32 sy = JMASSin(ry), cy = JMASCos(ry); + f32 sz = JMASSin(rz), cz = JMASCos(rz); + + dst[2][0] = -sy; + dst[0][0] = cz * cy; + dst[1][0] = sz * cy; + dst[2][1] = cy * sx; + dst[2][2] = cy * cx; + + f32 cxsz = cx * sz; + f32 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; + + dst[0][3] = tx; + dst[1][3] = ty; + dst[2][3] = tz; } -#pragma pop /* ############################################################################################## */ /* 8045637C-80456380 00497C 0004+00 4/4 0/0 0/0 .sdata2 @526 */ @@ -147,6 +212,32 @@ SECTION_SDATA2 static f32 lit_526 = 1.0f; /* 80311ACC-80311B80 30C40C 00B4+00 0/0 3/3 0/0 .text * J3DGetTextureMtx__FRC17J3DTextureSRTInfoRC3VecPA4_f */ +// matches with literals +#ifdef NONMATCHING +void J3DGetTextureMtx(const J3DTextureSRTInfo& srt, const Vec& center, Mtx dst) { + f32 sr = JMASSin(srt.mRotation), cr = JMASCos(srt.mRotation); + + f32 cx = srt.mScaleX * cr; + f32 sx = srt.mScaleX * sr; + f32 sy = srt.mScaleY * sr; + f32 cy = srt.mScaleY * cr; + + dst[0][0] = cx; + dst[0][1] = -sx; + dst[0][2] = (-cx * center.x + sx * center.y) + center.x + srt.mTranslationX; + + dst[1][0] = sy; + 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; +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -155,9 +246,36 @@ asm void J3DGetTextureMtx(J3DTextureSRTInfo const& param_0, Vec const& param_1, #include "asm/JSystem/J3DGraphBase/J3DTransform/J3DGetTextureMtx__FRC17J3DTextureSRTInfoRC3VecPA4_f.s" } #pragma pop +#endif /* 80311B80-80311C34 30C4C0 00B4+00 0/0 3/3 0/0 .text * J3DGetTextureMtxOld__FRC17J3DTextureSRTInfoRC3VecPA4_f */ +// matches with literals +#ifdef NONMATCHING +void J3DGetTextureMtxOld(const J3DTextureSRTInfo& srt, const Vec& center, Mtx dst) { + f32 sr = JMASSin(srt.mRotation), cr = JMASCos(srt.mRotation); + + f32 cx = srt.mScaleX * cr; + f32 sx = srt.mScaleX * sr; + f32 sy = srt.mScaleY * sr; + f32 cy = srt.mScaleY * cr; + + dst[0][0] = cx; + dst[0][1] = -sx; + dst[0][3] = (-cx * center.x + sx * center.y) + center.x + srt.mTranslationX; + + dst[1][0] = sy; + 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; +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -167,6 +285,7 @@ asm void J3DGetTextureMtxOld(J3DTextureSRTInfo const& param_0, Vec const& param_ #include "asm/JSystem/J3DGraphBase/J3DTransform/J3DGetTextureMtxOld__FRC17J3DTextureSRTInfoRC3VecPA4_f.s" } #pragma pop +#endif /* ############################################################################################## */ /* 80456380-80456388 004980 0004+04 2/2 0/0 0/0 .sdata2 @557 */ @@ -178,6 +297,29 @@ SECTION_SDATA2 static f32 lit_557[1 + 1 /* padding */] = { /* 80311C34-80311CE4 30C574 00B0+00 0/0 3/3 0/0 .text * J3DGetTextureMtxMaya__FRC17J3DTextureSRTInfoPA4_f */ +// matches with literals +#ifdef NONMATCHING +void J3DGetTextureMtxMaya(const J3DTextureSRTInfo& srt, Mtx dst) { + f32 sr = JMASSin(srt.mRotation), cr = JMASCos(srt.mRotation); + f32 tx = srt.mTranslationX - 0.5f; + f32 ty = srt.mTranslationY - 0.5f; + + dst[0][0] = srt.mScaleX * cr; + dst[0][1] = srt.mScaleY * sr; + dst[0][2] = tx * cr - sr * (ty + srt.mScaleY) + 0.5f; + + dst[1][0] = -srt.mScaleX * sr; + 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; +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -186,9 +328,33 @@ asm void J3DGetTextureMtxMaya(J3DTextureSRTInfo const& param_0, f32 (*param_1)[4 #include "asm/JSystem/J3DGraphBase/J3DTransform/J3DGetTextureMtxMaya__FRC17J3DTextureSRTInfoPA4_f.s" } #pragma pop +#endif /* 80311CE4-80311D94 30C624 00B0+00 0/0 3/3 0/0 .text * J3DGetTextureMtxMayaOld__FRC17J3DTextureSRTInfoPA4_f */ +// matches with literals +#ifdef NONMATCHING +void J3DGetTextureMtxMayaOld(const J3DTextureSRTInfo& srt, Mtx dst) { + f32 sr = JMASSin(srt.mRotation), cr = JMASCos(srt.mRotation); + f32 tx = srt.mTranslationX - 0.5f; + f32 ty = srt.mTranslationY - 0.5f; + + dst[0][0] = srt.mScaleX * cr; + dst[0][1] = srt.mScaleY * sr; + dst[0][3] = tx * cr - sr * (ty + srt.mScaleY) + 0.5f; + + dst[1][0] = -srt.mScaleX * sr; + 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; +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -197,8 +363,46 @@ asm void J3DGetTextureMtxMayaOld(J3DTextureSRTInfo const& param_0, f32 (*param_1 #include "asm/JSystem/J3DGraphBase/J3DTransform/J3DGetTextureMtxMayaOld__FRC17J3DTextureSRTInfoPA4_f.s" } #pragma pop +#endif /* 80311D94-80311DF8 30C6D4 0064+00 0/0 2/2 0/0 .text J3DScaleNrmMtx__FPA4_fRC3Vec */ +#ifdef NONMATCHING +void J3DScaleNrmMtx(register Mtx mtx, const register Vec& scl) { + register f32 mtx_xy, mtx_z_, scl_xy, scl_z_; + + asm { + /* Row 0 */ + psq_l scl_xy, 0(scl), 0, 0 + psq_l mtx_xy, 0(mtx), 0, 0 + lfs scl_z_, 8(scl) + lfs mtx_z_, 8(mtx) + ps_mul f4, mtx_xy, scl_xy + psq_st f4, 0(mtx), 0, 0 + fmuls f4, mtx_z_, scl_z_ + stfs f4, 8(mtx) + + /* Row 1 */ + psq_l scl_xy, 0(scl), 0, 0 + psq_l mtx_xy, 16(mtx), 0, 0 + lfs scl_z_, 8(scl) + lfs mtx_z_, 24(mtx) + ps_mul f4, mtx_xy, scl_xy + psq_st f4, 16(mtx), 0, 0 + fmuls f4, mtx_z_, scl_z_ + stfs f4, 24(mtx) + + /* Row 2 */ + psq_l scl_xy, 0(scl), 0, 0 + psq_l mtx_xy, 32(mtx), 0, 0 + lfs scl_z_, 8(scl) + lfs mtx_z_, 40(mtx) + ps_mul f4, mtx_xy, scl_xy + psq_st f4, 32(mtx), 0, 0 + fmuls f4, mtx_z_, scl_z_ + stfs f4, 40(mtx) + } +} +#else #pragma push #pragma optimization_level 0 #pragma optimizewithasm off @@ -207,6 +411,7 @@ asm void J3DScaleNrmMtx(f32 (*param_0)[4], Vec const& param_1) { #include "asm/JSystem/J3DGraphBase/J3DTransform/J3DScaleNrmMtx__FPA4_fRC3Vec.s" } #pragma pop +#endif /* 80311DF8-80311E4C 30C738 0054+00 0/0 5/5 0/0 .text J3DScaleNrmMtx33__FPA3_fRC3Vec */ #pragma push @@ -248,5 +453,6 @@ asm void J3DPSMtxArrayConcat(f32 (*param_0)[4], f32 (*param_1)[4], f32 (*param_2 /* ############################################################################################## */ /* 803CD8F8-803CD900 02AA18 0008+00 0/0 2/2 0/0 .data PSMulUnit01 */ SECTION_DATA extern f32 PSMulUnit01[2] = { - 0.0f, -1.0f, + 0.0f, + -1.0f, }; |
