move mtx to c

This commit is contained in:
Seth Barberee
2026-06-29 14:40:52 -07:00
parent f39cdece9e
commit 3e0ffaa64d
11 changed files with 488 additions and 453 deletions

View File

@@ -185,62 +185,62 @@ typedef struct {
void FX_Init(void);
// #if !(defined(SDK_WIN32) || defined(SDK_FROM_TOOL))
//
// SDK_DECL_INLINE s32 FX_Whole(fx32 v);
// SDK_DECL_INLINE fx32 FX_Floor(fx32 v);
//
// fx32 FX_Modf(fx32 x, fx32 * iPtr);
//
// SDK_INLINE s32 FX_Whole (fx32 v)
// {
// return (s32)(v >> FX32_SHIFT);
// }
//
// SDK_INLINE fx32 FX_Floor (fx32 v)
// {
// return (fx32)(v & (FX32_INT_MASK | FX32_SIGN_MASK));
// }
//
// SDK_INLINE fx32 FX32_CAST (s64 res)
// {
// SDK_WARNING(res >= FX32_MIN && res <= FX32_MAX, "FX_Mul: Overflow/Underflow");
// return (fx32)res;
// }
//
// fx32 FX_MulFunc(fx32 v1, fx32 v2);
// SDK_DECL_INLINE fx32 FX_MulInline(fx32 v1, fx32 v2);
//
// SDK_INLINE fx32 FX_MulInline (fx32 v1, fx32 v2)
// {
// return FX32_CAST(((s64)(v1) * v2 + 0x800LL) >> FX32_SHIFT);
// }
//
// #ifndef FX_Mul
// #ifdef SDK_CODE_ARM
// #define FX_Mul(v1, v2) FX_MulInline(v1, v2)
// #else
// #define FX_Mul(v1, v2) FX_MulFunc(v1, v2)
// #endif
// #endif
//
// #ifndef FX_Mul32x64c
// #ifdef SDK_CODE_ARM
// #define FX_Mul32x64c(v32, v64c) FX_Mul32x64cInline(v32, v64c)
// #else
// #define FX_Mul32x64c(v32, v64c) FX_Mul32x64cFunc(v32, v64c)
// #endif
// #endif
//
// fx32 FX_Mul32x64cFunc(fx32 v32, fx64c v64c);
// SDK_DECL_INLINE fx32 FX_Mul32x64cInline(fx32 v32, fx64c v64c);
//
// SDK_INLINE fx32 FX_Mul32x64cInline (fx32 v32, fx64c v64c)
// {
// fx64c tmp = v64c * v32 + 0x80000000LL;
// return FX32_CAST(tmp >> FX64C_SHIFT);
// }
// #endif
#if !(defined(SDK_WIN32) || defined(SDK_FROM_TOOL))
SDK_DECL_INLINE s32 FX_Whole(fx32 v);
SDK_DECL_INLINE fx32 FX_Floor(fx32 v);
fx32 FX_Modf(fx32 x, fx32 * iPtr);
SDK_INLINE s32 FX_Whole (fx32 v)
{
return (s32)(v >> FX32_SHIFT);
}
SDK_INLINE fx32 FX_Floor (fx32 v)
{
return (fx32)(v & (FX32_INT_MASK | FX32_SIGN_MASK));
}
SDK_INLINE fx32 FX32_CAST (s64 res)
{
SDK_WARNING(res >= FX32_MIN && res <= FX32_MAX, "FX_Mul: Overflow/Underflow");
return (fx32)res;
}
fx32 FX_MulFunc(fx32 v1, fx32 v2);
SDK_DECL_INLINE fx32 FX_MulInline(fx32 v1, fx32 v2);
SDK_INLINE fx32 FX_MulInline (fx32 v1, fx32 v2)
{
return FX32_CAST(((s64)(v1) * v2 + 0x800LL) >> FX32_SHIFT);
}
#ifndef FX_Mul
#ifdef SDK_CODE_ARM
#define FX_Mul(v1, v2) FX_MulInline(v1, v2)
#else
#define FX_Mul(v1, v2) FX_MulFunc(v1, v2)
#endif
#endif
#ifndef FX_Mul32x64c
#ifdef SDK_CODE_ARM
#define FX_Mul32x64c(v32, v64c) FX_Mul32x64cInline(v32, v64c)
#else
#define FX_Mul32x64c(v32, v64c) FX_Mul32x64cFunc(v32, v64c)
#endif
#endif
fx32 FX_Mul32x64cFunc(fx32 v32, fx64c v64c);
SDK_DECL_INLINE fx32 FX_Mul32x64cInline(fx32 v32, fx64c v64c);
SDK_INLINE fx32 FX_Mul32x64cInline (fx32 v32, fx64c v64c)
{
fx64c tmp = v64c * v32 + 0x80000000LL;
return FX32_CAST(tmp >> FX64C_SHIFT);
}
#endif
#ifdef __cplusplus
}

