mirror of
https://github.com/ACreTeam/ac-decomp
synced 2026-05-23 06:34:18 -04:00
Implement & link sys_math3d
This commit is contained in:
@@ -357,6 +357,11 @@ main.c:
|
||||
.text: [0x80407AE8, 0x80407CF4]
|
||||
.data: [0x8065F110, 0x8065F138]
|
||||
.bss: [0x812F4CC0, 0x812F5038]
|
||||
sys_math3d.c:
|
||||
.text: [0x80408A44, 0x8040C06C]
|
||||
.rodata: [0x806437D0, 0x80643810]
|
||||
.data: [0x8065F150, 0x8065F168]
|
||||
.bss: [0x812F54A0, 0x812F5668]
|
||||
#sys_math.c:
|
||||
# .text: [0x80408940, 0x80408A44]
|
||||
# .rodata: [0x806437C0, 0x806437D0]
|
||||
|
||||
+66
-46
@@ -4,36 +4,32 @@
|
||||
|
||||
/* this is needed to keep $localstatic$ variables out of the rel */
|
||||
#ifndef OPTIMIZED_SQRTF
|
||||
extern inline float sqrtf(float x)
|
||||
{
|
||||
static const double _half=.5;
|
||||
static const double _three=3.0;
|
||||
volatile float y;
|
||||
if(x > 0.0f)
|
||||
{
|
||||
double guess = __frsqrte((double)x); // returns an approximation to
|
||||
guess = _half*guess*(_three - guess*guess*x); // now have 12 sig bits
|
||||
guess = _half*guess*(_three - guess*guess*x); // now have 24 sig bits
|
||||
guess = _half*guess*(_three - guess*guess*x); // now have 32 sig bits
|
||||
y=(float)(x*guess);
|
||||
return y;
|
||||
}
|
||||
return x;
|
||||
extern inline float sqrtf(float x) {
|
||||
static const double _half = .5;
|
||||
static const double _three = 3.0;
|
||||
volatile float y;
|
||||
if (x > 0.0f) {
|
||||
double guess = __frsqrte((double)x); // returns an approximation to
|
||||
guess = _half * guess * (_three - guess * guess * x); // now have 12 sig bits
|
||||
guess = _half * guess * (_three - guess * guess * x); // now have 24 sig bits
|
||||
guess = _half * guess * (_three - guess * guess * x); // now have 32 sig bits
|
||||
y = (float)(x * guess);
|
||||
return y;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
#else
|
||||
extern inline float sqrtf(float x)
|
||||
{
|
||||
volatile float y;
|
||||
if(x > 0.0f)
|
||||
{
|
||||
double guess = __frsqrte((double)x); // returns an approximation to
|
||||
guess = .5*guess*(3.0 - guess*guess*x); // now have 12 sig bits
|
||||
guess = .5*guess*(3.0 - guess*guess*x); // now have 24 sig bits
|
||||
guess = .5*guess*(3.0 - guess*guess*x); // now have 32 sig bits
|
||||
y=(float)(x*guess);
|
||||
return y;
|
||||
}
|
||||
return x;
|
||||
extern inline float sqrtf(float x) {
|
||||
volatile float y;
|
||||
if (x > 0.0f) {
|
||||
double guess = __frsqrte((double)x); // returns an approximation to
|
||||
guess = .5 * guess * (3.0 - guess * guess * x); // now have 12 sig bits
|
||||
guess = .5 * guess * (3.0 - guess * guess * x); // now have 24 sig bits
|
||||
guess = .5 * guess * (3.0 - guess * guess * x); // now have 32 sig bits
|
||||
y = (float)(x * guess);
|
||||
return y;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -42,29 +38,53 @@ extern inline float sqrtf(float x)
|
||||
/*
|
||||
extern inline float sqrtf2(float x)
|
||||
{
|
||||
static const double _half=.5;
|
||||
static const double _three=3.0;
|
||||
volatile float y;
|
||||
if(x > 0.0f)
|
||||
{
|
||||
double guess = __frsqrte((double)x); // returns an approximation to
|
||||
guess = _half*guess*(_three - guess*guess*x); // now have 12 sig bits
|
||||
guess = _half*guess*(_three - guess*guess*x); // now have 24 sig bits
|
||||
guess = _half*guess*(_three - guess*guess*x); // now have 32 sig bits
|
||||
y=(float)(x*guess);
|
||||
return y;
|
||||
}
|
||||
return x;
|
||||
static const double _half=.5;
|
||||
static const double _three=3.0;
|
||||
volatile float y;
|
||||
if(x > 0.0f)
|
||||
{
|
||||
double guess = __frsqrte((double)x); // returns an approximation to
|
||||
guess = _half*guess*(_three - guess*guess*x); // now have 12 sig bits
|
||||
guess = _half*guess*(_three - guess*guess*x); // now have 24 sig bits
|
||||
guess = _half*guess*(_three - guess*guess*x); // now have 32 sig bits
|
||||
y=(float)(x*guess);
|
||||
return y;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
*/
|
||||
|
||||
extern inline double fabs(double x)
|
||||
{
|
||||
return __fabs(x) ;
|
||||
extern inline double fabs(double x) {
|
||||
return __fabs(x);
|
||||
}
|
||||
|
||||
inline float fabsf(float x) {
|
||||
return (float)fabs((double)x);
|
||||
return (float)fabs((double)x);
|
||||
}
|
||||
|
||||
int __float_huge[];
|
||||
int __float_nan[];
|
||||
int __double_huge[];
|
||||
int __extended_huge[];
|
||||
|
||||
#define INFINITY (*(float*)__float_huge)
|
||||
#define NAN (*(float*)__float_nan)
|
||||
#define HUGE_VALF (*(float*)__float_huge)
|
||||
|
||||
extern inline double sqrt(double x) {
|
||||
if (x > 0.0) {
|
||||
double guess = __frsqrte(x);
|
||||
guess = .5 * guess * (3.0 - guess * guess * x);
|
||||
guess = .5 * guess * (3.0 - guess * guess * x);
|
||||
guess = .5 * guess * (3.0 - guess * guess * x);
|
||||
guess = .5 * guess * (3.0 - guess * guess * x);
|
||||
return x * guess;
|
||||
} else if (x == 0.0f) {
|
||||
return 0.0;
|
||||
} else if (x) {
|
||||
return NAN;
|
||||
}
|
||||
return INFINITY;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -78,4 +98,4 @@ f64 acos(f32);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
+83
-27
@@ -8,43 +8,99 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct math_3d_linef_s {
|
||||
/* 0x0000 */ xyz_t a;
|
||||
/* 0x000C */ xyz_t b;
|
||||
} Math3D_linef_c; // size = 0x18
|
||||
|
||||
typedef struct math_3d_pipe_s {
|
||||
s16 radius;
|
||||
s16 height;
|
||||
s16 offset;
|
||||
s_xyz center;
|
||||
s16 radius;
|
||||
s16 height;
|
||||
s16 offset;
|
||||
s_xyz center;
|
||||
} Math3D_pipe_c;
|
||||
|
||||
typedef struct math_3d_sphere_s{
|
||||
s_xyz center;
|
||||
s16 radius;
|
||||
}Math3D_sphere_c;
|
||||
typedef struct math_3d_sphere_s {
|
||||
s_xyz center;
|
||||
s16 radius;
|
||||
} Math3D_sphere_c;
|
||||
|
||||
typedef struct math_3d_plane_s {
|
||||
xyz_t normal;
|
||||
f32 originDist;
|
||||
xyz_t normal;
|
||||
f32 originDist;
|
||||
} Math3D_plane_c; // size = 0x10
|
||||
|
||||
typedef struct math_3d_triangle_s {
|
||||
xyz_t vtx[3];
|
||||
Math3D_plane_c plane;
|
||||
xyz_t vtx[3];
|
||||
Math3D_plane_c plane;
|
||||
} Math3D_triangle_c; // size = 0x34
|
||||
|
||||
extern f32 Math3DVecLength(xyz_t* vec);
|
||||
extern f32 Math3DVecLengthSquare2D(f32 x, f32 y);
|
||||
extern void sMath_RotateX(xyz_t* pos, f32 rad);
|
||||
extern void sMath_RotateY(xyz_t* pos, f32 rad);
|
||||
extern void sMath_RotateZ(xyz_t* pos, f32 rad);
|
||||
extern f32 Math3d_normalizeXyz_t(xyz_t* vec);
|
||||
extern f32 Math3DLength(xyz_t* v0, xyz_t* v1);
|
||||
extern void Math3DInDivPos2(const xyz_t* v0, const xyz_t* v1, xyz_t* v2, f32 percent);
|
||||
extern void Math3DPlane(xyz_t* va, xyz_t* vb, xyz_t* vc, f32* nox, f32* noy, f32* noz, f32* odist);
|
||||
extern int Math3D_sphereCrossSphere_cl(Math3D_sphere_c* a, Math3D_sphere_c* b, f32* in);
|
||||
extern int Math3D_sphereVsPipe_cl(Math3D_sphere_c* s, Math3D_pipe_c* c, f32* in);
|
||||
extern int Math3D_pipeVsPipe_cl(Math3D_pipe_c* a, Math3D_pipe_c* b , f32* d);
|
||||
extern int Math3D_sphereCrossTriangle3_cp(Math3D_sphere_c* s, Math3D_triangle_c* tri, xyz_t* ip);
|
||||
extern int Math3D_pipeCrossTriangle_cp(Math3D_pipe_c* c,Math3D_triangle_c* tri, xyz_t* in);
|
||||
typedef struct math_3d_spheref_s {
|
||||
xyz_t center;
|
||||
f32 radius;
|
||||
} Math3D_sphereF_c;
|
||||
|
||||
typedef struct math_3d_pipef_s {
|
||||
f32 radius;
|
||||
f32 height;
|
||||
f32 offset;
|
||||
xyz_t center;
|
||||
} Math3D_pipeF_c;
|
||||
|
||||
// extern f32 Math3DVecLength(xyz_t* vec);
|
||||
// extern f32 Math3DVecLengthSquare2D(f32 x, f32 y);
|
||||
// extern void sMath_RotateX(xyz_t* pos, f32 rad);
|
||||
// extern void sMath_RotateY(xyz_t* pos, f32 rad);
|
||||
// extern void sMath_RotateZ(xyz_t* pos, f32 rad);
|
||||
// extern f32 Math3d_normalizeXyz_t(xyz_t* vec);
|
||||
// extern f32 Math3DLength(xyz_t* v0, xyz_t* v1);
|
||||
// extern void Math3DInDivPos2(const xyz_t* v0, const xyz_t* v1, xyz_t* v2, f32 percent);
|
||||
// extern void Math3DPlane(xyz_t* va, xyz_t* vb, xyz_t* vc, f32* nox, f32* noy, f32* noz, f32* odist);
|
||||
// extern int Math3D_sphereCrossSphere_cl(Math3D_sphere_c* a, Math3D_sphere_c* b, f32* in);
|
||||
// extern int Math3D_sphereVsPipe_cl(Math3D_sphere_c* s, Math3D_pipe_c* c, f32* in);
|
||||
// extern int Math3D_pipeVsPipe_cl(Math3D_pipe_c* a, Math3D_pipe_c* b, f32* d);
|
||||
// extern int Math3D_sphereCrossTriangle3_cp(Math3D_sphere_c* s, Math3D_triangle_c* tri, xyz_t* ip);
|
||||
// extern int Math3D_pipeCrossTriangle_cp(Math3D_pipe_c* c, Math3D_triangle_c* tri, xyz_t* in);
|
||||
// extern void Math3DVectorProduct2Vec(const xyz_t* a, xyz_t* b, xyz_t* ret);
|
||||
|
||||
extern f32 Math3d_normalizeXyz_t(xyz_t* a);
|
||||
extern void Math3DInDivPos1(const xyz_t* v, const xyz_t* d, f32 t, xyz_t* c);
|
||||
extern void Math3DInDivPos2(const xyz_t* v, const xyz_t* d, xyz_t* c, f32 t);
|
||||
extern f32 Math3DVecLengthSquare2D(f32 a, f32 b);
|
||||
extern f32 Math3DVecLength2D(f32 a, f32 b);
|
||||
extern f32 Math3DLengthSquare2D(f32 x0, f32 y0, f32 x1, f32 y1);
|
||||
extern f32 Math3DLength2D(f32 x0, f32 x1, f32 y0, f32 y1);
|
||||
extern f32 Math3DVecLengthSquare(xyz_t* v);
|
||||
extern f32 Math3DVecLength(xyz_t* v);
|
||||
extern f32 Math3DLengthSquare(xyz_t* a, xyz_t* b);
|
||||
extern f32 Math3DLength(xyz_t* a, xyz_t* b);
|
||||
extern void Math3DVectorProduct2Vec(const xyz_t* a, xyz_t* b, xyz_t* ret);
|
||||
extern void Math3DVectorProductXYZ(xyz_t* va, xyz_t* vb, xyz_t* vc, xyz_t* ret);
|
||||
extern void Math3DPlane(xyz_t* va, xyz_t* vb, xyz_t* vc, f32* nox, f32* noy, f32* noz, f32* odist);
|
||||
extern f32 Math3DPlaneFunc(f32 nox, f32 noy, f32 noz, f32 odist, xyz_t* pl);
|
||||
extern f32 Math3DLengthPlaneAndPos(f32 nox, f32 noy, f32 noz, f32 odist, xyz_t* pl);
|
||||
extern f32 Math3DSignedLengthPlaneAndPos(f32 nox, f32 noy, f32 noz, f32 odist, xyz_t* pl);
|
||||
extern int Math3DTriangleCrossYCheck_general(xyz_t* v0, xyz_t* v1, xyz_t* v2, f32 z, f32 x, f32 dt, f32 dist, f32 noy);
|
||||
extern int Math3DTriangleCrossYLine_scope(xyz_t* v0, xyz_t* v1, xyz_t* v2, f32 nox, f32 noy, f32 noz, f32 dst, f32 z,
|
||||
f32 x, f32* yint, f32 y0, f32 y1);
|
||||
extern int Math3DTriangleCrossZCheck_general(xyz_t* v0, xyz_t* v1, xyz_t* v2, f32 x, f32 y, f32 dt, f32 dist, f32 noz);
|
||||
extern int Math3D_sphereCollisionPoint(Math3D_sphere_c* s, xyz_t* p);
|
||||
extern int Math3D_pointVsLineSegmentLengthSquare2D(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* lsq);
|
||||
extern int Math3D_sphereCrossLineSegment(Math3D_sphere_c* s, Math3D_linef_c* l);
|
||||
extern void Math3D_sphereCrossTriangleCalc_cp(Math3D_sphere_c* s, Math3D_triangle_c* tri, xyz_t* ip);
|
||||
extern int Math3D_sphereCrossTriangle3_cp(Math3D_sphere_c* s, Math3D_triangle_c* tri, xyz_t* ip);
|
||||
extern int Math3D_pipeVsPos(Math3D_pipe_c* c, xyz_t* p);
|
||||
extern int Math3D_pipeCrossLine(Math3D_pipe_c* c, xyz_t* la, xyz_t* lb, xyz_t* ia, xyz_t* ib);
|
||||
extern int Math3D_pipeCrossTriangle_cp(Math3D_pipe_c* c, Math3D_triangle_c* tri, xyz_t* in);
|
||||
extern int Math3D_sphereCrossSphere_cl(Math3D_sphere_c* a, Math3D_sphere_c* b, f32* in);
|
||||
extern int Math3D_sphereCrossSphere_cl_cc(Math3D_sphere_c* a, Math3D_sphere_c* b, f32* in, f32* cdist);
|
||||
extern int Math3D_sphereVsPipe_cl(Math3D_sphere_c* s, Math3D_pipe_c* c, f32* in);
|
||||
extern int Math3D_sphereVsPipe_cl_cc(Math3D_sphere_c* s, Math3D_pipe_c* c, f32* in, f32* cdist);
|
||||
extern int Math3D_pipeVsPipe_cl(Math3D_pipe_c* a, Math3D_pipe_c* b, f32* d);
|
||||
extern int Math3D_pipeVsPipe_cl_cc(Math3D_pipe_c* a, Math3D_pipe_c* b, f32* d, f32* di);
|
||||
extern void sMath_RotateY(xyz_t* v, f32 y);
|
||||
extern void sMath_RotateX(xyz_t* v, f32 x);
|
||||
extern void sMath_RotateZ(xyz_t* v, f32 z);
|
||||
|
||||
extern xyz_t ZeroVec;
|
||||
extern s_xyz ZeroSVec;
|
||||
@@ -53,4 +109,4 @@ extern s_xyz ZeroSVec;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
+1047
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user