Skip to content

Commit

Permalink
Finish matching xVec3
Browse files Browse the repository at this point in the history
  • Loading branch information
tgsm committed Jul 4, 2024
1 parent 2d9eb0d commit 53bae90
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 61 deletions.
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
113 changes: 56 additions & 57 deletions src/SB/Core/x/xVec3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,90 +2,89 @@
#include "xCollide.h"
#include "xMathInlines.h"
#include "iMath.h"
#include "xMath.h"

#include <types.h>
#include <fastmath.h>

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);
Expand Down
6 changes: 3 additions & 3 deletions src/SB/Core/x/xVec3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 53bae90

Please sign in to comment.