From 53bae903665e234f36f03a0acbd6dee2e34c64db Mon Sep 17 00:00:00 2001 From: tgsm Date: Wed, 3 Jul 2024 20:14:42 -0500 Subject: [PATCH] Finish matching xVec3 --- configure.py | 2 +- src/SB/Core/x/xVec3.cpp | 113 ++++++++++++++++++++-------------------- src/SB/Core/x/xVec3.h | 6 +-- 3 files changed, 60 insertions(+), 61 deletions(-) diff --git a/configure.py b/configure.py index d9a59965d..8f21e76ac 100644 --- a/configure.py +++ b/configure.py @@ -335,7 +335,7 @@ def Rel(lib_name: str, objects: List[Object]) -> Dict[str, Any]: Object(NonMatching, "SB/Core/x/xTimer.cpp"), Object(NonMatching, "SB/Core/x/xTRC.cpp"), Object(Matching, "SB/Core/x/xutil.cpp"), - Object(NonMatching, "SB/Core/x/xVec3.cpp"), + Object(Matching, "SB/Core/x/xVec3.cpp"), Object(NonMatching, "SB/Game/zActionLine.cpp"), Object(Equivalent, "SB/Game/zAnimList.cpp"), Object(NonMatching, "SB/Game/zAssetTypes.cpp"), diff --git a/src/SB/Core/x/xVec3.cpp b/src/SB/Core/x/xVec3.cpp index b0014ef3f..1a6f9c5d7 100644 --- a/src/SB/Core/x/xVec3.cpp +++ b/src/SB/Core/x/xVec3.cpp @@ -2,90 +2,89 @@ #include "xCollide.h" #include "xMathInlines.h" #include "iMath.h" +#include "xMath.h" #include #include -extern float32 lbl_803CD158; // 1.0f -extern float32 lbl_803CD15C; // 1.0 * 10^-5f -extern float32 lbl_803CD160; // 0.0f +const xVec3 xVec3::m_Null = { 0.0f, 0.0f, 0.0f }; +const xVec3 xVec3::m_UnitAxisX = { 1.0f, 0.0f, 0.0f }; +const xVec3 xVec3::m_UnitAxisY = { 0.0f, 1.0f, 0.0f }; -#if 0 -// Works except for register swapping. float32 xVec3Normalize(xVec3* o, const xVec3* v) { + float32 x = v->x; + float32 x2 = SQR(v->x); + float32 y = v->y; + float32 y2 = SQR(v->y); + float32 z = v->z; + float32 z2 = SQR(v->z); + float32 len; - float32 len2 = v->x * v->x; - len2 += v->y * v->y; - len2 += v->z * v->z; - if ((float32)iabs(len2 - lbl_803CD158) <= lbl_803CD15C) + float32 len2 = x2 + y2 + z2; + + if ((float32)iabs(len2 - 1.0f) <= 0.00001f) { - o->x = v->x; - o->y = v->y; - o->z = v->z; - len = lbl_803CD158; + o->x = x; + o->y = y; + o->z = z; + len = 1.0f; + } + else if ((float32)iabs(len2) <= 0.00001f) + { + o->x = 0.0f; + o->y = 1.0f; + o->z = 0.0f; + len = 0.0f; } else { - if ((float32)iabs(len2) <= lbl_803CD15C) - { - o->x = lbl_803CD160; - o->y = lbl_803CD158; - o->z = lbl_803CD160; - len = lbl_803CD160; - } - else - { - len = xsqrt(len2); - float32 inv_len = lbl_803CD158 / len; - o->x = v->x * inv_len; - o->y = v->y * inv_len; - o->z = v->z * inv_len; - } + len = xsqrt(len2); + float32 inv_len = 1.0f / len; + o->x = v->x * inv_len; + o->y = v->y * inv_len; + o->z = v->z * inv_len; } return len; } -#endif - -#if 0 -// Works except for register swapping. float32 xVec3NormalizeFast(xVec3* o, const xVec3* v) { + float32 x = v->x; + float32 x2 = SQR(v->x); + float32 y = v->y; + float32 y2 = SQR(v->y); + float32 z = v->z; + float32 z2 = SQR(v->z); + float32 len; - float32 len2 = v->x * v->x; - len2 += v->y * v->y; - len2 += v->z * v->z; - if ((float32)iabs(len2 - lbl_803CD158) <= lbl_803CD15C) + float32 len2 = x2 + y2 + z2; + + if ((float32)iabs(len2 - 1.0f) <= 0.00001f) { - o->x = v->x; - o->y = v->y; - o->z = v->z; - len = lbl_803CD158; + o->x = x; + o->y = y; + o->z = z; + len = 1.0f; + } + else if ((float32)iabs(len2) <= 0.00001f) + { + o->x = 0.0f; + o->y = 1.0f; + o->z = 0.0f; + len = 0.0f; } else { - if ((float32)iabs(len2) <= lbl_803CD15C) - { - o->x = lbl_803CD160; - o->y = lbl_803CD158; - o->z = lbl_803CD160; - len = lbl_803CD160; - } - else - { - xsqrtfast(len, len2); - float32 inv_len = lbl_803CD158 / len; - o->x = v->x * inv_len; - o->y = v->y * inv_len; - o->z = v->z * inv_len; - } + xsqrtfast(len, len2); + float32 inv_len = 1.0f / len; + o->x = v->x * inv_len; + o->y = v->y * inv_len; + o->z = v->z * inv_len; } return len; } -#endif - void xVec3Copy(register xVec3* dst, const register xVec3* src) { PSVECCopy(dst, src); diff --git a/src/SB/Core/x/xVec3.h b/src/SB/Core/x/xVec3.h index bea497003..fbd7f0543 100644 --- a/src/SB/Core/x/xVec3.h +++ b/src/SB/Core/x/xVec3.h @@ -9,9 +9,9 @@ struct xVec3 float32 y; float32 z; - static xVec3 m_Null; - static xVec3 m_UnitAxisX; - static xVec3 m_UnitAxisY; + static const xVec3 m_Null; + static const xVec3 m_UnitAxisX; + static const xVec3 m_UnitAxisY; static xVec3 create(float32 x, float32 y, float32 z); static xVec3 create(float32 f);