tp/libs/JSystem/J3DGraphBase/J3DTransform.cpp

459 lines
14 KiB
C++

//
// Generated By: dol2asm
// Translation Unit: J3DTransform
//
#include "JSystem/J3DGraphBase/J3DTransform.h"
#include "JSystem/J3DGraphBase/J3DStruct.h"
#include "JSystem/JMath/JMATrigonometric.h"
#include "dol2asm.h"
#include "dolphin/base/PPCArch.h"
//
// Forward References:
//
extern "C" void __MTGQR7__FUl();
extern "C" void J3DGQRSetup7__FUlUlUlUl();
extern "C" void J3DCalcBBoardMtx__FPA4_f();
extern "C" void J3DCalcYBBoardMtx__FPA4_f();
extern "C" void J3DPSCalcInverseTranspose__FPA4_fPA3_f();
extern "C" void J3DGetTranslateRotateMtx__FRC16J3DTransformInfoPA4_f();
extern "C" void J3DGetTranslateRotateMtx__FsssfffPA4_f();
extern "C" void J3DGetTextureMtx__FRC17J3DTextureSRTInfoRC3VecPA4_f();
extern "C" void J3DGetTextureMtxOld__FRC17J3DTextureSRTInfoRC3VecPA4_f();
extern "C" void J3DGetTextureMtxMaya__FRC17J3DTextureSRTInfoPA4_f();
extern "C" void J3DGetTextureMtxMayaOld__FRC17J3DTextureSRTInfoPA4_f();
extern "C" void J3DScaleNrmMtx__FPA4_fRC3Vec();
extern "C" void J3DScaleNrmMtx33__FPA3_fRC3Vec();
extern "C" void J3DMtxProjConcat__FPA4_fPA4_fPA4_f();
extern "C" void J3DPSMtxArrayConcat__FPA4_fPA4_fPA4_fUl();
extern "C" extern f32 PSMulUnit01[2];
//
// External References:
//
extern "C" u8 sincosTable___5JMath[65536];
//
// Declarations:
//
/* 80311630-80311638 -00001 0008+00 0/0 0/0 0/0 .text __MTGQR7__FUl */
void __MTGQR7(register u32 v) {
// clang-format off
asm {
mtspr GQR7, v
}
// clang-format on
}
/* 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);
__MTGQR7(v);
}
/* ############################################################################################## */
/* 80456378-8045637C 004978 0004+00 6/6 0/0 0/0 .sdata2 @435 */
SECTION_SDATA2 static u8 lit_435[4] = {
0x00,
0x00,
0x00,
0x00,
};
/* 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
asm void J3DCalcBBoardMtx(f32 (*param_0)[4]) {
nofralloc
#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 */
extern J3DTransformInfo const j3dDefaultTransformInfo = {
{1.0f, 1.0f, 1.0f}, {0, 0, 0}, {0.0f, 0.0f, 0.0f}};
/* 803A1E50-803A1E5C 02E4B0 000C+00 0/0 1/1 0/0 .rodata j3dDefaultScale */
extern Vec const j3dDefaultScale = {1.0f, 1.0f, 1.0f};
/* 803A1E5C-803A1E8C 02E4BC 0030+00 0/0 8/8 7/7 .rodata j3dDefaultMtx */
extern Mtx const j3dDefaultMtx = {
{1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}};
/* 803A1E8C-803A1E98 02E4EC 000C+00 1/1 0/0 0/0 .rodata @443 */
SECTION_RODATA static u8 const lit_443[12] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
COMPILER_STRIP_GATE(0x803A1E8C, &lit_443);
/* 80311760-8031189C 30C0A0 013C+00 0/0 2/2 0/0 .text J3DCalcYBBoardMtx__FPA4_f */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void J3DCalcYBBoardMtx(f32 (*param_0)[4]) {
nofralloc
#include "asm/JSystem/J3DGraphBase/J3DTransform/J3DCalcYBBoardMtx__FPA4_f.s"
}
#pragma pop
/* 8031189C-80311964 30C1DC 00C8+00 0/0 6/6 0/0 .text J3DPSCalcInverseTranspose__FPA4_fPA3_f */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void J3DPSCalcInverseTranspose(f32 (*param_0)[4], f32 (*param_1)[3]) {
nofralloc
#include "asm/JSystem/J3DGraphBase/J3DTransform/J3DPSCalcInverseTranspose__FPA4_fPA3_f.s"
}
#pragma pop
/* 80311964-80311A24 30C2A4 00C0+00 0/0 2/2 2/2 .text
* J3DGetTranslateRotateMtx__FRC16J3DTransformInfoPA4_f */
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;
}
/* 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 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;
}
/* ############################################################################################## */
/* 8045637C-80456380 00497C 0004+00 4/4 0/0 0/0 .sdata2 @526 */
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
asm void J3DGetTextureMtx(J3DTextureSRTInfo const& param_0, Vec const& param_1, f32 (*param_2)[4]) {
nofralloc
#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
asm void J3DGetTextureMtxOld(J3DTextureSRTInfo const& param_0, Vec const& param_1,
f32 (*param_2)[4]) {
nofralloc
#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 */
SECTION_SDATA2 static f32 lit_557[1 + 1 /* padding */] = {
0.5f,
/* padding */
0.0f,
};
/* 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
asm void J3DGetTextureMtxMaya(J3DTextureSRTInfo const& param_0, f32 (*param_1)[4]) {
nofralloc
#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
asm void J3DGetTextureMtxMayaOld(J3DTextureSRTInfo const& param_0, f32 (*param_1)[4]) {
nofralloc
#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
asm void J3DScaleNrmMtx(f32 (*param_0)[4], Vec const& param_1) {
nofralloc
#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
#pragma optimization_level 0
#pragma optimizewithasm off
asm void J3DScaleNrmMtx33(f32 (*param_0)[3], Vec const& param_1) {
nofralloc
#include "asm/JSystem/J3DGraphBase/J3DTransform/J3DScaleNrmMtx33__FPA3_fRC3Vec.s"
}
#pragma pop
/* 80311E4C-80311F70 30C78C 0124+00 0/0 3/3 0/0 .text J3DMtxProjConcat__FPA4_fPA4_fPA4_f
*/
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void J3DMtxProjConcat(f32 (*param_0)[4], f32 (*param_1)[4], f32 (*param_2)[4]) {
nofralloc
#include "asm/JSystem/J3DGraphBase/J3DTransform/J3DMtxProjConcat__FPA4_fPA4_fPA4_f.s"
}
#pragma pop
/* ############################################################################################## */
/* 80450958-80450960 0003D8 0008+00 1/1 0/0 0/0 .sdata Unit01 */
SECTION_SDATA static u8 Unit01[8] = {
0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00,
};
/* 80311F70-8031204C 30C8B0 00DC+00 0/0 1/1 0/0 .text J3DPSMtxArrayConcat__FPA4_fPA4_fPA4_fUl */
#pragma push
#pragma optimization_level 0
#pragma optimizewithasm off
asm void J3DPSMtxArrayConcat(f32 (*param_0)[4], f32 (*param_1)[4], f32 (*param_2)[4], u32 param_3) {
nofralloc
#include "asm/JSystem/J3DGraphBase/J3DTransform/J3DPSMtxArrayConcat__FPA4_fPA4_fPA4_fUl.s"
}
#pragma pop
/* ############################################################################################## */
/* 803CD8F8-803CD900 02AA18 0008+00 0/0 2/2 0/0 .data PSMulUnit01 */
SECTION_DATA extern f32 PSMulUnit01[2] = {
0.0f,
-1.0f,
};