View File

@@ -40,13 +40,13 @@ s32 FX_ModS32(s32 a, s32 b);
#define FX_DIVISION_BY_ZERO(a, b) \
SDK_WARNING(b != 0, "Division by zero(%d / %d)", a, b)
// SDK_INLINE void FX_InvAsyncImm (fx32 denom)
// {
// SDK_ASSERT(!CP_IsDivBusy());
// FX_DIVISION_BY_ZERO(FX32_ONE, denom);
//
// CP_SetDivImm64_32((u64)FX32_ONE << 32, (u32)denom);
// }
SDK_INLINE void FX_InvAsyncImm (fx32 denom)
{
SDK_ASSERT(!CP_IsDivBusy());
FX_DIVISION_BY_ZERO(FX32_ONE, denom);
CP_SetDivImm64_32((u64)FX32_ONE << 32, (u32)denom);
}
SDK_INLINE fx64c FX_GetInvResultFx64c (void)
{

View File

@@ -0,0 +1,99 @@
#ifndef NITRO_FX_MTX43_H_
#define NITRO_FX_MTX43_H_
#include <nitro/fx/fx.h>
#include <nitro/mi/memory.h>
#ifdef __cplusplus
extern "C" {
#endif
SDK_DECL_INLINE void MTX_Identity43(MtxFx43 * pDst);
SDK_DECL_INLINE void MTX_Copy43(const MtxFx43 * pSrc, MtxFx43 * pDst);
SDK_DECL_INLINE void MTX_Copy43To33(const MtxFx43 * pSrc, MtxFx33 * pDst);
SDK_DECL_INLINE void MTX_Copy43To44(const MtxFx43 * pSrc, MtxFx44 * pDst);
SDK_DECL_INLINE void MTX_Transpose43(const MtxFx43 * pSrc, MtxFx43 * pDst);
void MTX_TransApply43(const MtxFx43 * pSrc, MtxFx43 * pDst, fx32 x, fx32 y, fx32 z);
SDK_DECL_INLINE void MTX_Scale43(MtxFx43 * pDst, fx32 x, fx32 y, fx32 z);
void MTX_ScaleApply43(const MtxFx43 * pSrc, MtxFx43 * pDst, fx32 x, fx32 y, fx32 z);
SDK_DECL_INLINE void MTX_RotX43(MtxFx43 * pDst, fx32 sinVal, fx32 cosVal);
SDK_DECL_INLINE void MTX_RotY43(MtxFx43 * pDst, fx32 sinVal, fx32 cosVal);
SDK_DECL_INLINE void MTX_RotZ43(MtxFx43 * pDst, fx32 sinVal, fx32 cosVal);
void MTX_RotAxis43(MtxFx43 * pDst, const VecFx32 * vec, fx32 sinVal, fx32 cosVal);
int MTX_Inverse43(const MtxFx43 * pSrc, MtxFx43 * pDst);
void MTX_Concat43(const MtxFx43 * a, const MtxFx43 * b, MtxFx43 * ab);
void MTX_MultVec43(const VecFx32 * vec, const MtxFx43 * m, VecFx32 * dst);
void MTX_LookAt(const VecFx32 * camPos, const VecFx32 * camUp, const VecFx32 * target, MtxFx43 * mtx);
void MTX_Identity43_(register MtxFx43 * pDst);
void MTX_Copy43To44_(register const MtxFx43 * pSrc, register MtxFx44 * pDst);
void MTX_Transpose43_(register const MtxFx43 * pSrc, register MtxFx43 * pDst);
void MTX_Scale43_(register MtxFx43 * pDst, register fx32 x, register fx32 y, register fx32 z);
void MTX_RotX43_(register MtxFx43 * pDst, register fx32 sinVal, register fx32 cosVal);
void MTX_RotY43_(register MtxFx43 * pDst, register fx32 sinVal, register fx32 cosVal);
void MTX_RotZ43_(register MtxFx43 * pDst, register fx32 sinVal, register fx32 cosVal);
SDK_INLINE void MTX_Identity43 (MtxFx43 * pDst)
{
SDK_NULL_ASSERT(pDst);
MTX_Identity43_(pDst);
}
SDK_INLINE void MTX_Copy43 (const MtxFx43 * pSrc, MtxFx43 * pDst)
{
SDK_NULL_ASSERT(pSrc);
SDK_NULL_ASSERT(pDst);
MI_Copy48B(pSrc, pDst);
}
SDK_INLINE void MTX_Copy43To33 (const MtxFx43 * pSrc, MtxFx33 * pDst)
{
SDK_NULL_ASSERT(pSrc);
SDK_NULL_ASSERT(pDst);
MI_Copy36B(pSrc, pDst);
}
SDK_INLINE void MTX_Copy43To44 (const MtxFx43 * pSrc, MtxFx44 * pDst)
{
SDK_NULL_ASSERT(pSrc);
SDK_NULL_ASSERT(pDst);
MTX_Copy43To44_(pSrc, pDst);
}
SDK_INLINE void MTX_Transpose43 (const MtxFx43 * pSrc, MtxFx43 * pDst)
{
SDK_NULL_ASSERT(pSrc);
SDK_NULL_ASSERT(pDst);
MTX_Transpose43_(pSrc, pDst);
}
SDK_INLINE void MTX_Scale43 (MtxFx43 * pDst, fx32 x, fx32 y, fx32 z)
{
SDK_NULL_ASSERT(pDst);
MTX_Scale43_(pDst, x, y, z);
}
SDK_INLINE void MTX_RotX43 (MtxFx43 * pDst, fx32 sinVal, fx32 cosVal)
{
SDK_NULL_ASSERT(pDst);
MTX_RotX43_(pDst, sinVal, cosVal);
}
SDK_INLINE void MTX_RotY43 (MtxFx43 * pDst, fx32 sinVal, fx32 cosVal)
{
SDK_NULL_ASSERT(pDst);
MTX_RotY43_(pDst, sinVal, cosVal);
}
SDK_INLINE void MTX_RotZ43 (MtxFx43 * pDst, fx32 sinVal, fx32 cosVal)
{
SDK_NULL_ASSERT(pDst);
MTX_RotZ43_(pDst, sinVal, cosVal);
}
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,119 @@
#ifndef NITRO_FX_MTX44_H_
#define NITRO_FX_MTX44_H_
#include <nitro/fx/fx.h>
#include <nitro/fx/fx_const.h>
#include <nitro/mi/memory.h>
#ifdef __cplusplus
extern "C" {
#endif
SDK_DECL_INLINE void MTX_Identity44(MtxFx44 * pDst);
SDK_DECL_INLINE void MTX_Copy44To33(const MtxFx44 * pSrc, MtxFx33 * pDst);
SDK_DECL_INLINE void MTX_Copy44To43(const MtxFx44 * pSrc, MtxFx43 * pDst);
SDK_DECL_INLINE void MTX_Transpose44(const MtxFx44 * pSrc, MtxFx44 * pDst);
void MTX_TransApply44(const MtxFx44 * pSrc, MtxFx44 * pDst, fx32 x, fx32 y, fx32 z);
SDK_DECL_INLINE void MTX_Scale44(MtxFx44 * pDst, fx32 x, fx32 y, fx32 z);
void MTX_ScaleApply44(const MtxFx44 * pSrc, MtxFx44 * pDst, fx32 x, fx32 y, fx32 z);
SDK_DECL_INLINE void MTX_RotX44(MtxFx44 * pDst, fx32 sinVal, fx32 cosVal);
SDK_DECL_INLINE void MTX_RotY44(MtxFx44 * pDst, fx32 sinVal, fx32 cosVal);
SDK_DECL_INLINE void MTX_RotZ44(MtxFx44 * pDst, fx32 sinVal, fx32 cosVal);
void MTX_RotAxis44(MtxFx44 * pDst, const VecFx32 * vec, fx32 sinVal, fx32 cosVal);
void MTX_Concat44(const MtxFx44 * a, const MtxFx44 * b, MtxFx44 * ab);
void MTX_FrustumW(fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, fx32 scaleW, MtxFx44 * mtx);
void MTX_PerspectiveW(fx32 fovySin, fx32 fovyCos, fx32 aspect, fx32 n, fx32 f, fx32 scaleW, MtxFx44 * mtx);
void MTX_OrthoW(fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, fx32 scaleW, MtxFx44 * mtx);
void MTX_Identity44_(register MtxFx44 * pDst);
void MTX_Copy44To33_(register const MtxFx44 * pSrc, register MtxFx33 * pDst);
void MTX_Copy44To43_(register const MtxFx44 * pSrc, register MtxFx43 * pDst);
void MTX_Transpose44_(register const MtxFx44 * pSrc, register MtxFx44 * pDst);
void MTX_Scale44_(register MtxFx44 * pDst, register fx32 x, register fx32 y, register fx32 z);
void MTX_RotX44_(register MtxFx44 * pDst, register fx32 sinVal, register fx32 cosVal);
void MTX_RotY44_(register MtxFx44 * pDst, register fx32 sinVal, register fx32 cosVal);
void MTX_RotZ44_(register MtxFx44 * pDst, register fx32 sinVal, register fx32 cosVal);
SDK_INLINE void MTX_Identity44 (MtxFx44 * pDst)
{
SDK_NULL_ASSERT(pDst);
MTX_Identity44_(pDst);
}
SDK_INLINE void MTX_Copy44 (const MtxFx44 * pSrc, MtxFx44 * pDst)
{
SDK_NULL_ASSERT(pSrc);
SDK_NULL_ASSERT(pDst);
MI_Copy64B(pSrc, pDst);
}
SDK_INLINE void MTX_Copy44To33 (const MtxFx44 * pSrc, MtxFx33 * pDst)
{
SDK_NULL_ASSERT(pSrc);
SDK_NULL_ASSERT(pDst);
MTX_Copy44To33_(pSrc, pDst);
}
SDK_INLINE void MTX_Copy44To43 (const MtxFx44 * pSrc, MtxFx43 * pDst)
{
SDK_NULL_ASSERT(pSrc);
SDK_NULL_ASSERT(pDst);
MTX_Copy44To43_(pSrc, pDst);
}
SDK_INLINE void MTX_Transpose44 (const MtxFx44 * pSrc, MtxFx44 * pDst)
{
SDK_NULL_ASSERT(pSrc);
SDK_NULL_ASSERT(pDst);
MTX_Transpose44_(pSrc, pDst);
}
SDK_INLINE void MTX_Scale44 (MtxFx44 * pDst, fx32 x, fx32 y, fx32 z)
{
SDK_NULL_ASSERT(pDst);
MTX_Scale44_(pDst, x, y, z);
}
SDK_INLINE void MTX_RotX44 (MtxFx44 * pDst, fx32 sinVal, fx32 cosVal)
{
SDK_NULL_ASSERT(pDst);
MTX_RotX44_(pDst, sinVal, cosVal);
}
SDK_INLINE void MTX_RotY44 (MtxFx44 * pDst, fx32 sinVal, fx32 cosVal)
{
SDK_NULL_ASSERT(pDst);
MTX_RotY44_(pDst, sinVal, cosVal);
}
SDK_INLINE void MTX_RotZ44 (MtxFx44 * pDst, fx32 sinVal, fx32 cosVal)
{
SDK_NULL_ASSERT(pDst);
MTX_RotZ44_(pDst, sinVal, cosVal);
}
SDK_INLINE void MTX_Frustum (fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, MtxFx44 * mtx)
{
MTX_FrustumW(t, b, l, r, n, f, FX32_ONE, mtx);
}
SDK_INLINE
void MTX_Perspective (fx32 fovySin, fx32 fovyCos, fx32 aspect, fx32 n, fx32 f, MtxFx44 * mtx)
{
MTX_PerspectiveW(fovySin, fovyCos, aspect, n, f, FX32_ONE, mtx);
}
SDK_INLINE void MTX_Ortho (fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, MtxFx44 * mtx)
{
MTX_OrthoW(t, b, l, r, n, f, FX32_ONE, mtx);
}
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,72 @@
#ifndef NITRO_G3_UTIL_H_
#define NITRO_G3_UTIL_H_
#include <nitro/gx/gxcommon.h>
#include <nitro/gx/g3.h>
#include <nitro/fx/fx_const.h>
#include <nitro/fx/fx_mtx43.h>
#include <nitro/fx/fx_mtx44.h>
#ifdef __cplusplus
extern "C" {
#endif
void G3i_FrustumW_(fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, fx32 scaleW, BOOL draw, MtxFx44 * mtx);
void G3i_PerspectiveW_(fx32 fovySin, fx32 fovyCos, fx32 aspect, fx32 n, fx32 f, fx32 scaleW, BOOL draw, MtxFx44 * mtx);
void G3i_OrthoW_(fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, fx32 scaleW, BOOL draw, MtxFx44 * mtx);
void G3i_LookAt_(const VecFx32 * camPos, const VecFx32 * camUp, const VecFx32 * target, BOOL draw, MtxFx43 * mtx);
void G3_RotX(fx32 s, fx32 c);
void G3_RotY(fx32 s, fx32 c);
void G3_RotZ(fx32 s, fx32 c);
void G3_LoadTexMtxTexCoord(const MtxFx44 * mtx);
void G3_LoadTexMtxEnv(const MtxFx44 * mtx);
void G3BS_LoadTexMtxTexCoord(GXDLInfo * info, const MtxFx44 * mtx);
void G3CS_LoadTexMtxTexCoord(GXDLInfo * info, const MtxFx44 * mtx);
void G3B_LoadTexMtxTexCoord(GXDLInfo * info, const MtxFx44 * mtx);
void G3C_LoadTexMtxTexCoord(GXDLInfo * info, const MtxFx44 * mtx);
void G3BS_LoadTexMtxEnv(GXDLInfo * info, const MtxFx44 * mtx);
void G3B_LoadTexMtxEnv(GXDLInfo * info, const MtxFx44 * mtx);
void G3CS_LoadTexMtxEnv(GXDLInfo * info, const MtxFx44 * mtx);
void G3C_LoadTexMtxEnv(GXDLInfo * info, const MtxFx44 * mtx);
static inline void G3_Frustum (fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, MtxFx44 * mtx)
{
G3i_FrustumW_(t, b, l, r, n, f, FX32_ONE, TRUE, mtx);
}
static inline void G3_Perspective (fx32 fovySin, fx32 fovyCos, fx32 aspect, fx32 n, fx32 f, MtxFx44 * mtx)
{
G3i_PerspectiveW_(fovySin, fovyCos, aspect, n, f, FX32_ONE, TRUE, mtx);
}
static inline void G3_Ortho (fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, MtxFx44 * mtx)
{
G3i_OrthoW_(t, b, l, r, n, f, FX32_ONE, TRUE, mtx);
}
static inline void G3_FrustumW (fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, fx32 scaleW, MtxFx44 * mtx)
{
G3i_FrustumW_(t, b, l, r, n, f, scaleW, TRUE, mtx);
}
static inline void G3_PerspectiveW (fx32 fovySin, fx32 fovyCos, fx32 aspect, fx32 n, fx32 f, fx32 scaleW, MtxFx44 * mtx)
{
G3i_PerspectiveW_(fovySin, fovyCos, aspect, n, f, scaleW, TRUE, mtx);
}
static inline void G3_OrthoW (fx32 t, fx32 b, fx32 l, fx32 r, fx32 n, fx32 f, fx32 scaleW, MtxFx44 * mtx)
{
G3i_OrthoW_(t, b, l, r, n, f, scaleW, TRUE, mtx);
}
static inline void G3_LookAt (const VecFx32 * camPos, const VecFx32 * camUp, const VecFx32 * target, MtxFx43 * mtx)
{
G3i_LookAt_(camPos, camUp, target, TRUE, mtx);
}
#ifdef __cplusplus
}
#endif
#endif