From 8af1430e9b669e0ef743165efd84d5a5f44ce2f1 Mon Sep 17 00:00:00 2001 From: angie Date: Fri, 1 Apr 2022 23:31:55 -0300 Subject: [PATCH 01/29] Use matched sys_math3d functions by Tharo Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com> --- include/functions.h | 26 +- include/variables.h | 6 +- include/z64collision_check.h | 2 +- include/z64math.h | 2 +- src/code/sys_math3d.c | 2188 ++++++++++++++++++++++++++++++++-- src/code/z_bgcheck.c | 2 +- src/code/z_collision_check.c | 4 +- tools/disasm/variables.txt | 2 +- 8 files changed, 2136 insertions(+), 96 deletions(-) diff --git a/include/functions.h b/include/functions.h index 79d2f0d55..8fa47f170 100644 --- a/include/functions.h +++ b/include/functions.h @@ -3002,7 +3002,7 @@ s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 s32 func_80179798(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3, Vec3f* param_4, Vec3f* param_5, Vec3f* param_6); // void func_80179A44(void); void func_80179B34(float fParm1, f32 fParm2, f32 fParm5, f32 fParm6, f32 param_5, f32 param_6, f32 param_7, float* param_8, float* param_9); -// UNK_TYPE4 func_80179B94(f32 fParm1, f32 fParm2, f32 fParm5, f32 param_4, f32 param_5, f32 param_6, f32 param_7, f32 param_8, Vec3f* param_9); +s32 func_80179B94(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, InfiniteLine* intersect); // void func_80179D74(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); void Math3D_ScaleAndAdd(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dst); void Math3D_Lerp(Vec3f* a, Vec3f* b, f32 t, Vec3f* dst); @@ -3028,15 +3028,15 @@ f32 func_8017A7F8(f32* param_1, f32* param_2, f32 param_3, f32 param_4); f32 func_8017A838(f32* param_1, f32* param_2, f32 param_3, f32 param_4); void Math3D_CrossProduct(Vec3f* a, Vec3f* b, Vec3f* res); void Math3D_SurfaceNorm(Vec3f* a, Vec3f* b, Vec3f* c, Vec3f* res); -u32 Math3D_PointRelativeToCubeFaces(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); -u32 Math3D_PointRelativeToCubeEdges(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); -u32 Math3D_PointRelativeToCubeVertices(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); +s32 Math3D_PointRelativeToCubeFaces(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); +s32 Math3D_PointRelativeToCubeEdges(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); +s32 Math3D_PointRelativeToCubeVertices(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b); // void func_8017B68C(void); void func_8017B7F8(Vec3f* arg0, s16 arg1, f32* arg2, f32* arg3, f32* arg4); void Math3D_UnitNormalVector(Vec3f* a, Vec3f* b, Vec3f* c, f32* normX, f32* normY, f32* normZ, f32* param_7); f32 Math3D_SignedDistanceFromPlane(f32 normX, f32 normY, f32 normZ, f32 d, Vec3f* position); -// void func_8017B9D8(void); +f32 func_8017B9D8(Plane* plane, Vec3f* pointOnPlane); f32 Math3D_UDistPlaneToPos(f32 normX, f32 normY, f32 normZ, f32 d, Vec3f* position); f32 Math3D_DistPlaneToPos(f32 normX, f32 normY, f32 normZ, f32 d, Vec3f* position); s32 Math3D_TriChkPointParaYDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 unk, f32 chkDist, f32 ny); @@ -3063,19 +3063,19 @@ s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, // void func_8017D1AC(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); // void func_8017D220(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); s32 Math3D_LineSegVsPlane(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersect, s32 fromFront); -// void func_8017D404(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11); +s32 func_8017D404(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersect, s32 fromFront) ; void Math3D_TriSetCoords(TriNorm* tri, Vec3f* pointA, Vec3f* pointB, Vec3f* pointC); -u32 Math3D_IsPointInSphere(Sphere16* sphere, Vec3f* point); +s32 Math3D_IsPointInSphere(Sphere16* sphere, Vec3f* point); s32 Math3D_PointDistToLine2D(f32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f32* arg6, f32* arg7, f32* arg8); // returns boolean s32 func_8017D7C0(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* lineLenSq); -// void func_8017D814(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); -// void func_8017D91C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); -// void func_8017DA24(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); -s32 Math3D_LineVsSph(Sphere16* sphere, LineSegment* line); +s32 func_8017D814(f32 x0, f32 y0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); +s32 func_8017D91C(f32 y0, f32 z0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); +s32 func_8017DA24(f32 z0, f32 x0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); +s32 Math3D_LineVsSph(Sphere16* sphere, Linef* line); void func_8017DD34(Sphere16* sphere, TriNorm* tri, Vec3f* pfParm3); s32 Math3D_ColSphereTri(Sphere16* sphere, TriNorm* tri, Vec3f* uParm3); -// void func_8017E294(void); -UNK_TYPE func_8017E350(UNK_PTR, Vec3f*, Vec3f*, Vec3f*, Vec3f*); +s32 func_8017E294(Cylinder16* cyl, Vec3f* point); +s32 func_8017E350(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersectA, Vec3f* intersectB); s32 Math3D_ColCylinderTri(Cylinder16* cylinder, TriNorm* tri, Vec3f* pzParm3); // void func_8017F1A0(void); s32 Math3D_SphVsSph(Sphere16* sphere1, Sphere16* sphere2); diff --git a/include/variables.h b/include/variables.h index 1ce8e336d..20af3294f 100644 --- a/include/variables.h +++ b/include/variables.h @@ -3097,14 +3097,14 @@ extern Vec3f D_801EDE20; extern Vec3f D_801EDE30; extern TriNorm D_801EDE40; extern TriNorm D_801EDE78; -extern LineSegment D_801EDEB0; +extern Linef D_801EDEB0; extern TriNorm D_801EDEC8; extern TriNorm D_801EDF00; extern Vec3f D_801EDF38; extern Vec3f D_801EDF48; extern TriNorm D_801EDF58; extern TriNorm D_801EDF90; -extern LineSegment D_801EDFC8; +extern Linef D_801EDFC8; extern Vec3f D_801EDFE0; extern Vec3f D_801EDFF0; extern TriNorm D_801EE000; @@ -3342,7 +3342,7 @@ extern UNK_TYPE2 D_801FBBCE; // extern UNK_TYPE1 D_801FBBD4; // extern UNK_TYPE1 D_801FBBE0; extern Vec3f D_801FBBF0; -extern LineSegment Math3D_ColSphereTri_line; +extern Linef Math3D_ColSphereTri_line; extern Vec3f Math3D_ColSphereTri_point; // extern UNK_TYPE1 D_801FBC28; // extern UNK_TYPE1 D_801FBC2C; diff --git a/include/z64collision_check.h b/include/z64collision_check.h index fbfcff7ae..c7f944882 100644 --- a/include/z64collision_check.h +++ b/include/z64collision_check.h @@ -237,7 +237,7 @@ typedef struct { } ColliderSphereInit; // size = 0x2C typedef struct { - /* 0x00 */ LineSegment line; + /* 0x00 */ Linef line; /* 0x18 */ u16 ocFlags; } OcLine; // size = 0x1C diff --git a/include/z64math.h b/include/z64math.h index de0285e6c..0c3b3b662 100644 --- a/include/z64math.h +++ b/include/z64math.h @@ -81,7 +81,7 @@ typedef struct { typedef struct { /* 0x00 */ Vec3f a; /* 0x0C */ Vec3f b; -} LineSegment; // size = 0x18 +} Linef; // size = 0x18 // Defines a point in the spherical coordinate system typedef struct { diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 45b94d569..7adfcad28 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -1,56 +1,555 @@ #include "global.h" -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_Normalize.s") +#define Math3D_PlaneVsPlaneNewLine func_80179B94 +#define Math3D_LineSegMakePerpLineSeg func_80179798 +#define Math3D_Vec3f_Cross Math3D_CrossProduct +#define Math3D_Plane func_8017B9D8 +#define Math3D_TriLineIntersect func_8017D404 +#define Math3D_CylOutsideCylDist Math3D_ColCylinderCylinderAmountAndDistance +#define Math3D_CylOutsideCyl Math3D_ColCylinderCylinderAmount +#define Math3D_SphVsCylOverlapCenterDist Math3D_ColSphereCylinderDistanceAndAmount +#define Math3D_CylTriVsIntersect Math3D_ColCylinderTri +#define Math3D_CylVsTri func_8017F1A0 +#define Math3D_SphVsSph Math3D_SphVsSph +#define Math3D_SphVsSphOverlap Math3D_ColSphereSphereIntersect +#define Math3D_SphVsSphOverlapCenter Math3D_ColSphereSphereIntersectAndDistance +#define Math3D_SphVsCylOverlapDist Math3D_ColSphereCylinderDistance +#define Math3D_CylVsLineSeg func_8017E350 +#define Math3D_TriVsSphIntersect Math3D_ColSphereTri +#define Math3D_PointOnInfiniteLine Math3D_ScaleAndAdd +#define Math3D_LineSplitRatio Math3D_Lerp +#define Math3D_PlaneVsPlaneVsLineClosestPoint func_80179D74 +#define Math3D_PointInCyl func_8017E294 +#define Math3D_Cos Math3D_Parallel +#define Math3D_CosOut Math3D_AngleBetweenVectors +#define Math3D_Vec3fReflect func_80179F64 +#define Math3D_PointInSquare2D Math3D_XZBoundCheck +#define Math3D_Dist1DSq Math3D_XZLengthSquared +#define Math3D_Dist1D Math3D_XZLength +#define Math3D_Dist2DSq Math3D_XZDistanceSquared +#define Math3D_Dist2D Math3D_XZDistance +#define Math3D_Vec3fMagnitudeSq Math3D_LengthSquared +#define Math3D_Vec3fMagnitude Math3D_Vec3fMagnitude +#define Math3D_Vec3fDistSq Math3D_Vec3fDistSq +#define Math3D_Vec3f_DistXYZ Math3D_Distance +#define Math3D_DistXYZ16toF Math3D_DistanceS +#define Math3D_RotateXZPlane func_8017B7F8 +#define Math3D_DefPlane Math3D_UnitNormalVector +#define Math3D_PlaneF Math3D_SignedDistanceFromPlane +#define Math3D_Plane func_8017B9D8 +#define Math3D_DistPlaneToPos Math3D_DistPlaneToPos +#define Math3D_TriChkPointParaYImpl Math3D_TriChkPointParaYDist +#define Math3D_TriChkPointParaYDeterminate func_8017BD98 +#define Math3D_TriChkPointParaYSlopedY func_8017BDE0 +#define Math3D_TriChkPointParaY func_8017BF8C +#define Math3D_TriChkPointParaYDist_ func_8017C17C +#define Math3D_TriChkPointParaYImplNoCheckRange func_8017C1F0 +#define Math3D_TriChkPointParaYNoRangeCheckIntersectInsideTri Math3D_TriChkPointParaYIntersectInsideTri2 +#define Math3D_TriChkPointParaXImpl Math3D_TriChkPointParaXDist +#define Math3D_TriChkPointParaXDeterminate func_8017C808 +#define Math3D_TriChkPointParaX func_8017C904 +#define Math3D_TriChkLineSegParaXDist func_8017CB08 +#define Math3D_TriChkPointParaZImpl Math3D_TriChkLineSegParaZDist +#define Math3D_TriChkPointParaZDeterminate func_8017CEA8 +#define func_801B8B38 Math3D_TriChkPointParaZIntersect +#define Math3D_TriChkPointParaZ func_8017CFA4 +#define Math3D_TriChkLineSegParaZDist_ func_8017D1AC +#define Math3D_LineSegFindPlaneIntersect func_8017D220 +#define Math3D_TriLineIntersect func_8017D404 +#define Math3D_TriNorm Math3D_TriSetCoords +#define Math3D_PointInSph Math3D_IsPointInSphere +#define func_801B93AC Math3D_PointDistToLine2D +#define Math3D_PointDistToLine2D_ func_8017D814 +f32 Math3D_Normalize(Vec3f* vec) { + f32 magnitude = Math3D_Vec3fMagnitude(vec); + + if (IS_ZERO(magnitude)) { + return 0.0f; + } + + vec->x *= 1.0f / magnitude; + vec->y *= 1.0f / magnitude; + vec->z *= 1.0f / magnitude; + return magnitude; +} + +#ifdef NON_MATCHING +// in-function static bss +s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, + f32 planeBC, f32 planeBDist, Vec3f* linePointA, Vec3f* linePointB, + Vec3f* closestPoint) { + static InfiniteLine planeIntersectLine; + static Linef planeIntersectSeg; + + Vec3f sp34; // unused + + if (!Math3D_PlaneVsPlaneNewLine(planeAA, planeAB, planeAC, planeADist, planeBA, planeBB, planeBC, planeBDist, + &planeIntersectLine)) { + // The planes are parallel + return false; + } + + // create a line segment on the plane. + Math_Vec3f_Copy(&planeIntersectSeg.a, &planeIntersectLine.point); + planeIntersectSeg.b.x = (planeIntersectLine.dir.x * 100.0f) + planeIntersectLine.point.x; + planeIntersectSeg.b.y = (planeIntersectLine.dir.y * 100.0f) + planeIntersectLine.point.y; + planeIntersectSeg.b.z = (planeIntersectLine.dir.z * 100.0f) + planeIntersectLine.point.z; + + // closestPoint is a point on planeIntersect, sp34 is a point on linePointA, linePointB + if (!Math3D_LineSegMakePerpLineSeg(&planeIntersectSeg.a, &planeIntersectSeg.b, linePointA, linePointB, closestPoint, + &sp34)) { + return false; + } + return true; +} +#else +// static InfiniteLine planeIntersectLine; +// static Linef planeIntersectSeg; #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PlaneVsLineSegClosestPoint.s") +#endif +#ifdef NON_MATCHING +s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, + Vec3f* lineAIntersect, Vec3f* lineBIntersect) { + f32 sp5C; + f32 sp50; + f32 sp4C; + f32 sp30; + f32 temp_f0_4; + f32 temp_f18; + Vec3f lineADiff; + Vec3f lineBDiff; + Vec3f lineABPointADiff; + f32 t; + f32 t2; + f32 tempf2; + f32 tempf3; + f32 tempf4; + f32 tempf5; + + lineADiff.x = lineAPointB->x - lineAPointA->x; + lineADiff.y = lineAPointB->y - lineAPointA->y; + lineADiff.z = lineAPointB->z - lineAPointA->z; + lineBDiff.x = lineBPointB->x - lineBPointA->x; + lineBDiff.y = lineBPointB->y - lineBPointA->y; + lineBDiff.z = lineBPointB->z - lineBPointA->z; + + if (IS_ZERO(SQXYZ(lineBDiff))) { + return false; + } + sp5C = DOTXYZ(lineADiff, lineBDiff) * (1.0f / SQXYZ(lineBDiff)); + + lineABPointADiff.x = lineAPointA->x - lineBPointA->x; + lineABPointADiff.y = lineAPointA->y - lineBPointA->y; + lineABPointADiff.z = lineAPointA->z - lineBPointA->z; + + // most reordering is here. + temp_f18 = DOTXYZ(lineABPointADiff, lineBDiff) * (1.0f / SQXYZ(lineBDiff)); + + sp4C = lineADiff.x - (lineBDiff.x * sp5C); + sp50 = lineADiff.y - (lineBDiff.y * sp5C); + sp30 = lineADiff.z - (lineBDiff.z * sp5C); + + if (IS_ZERO(SQ(sp4C) + SQ(sp50) + SQ(sp30))) { + return false; + } + + t = SQ(sp4C) + SQ(sp50) + SQ(sp30); + temp_f0_4 = -((sp4C * (lineABPointADiff.x - (lineBDiff.x * temp_f18))) + + (sp50 * (lineABPointADiff.y - (lineBDiff.y * temp_f18))) + + (sp30 * (lineABPointADiff.z - (lineBDiff.z * temp_f18)))) / + t; + + lineAIntersect->x = lineAPointA->x + (lineADiff.x * temp_f0_4); + lineAIntersect->y = lineAPointA->y + (lineADiff.y * temp_f0_4); + lineAIntersect->z = lineAPointA->z + (lineADiff.z * temp_f0_4); + + lineBIntersect->x = (lineBDiff.x * (temp_f18 + (temp_f0_4 * sp5C))) + lineBPointA->x; + lineBIntersect->y = (lineBDiff.y * (temp_f18 + (temp_f0_4 * sp5C))) + lineBPointA->y; + lineBIntersect->z = (lineBDiff.z * (temp_f18 + (temp_f0_4 * sp5C))) + lineBPointA->z; + return true; +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_80179798.s") +#endif -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_80179A44.s") +#define Math3D_Vec3fMagnitudeSq Math3D_LengthSquared -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_80179B34.s") +#define Math3D_LineClosestToPoint func_80179A44 +f32 Math3D_LineClosestToPoint(Linef* line, Vec3f* pos, Vec3f* closestPoint) { + f32 dirVectorSize = Math3D_Vec3fMagnitudeSq(&line->b); + f32 t; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_80179B94.s") + if (IS_ZERO(dirVectorSize)) { + Math_Vec3f_Copy(closestPoint, pos); + } + t = (((pos->x - line->a.x) * line->b.x) + ((pos->y - line->a.y) * line->b.y) + ((pos->z - line->a.z) * line->b.z)) / + dirVectorSize; + closestPoint->x = (line->b.x * t) + line->a.x; + closestPoint->y = (line->b.y * t) + line->a.y; + closestPoint->z = (line->b.z * t) + line->a.z; + + return t; +} + +#define Math3D_FindPointOnPlaneIntersect func_80179B34 +void Math3D_FindPointOnPlaneIntersect(f32 planeAAxis1Norm, f32 planeAAxis2Norm, f32 planeBAxis1Norm, + f32 planeBAxis2Norm, f32 axis3Direction, f32 planeADist, f32 planeBDist, + f32* axis1Point, f32* axis2Point) { + *axis1Point = ((planeAAxis2Norm * planeBDist) - (planeBAxis2Norm * planeADist)) / axis3Direction; + *axis2Point = ((planeBAxis1Norm * planeADist) - (planeAAxis1Norm * planeBDist)) / axis3Direction; +} + +#define Math3D_PlaneVsPlaneNewLine func_80179B94 +s32 Math3D_PlaneVsPlaneNewLine(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, + f32 planeBC, f32 planeBDist, InfiniteLine* intersect) { + char pad[4]; + Vec3f planeANormal; + Vec3f planeBNormal; + f32 dirX; + f32 dirY; + f32 dirZ; + + VEC_SET(planeANormal, planeAA, planeAB, planeAC); + VEC_SET(planeBNormal, planeBA, planeBB, planeBC); + + Math3D_Vec3f_Cross(&planeANormal, &planeBNormal, &intersect->dir); + + if (IS_ZERO(intersect->dir.x) && IS_ZERO(intersect->dir.y) && IS_ZERO(intersect->dir.z)) { + // planes are parallel + return false; + } + + dirX = fabsf(intersect->dir.x); + dirY = fabsf(intersect->dir.y); + dirZ = fabsf(intersect->dir.z); + + if ((dirX >= dirY) && (dirX >= dirZ)) { + Math3D_FindPointOnPlaneIntersect(planeAB, planeAC, planeBB, planeBC, intersect->dir.x, planeADist, planeBDist, + &intersect->point.y, &intersect->point.z); + intersect->point.x = 0.0f; + } else if ((dirY >= dirX) && (dirY >= dirZ)) { + Math3D_FindPointOnPlaneIntersect(planeAC, planeAA, planeBC, planeBA, intersect->dir.y, planeADist, planeBDist, + &intersect->point.z, &intersect->point.x); + intersect->point.y = 0.0f; + } else { + Math3D_FindPointOnPlaneIntersect(planeAA, planeAB, planeBA, planeBB, intersect->dir.z, planeADist, planeBDist, + &intersect->point.x, &intersect->point.y); + intersect->point.z = 0.0f; + } + return true; +} + +#ifdef NON_MATCHING +// in-function static bss +s32 Math3D_PlaneVsPlaneVsLineClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, + f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* point, Vec3f* closestPoint) { + static Linef planeIntersect; + + if (!Math3D_PlaneVsPlaneNewLine(planeAA, planeAB, planeAC, planeADist, planeBA, planeBB, planeBC, planeBDist, + (InfiniteLine*)&planeIntersect)) { + return false; + } + Math3D_LineClosestToPoint(&planeIntersect, point, closestPoint); + return true; +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_80179D74.s") +#endif -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ScaleAndAdd.s") +void Math3D_PointOnInfiniteLine(Vec3f* v0, Vec3f* dir, f32 dist, Vec3f* ret) { + ret->x = (dir->x * dist) + v0->x; + ret->y = (dir->y * dist) + v0->y; + ret->z = (dir->z * dist) + v0->z; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_Lerp.s") +void Math3D_LineSplitRatio(Vec3f* v0, Vec3f* v1, f32 ratio, Vec3f* ret) { + Vec3f diff; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_Parallel.s") + Math_Vec3f_Diff(v1, v0, &diff); + Math3D_PointOnInfiniteLine(v0, &diff, ratio, ret); +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_AngleBetweenVectors.s") +f32 Math3D_Cos(Vec3f* a, Vec3f* b) { + f32 ret; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_80179F64.s") + Math3D_CosOut(a, b, &ret); + return ret; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_XZBoundCheck.s") +s32 Math3D_CosOut(Vec3f* a, Vec3f* b, f32* dst) { + f32 magProduct = Math3D_Vec3fMagnitude(a) * Math3D_Vec3fMagnitude(b); -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017A09C.s") + if (IS_ZERO(magProduct)) { + *dst = 0.0f; + return true; + } + *dst = ((a->x * b->x) + (a->y * b->y) + (a->z * b->z)) / magProduct; + return false; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017A1D0.s") +void Math3D_Vec3fReflect(Vec3f* vec, Vec3f* normal, Vec3f* reflVec) { + f32 normScaleY; + Vec3f negVec; + f32 normScaleZ; + f32 normScaleX; + f32 vecDotNorm; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017A304.s") + negVec.x = vec->x * -1.0f; + negVec.y = vec->y * -1.0f; + negVec.z = vec->z * -1.0f; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017A438.s") + vecDotNorm = Math3D_Cos(&negVec, normal); -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_XZLengthSquared.s") + normScaleX = normal->x * vecDotNorm; + normScaleY = normal->y * vecDotNorm; + normScaleZ = normal->z * vecDotNorm; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_XZLength.s") + reflVec->x = ((normScaleX + vec->x) + (normScaleX + vec->x)) + negVec.x; + reflVec->y = ((normScaleY + vec->y) + (normScaleY + vec->y)) + negVec.y; + reflVec->z = ((normScaleZ + vec->z) + (normScaleZ + vec->z)) + negVec.z; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_XZDistanceSquared.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_XZDistance.s") +s32 Math3D_PointInSquare2D(f32 upperLeftX, f32 lowerRightX, f32 upperLeftY, f32 lowerRightY, f32 x, f32 y) { + if (x >= upperLeftX && x <= lowerRightX && y >= upperLeftY && y <= lowerRightY) { + return true; + } + return false; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_LengthSquared.s") +s32 func_8017A09C(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 arg5) { + f32 phi_f12; + f32 phi_f14; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_Vec3fMagnitude.s") + if (arg0->x < arg1->x) { + phi_f12 = arg0->x; + phi_f14 = arg1->x; + } else { + phi_f12 = arg1->x; + phi_f14 = arg0->x; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_Vec3fDistSq.s") + if (arg2->x < phi_f12) { + phi_f12 = arg2->x; + } else if (phi_f14 < arg2->x) { + phi_f14 = arg2->x; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_Distance.s") + if (arg3 < (phi_f12 - arg5) || (phi_f14 + arg5) < arg3) { + return 0; + } + if (arg0->y < arg1->y) { + phi_f12 = arg0->y; + phi_f14 = arg1->y; + } else { + phi_f12 = arg1->y; + phi_f14 = arg0->y; + } + if (arg2->y < phi_f12) { + phi_f12 = arg2->y; + } else if (phi_f14 < arg2->y) { + phi_f14 = arg2->y; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_DistanceS.s") + if (arg4 < (phi_f12 - arg5) || arg4 > (phi_f14 + arg5)) { + return 0; + } + return 1; +} + +s32 func_8017A1D0(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 arg5) { + f32 phi_f12; + f32 phi_f14; + + if (arg0->z < arg1->z) { + phi_f12 = arg0->z; + phi_f14 = arg1->z; + } else { + phi_f12 = arg1->z; + phi_f14 = arg0->z; + } + + if (arg2->z < phi_f12) { + phi_f12 = arg2->z; + } else if (phi_f14 < arg2->z) { + phi_f14 = arg2->z; + } + + if (arg4 < (phi_f12 - arg5) || (phi_f14 + arg5) < arg4) { + return 0; + } + + if (arg0->y < arg1->y) { + phi_f12 = arg0->y; + phi_f14 = arg1->y; + } else { + phi_f12 = arg1->y; + phi_f14 = arg0->y; + } + + if (arg2->y < phi_f12) { + phi_f12 = arg2->y; + } else if (phi_f14 < arg2->y) { + phi_f14 = arg2->y; + } + + if (arg3 < (phi_f12 - arg5) || (phi_f14 + arg5) < arg3) { + return 0; + } + return 1; +} + +s32 func_8017A304(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 arg5) { + f32 phi_f12; + f32 phi_f14; + + if (arg0->x < arg1->x) { + phi_f12 = arg0->x; + phi_f14 = arg1->x; + } else { + phi_f12 = arg1->x; + phi_f14 = arg0->x; + } + + if (arg2->x < phi_f12) { + phi_f12 = arg2->x; + } else if (phi_f14 < arg2->x) { + phi_f14 = arg2->x; + } + + if (arg4 < (phi_f12 - arg5) || (phi_f14 + arg5) < arg4) { + return 0; + } + + if (arg0->z < arg1->z) { + phi_f12 = arg0->z; + phi_f14 = arg1->z; + } else { + phi_f12 = arg1->z; + phi_f14 = arg0->z; + } + + if (arg2->z < phi_f12) { + phi_f12 = arg2->z; + } else if (phi_f14 < arg2->z) { + phi_f14 = arg2->z; + } + + if (arg3 < (phi_f12 - arg5) || (phi_f14 + arg5) < arg3) { + return 0; + } + return 1; +} + +// Math3D_SphCubeVsTriCube +s32 func_8017A438(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, f32 arg4) { + f32 phi_f0; + f32 phi_f2; + + if (arg0->x < arg1->x) { + phi_f0 = arg0->x; + phi_f2 = arg1->x; + } else { + phi_f0 = arg1->x; + phi_f2 = arg0->x; + } + + if (arg2->x < phi_f0) { + phi_f0 = arg2->x; + } else if (phi_f2 < arg2->x) { + phi_f2 = arg2->x; + } + + if (arg3->x < (phi_f0 - arg4) || (phi_f2 + arg4) < arg3->x) { + return 0; + } + + if (arg0->z < arg1->z) { + phi_f0 = arg0->z; + phi_f2 = arg1->z; + } else { + phi_f0 = arg1->z; + phi_f2 = arg0->z; + } + + if (arg2->z < phi_f0) { + phi_f0 = arg2->z; + } else if (phi_f2 < arg2->z) { + phi_f2 = arg2->z; + } + + if (arg3->z < (phi_f0 - arg4) || (phi_f2 + arg4) < arg3->z) { + return 0; + } + + if (arg0->y < arg1->y) { + phi_f0 = arg0->y; + phi_f2 = arg1->y; + } else { + phi_f0 = arg1->y; + phi_f2 = arg0->y; + } + + if (arg2->y < phi_f0) { + phi_f0 = arg2->y; + } else if (phi_f2 < arg2->y) { + phi_f2 = arg2->y; + } + + if (arg3->y < (phi_f0 - arg4) || (phi_f2 + arg4) < arg3->y) { + return 0; + } + return 1; +} + +f32 Math3D_Dist1DSq(f32 a, f32 b) { + return SQ(a) + SQ(b); +} + +f32 Math3D_Dist1D(f32 a, f32 b) { + return sqrtf(Math3D_Dist1DSq(a, b)); +} + +f32 Math3D_Dist2DSq(f32 x0, f32 y0, f32 x1, f32 y1) { + return Math3D_Dist1DSq(x0 - x1, y0 - y1); +} + +f32 Math3D_Dist2D(f32 x0, f32 y0, f32 x1, f32 y1) { + return sqrtf(Math3D_Dist2DSq(x0, y0, x1, y1)); +} + +f32 Math3D_Vec3fMagnitudeSq(Vec3f* vec) { + return SQ(vec->x) + SQ(vec->y) + SQ(vec->z); +} + +f32 Math3D_Vec3fMagnitude(Vec3f* vec) { + return sqrtf(Math3D_Vec3fMagnitudeSq(vec)); +} + +f32 Math3D_Vec3fDistSq(Vec3f* a, Vec3f* b) { + Vec3f diff; + + Math_Vec3f_Diff(a, b, &diff); + + return Math3D_Vec3fMagnitudeSq(&diff); +} + +f32 Math3D_Vec3f_DistXYZ(Vec3f* a, Vec3f* b) { + return Math_Vec3f_DistXYZ(a, b); +} + +f32 Math3D_DistXYZ16toF(Vec3s* a, Vec3f* b) { + Vec3f diff; + + diff.x = a->x - b->x; + diff.y = a->y - b->y; + diff.z = a->z - b->z; + + return Math3D_Vec3fMagnitude(&diff); +} #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017A7B8.s") @@ -58,132 +557,1673 @@ #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017A838.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_CrossProduct.s") +void Math3D_Vec3f_Cross(Vec3f* a, Vec3f* b, Vec3f* ret) { + ret->x = (a->y * b->z) - (a->z * b->y); + ret->y = (a->z * b->x) - (a->x * b->z); + ret->z = (a->x * b->y) - (a->y * b->x); +} +#ifdef NON_MATCHING +// in-function static bss +void Math3D_SurfaceNorm(Vec3f* va, Vec3f* vb, Vec3f* vc, Vec3f* normal) { + static Vec3f abDiff; + static Vec3f acDiff; + + Math_Vec3f_Diff(vb, va, &abDiff); + Math_Vec3f_Diff(vc, va, &acDiff); + Math3D_Vec3f_Cross(&abDiff, &acDiff, normal); +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_SurfaceNorm.s") +#endif -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PointRelativeToCubeFaces.s") +s32 Math3D_PointRelativeToCubeFaces(Vec3f* point, Vec3f* min, Vec3f* max) { + s32 ret = 0; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PointRelativeToCubeEdges.s") + if (point->x > max->x) { + ret = 1; + } else if (point->x < min->x) { + ret |= 2; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PointRelativeToCubeVertices.s") + if (point->y > max->y) { + ret |= 4; + } else if (point->y < min->y) { + ret |= 8; + } + if (point->z > max->z) { + ret |= 0x10; + } else if (point->z < min->z) { + ret |= 0x20; + } + + return ret; +} + +s32 Math3D_PointRelativeToCubeEdges(Vec3f* point, Vec3f* min, Vec3f* max) { + s32 ret = 0; + + if ((-min->x + max->y) < (-point->x + point->y)) { + ret |= 1; + } + + if ((-point->x + point->y) < (-max->x + min->y)) { + ret |= 2; + } + + if ((max->x + max->y) < (point->x + point->y)) { + ret |= 4; + } + + if ((point->x + point->y) < (min->x + min->y)) { + ret |= 8; + } + + if ((-min->z + max->y) < (-point->z + point->y)) { + ret |= 0x10; + } + + if ((-point->z + point->y) < (-max->z + min->y)) { + ret |= 0x20; + } + + if ((max->z + max->y) < (point->z + point->y)) { + ret |= 0x40; + } + + if ((point->z + point->y) < (min->z + min->y)) { + ret |= 0x80; + } + + if ((-min->z + max->x) < (-point->z + point->x)) { + ret |= 0x100; + } + + if ((-point->z + point->x) < (-max->z + min->x)) { + ret |= 0x200; + } + + if ((max->z + max->x) < (point->z + point->x)) { + ret |= 0x400; + } + + if ((point->z + point->x) < (min->z + min->x)) { + ret |= 0x800; + } + return ret; +} + +s32 Math3D_PointRelativeToCubeVertices(Vec3f* point, Vec3f* min, Vec3f* max) { + s32 ret = 0; + + if ((max->x + max->y + max->z) < (point->x + point->y + point->z)) { + ret = 1; + } + + if ((-min->x + max->y + max->z) < (-point->x + point->y + point->z)) { + ret |= 2; + } + + if ((-min->x + max->y - min->z) < (-point->x + point->y - point->z)) { + ret |= 4; + } + + if ((max->x + max->y - min->z) < (point->x + point->y - point->z)) { + ret |= 8; + } + + if ((max->x - min->y + max->z) < (point->x - point->y + point->z)) { + ret |= 0x10; + } + + //! @bug: The next 2 conditions are the same check. + if ((-min->x - min->y + max->z) < (-point->x - point->y + point->z)) { + ret |= 0x20; + } + + if ((-min->x - min->y + max->z) < (-point->x - point->y + point->z)) { + ret |= 0x40; + } + + if ((-min->x - min->y - min->z) < (-point->x - point->y - point->z)) { + ret |= 0x80; + } + return ret; +} + +#ifdef BSS_MATCHING +// in-function static bss +s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { + static Vec3f triVtx0; + static Vec3f triVtx1; + static Vec3f triVtx2; + static Vec3f intersectPoint; + + s32 flags[2]; + + flags[0] = flags[1] = 0; + flags[0] = Math3D_PointRelativeToCubeFaces(a, min, max); + if (!flags[0]) { + return true; + } + + flags[1] = Math3D_PointRelativeToCubeFaces(b, min, max); + if (!flags[1]) { + return true; + } + + if (flags[0] & flags[1]) { + return false; + } + + flags[0] |= (Math3D_PointRelativeToCubeEdges(a, min, max) << 8); + flags[1] |= (Math3D_PointRelativeToCubeEdges(b, min, max) << 8); + if (flags[0] & flags[1]) { + return false; + } + + flags[0] |= (Math3D_PointRelativeToCubeVertices(a, min, max) << 0x18); + flags[1] |= (Math3D_PointRelativeToCubeVertices(b, min, max) << 0x18); + if (flags[0] & flags[1]) { + return false; + } + + // face 1 + triVtx0.x = min->x; + triVtx0.y = min->y; + triVtx0.z = min->z; + triVtx1.x = min->x; + triVtx1.y = min->y; + triVtx1.z = max->z; + triVtx2.x = min->x; + triVtx2.y = max->y; + triVtx2.z = max->z; + if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, -1.0f, 0.0f, 0.0f, min->x, a, b, &intersectPoint, 0)) { + return true; + } + + triVtx1.x = min->x; + triVtx1.y = max->y; + triVtx1.z = max->z; + triVtx2.x = min->x; + triVtx2.y = max->y; + triVtx2.z = min->z; + if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, -1.0f, 0.0f, 0.0f, min->x, a, b, &intersectPoint, 0)) { + return true; + } + + // face 2 + triVtx0.x = min->x; + triVtx0.y = max->y; + triVtx0.z = max->z; + triVtx1.x = min->x; + triVtx1.y = min->y; + triVtx1.z = max->z; + triVtx2.x = max->x; + triVtx2.y = max->y; + triVtx2.z = max->z; + if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 0.0f, 0.0f, 1.0f, -max->z, a, b, &intersectPoint, 0)) { + return true; + } + triVtx0.x = max->x; + triVtx0.y = max->y; + triVtx0.z = max->z; + triVtx2.x = max->x; + //! @bug trVtx1.y should be triVtx2.y, prevents a tri on the cube from being checked. + triVtx1.y = min->y; + triVtx2.z = max->z; + if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 0.0f, 0.0f, 1.0f, -max->z, a, b, &intersectPoint, 0)) { + return true; + } + + // face 3 + triVtx0.x = min->x; + triVtx0.y = max->y; + triVtx0.z = min->z; + triVtx2.x = min->x; + triVtx2.y = max->y; + triVtx2.z = max->z; + if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 0.0f, 1.0f, 0.0f, -max->y, a, b, &intersectPoint, 0)) { + return true; + } + triVtx0.x = max->x; + triVtx0.y = max->y; + triVtx0.z = max->z; + triVtx1.x = min->x; + triVtx1.y = max->y; + triVtx1.z = min->z; + if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 0.0f, 1.0f, 0.0f, -max->y, a, b, &intersectPoint, 0)) { + return true; + } + + // face 4 + triVtx0.x = min->x; + triVtx0.y = min->y; + triVtx0.z = min->z; + triVtx1.x = min->x; + triVtx1.y = max->y; + triVtx1.z = min->z; + triVtx2.x = max->x; + triVtx2.y = max->y; + triVtx2.z = min->z; + if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 0.0f, 0.0f, -1.0f, min->z, a, b, &intersectPoint, 0)) { + return true; + } + triVtx0.x = max->x; + triVtx0.y = max->y; + triVtx0.z = min->z; + triVtx1.x = max->x; + triVtx1.y = min->y; + triVtx1.z = min->z; + + // face 5 + if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 0.0f, 0.0f, -1.0f, min->z, a, b, &intersectPoint, 0)) { + return true; + } + triVtx0.x = max->x; + triVtx0.y = min->y; + triVtx0.z = min->z; + triVtx1.x = max->x; + triVtx1.y = min->y; + triVtx1.z = max->z; + if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 0.0f, -1.0f, 0.0f, min->y, a, b, &intersectPoint, 0)) { + return true; + } + triVtx0.x = max->x; + triVtx0.y = min->y; + triVtx0.z = max->z; + triVtx1.x = min->x; + triVtx1.y = min->y; + triVtx1.z = max->z; + + // face 6 + if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 0.0f, -1.0f, 0.0f, min->y, a, b, &intersectPoint, 0)) { + return true; + } + triVtx0.x = max->x; + triVtx0.y = max->y; + triVtx0.z = max->z; + triVtx1.x = max->x; + triVtx1.y = min->y; + triVtx1.z = min->z; + triVtx2.x = max->x; + triVtx2.y = max->y; + triVtx2.z = min->z; + if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 1.0f, 0.0f, 0.0f, -max->x, a, b, &intersectPoint, 0)) { + return true; + } + triVtx0.x = max->x; + triVtx0.y = min->y; + triVtx0.z = max->z; + triVtx1.x = max->x; + triVtx1.y = min->y; + triVtx1.z = min->z; + if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 1.0f, 0.0f, 0.0f, -max->x, a, b, &intersectPoint, 0)) { + return true; + } + + return false; +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_LineVsCube.s") +#endif #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017B68C.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017B7F8.s") +void Math3D_RotateXZPlane(Vec3f* pointOnPlane, s16 angle, f32* a, f32* c, f32* d) { + *a = Math_SinS(angle) * 32767.0f; + *c = Math_CosS(angle) * 32767.0f; + *d = -((*a * pointOnPlane->x) + (*c * pointOnPlane->z)); +} +#ifdef NON_MATCHING +// in-function static bss +void Math3D_DefPlane(Vec3f* va, Vec3f* vb, Vec3f* vc, f32* nx, f32* ny, f32* nz, f32* originDist) { + static Vec3f normal; + + f32 normMagnitude; + f32 normMagInv; + + Math3D_SurfaceNorm(va, vb, vc, &normal); + normMagnitude = sqrtf(SQ(normal.x) + SQ(normal.y) + SQ(normal.z)); + if (!IS_ZERO(normMagnitude)) { + normMagInv = 1.0f / normMagnitude; + *nx = normal.x * normMagInv; + *ny = normal.y * normMagInv; + *nz = normal.z * normMagInv; + *originDist = -((*nx * va->x) + (*ny * va->y) + (*nz * va->z)); + } else { + *originDist = 0.0f; + *nz = 0.0f; + *ny = 0.0f; + *nx = 0.0f; + } +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_UnitNormalVector.s") +#endif -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_SignedDistanceFromPlane.s") +f32 Math3D_PlaneF(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* pointOnPlane) { + return (nx * pointOnPlane->x) + (ny * pointOnPlane->y) + (nz * pointOnPlane->z) + originDist; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017B9D8.s") +f32 Math3D_Plane(Plane* plane, Vec3f* pointOnPlane) { + return (plane->normal.x * pointOnPlane->x) + (plane->normal.y * pointOnPlane->y) + + (plane->normal.z * pointOnPlane->z) + plane->originDist; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_UDistPlaneToPos.s") +f32 Math3D_UDistPlaneToPos(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* p) { + return fabsf(Math3D_DistPlaneToPos(nx, ny, nz, originDist, p)); +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_DistPlaneToPos.s") +f32 Math3D_DistPlaneToPos(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* p) { + f32 normMagnitude = sqrtf(SQ(nx) + SQ(ny) + SQ(nz)); -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYDist.s") + if (IS_ZERO(normMagnitude)) { + return 0.0f; + } + return Math3D_PlaneF(nx, ny, nz, originDist, p) / normMagnitude; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017BD98.s") +s32 Math3D_TriChkPointParaYImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f32 detMax, f32 chkDist, f32 ny) { + f32 detv0v1; + f32 detv1v2; + f32 detv2v0; + f32 distToEdgeSq; + f32 chkDistSq; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017BDE0.s") + // first check if the point is within range of the triangle. + if (!func_8017A304(v0, v1, v2, z, x, chkDist)) { + return false; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYIntersectDist.s") + // check if the point is within `chkDist` units of any vertex of the triangle. + chkDistSq = SQ(chkDist); + if (SQ(v0->z - z) + SQ(v0->x - x) < chkDistSq || SQ(v1->z - z) + SQ(v1->x - x) < chkDistSq || + SQ(v2->z - z) + SQ(v2->x - x) < chkDistSq) { + return true; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYIntersectInsideTri.s") + // Calculate the determinant of each face of the triangle to the point. + // If all the of determinants are within abs(`detMax`), return true. + if (((detMax >= (detv0v1 = ((v0->z - z) * (v1->x - x)) - ((v0->x - x) * (v1->z - z)))) && + (detMax >= (detv1v2 = ((v1->z - z) * (v2->x - x)) - ((v1->x - x) * (v2->z - z)))) && + (detMax >= (detv2v0 = ((v2->z - z) * (v0->x - x)) - ((v2->x - x) * (v0->z - z)))))) { + return true; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017BF8C.s") + if (((-detMax <= (detv0v1 = ((v0->z - z) * (v1->x - x)) - ((v0->x - x) * (v1->z - z)))) && + (-detMax <= (detv1v2 = ((v1->z - z) * (v2->x - x)) - ((v1->x - x) * (v2->z - z)))) && + (-detMax <= (detv2v0 = ((v2->z - z) * (v0->x - x)) - ((v2->x - x) * (v0->z - z)))))) { + return true; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaYIntersect.s") + if (fabsf(ny) > 0.5f && chkDistSq > 0.0f) { + // Do a check on each face of the triangle, if the point is within `chkDist` units return true. + if ((func_8017DA24(z, x, v0, v1, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { + return 1; + } + if ((func_8017DA24(z, x, v1, v2, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { + return 1; + } + if ((func_8017DA24(z, x, v2, v0, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { + return 1; + } + } + return 0; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017C17C.s") +s32 Math3D_TriChkPointParaYDeterminate(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f32 detMax, f32 ny) { + return Math3D_TriChkPointParaYImpl(v0, v1, v2, z, x, detMax, 1.0f, ny); +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017C1F0.s") +s32 Math3D_TriChkPointParaYSlopedY(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x) { + return Math3D_TriChkPointParaYImpl(v0, v1, v2, z, x, 300.0f, 1.0f, 0.6f); +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYIntersectInsideTri2.s") +s32 Math3D_TriChkPointParaYIntersectDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, + f32 x, f32* yIntersect, f32 chkDist) { + if (IS_ZERO(ny)) { + return false; + } + if (Math3D_TriChkPointParaYImpl(v0, v1, v2, z, x, 300.0f, chkDist, ny)) { + *yIntersect = (f32)((((-nx * x) - (nz * z)) - originDist) / ny); + return true; + } + return false; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaXDist.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017C808.s") +s32 Math3D_TriChkPointParaYIntersectInsideTri(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, + f32 z, f32 x, f32* yIntersect, f32 chkDist) { + if (IS_ZERO(ny)) { + return false; + } + if (Math3D_TriChkPointParaYImpl(v0, v1, v2, z, x, 0.0f, chkDist, ny)) { + *yIntersect = (f32)((((-nx * x) - (nz * z)) - originDist) / ny); + return true; + } + return false; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaXIntersect.s") +s32 Math3D_TriChkPointParaY(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 ny, f32 z, f32 x) { + if (IS_ZERO(ny)) { + return false; + } + if (Math3D_TriChkPointParaYImpl(v0, v1, v2, z, x, 300.0f, 1.0f, ny)) { + return true; + } + return false; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017C904.s") +s32 Math3D_TriChkLineSegParaYIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, + f32 x, f32* yIntersect, f32 y0, f32 y1) { + f32 pointADist; + f32 pointBDist; + Vec3f planePos; + if (IS_ZERO(ny)) { + return false; + } + + planePos.x = x; + planePos.y = y0; + planePos.z = z; + + pointADist = Math3D_PlaneF(nx, ny, nz, originDist, &planePos); + planePos.y = y1; + pointBDist = Math3D_PlaneF(nx, ny, nz, originDist, &planePos); + + if (((pointADist > 0.0f) && (pointBDist > 0.0f)) || ((pointADist < 0.0f) && (pointBDist < 0.0f))) { + return false; + } + if (Math3D_TriChkPointParaYImpl(v0, v1, v2, z, x, 300.0f, 1.0f, ny)) { + *yIntersect = (((-nx * x) - (nz * z)) - originDist) / ny; + return true; + } + return false; +} + +s32 Math3D_TriChkPointParaYDist_(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 z, f32 x, f32 chkDist) { + if (IS_ZERO(plane->normal.y)) { + return false; + } + if (Math3D_TriChkPointParaYImpl(v0, v1, v2, z, x, 0.0f, chkDist, plane->normal.y)) { + return true; + } + return false; +} + +s32 Math3D_TriChkPointParaYImplNoCheckRange(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f32 detMax, f32 chkDist, + f32 ny) { + f32 detv0v1; + f32 detv1v2; + f32 detv2v0; + f32 distToEdgeSq; + f32 chkDistSq; + + // check if the point is within `chkDist` units of any vertex of the triangle. + chkDistSq = SQ(chkDist); + if (SQ(v0->z - z) + SQ(v0->x - x) < chkDistSq || SQ(v1->z - z) + SQ(v1->x - x) < chkDistSq || + SQ(v2->z - z) + SQ(v2->x - x) < chkDistSq) { + return true; + } + + // Calculate the determinant of each face of the triangle to the point. + // If all the of determinants are within abs(`detMax`), return true. + if (((detMax >= (detv0v1 = ((v0->z - z) * (v1->x - x)) - ((v0->x - x) * (v1->z - z)))) && + (detMax >= (detv1v2 = ((v1->z - z) * (v2->x - x)) - ((v1->x - x) * (v2->z - z)))) && + (detMax >= (detv2v0 = ((v2->z - z) * (v0->x - x)) - ((v2->x - x) * (v0->z - z)))))) { + return 1; + } + if (((-detMax <= (detv0v1 = ((v0->z - z) * (v1->x - x)) - ((v0->x - x) * (v1->z - z)))) && + (-detMax <= (detv1v2 = ((v1->z - z) * (v2->x - x)) - ((v1->x - x) * (v2->z - z)))) && + (-detMax <= (detv2v0 = ((v2->z - z) * (v0->x - x)) - ((v2->x - x) * (v0->z - z)))))) { + return true; + } + + if (fabsf(ny) > 0.5f && chkDistSq > 0.0f) { + // Do a check on each face of the triangle, if the point is within `chkDist` units return true. + if ((func_8017DA24(z, x, v0, v1, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { + return 1; + } + if ((func_8017DA24(z, x, v1, v2, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { + return 1; + } + if ((func_8017DA24(z, x, v2, v0, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { + return 1; + } + } + return 0; +} + +s32 Math3D_TriChkPointParaYNoRangeCheckIntersectInsideTri(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, + f32 originDist, f32 z, f32 x, f32* yIntersect, f32 chkDist) { + if (IS_ZERO(ny)) { + return false; + } + if (Math3D_TriChkPointParaYImplNoCheckRange(v0, v1, v2, z, x, 0.0f, chkDist, ny)) { + *yIntersect = (f32)((((-nx * x) - (nz * z)) - originDist) / ny); + return true; + } + return false; +} + +s32 Math3D_TriChkPointParaXImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 detMax, f32 chkDist, f32 ny) { + f32 detv0v1; + f32 detv1v2; + f32 detv2v0; + f32 distToEdgeSq; + f32 chkDistSq; + + // first check if the point is within range of the triangle. + if (!func_8017A1D0(v0, v1, v2, y, z, chkDist)) { + return false; + } + + // check if the point is within `chkDist` units of any vertex of the triangle. + chkDistSq = SQ(chkDist); + if (SQ(v0->y - y) + SQ(v0->z - z) < chkDistSq || SQ(v1->y - y) + SQ(v1->z - z) < chkDistSq || + SQ(v2->y - y) + SQ(v2->z - z) < chkDistSq) { + return true; + } + + // Calculate the determinant of each face of the triangle to the point. + // If all the of determinants are within abs(`detMax`), return true. + if (((detMax >= (detv0v1 = ((v0->y - y) * (v1->z - z)) - ((v0->z - z) * (v1->y - y)))) && + (detMax >= (detv1v2 = ((v1->y - y) * (v2->z - z)) - ((v1->z - z) * (v2->y - y)))) && + (detMax >= (detv2v0 = ((v2->y - y) * (v0->z - z)) - ((v2->z - z) * (v0->y - y)))))) { + return 1; + } + if (((-detMax <= (detv0v1 = ((v0->y - y) * (v1->z - z)) - ((v0->z - z) * (v1->y - y)))) && + (-detMax <= (detv1v2 = ((v1->y - y) * (v2->z - z)) - ((v1->z - z) * (v2->y - y)))) && + (-detMax <= (detv2v0 = ((v2->y - y) * (v0->z - z)) - ((v2->z - z) * (v0->y - y)))))) { + return true; + } + + if (fabsf(ny) > 0.5f && chkDistSq > 0.0f) { + // Do a check on each face of the triangle, if the point is within `chkDist` units return true. + if ((func_8017D91C(y, z, v0, v1, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { + return 1; + } + if ((func_8017D91C(y, z, v1, v2, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { + return 1; + } + if ((func_8017D91C(y, z, v2, v0, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { + return 1; + } + } + return 0; +} + +s32 Math3D_TriChkPointParaXDeterminate(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 detMax, f32 nx) { + return Math3D_TriChkPointParaXImpl(v0, v1, v2, y, z, detMax, 1.0f, nx); +} + +s32 Math3D_TriChkPointParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 y, + f32 z, f32* xIntersect) { + if (IS_ZERO(nx)) { + return false; + } + + if (Math3D_TriChkPointParaXImpl(v0, v1, v2, y, z, 300.0f, 1.0f, nx)) { + *xIntersect = (((-ny * y) - (nz * z)) - originDist) / nx; + return true; + } + return false; +} + +s32 Math3D_TriChkPointParaX(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 y, f32 z) { + if (IS_ZERO(nx)) { + return false; + } + if (Math3D_TriChkPointParaXImpl(v0, v1, v2, y, z, 300.0f, 1.0f, nx)) { + return true; + } + return false; +} + +#ifdef NON_MATCHING +// in-function static bss +s32 Math3D_TriChkLineSegParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 y, + f32 z, f32* xIntersect, f32 x0, f32 x1) { + static Vec3f planePos; + + f32 pointADist; + f32 pointBDist; + + if (IS_ZERO(nx)) { + return false; + } + + planePos.x = x0; + planePos.y = y; + planePos.z = z; + pointADist = Math3D_PlaneF(nx, ny, nz, originDist, &planePos); + + planePos.x = x1; + pointBDist = Math3D_PlaneF(nx, ny, nz, originDist, &planePos); + + if (((pointADist > 0.0f) && (pointBDist > 0.0f)) || ((pointADist < 0.0f) && (pointBDist < 0.0f))) { + return false; + } + + if (Math3D_TriChkPointParaXImpl(v0, v1, v2, y, z, 300.0f, 1.0f, nx)) { + *xIntersect = (((-ny * y) - (nz * z)) - originDist) / nx; + return true; + } + return false; +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaXIntersect.s") +#endif -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017CB08.s") +s32 Math3D_TriChkLineSegParaXDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 y, f32 z, f32 chkDist) { + if (IS_ZERO(plane->normal.x)) { + return false; + } + if (Math3D_TriChkPointParaXImpl(v0, v1, v2, y, z, 0.0f, chkDist, plane->normal.x)) { + return true; + } + return false; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaZDist.s") +s32 Math3D_TriChkPointParaZImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 x, f32 y, f32 detMax, f32 chkDist, f32 nz) { + f32 detv0v1; + f32 detv1v2; + f32 detv2v0; + f32 distToEdgeSq; + f32 chkDistSq; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017CEA8.s") + if (!func_8017A09C(v0, v1, v2, x, y, chkDist)) { + return false; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaZIntersect.s") + chkDistSq = SQ(chkDist); -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017CFA4.s") + if (((SQ(x - v0->x) + SQ(y - v0->y)) < chkDistSq) || ((SQ(x - v1->x) + SQ(y - v1->y)) < chkDistSq) || + ((SQ(x - v2->x) + SQ(y - v2->y)) < chkDistSq)) { + // Distance from any vertex to a point is less than chkDist + return true; + } + if (((detMax >= (detv0v1 = ((v0->x - x) * (v1->y - y)) - ((v0->y - y) * (v1->x - x)))) && + (detMax >= (detv1v2 = ((v1->x - x) * (v2->y - y)) - ((v1->y - y) * (v2->x - x)))) && + (detMax >= (detv2v0 = ((v2->x - x) * (v0->y - y)) - ((v2->y - y) * (v0->x - x)))))) { + return true; + } + + if (((-detMax <= (detv0v1 = ((v0->x - x) * (v1->y - y)) - ((v0->y - y) * (v1->x - x)))) && + (-detMax <= (detv1v2 = ((v1->x - x) * (v2->y - y)) - ((v1->y - y) * (v2->x - x)))) && + (-detMax <= (detv2v0 = ((v2->x - x) * (v0->y - y)) - ((v2->y - y) * (v0->x - x)))))) { + return true; + } + + if (fabsf(nz) > 0.5f && chkDistSq > 0.0f) { + + if (func_8017D814(x, y, v0, v1, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { + return true; + } + + if (func_8017D814(x, y, v1, v2, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { + return true; + } + + if (func_8017D814(x, y, v2, v0, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { + return true; + } + } + + return false; +} + +s32 Math3D_TriChkPointParaZDeterminate(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 detMax, f32 nx) { + return Math3D_TriChkPointParaZImpl(v0, v1, v2, y, z, detMax, 1.0f, nx); +} + +// Math3D_TriChkPointParaZIntersect +s32 func_801B8B38(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, f32 y, + f32* zIntersect) { + if (IS_ZERO(nz)) { + return 0; + } + + if (Math3D_TriChkPointParaZImpl(v0, v1, v2, x, y, 300.0f, 1.0f, nz)) { + *zIntersect = (((-nx * x) - (ny * y)) - originDist) / nz; + return 1; + } + + return 0; +} + +s32 Math3D_TriChkPointParaZ(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 y, f32 z) { + if (IS_ZERO(nx)) { + return false; + } + if (Math3D_TriChkPointParaZImpl(v0, v1, v2, y, z, 300.0f, 1.0f, nx)) { + return true; + } + return false; +} + +#ifdef NON_MATCHING +// in-function static bss +s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, + f32 y, f32* zIntersect, f32 z0, f32 z1) { + static Vec3f planePos; + + f32 pointADist; + f32 pointBDist; + + if (IS_ZERO(nz)) { + return false; + } + planePos.x = x; + planePos.y = y; + planePos.z = z0; + pointADist = Math3D_PlaneF(nx, ny, nz, originDist, &planePos); + + planePos.z = z1; + pointBDist = Math3D_PlaneF(nx, ny, nz, originDist, &planePos); + if (((pointADist > 0.0f) && (pointBDist > 0.0f)) || ((pointADist < 0.0f) && (pointBDist < 0.0f))) { + // points on the line segment are on the same side of the plane + return false; + } + + if (Math3D_TriChkPointParaXImpl(v0, v1, v2, x, y, 300.0f, 1.0f, nz)) { + *zIntersect = (((-nx * x) - (ny * y)) - originDist) / nz; + return true; + } + return false; +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaZIntersect.s") +#endif -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017D1AC.s") +s32 Math3D_TriChkLineSegParaZDist_(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 x, f32 y, f32 chkDist) { + if (IS_ZERO(plane->normal.z)) { + return false; + } + if (Math3D_TriChkPointParaZImpl(v0, v1, v2, x, y, 0.0f, chkDist, plane->normal.z)) { + return true; + } + return false; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017D220.s") +s32 Math3D_LineSegFindPlaneIntersect(f32 pointADist, f32 pointBDist, Vec3f* pointA, Vec3f* pointB, Vec3f* intersect) { + f32 distDiff = pointADist - pointBDist; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_LineSegVsPlane.s") + if (IS_ZERO(distDiff)) { + // both points lie on the plane. + *intersect = *pointB; + return false; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017D404.s") + if (pointADist == 0.0f) { + // pointA is on the plane + *intersect = *pointA; + } else if (pointBDist == 0.0f) { + // pointB is on the plane + *intersect = *pointB; + } else { + // place the point at the intersection point. + Math3D_LineSplitRatio(pointA, pointB, pointADist / distDiff, intersect); + } + return true; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriSetCoords.s") +s32 Math3D_LineSegVsPlane(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, + Vec3f* intersect, s32 fromFront) { + f32 pointADist = Math3D_PlaneF(nx, ny, nz, originDist, linePointA); + f32 pointBDist = Math3D_PlaneF(nx, ny, nz, originDist, linePointB); -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_IsPointInSphere.s") + if ((pointADist * pointBDist) > 0.0f) { + *intersect = *linePointB; + return false; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PointDistToLine2D.s") + if (fromFront && (pointADist < 0.0f) && (pointBDist > 0.0f)) { + *intersect = *linePointB; + return false; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017D7C0.s") + return Math3D_LineSegFindPlaneIntersect(pointADist, pointBDist, linePointA, linePointB, intersect); +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017D814.s") +s32 Math3D_TriLineIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, + Vec3f* linePointB, Vec3f* intersect, s32 fromFront) { -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017D91C.s") + if (!Math3D_LineSegVsPlane(nx, ny, nz, originDist, linePointA, linePointB, intersect, fromFront)) { + return false; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017DA24.s") + if (((nx == 0.0f) || (Math3D_TriChkPointParaX(v0, v1, v2, nx, intersect->y, intersect->z))) && + ((ny == 0.0f) || (Math3D_TriChkPointParaY(v0, v1, v2, ny, intersect->z, intersect->x))) && + ((nz == 0.0f) || (Math3D_TriChkPointParaZ(v0, v1, v2, nz, intersect->x, intersect->y)))) { + return true; + } + *intersect = *linePointB; + return false; +} + +void Math3D_TriNorm(TriNorm* tri, Vec3f* va, Vec3f* vb, Vec3f* vc) { + tri->vtx[0] = *va; + tri->vtx[1] = *vb; + tri->vtx[2] = *vc; + Math3D_DefPlane(va, vb, vc, &tri->plane.normal.x, &tri->plane.normal.y, &tri->plane.normal.z, + &tri->plane.originDist); +} + +s32 Math3D_PointInSph(Sphere16* sphere, Vec3f* point) { + if (Math3D_DistXYZ16toF(&sphere->center, point) < sphere->radius) { + return true; + } + return false; +} + +s32 func_801B93AC(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* perpXOut, f32* perpYOut, f32* lineLenSq) { + f32 perpendicularRatio; + f32 xDiff = x2 - x1; + f32 yDiff = y2 - y1; + f32 distSq = SQ(xDiff) + SQ(yDiff); + s32 ret = false; + + if (IS_ZERO(distSq)) { + *lineLenSq = 0.0f; + return false; + } + + perpendicularRatio = ((x0 - x1) * xDiff + (y0 - y1) * yDiff) / distSq; + if (perpendicularRatio >= 0.0f && perpendicularRatio <= 1.0f) { + ret = true; + } + + *perpXOut = (xDiff * perpendicularRatio) + x1; + *perpYOut = (yDiff * perpendicularRatio) + y1; + + *lineLenSq = SQ(*perpXOut - x0) + SQ(*perpYOut - y0); + return ret; +} + +s32 func_8017D7C0(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* lineLenSq) { + f32 perpX; + f32 perpY; + + return func_801B93AC(x0, y0, x1, y1, x2, y2, &perpX, &perpY, lineLenSq); +} + +s32 Math3D_PointDistToLine2D_(f32 x0, f32 y0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { + f32 perpendicularRatio; + f32 xDiff = p2->x - p1->x; + f32 yDiff = p2->y - p1->y; + f32 distSq = SQ(xDiff) + SQ(yDiff); + f32 perpX; + f32 perpY; + s32 ret = false; + + if (IS_ZERO(distSq)) { + *lineLenSq = 0.0f; + return false; + } + + perpendicularRatio = ((x0 - p1->x) * xDiff + (y0 - p1->y) * yDiff) / distSq; + if (perpendicularRatio >= 0.0f && perpendicularRatio <= 1.0f) { + ret = true; + } + perpX = (xDiff * perpendicularRatio) + p1->x; + perpY = (yDiff * perpendicularRatio) + p1->y; + *lineLenSq = SQ(perpX - x0) + SQ(perpY - y0); + + return ret; +} + +s32 func_8017D91C(f32 y0, f32 z0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { + f32 perpendicularRatio; + f32 yDiff = p2->y - p1->y; + f32 zDiff = p2->z - p1->z; + f32 distSq = SQ(yDiff) + SQ(zDiff); + f32 perpY; + f32 perpZ; + s32 ret = false; + + if (IS_ZERO(distSq)) { + *lineLenSq = 0.0f; + return false; + } + + perpendicularRatio = ((y0 - p1->y) * yDiff + (z0 - p1->z) * zDiff) / distSq; + if (perpendicularRatio >= 0.0f && perpendicularRatio <= 1.0f) { + ret = true; + } + perpY = (yDiff * perpendicularRatio) + p1->y; + perpZ = (zDiff * perpendicularRatio) + p1->z; + *lineLenSq = SQ(perpY - y0) + SQ(perpZ - z0); + + return ret; +} + +s32 func_8017DA24(f32 z0, f32 x0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { + f32 perpendicularRatio; + f32 zDiff = p2->z - p1->z; + f32 xDiff = p2->x - p1->x; + f32 distSq = SQ(zDiff) + SQ(xDiff); + f32 perpZ; + f32 perpX; + s32 ret = false; + + if (IS_ZERO(distSq)) { + *lineLenSq = 0.0f; + return false; + } + + perpendicularRatio = ((z0 - p1->z) * zDiff + (x0 - p1->x) * xDiff) / distSq; + if (perpendicularRatio >= 0.0f && perpendicularRatio <= 1.0f) { + ret = true; + } + perpZ = (zDiff * perpendicularRatio) + p1->z; + perpX = (xDiff * perpendicularRatio) + p1->x; + *lineLenSq = SQ(perpZ - z0) + SQ(perpX - x0); + + return ret; +} + +#define Math3D_TriVsSphIntersect Math3D_ColSphereTri +#define Math3D_GetSphVsTriIntersectPoint func_8017DD34 + +#ifdef NON_MATCHING +// in-function static bss +s32 Math3D_LineVsSph(Sphere16* sphere, Linef* line) { + static Vec3f sphLinePerpendicularPoint; + + Vec3f lineDiff; + f32 temp_f0_2; + f32 lineLenSq; + + if ((Math3D_PointInSph(sphere, &line->a)) || (Math3D_PointInSph(sphere, &line->b))) { + // either point of the line is in the sphere. + return true; + } + lineDiff.x = line->b.x - line->a.x; + lineDiff.y = line->b.y - line->a.y; + lineDiff.z = line->b.z - line->a.z; + + lineLenSq = SQ(lineDiff.x) + SQ(lineDiff.y) + SQ(lineDiff.z); + if (IS_ZERO(lineLenSq)) { + // line length is "0" + return false; + } + temp_f0_2 = ((((sphere->center.x - line->a.x) * lineDiff.x) + ((sphere->center.y - line->a.y) * lineDiff.y)) + + ((sphere->center.z - line->a.z) * lineDiff.z)) / + lineLenSq; + if ((temp_f0_2 < 0.0f) || (temp_f0_2 > 1.0f)) { + return false; + } + + sphLinePerpendicularPoint.x = (lineDiff.x * temp_f0_2) + line->a.x; + sphLinePerpendicularPoint.y = (lineDiff.y * temp_f0_2) + line->a.y; + sphLinePerpendicularPoint.z = (lineDiff.z * temp_f0_2) + line->a.z; + + if (SQ(sphLinePerpendicularPoint.x - sphere->center.x) + SQ(sphLinePerpendicularPoint.y - sphere->center.y) + + SQ(sphLinePerpendicularPoint.z - sphere->center.z) <= + SQ((f32)sphere->radius)) { + return true; + } + return false; +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_LineVsSph.s") +#endif +#ifdef NON_MATCHING +// in-function static bss +void Math3D_GetSphVsTriIntersectPoint(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoint) { + static Vec3f v0v1Center; + static Vec3f sphereCenter; + + f32 dist; + f32 splitRatio; + + v0v1Center.x = ((tri->vtx[0].x + tri->vtx[1].x) * 0.5f); + v0v1Center.y = ((tri->vtx[0].y + tri->vtx[1].y) * 0.5f); + v0v1Center.z = ((tri->vtx[0].z + tri->vtx[1].z) * 0.5f); + sphereCenter.x = sphere->center.x; + sphereCenter.y = sphere->center.y; + sphereCenter.z = sphere->center.z; + dist = Math3D_Vec3f_DistXYZ(&v0v1Center, &sphereCenter); + // Distance from the sphere's center to the center of the line formed from v0->v1 + if (IS_ZERO(dist)) { + intersectPoint->x = sphereCenter.x; + intersectPoint->y = sphereCenter.y; + intersectPoint->z = sphereCenter.z; + return; + } + splitRatio = sphere->radius / dist; + Math3D_LineSplitRatio(&sphereCenter, &v0v1Center, splitRatio, intersectPoint); +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017DD34.s") +#endif +#ifdef NON_MATCHING +// in-function static bss +s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoint) { + static Linef triTestLine; + static Vec3f sphereCenter; + static Vec3f sphPlanePos; + + f32 radius; + f32 nx; + f32 ny; + f32 nz; + f32 planeDist; + + sphereCenter.x = sphere->center.x; + sphereCenter.y = sphere->center.y; + sphereCenter.z = sphere->center.z; + radius = sphere->radius; + + if (!func_8017A438(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], &sphereCenter, radius)) { + return false; + } + + planeDist = Math3D_UDistPlaneToPos(tri->plane.normal.x, tri->plane.normal.y, tri->plane.normal.z, + tri->plane.originDist, &sphereCenter); + if (radius < planeDist) { + // the point that lies within the plane of the triangle which is perpendicular to the sphere's center is more + // than the radius of the sphere, the plane never crosses the sphere. + return false; + } + + // tests if any of the edges of the triangle are intersecting the sphere + triTestLine.a = tri->vtx[0]; + triTestLine.b = tri->vtx[1]; + if (Math3D_LineVsSph(sphere, &triTestLine)) { + Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); + return true; + } + + triTestLine.a = tri->vtx[1]; + triTestLine.b = tri->vtx[2]; + if (Math3D_LineVsSph(sphere, &triTestLine)) { + Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); + return true; + } + + triTestLine.a = tri->vtx[2]; + triTestLine.b = tri->vtx[0]; + if (Math3D_LineVsSph(sphere, &triTestLine)) { + Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); + return true; + } + + nx = tri->plane.normal.x * planeDist; + ny = tri->plane.normal.y * planeDist; + nz = tri->plane.normal.z * planeDist; + + if (Math3D_PlaneF(tri->plane.normal.x, tri->plane.normal.y, tri->plane.normal.z, tri->plane.originDist, + &sphereCenter) > 0.0f) { + sphPlanePos.x = sphereCenter.x - nx; + sphPlanePos.y = sphereCenter.y - ny; + sphPlanePos.z = sphereCenter.z - nz; + } else { + sphPlanePos.x = sphereCenter.x + nx; + sphPlanePos.y = sphereCenter.y + ny; + sphPlanePos.z = sphereCenter.z + nz; + } + + if (fabsf(tri->plane.normal.y) > 0.5f) { + if (Math3D_TriChkPointParaYDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], sphPlanePos.z, sphPlanePos.x, + 0.0f, tri->plane.normal.y)) { + Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); + return true; + } + } else if (fabsf(tri->plane.normal.x) > 0.5f) { + if (Math3D_TriChkPointParaXDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], sphPlanePos.y, sphPlanePos.z, + 0.0f, tri->plane.normal.x)) { + Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); + return true; + } + } else if (Math3D_TriChkPointParaZDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], sphPlanePos.x, + sphPlanePos.y, 0.0f, tri->plane.normal.z)) { + Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); + return true; + } + return false; +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColSphereTri.s") +#endif -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017E294.s") +s32 Math3D_PointInCyl(Cylinder16* cyl, Vec3f* point) { + f32 bottom; + f32 top; + f32 x = cyl->pos.x - point->x; + f32 z = cyl->pos.z - point->z; + bottom = (f32)cyl->pos.y + cyl->yShift; + top = cyl->height + bottom; + + if ((SQ(x) + SQ(z)) < SQ(cyl->radius) && (bottom < point->y) && (point->y < top)) { + return true; + } else { + return false; + } +} + +#ifdef NON_MATCHING +// fracA and fracB are init to 0 but this causes problems everywhere +s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersectA, Vec3f* intersectB) { + Vec3f cylToPtA; + Vec3f cylToPtB; + Vec3f ptAToPtB; + f32 fracA; + f32 fracB; + f32 fracBase; + f32 zero = 0.0f; + f32 pad; + f32 cylRadiusSq; + f32 radSqDiff; + f32 distCent2; + f32 dot2AB; + s32 sideIntA; + s32 sideIntB; + s32 intBeyondA; + s32 intBeyondB; + s32 intFlags = 0; + Vec3f intPts[4]; + s32 count; + s32 i; + + if (Math3D_PointInCyl(cyl, linePointA) && Math3D_PointInCyl(cyl, linePointB)) { + // both points are in the cylinder + *intersectA = *linePointA; + *intersectB = *linePointB; + return 2; + } + + cylToPtA.x = linePointA->x - cyl->pos.x; + cylToPtA.y = linePointA->y - cyl->pos.y - cyl->yShift; + cylToPtA.z = linePointA->z - cyl->pos.z; + cylToPtB.x = linePointB->x - cyl->pos.x; + cylToPtB.y = linePointB->y - cyl->pos.y - cyl->yShift; + cylToPtB.z = linePointB->z - cyl->pos.z; + Math_Vec3f_Diff(&cylToPtB, &cylToPtA, &ptAToPtB); + cylRadiusSq = SQ(cyl->radius); + + /** + * This section checks for intersections with the cylinder's base and top + */ + if (!IS_ZERO(ptAToPtB.y)) { + // fraction of length along AB to reach y = 0 + fracBase = -cylToPtA.y / ptAToPtB.y; + if ((0.0f <= fracBase) && (fracBase <= 1.0f)) { + f32 baseIntX = (ptAToPtB.x * fracBase) + cylToPtA.x; + f32 baseIntZ = (ptAToPtB.z * fracBase) + cylToPtA.z; + + if (SQ(baseIntX) + SQ(baseIntZ) < cylRadiusSq) { + // adds base intersection point to intPts and sets its flag + intPts[0].x = cyl->pos.x + baseIntX; + intPts[0].y = (f32)cyl->pos.y + cyl->yShift; + intPts[0].z = cyl->pos.z + baseIntZ; + intFlags |= 1; + } + } + // fraction of length along AB to reach y = cyl->height + fracA = (cyl->height - cylToPtA.y) / ptAToPtB.y; + if ((0.0f <= fracA) && (fracA <= 1.0f)) { + f32 topIntX = ptAToPtB.x * fracA + cylToPtA.x; + f32 topIntZ = ptAToPtB.z * fracA + cylToPtA.z; + + if (SQ(topIntX) + SQ(topIntZ) < cylRadiusSq) { + // adds top intersection point to intPts and sets its flag + intPts[1].x = cyl->pos.x + topIntX; + intPts[1].y = (f32)cyl->pos.y + cyl->yShift + cyl->height; + intPts[1].z = cyl->pos.z + topIntZ; + intFlags |= 2; + } + } + } + /** + * This section finds the points of intersection of the infinite line containing AB with the side of the infinite + * cylinder containing cyl. Intersection points beyond the bounds of the segment and cylinder are filtered out + * afterward. + */ + radSqDiff = SQXZ(cylToPtA) - cylRadiusSq; + if (!IS_ZERO(2.0f * SQXZ(ptAToPtB))) { + dot2AB = 2.0f * DOTXZ(ptAToPtB, cylToPtA); + if (SQ(dot2AB) < 4.0f * SQXZ(ptAToPtB) * radSqDiff) { + // Line's closest xz-approach is outside cylinder. No intersections. + return 0; + } + if (SQ(dot2AB) - (4.0f * SQXZ(ptAToPtB) * radSqDiff) > zero) { + sideIntA = sideIntB = 1; + } else { + // Line is tangent in xz-plane. At most 1 side intersection. + sideIntA = 1; + sideIntB = 0; + } + distCent2 = sqrtf(SQ(dot2AB) - (4.0f * SQXZ(ptAToPtB) * radSqDiff)); + if (sideIntA != 0) { + // fraction of length along AB for side intersection closer to A + fracA = (distCent2 - dot2AB) / (2.0f * SQXZ(ptAToPtB)); + } + if (sideIntB != 0) { + // fraction of length along AB for side intersection closer to B + fracB = (-dot2AB - distCent2) / (2.0f * SQXZ(ptAToPtB)); + } + } else if (!IS_ZERO(2.0f * DOTXZ(ptAToPtB, cylToPtA))) { + // Used if the line segment is nearly vertical. Unclear what it's calculating. + fracA = -radSqDiff / (2.0f * DOTXZ(ptAToPtB, cylToPtA)); + sideIntA = 1; + sideIntB = 0; + } else { + return 0; + } + // checks for intersection points outside the bounds of the segment + if (!sideIntB) { + if (fracA < 0.0f || 1.0f < fracA) { + return 0; + } + } else { + intBeyondA = fracA < 0.0f || 1.0f < fracA; + intBeyondB = fracB < 0.0f || 1.0f < fracB; + if (intBeyondA && intBeyondB) { + return 0; + } + if (intBeyondA) { + sideIntA = 0; + } + if (intBeyondB) { + sideIntB = 0; + } + } + // checks for intersection points outside the bounds of the cylinder + if ((sideIntA != 0) && + ((fracA * ptAToPtB.y + cylToPtA.y) < 0.0f || cyl->height < (fracA * ptAToPtB.y + cylToPtA.y))) { + sideIntA = 0; + } + if ((sideIntB != 0) && + ((fracB * ptAToPtB.y + cylToPtA.y) < 0.0f || cyl->height < (fracB * ptAToPtB.y + cylToPtA.y))) { + sideIntB = 0; + } + if (sideIntA == 0 && sideIntB == 0) { + return 0; + } + // Adds intersection points to intPts and sets side A and side B flags + if (sideIntA != 0 && sideIntB != 0) { + intPts[2].x = (fracA * ptAToPtB.x + cylToPtA.x) + cyl->pos.x; + intPts[2].y = (fracA * ptAToPtB.y + cylToPtA.y) + cyl->pos.y + cyl->yShift; + intPts[2].z = (fracA * ptAToPtB.z + cylToPtA.z) + cyl->pos.z; + intFlags |= 4; + intPts[3].x = (fracB * ptAToPtB.x + cylToPtA.x) + cyl->pos.x; + intPts[3].y = (fracB * ptAToPtB.y + cylToPtA.y) + cyl->pos.y + cyl->yShift; + intPts[3].z = (fracB * ptAToPtB.z + cylToPtA.z) + cyl->pos.z; + intFlags |= 8; + } else if (sideIntA != 0) { + intPts[2].x = (fracA * ptAToPtB.x + cylToPtA.x) + cyl->pos.x; + intPts[2].y = (fracA * ptAToPtB.y + cylToPtA.y) + cyl->pos.y + cyl->yShift; + intPts[2].z = (fracA * ptAToPtB.z + cylToPtA.z) + cyl->pos.z; + intFlags |= 4; + } else if (sideIntB != 0) { + intPts[2].x = (fracB * ptAToPtB.x + cylToPtA.x) + cyl->pos.x; + intPts[2].y = (fracB * ptAToPtB.y + cylToPtA.y) + cyl->pos.y + cyl->yShift; + intPts[2].z = (fracB * ptAToPtB.z + cylToPtA.z) + cyl->pos.z; + intFlags |= 4; + } + + /** + * Places the found intersection points into intersectA and intersectB. IntersectA is always closer to point A + */ + for (count = 0, i = 0; i < 4; i++) { + if (intFlags & (1 << i)) { + if (count == 0) { + *intersectA = intPts[i]; + } else if (count == 1) { + if (Math3D_Vec3fDistSq(intersectA, linePointA) < Math3D_Vec3fDistSq(intersectA, &intPts[i])) { + *intersectB = intPts[i]; + } else { + *intersectB = *intersectA; + *intersectA = intPts[i]; + } + break; + } + count++; + } + } + return count; +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017E350.s") +#endif +#ifdef NON_MATCHING +// in-function static bss +s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect) { + static Sphere16 topSphere; + static Sphere16 bottomSphere; + static Vec3f cylIntersectA; + static Vec3f cylIntersectB; + + f32 yIntersect; + f32 cylTop; + f32 cylBottom; + f32 minDistSq; + f32 radiusTodistFromCylYIntersectTov0v1; + f32 distFromPointAToIntersectASq; + Vec3f cylIntersectCenter; + + cylBottom = (f32)cyl->pos.y + cyl->yShift; + cylTop = cyl->height + cylBottom; + + if (((tri->vtx[0].y < cylBottom) && (tri->vtx[1].y < cylBottom) && (tri->vtx[2].y < cylBottom)) || + ((cylTop < tri->vtx[0].y) && (cylTop < tri->vtx[1].y) && (cylTop < tri->vtx[2].y))) { + // If all of the verticies are below or all of the verticies are above the cylinder. + return false; + } + + minDistSq = 1.e38f; + if (Math3D_CylVsLineSeg(cyl, &tri->vtx[0], &tri->vtx[1], &cylIntersectA, &cylIntersectB)) { + distFromPointAToIntersectASq = Math3D_Vec3fDistSq(&cylIntersectA, &tri->vtx[0]); + minDistSq = distFromPointAToIntersectASq; + *intersect = cylIntersectA; + } + + if (Math3D_CylVsLineSeg(cyl, &tri->vtx[2], &tri->vtx[1], &cylIntersectA, &cylIntersectB)) { + distFromPointAToIntersectASq = Math3D_Vec3fDistSq(&cylIntersectA, &tri->vtx[2]); + if (distFromPointAToIntersectASq < minDistSq) { + *intersect = cylIntersectA; + minDistSq = distFromPointAToIntersectASq; + } + } + + if (Math3D_CylVsLineSeg(cyl, &tri->vtx[0], &tri->vtx[2], &cylIntersectA, &cylIntersectB)) { + distFromPointAToIntersectASq = Math3D_Vec3fDistSq(&cylIntersectA, &tri->vtx[0]); + if (distFromPointAToIntersectASq < minDistSq) { + *intersect = cylIntersectA; + minDistSq = distFromPointAToIntersectASq; + } + } + + if (minDistSq != 1.e38f) { + return true; + } + + if (Math3D_TriChkLineSegParaYIntersect(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], tri->plane.normal.x, + tri->plane.normal.y, tri->plane.normal.z, tri->plane.originDist, cyl->pos.z, + cyl->pos.x, &yIntersect, cylBottom, cylTop)) { + Vec3f midpointv0v1; + Vec3f diffMidpointIntersect; + f32 distFromCylYIntersectTov0v1; + s32 pad; + + cylIntersectCenter.x = cyl->pos.x; + cylIntersectCenter.y = yIntersect; + cylIntersectCenter.z = cyl->pos.z; + + midpointv0v1.x = (tri->vtx[0].x + tri->vtx[1].x) * 0.5f; + midpointv0v1.y = (tri->vtx[0].y + tri->vtx[1].y) * 0.5f; + midpointv0v1.z = (tri->vtx[0].z + tri->vtx[1].z) * 0.5f; + + Math_Vec3f_Diff(&midpointv0v1, &cylIntersectCenter, &diffMidpointIntersect); + distFromCylYIntersectTov0v1 = sqrtf(SQ(diffMidpointIntersect.x) + SQ(diffMidpointIntersect.z)); + + if (IS_ZERO(distFromCylYIntersectTov0v1)) { + Math_Vec3f_Copy(intersect, &midpointv0v1); + return true; + } + + radiusTodistFromCylYIntersectTov0v1 = cyl->radius / distFromCylYIntersectTov0v1; + Math3D_PointOnInfiniteLine(&cylIntersectCenter, &diffMidpointIntersect, radiusTodistFromCylYIntersectTov0v1, + intersect); + return true; + } + + topSphere.center.x = bottomSphere.center.x = cyl->pos.x; + topSphere.center.z = bottomSphere.center.z = cyl->pos.z; + topSphere.center.y = cylTop; + bottomSphere.center.y = cylBottom; + topSphere.radius = bottomSphere.radius = cyl->radius; + + if ((Math3D_TriVsSphIntersect(&topSphere, tri, intersect)) || + (Math3D_TriVsSphIntersect(&bottomSphere, tri, intersect))) { + return true; + } + return false; +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColCylinderTri.s") +#endif -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017F1A0.s") +s32 Math3D_CylVsTri(Cylinder16* cyl, TriNorm* tri) { + Vec3f intersect; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_SphVsSph.s") + return Math3D_CylTriVsIntersect(cyl, tri, &intersect); +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColSphereSphereIntersect.s") +s32 Math3D_SphVsSph(Sphere16* sphereA, Sphere16* sphereB) { + f32 overlapSize; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColSphereSphereIntersectAndDistance.s") + return Math3D_SphVsSphOverlap(sphereA, sphereB, &overlapSize); +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColSphereCylinderDistance.s") +s32 Math3D_SphVsSphOverlap(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize) { + f32 centerDist; + return Math3D_SphVsSphOverlapCenter(sphereA, sphereB, overlapSize, ¢erDist); +} + +s32 Math3D_SphVsSphOverlapCenter(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize, f32* centerDist) { + Vec3f diff; + + diff.x = (f32)sphereA->center.x - (f32)sphereB->center.x; + diff.y = (f32)sphereA->center.y - (f32)sphereB->center.y; + diff.z = (f32)sphereA->center.z - (f32)sphereB->center.z; + + *centerDist = sqrtf(SQ(diff.x) + SQ(diff.y) + SQ(diff.z)); + + *overlapSize = (((f32)sphereA->radius + (f32)sphereB->radius) - *centerDist); + if (*overlapSize > 0.008f) { + return true; + } + + *overlapSize = 0.0f; + return false; +} + +s32 Math3D_SphVsCylOverlapDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize) { + f32 centerDist; + + return Math3D_SphVsCylOverlapCenterDist(sph, cyl, overlapSize, ¢erDist); +} + +#ifdef NON_MATCHING +// in-function static bss +s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize, f32* centerDist) { + static Cylinderf cylf; + static Spheref sphf; + + f32 x; + f32 z; + f32 combinedRadius; + f32 cylBottom; + f32 cylTop; + f32 sphBottom; + f32 sphTop; + + if (sph->radius <= 0 || cyl->radius <= 0) { + // either radius is 0 + return false; + } + sphf.center.y = sph->center.y; + sphf.radius = sph->radius; + cylf.pos.y = cyl->pos.y; + cylf.yShift = cyl->yShift; + cylf.height = cyl->height; + x = (f32)sph->center.x - cyl->pos.x; + z = (f32)sph->center.z - cyl->pos.z; + combinedRadius = (f32)sph->radius + cyl->radius; + *centerDist = sqrtf(SQ(x) + SQ(z)); + if (combinedRadius < *centerDist) { + // if the combined radii is less than the distance to the centers, they cannot be touching. + return false; + } + + cylBottom = (cylf.pos.y + cylf.yShift); + cylTop = cylBottom + cylf.height; + sphBottom = sphf.center.y - sphf.radius; + sphTop = sphf.center.y + sphf.radius; + + if ((sphTop >= cylBottom) && (sphBottom <= cylTop)) { + // if the cylinder and sphere are intersecting on the xz plane, check if they're intersecting on + // the y axis. + *overlapSize = combinedRadius - *centerDist; + return true; + } + return false; +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColSphereCylinderDistanceAndAmount.s") +#endif -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColCylinderCylinderAmount.s") +s32 Math3D_CylOutsideCyl(Cylinder16* ca, Cylinder16* cb, f32* deadSpace) { + f32 xzDist; + return Math3D_CylOutsideCylDist(ca, cb, deadSpace, &xzDist); +} + +#ifdef NON_MATCHING +// in-function static bss +s32 Math3D_CylOutsideCylDist(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32* xzDist) { + static Cylinderf caf; + static Cylinderf cbf; + + Math_Vec3s_ToVec3f(&caf.pos, &ca->pos); + caf.radius = ca->radius; + caf.yShift = ca->yShift; + caf.height = ca->height; + + Math_Vec3s_ToVec3f(&cbf.pos, &cb->pos); + cbf.radius = cb->radius; + cbf.yShift = cb->yShift; + cbf.height = cb->height; + + *xzDist = sqrtf(SQ(caf.pos.x - cbf.pos.x) + SQ(caf.pos.z - cbf.pos.z)); + + // The combined radix are within the xz distance + if ((caf.radius + cbf.radius) < *xzDist) { + return false; + } + + // top of ca < bottom of cb or top of cb < bottom of ca + if (((caf.pos.y + caf.yShift) + caf.height) < (cbf.pos.y + cbf.yShift) || + (((cbf.pos.y + cbf.yShift) + cbf.height) < (caf.pos.y + caf.yShift))) { + return false; + } + + *deadSpace = caf.radius + cbf.radius - *xzDist; + return true; +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColCylinderCylinderAmountAndDistance.s") +#endif -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3d_ColTriTri.s") +// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3d_ColTriTri.s") +#define Math3D_TriVsTriIntersect Math3d_ColTriTri +s32 Math3D_TriVsTriIntersect(TriNorm* ta, TriNorm* tb, Vec3f* intersect) { + f32 dist0 = Math3D_Plane(&ta->plane, &tb->vtx[0]); + f32 dist1 = Math3D_Plane(&ta->plane, &tb->vtx[1]); + f32 dist2 = Math3D_Plane(&ta->plane, &tb->vtx[2]); -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_XZInSphere.s") + if (((dist0 > 0.0f) && (dist1 > 0.0f) && (dist2 > 0.0f)) || + (((dist0 < 0.0f) && (dist1 < 0.0f)) && (dist2 < 0.0f))) { + return false; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_XYInSphere.s") + dist0 = Math3D_Plane(&tb->plane, &ta->vtx[0]); + dist1 = Math3D_Plane(&tb->plane, &ta->vtx[1]); + dist2 = Math3D_Plane(&tb->plane, &ta->vtx[2]); + + if ((((dist0 > 0.0f) && (dist1 > 0.0f)) && (dist2 > 0.0f)) || + ((dist0 < 0.0f) && (dist1 < 0.0f) && (dist2 < 0.0f))) { + return false; + } + + if (Math3D_TriLineIntersect(&tb->vtx[0], &tb->vtx[1], &tb->vtx[2], tb->plane.normal.x, tb->plane.normal.y, + tb->plane.normal.z, tb->plane.originDist, &ta->vtx[0], &ta->vtx[1], intersect, 0)) { + return true; + } + if (Math3D_TriLineIntersect(&tb->vtx[0], &tb->vtx[1], &tb->vtx[2], tb->plane.normal.x, tb->plane.normal.y, + tb->plane.normal.z, tb->plane.originDist, &ta->vtx[1], &ta->vtx[2], intersect, 0)) { + return true; + } + if (Math3D_TriLineIntersect(&tb->vtx[0], &tb->vtx[1], &tb->vtx[2], tb->plane.normal.x, tb->plane.normal.y, + tb->plane.normal.z, tb->plane.originDist, &ta->vtx[2], &ta->vtx[0], intersect, 0)) { + return true; + } + if (Math3D_TriLineIntersect(&ta->vtx[0], &ta->vtx[1], &ta->vtx[2], ta->plane.normal.x, ta->plane.normal.y, + ta->plane.normal.z, ta->plane.originDist, &tb->vtx[0], &tb->vtx[1], intersect, 0)) { + return true; + } + if (Math3D_TriLineIntersect(&ta->vtx[0], &ta->vtx[1], &ta->vtx[2], ta->plane.normal.x, ta->plane.normal.y, + ta->plane.normal.z, ta->plane.originDist, &tb->vtx[1], &tb->vtx[2], intersect, 0)) { + return true; + } + if (Math3D_TriLineIntersect(&ta->vtx[0], &ta->vtx[1], &ta->vtx[2], ta->plane.normal.x, ta->plane.normal.y, + ta->plane.normal.z, ta->plane.originDist, &tb->vtx[2], &tb->vtx[0], intersect, 0)) { + return true; + } + return false; +} + + +s32 Math3D_XZInSphere(Sphere16* sphere, f32 x, f32 z) { + f32 xDiff = sphere->center.x - x; + f32 zDiff = sphere->center.z - z; + + if ((SQ(xDiff) + SQ(zDiff)) <= SQ(sphere->radius)) { + return true; + } + return false; +} + +s32 Math3D_XYInSphere(Sphere16* sphere, f32 x, f32 y) { + f32 xDiff = sphere->center.x - x; + f32 yDiff = sphere->center.y - y; + + if ((SQ(xDiff) + SQ(yDiff)) <= SQ(sphere->radius)) { + return true; + } + return false; +} + +s32 Math3D_YZInSphere(Sphere16* sphere, f32 y, f32 z) { + f32 yDiff = sphere->center.y - y; + f32 zDiff = sphere->center.z - z; + + if ((SQ(yDiff) + SQ(zDiff)) <= SQ(sphere->radius)) { + return true; + } + return false; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_YZInSphere.s") #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017FB1C.s") -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017FD44.s") +void func_8017FD44(Vec3f* arg0, Vec3f* arg1, Vec3f* dst, f32 arg3) { + Vec3f sp2C; + s16 sp2A; + f32 sp24; + + if (!(arg3 < -1.0f) || !(arg3 > 1.0f)) { + sp2C.x = (arg0->x + arg1->x) * 0.5f; + sp2C.z = (arg0->z + arg1->z) * 0.5f; + sp24 = sqrtf(SQ(sp2C.x - arg0->x) + SQ(sp2C.z - arg0->z)); + dst->y = (arg1->y - arg0->y) * arg3 + arg0->y; + sp2A = Math_Vec3f_Yaw(&sp2C, arg0); + dst->x = Math_SinS((s16)(32767.0f * arg3) + sp2A) * sp24 + sp2C.x; + dst->z = Math_CosS((s16)(32767.0f * arg3) + sp2A) * sp24 + sp2C.z; + } +} + diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c index b2891de90..c6061b8ec 100644 --- a/src/code/z_bgcheck.c +++ b/src/code/z_bgcheck.c @@ -3823,7 +3823,7 @@ s32 BgCheck_CheckLineAgainstDyna(CollisionContext* colCtx, u16 xpFlags, Vec3f* p s32 pad; s32 i; s32 result = false; - LineSegment line; + Linef line; f32 ay; f32 by; diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c index 4b7f48696..93697dd61 100644 --- a/src/code/z_collision_check.c +++ b/src/code/z_collision_check.c @@ -7,14 +7,14 @@ Vec3f D_801EDE20; Vec3f D_801EDE30; TriNorm D_801EDE40; TriNorm D_801EDE78; -LineSegment D_801EDEB0; +Linef D_801EDEB0; TriNorm D_801EDEC8; TriNorm D_801EDF00; Vec3f D_801EDF38; Vec3f D_801EDF48; TriNorm D_801EDF58; TriNorm D_801EDF90; -LineSegment D_801EDFC8; +Linef D_801EDFC8; Vec3f D_801EDFE0; Vec3f D_801EDFF0; TriNorm D_801EE000; diff --git a/tools/disasm/variables.txt b/tools/disasm/variables.txt index 4fac6bb9e..9b898c50d 100644 --- a/tools/disasm/variables.txt +++ b/tools/disasm/variables.txt @@ -4194,7 +4194,7 @@ 0x801FBBD4:("D_801FBBD4","UNK_TYPE1","",0x1), 0x801FBBE0:("D_801FBBE0","UNK_TYPE1","",0x1), 0x801FBBF0:("D_801FBBF0","Vec3f","",0xc), - 0x801FBC00:("Math3D_ColSphereTri_line","LineSegment","",0x18), + 0x801FBC00:("Math3D_ColSphereTri_line","Linef","",0x18), 0x801FBC18:("Math3D_ColSphereTri_point","Vec3f","",0xc), 0x801FBC28:("D_801FBC28","UNK_TYPE1","",0x1), 0x801FBC2C:("D_801FBC2C","UNK_TYPE1","",0x1), From 378f8ec73a084e775b5aa95cd59fc9f8b3974a3b Mon Sep 17 00:00:00 2001 From: angie Date: Sat, 2 Apr 2022 00:30:28 -0300 Subject: [PATCH 02/29] kinda match some unattempted functions --- include/functions.h | 8 ++-- src/code/sys_math3d.c | 76 ++++++++++++++++++++++++++-------- tools/disasm/functions.txt | 8 ++-- tools/sizes/code_functions.csv | 8 ++-- 4 files changed, 71 insertions(+), 29 deletions(-) diff --git a/include/functions.h b/include/functions.h index 8fa47f170..0f1b08b2c 100644 --- a/include/functions.h +++ b/include/functions.h @@ -3023,16 +3023,16 @@ f32 Math3D_Vec3fMagnitude(Vec3f* vec); f32 Math3D_Vec3fDistSq(Vec3f* a, Vec3f* b); f32 Math3D_Distance(Vec3f* a, Vec3f* b); f32 Math3D_DistanceS(Vec3s* s, Vec3f* f); -f32 func_8017A7B8(f32* param_1, f32* param_2, f32 param_3, f32 param_4); -f32 func_8017A7F8(f32* param_1, f32* param_2, f32 param_3, f32 param_4); -f32 func_8017A838(f32* param_1, f32* param_2, f32 param_3, f32 param_4); +f32 Math3D_Vec3fDiff_CrossZ(Vec3f* a, Vec3f* b, f32 dx, f32 dy); +f32 Math3D_Vec3fDiff_CrossX(Vec3f* a, Vec3f* b, f32 dy, f32 dz); +f32 Math3D_Vec3fDiff_CrossY(Vec3f* a, Vec3f* b, f32 dz, f32 dx); void Math3D_CrossProduct(Vec3f* a, Vec3f* b, Vec3f* res); void Math3D_SurfaceNorm(Vec3f* a, Vec3f* b, Vec3f* c, Vec3f* res); s32 Math3D_PointRelativeToCubeFaces(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); s32 Math3D_PointRelativeToCubeEdges(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); s32 Math3D_PointRelativeToCubeVertices(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b); -// void func_8017B68C(void); +s32 Math3D_LineVsCubeShort(Vec3s* min, Vec3s* max, Vec3s* a, Vec3s* b); void func_8017B7F8(Vec3f* arg0, s16 arg1, f32* arg2, f32* arg3, f32* arg4); void Math3D_UnitNormalVector(Vec3f* a, Vec3f* b, Vec3f* c, f32* normX, f32* normY, f32* normZ, f32* param_7); f32 Math3D_SignedDistanceFromPlane(f32 normX, f32 normY, f32 normZ, f32 d, Vec3f* position); diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 7adfcad28..7d4c60cb1 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -29,7 +29,6 @@ #define Math3D_Dist2DSq Math3D_XZDistanceSquared #define Math3D_Dist2D Math3D_XZDistance #define Math3D_Vec3fMagnitudeSq Math3D_LengthSquared -#define Math3D_Vec3fMagnitude Math3D_Vec3fMagnitude #define Math3D_Vec3fDistSq Math3D_Vec3fDistSq #define Math3D_Vec3f_DistXYZ Math3D_Distance #define Math3D_DistXYZ16toF Math3D_DistanceS @@ -51,15 +50,15 @@ #define Math3D_TriChkLineSegParaXDist func_8017CB08 #define Math3D_TriChkPointParaZImpl Math3D_TriChkLineSegParaZDist #define Math3D_TriChkPointParaZDeterminate func_8017CEA8 -#define func_801B8B38 Math3D_TriChkPointParaZIntersect #define Math3D_TriChkPointParaZ func_8017CFA4 #define Math3D_TriChkLineSegParaZDist_ func_8017D1AC #define Math3D_LineSegFindPlaneIntersect func_8017D220 #define Math3D_TriLineIntersect func_8017D404 #define Math3D_TriNorm Math3D_TriSetCoords #define Math3D_PointInSph Math3D_IsPointInSphere -#define func_801B93AC Math3D_PointDistToLine2D #define Math3D_PointDistToLine2D_ func_8017D814 +#define Math3D_Vec3fMagnitudeSq Math3D_LengthSquared +#define Math3D_LineClosestToPoint func_80179A44 f32 Math3D_Normalize(Vec3f* vec) { f32 magnitude = Math3D_Vec3fMagnitude(vec); @@ -174,9 +173,6 @@ s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_80179798.s") #endif -#define Math3D_Vec3fMagnitudeSq Math3D_LengthSquared - -#define Math3D_LineClosestToPoint func_80179A44 f32 Math3D_LineClosestToPoint(Linef* line, Vec3f* pos, Vec3f* closestPoint) { f32 dirVectorSize = Math3D_Vec3fMagnitudeSq(&line->b); f32 t; @@ -272,6 +268,9 @@ void Math3D_LineSplitRatio(Vec3f* v0, Vec3f* v1, f32 ratio, Vec3f* ret) { Math3D_PointOnInfiniteLine(v0, &diff, ratio, ret); } +/** + * Calculates the cosine between vectors `a` and `b` + */ f32 Math3D_Cos(Vec3f* a, Vec3f* b) { f32 ret; @@ -279,6 +278,10 @@ f32 Math3D_Cos(Vec3f* a, Vec3f* b) { return ret; } +/** + * Calculates the cosine between vectors `a` and `b` and places the result in `ret` + * returns true if the cosine cannot be calculated because the product of the magnitudes is zero + */ s32 Math3D_CosOut(Vec3f* a, Vec3f* b, f32* dst) { f32 magProduct = Math3D_Vec3fMagnitude(a) * Math3D_Vec3fMagnitude(b); @@ -551,11 +554,26 @@ f32 Math3D_DistXYZ16toF(Vec3s* a, Vec3f* b) { return Math3D_Vec3fMagnitude(&diff); } -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017A7B8.s") +/** + * Gets the Z portion of the cross product of vectors `a - (`dx`,`dy`,z) and `b` - (`dx`,`dy`,z) + */ +f32 Math3D_Vec3fDiff_CrossZ(Vec3f* a, Vec3f* b, f32 dx, f32 dy) { + return ((a->x - dx) * (b->y - dy)) - ((a->y - dy) * (b->x - dx)); +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017A7F8.s") +/** + * Gets the X portion of the cross product of vectors `a - (x,`dy`,`dz`) and `b` - (x,`dy`,`dz`) + */ +f32 Math3D_Vec3fDiff_CrossX(Vec3f* a, Vec3f* b, f32 dy, f32 dz) { + return ((a->y - dy) * (b->z - dz)) - ((a->z - dz) * (b->y - dy)); +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017A838.s") +/** + * Gets the Y portion of the cross product of vectors `a - (`dx`,y,`dz`) and `b` - (`dx`,y,`dz`) + */ +f32 Math3D_Vec3fDiff_CrossY(Vec3f* a, Vec3f* b, f32 dz, f32 dx) { + return ((a->z - dz) * (b->x - dx)) - ((a->x - dx) * (b->z - dz)); +} void Math3D_Vec3f_Cross(Vec3f* a, Vec3f* b, Vec3f* ret) { ret->x = (a->y * b->z) - (a->z * b->y); @@ -692,7 +710,7 @@ s32 Math3D_PointRelativeToCubeVertices(Vec3f* point, Vec3f* min, Vec3f* max) { return ret; } -#ifdef BSS_MATCHING +#ifdef NON_MATCHING // in-function static bss s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { static Vec3f triVtx0; @@ -869,7 +887,35 @@ s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_LineVsCube.s") #endif +#ifdef NON_MATCHING +/** + * Checks if a line segment with endpoints `a` and `b` intersect a cube + */ +// in-static bss +s32 Math3D_LineVsCubeShort(Vec3s* min, Vec3s* max, Vec3s* a, Vec3s* b) { + static Vec3f D_801FBD20; // minF + static Vec3f D_801FBD30; // maxF + static Vec3f D_801FBD40; // aF + static Vec3f D_801FBD50; // bF + + D_801FBD20.x = min->x; + D_801FBD20.y = min->y; + D_801FBD20.z = min->z; + D_801FBD30.x = max->x; + D_801FBD30.y = max->y; + D_801FBD30.z = max->z; + D_801FBD40.x = a->x; + D_801FBD40.y = a->y; + D_801FBD40.z = a->z; + D_801FBD50.x = b->x; + D_801FBD50.y = b->y; + D_801FBD50.z = b->z; + + return Math3D_LineVsCube(&D_801FBD20, &D_801FBD30, &D_801FBD40, &D_801FBD50); +} +#else #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017B68C.s") +#endif void Math3D_RotateXZPlane(Vec3f* pointOnPlane, s16 angle, f32* a, f32* c, f32* d) { *a = Math_SinS(angle) * 32767.0f; @@ -1282,8 +1328,7 @@ s32 Math3D_TriChkPointParaZDeterminate(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f return Math3D_TriChkPointParaZImpl(v0, v1, v2, y, z, detMax, 1.0f, nx); } -// Math3D_TriChkPointParaZIntersect -s32 func_801B8B38(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, f32 y, +s32 Math3D_TriChkPointParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, f32 y, f32* zIntersect) { if (IS_ZERO(nz)) { return 0; @@ -1423,7 +1468,7 @@ s32 Math3D_PointInSph(Sphere16* sphere, Vec3f* point) { return false; } -s32 func_801B93AC(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* perpXOut, f32* perpYOut, f32* lineLenSq) { +s32 Math3D_PointDistToLine2D(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* perpXOut, f32* perpYOut, f32* lineLenSq) { f32 perpendicularRatio; f32 xDiff = x2 - x1; f32 yDiff = y2 - y1; @@ -1451,7 +1496,7 @@ s32 func_8017D7C0(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* lineLenSq f32 perpX; f32 perpY; - return func_801B93AC(x0, y0, x1, y1, x2, y2, &perpX, &perpY, lineLenSq); + return Math3D_PointDistToLine2D(x0, y0, x1, y1, x2, y2, &perpX, &perpY, lineLenSq); } s32 Math3D_PointDistToLine2D_(f32 x0, f32 y0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { @@ -2129,7 +2174,6 @@ s32 Math3D_CylOutsideCylDist(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32 #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColCylinderCylinderAmountAndDistance.s") #endif -// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3d_ColTriTri.s") #define Math3D_TriVsTriIntersect Math3d_ColTriTri s32 Math3D_TriVsTriIntersect(TriNorm* ta, TriNorm* tb, Vec3f* intersect) { f32 dist0 = Math3D_Plane(&ta->plane, &tb->vtx[0]); @@ -2208,7 +2252,6 @@ s32 Math3D_YZInSphere(Sphere16* sphere, f32 y, f32 z) { return false; } - #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017FB1C.s") void func_8017FD44(Vec3f* arg0, Vec3f* arg1, Vec3f* dst, f32 arg3) { @@ -2226,4 +2269,3 @@ void func_8017FD44(Vec3f* arg0, Vec3f* arg1, Vec3f* dst, f32 arg3) { dst->z = Math_CosS((s16)(32767.0f * arg3) + sp2A) * sp24 + sp2C.z; } } - diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index 72fadfea5..ec16f5d28 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -3281,16 +3281,16 @@ 0x8017A6F8:("Math3D_Vec3fDistSq",), 0x8017A720:("Math3D_Distance",), 0x8017A740:("Math3D_DistanceS",), - 0x8017A7B8:("func_8017A7B8",), - 0x8017A7F8:("func_8017A7F8",), - 0x8017A838:("func_8017A838",), + 0x8017A7B8:("Math3D_Vec3fDiff_CrossZ",), + 0x8017A7F8:("Math3D_Vec3fDiff_CrossX",), + 0x8017A838:("Math3D_Vec3fDiff_CrossY",), 0x8017A878:("Math3D_CrossProduct",), 0x8017A8EC:("Math3D_SurfaceNorm",), 0x8017A954:("Math3D_PointRelativeToCubeFaces",), 0x8017AA0C:("Math3D_PointRelativeToCubeEdges",), 0x8017ABBC:("Math3D_PointRelativeToCubeVertices",), 0x8017AD38:("Math3D_LineVsCube",), - 0x8017B68C:("func_8017B68C",), + 0x8017B68C:("Math3D_LineVsCubeShort",), 0x8017B7F8:("func_8017B7F8",), 0x8017B884:("Math3D_UnitNormalVector",), 0x8017B998:("Math3D_SignedDistanceFromPlane",), diff --git a/tools/sizes/code_functions.csv b/tools/sizes/code_functions.csv index a1267e0d3..5c02ab756 100644 --- a/tools/sizes/code_functions.csv +++ b/tools/sizes/code_functions.csv @@ -2795,16 +2795,16 @@ asm/non_matchings/code/sys_math3d/Math3D_Vec3fMagnitude.s,Math3D_Vec3fMagnitude, asm/non_matchings/code/sys_math3d/Math3D_Vec3fDistSq.s,Math3D_Vec3fDistSq,0x8017A6F8,0xA asm/non_matchings/code/sys_math3d/Math3D_Distance.s,Math3D_Distance,0x8017A720,0x8 asm/non_matchings/code/sys_math3d/Math3D_DistanceS.s,Math3D_DistanceS,0x8017A740,0x1E -asm/non_matchings/code/sys_math3d/func_8017A7B8.s,func_8017A7B8,0x8017A7B8,0x10 -asm/non_matchings/code/sys_math3d/func_8017A7F8.s,func_8017A7F8,0x8017A7F8,0x10 -asm/non_matchings/code/sys_math3d/func_8017A838.s,func_8017A838,0x8017A838,0x10 +asm/non_matchings/code/sys_math3d/Math3D_Vec3fDiff_CrossZ.s,Math3D_Vec3fDiff_CrossZ,0x8017A7B8,0x10 +asm/non_matchings/code/sys_math3d/Math3D_Vec3fDiff_CrossX.s,Math3D_Vec3fDiff_CrossX,0x8017A7F8,0x10 +asm/non_matchings/code/sys_math3d/Math3D_Vec3fDiff_CrossY.s,Math3D_Vec3fDiff_CrossY,0x8017A838,0x10 asm/non_matchings/code/sys_math3d/Math3D_CrossProduct.s,Math3D_CrossProduct,0x8017A878,0x1D asm/non_matchings/code/sys_math3d/Math3D_SurfaceNorm.s,Math3D_SurfaceNorm,0x8017A8EC,0x1A asm/non_matchings/code/sys_math3d/Math3D_PointRelativeToCubeFaces.s,Math3D_PointRelativeToCubeFaces,0x8017A954,0x2E asm/non_matchings/code/sys_math3d/Math3D_PointRelativeToCubeEdges.s,Math3D_PointRelativeToCubeEdges,0x8017AA0C,0x6C asm/non_matchings/code/sys_math3d/Math3D_PointRelativeToCubeVertices.s,Math3D_PointRelativeToCubeVertices,0x8017ABBC,0x5F asm/non_matchings/code/sys_math3d/Math3D_LineVsCube.s,Math3D_LineVsCube,0x8017AD38,0x255 -asm/non_matchings/code/sys_math3d/func_8017B68C.s,func_8017B68C,0x8017B68C,0x5B +asm/non_matchings/code/sys_math3d/Math3D_LineVsCubeShort.s,Math3D_LineVsCubeShort,0x8017B68C,0x5B asm/non_matchings/code/sys_math3d/func_8017B7F8.s,func_8017B7F8,0x8017B7F8,0x23 asm/non_matchings/code/sys_math3d/Math3D_UnitNormalVector.s,Math3D_UnitNormalVector,0x8017B884,0x45 asm/non_matchings/code/sys_math3d/Math3D_SignedDistanceFromPlane.s,Math3D_SignedDistanceFromPlane,0x8017B998,0x10 From 5650a065750a269c9c64457d6b381f5d596d8ebf Mon Sep 17 00:00:00 2001 From: angie Date: Sat, 2 Apr 2022 00:55:58 -0300 Subject: [PATCH 03/29] move sys_math3d function declarations to z64math.h --- include/functions.h | 153 +---------------------------------------- include/macros.h | 3 - include/ultra64.h | 4 +- include/z64math.h | 154 +++++++++++++++++++++++++++++++++++++++++- src/code/sys_math3d.c | 5 +- tools/actorfixer.py | 4 +- 6 files changed, 160 insertions(+), 163 deletions(-) diff --git a/include/functions.h b/include/functions.h index 0f1b08b2c..a32deb8c6 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1589,70 +1589,19 @@ void func_800FEA50(GlobalContext* globalCtx); void func_800FEAB0(void); // void func_800FEAC0(void); void func_800FEAF4(EnvironmentContext* envCtx); + void* Lib_MemCpy(void* dest, void* src, size_t size); void* Lib_MemSet(void* buffer, s32 value, size_t size); -f32 Math_CosS(s16 angle); -f32 Math_SinS(s16 angle); -s32 Math_StepToIImpl(s32 start, s32 target, s32 step); -void Math_StepToIGet(s32* pValue, s32 target, s32 step); -s32 Math_StepToI(s32* pValue, s32 target, s32 step); -s32 Math_ScaledStepToS(s16* pValue, s16 target, s16 step); -s32 Math_StepToS(s16* pValue, s16 target, s16 step); -s32 Math_StepToC(s8* pValue, s8 target, s8 step); -s32 Math_StepToF(f32* pValue, f32 target, f32 step); -s32 Math_StepUntilAngleS(s16* pValue, s16 target, s16 step); -s32 Math_StepToAngleS(s16* pValue, s16 target, s16 step); -s32 Math_AsymStepToS(s16* pValue, s16 target, s16 incrStep, s16 decrStep); -s32 Math_StepUntilF(f32* pValue, f32 limit, f32 step); -s32 Math_AsymStepToF(f32* pValue, f32 target, f32 incrStep, f32 decrStep); void func_800FF3A0(f32* distOut, s16* angleOut, Input* input); s16 Rand_S16Offset(s16 base, s16 range); s16 Rand_S16OffsetStride(s16 base, s16 stride, s16 range); -void Math_Vec3f_Copy(Vec3f* dest, Vec3f* src); -void Math_Vec3s_Copy(Vec3s* dest, Vec3s* src); -void Math_Vec3s_ToVec3f(Vec3f* dest, Vec3s* src); -void Math_Vec3f_ToVec3s(Vec3s* dest, Vec3f* src); -void Math_Vec3f_Sum(Vec3f* l, Vec3f* r, Vec3f* dest); -void Math_Vec3f_Diff(Vec3f* l, Vec3f* r, Vec3f* dest); -void Math_Vec3s_DiffToVec3f(Vec3f* dest, Vec3s* l, Vec3s* r); -void Math_Vec3f_Scale(Vec3f* vec, f32 scale); -void Math_Vec3f_ScaleAndStore(Vec3f* vec, f32 scale, Vec3f* dest); -void Math_Vec3f_Lerp(Vec3f* a, Vec3f* b, f32 t, Vec3f* dest); -void Math_Vec3f_SumScaled(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dest); -void Math_Vec3f_AddRand(Vec3f* orig, f32 scale, Vec3f* dest); -void Math_Vec3f_DistXYZAndStoreNormDiff(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dest); -f32 Math_Vec3f_DistXYZ(Vec3f* a, Vec3f* b); -f32 Math_Vec3f_DistXYZAndStoreDiff(Vec3f* a, Vec3f* b, Vec3f* dest); -f32 Math_Vec3f_DistXZ(Vec3f* a, Vec3f* b); -f32 Math_Vec3f_DistXZAndStore(Vec3f* a, Vec3f* b, f32* dx, f32* dz); -f32 Math_Vec3f_StepToXZ(Vec3f* start, Vec3f* target, f32 speed); -f32 Math_Vec3f_DiffY(Vec3f* a, Vec3f* b); -s16 Math_Vec3f_Yaw(Vec3f* a, Vec3f* b); -s16 Math_Vec3f_Pitch(Vec3f* a, Vec3f* b); void Actor_ProcessInitChain(Actor* actor, InitChainEntry* ichain); -// void IChain_Apply_u8(u8* actor, InitChainEntry* init); -// void IChain_Apply_s8(u8* actor, InitChainEntry* init); -// void IChain_Apply_u16(u8* actor, InitChainEntry* init); -// void IChain_Apply_s16(u8* actor, InitChainEntry* init); -// void IChain_Apply_u32(u8* actor, InitChainEntry* init); -// void IChain_Apply_s32(u8* actor, InitChainEntry* init); -// void IChain_Apply_f32(u8* actor, InitChainEntry* init); -// void IChain_Apply_f32div1000(u8* actor, InitChainEntry* init); -// void IChain_Apply_Vec3f(u8* actor, InitChainEntry* init); -// void IChain_Apply_Vec3fdiv1000(u8* actor, InitChainEntry* init); -// void IChain_Apply_Vec3s(u8* actor, InitChainEntry* init); -f32 Math_SmoothStepToF(f32* pValue, f32 target, f32 fraction, f32 step, f32 minStep); -void Math_ApproachF(f32* pValue, f32 target, f32 scale, f32 maxStep); -void Math_ApproachZeroF(f32* pValue, f32 scale, f32 maxStep); -s16 Math_SmoothStepToS(s16* pValue, s16 target, s16 scale, s16 step, s16 minStep); -void Math_ApproachS(s16* pValue, s16 target, s16 scale, s16 maxStep); void Color_RGBA8_Copy(Color_RGBA8* dst, Color_RGBA8* src); void func_801000A4(u16 sfxId); void func_801000CC(u16 sfxId); void Lib_PlaySfxAtPos(Vec3f* pos, u16 sfxId); void Lib_Vec3f_TranslateAndRotateY(Vec3f* translation, s16 a, Vec3f* src, Vec3f* dst); void Lib_LerpRGB(Color_RGB8* a, Color_RGB8* b, f32 t, Color_RGB8* dst); -f32 Math_Vec3f_StepTo(Vec3f* start, Vec3f* target, f32 speed); void Lib_Nop801004FC(void); void* Lib_SegmentedToVirtual(void* ptr); void* Lib_SegmentedToVirtualNull(void* ptr); @@ -2997,105 +2946,7 @@ f32 sin_rad(f32 rad); f32 cos_rad(f32 rad); f32 Rand_ZeroFloat(f32 scale); f32 randPlusMinusPoint5Scaled(f32 scale); -f32 Math3D_Normalize(Vec3f* vec); -s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* closestPoint); -s32 func_80179798(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3, Vec3f* param_4, Vec3f* param_5, Vec3f* param_6); -// void func_80179A44(void); -void func_80179B34(float fParm1, f32 fParm2, f32 fParm5, f32 fParm6, f32 param_5, f32 param_6, f32 param_7, float* param_8, float* param_9); -s32 func_80179B94(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, InfiniteLine* intersect); -// void func_80179D74(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); -void Math3D_ScaleAndAdd(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dst); -void Math3D_Lerp(Vec3f* a, Vec3f* b, f32 t, Vec3f* dst); -f32 Math3D_Parallel(Vec3f* a, Vec3f* b); -s32 Math3D_AngleBetweenVectors(Vec3f* a, Vec3f* b, f32* angle); -void func_80179F64(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); -s32 Math3D_XZBoundCheck(f32 xMin, f32 xMax, f32 zMin, f32 zMax, f32 x, f32 z); -// void func_8017A09C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -// void func_8017A1D0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -s32 func_8017A304(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f32 chkDist); -// UNK_TYPE4 func_8017A438(Vec3f* pfParm1, Vec3f* pfParm2, Vec3f* pfParm3, Vec3f* pfParm4, f32 param_5); -f32 Math3D_XZLengthSquared(f32 x, f32 z); -f32 Math3D_XZLength(f32 x, f32 z); -f32 Math3D_XZDistanceSquared(f32 x1, f32 x2, f32 z1, f32 z2); -f32 Math3D_XZDistance(f32 x1, f32 x2, f32 z1, f32 z2); -f32 Math3D_LengthSquared(Vec3f* vec); -f32 Math3D_Vec3fMagnitude(Vec3f* vec); -f32 Math3D_Vec3fDistSq(Vec3f* a, Vec3f* b); -f32 Math3D_Distance(Vec3f* a, Vec3f* b); -f32 Math3D_DistanceS(Vec3s* s, Vec3f* f); -f32 Math3D_Vec3fDiff_CrossZ(Vec3f* a, Vec3f* b, f32 dx, f32 dy); -f32 Math3D_Vec3fDiff_CrossX(Vec3f* a, Vec3f* b, f32 dy, f32 dz); -f32 Math3D_Vec3fDiff_CrossY(Vec3f* a, Vec3f* b, f32 dz, f32 dx); -void Math3D_CrossProduct(Vec3f* a, Vec3f* b, Vec3f* res); -void Math3D_SurfaceNorm(Vec3f* a, Vec3f* b, Vec3f* c, Vec3f* res); -s32 Math3D_PointRelativeToCubeFaces(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); -s32 Math3D_PointRelativeToCubeEdges(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); -s32 Math3D_PointRelativeToCubeVertices(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); -s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b); -s32 Math3D_LineVsCubeShort(Vec3s* min, Vec3s* max, Vec3s* a, Vec3s* b); -void func_8017B7F8(Vec3f* arg0, s16 arg1, f32* arg2, f32* arg3, f32* arg4); -void Math3D_UnitNormalVector(Vec3f* a, Vec3f* b, Vec3f* c, f32* normX, f32* normY, f32* normZ, f32* param_7); -f32 Math3D_SignedDistanceFromPlane(f32 normX, f32 normY, f32 normZ, f32 d, Vec3f* position); -f32 func_8017B9D8(Plane* plane, Vec3f* pointOnPlane); -f32 Math3D_UDistPlaneToPos(f32 normX, f32 normY, f32 normZ, f32 d, Vec3f* position); -f32 Math3D_DistPlaneToPos(f32 normX, f32 normY, f32 normZ, f32 d, Vec3f* position); -s32 Math3D_TriChkPointParaYDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 unk, f32 chkDist, f32 ny); -// void func_8017BD98(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void func_8017BDE0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); -s32 Math3D_TriChkPointParaYIntersectDist(Vec3f* a, Vec3f* b, Vec3f* c, f32 nx, f32 ny, f32 nz, f32 dist, f32 z, f32 x, f32* yIntersect, f32 chkDist); -s32 Math3D_TriChkPointParaYIntersectInsideTri(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 chkDist); -// void func_8017BF8C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -s32 Math3D_TriChkLineSegParaYIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 y0, f32 y1); -// void func_8017C17C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void func_8017C1F0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); -s32 Math3D_TriChkPointParaYIntersectInsideTri2(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 chkDist); -s32 Math3D_TriChkPointParaXDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 unk, f32 chkDist, f32 nx); -// void func_8017C808(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -s32 Math3D_TriChkPointParaXIntersect(Vec3f* a, Vec3f* b, Vec3f* c, f32 nx, f32 ny, f32 nz, f32 dist, f32 y, f32 z, f32* xIntersect); -// void func_8017C904(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -s32 Math3D_TriChkLineSegParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 y, f32 z, f32* xIntersect, f32 x0, f32 x1); -// void func_8017CB08(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -s32 Math3D_TriChkLineSegParaZDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 unk, f32 chkDist, f32 nz); -// void func_8017CEA8(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -s32 Math3D_TriChkPointParaZIntersect(Vec3f* a, Vec3f* b, Vec3f* c, f32 nx, f32 ny, f32 nz, f32 dist, f32 x, f32 y, f32* zIntersect); -// void func_8017CFA4(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, f32 y, f32* zIntersect, f32 z0, f32 z1); -// void func_8017D1AC(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void func_8017D220(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); -s32 Math3D_LineSegVsPlane(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersect, s32 fromFront); -s32 func_8017D404(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersect, s32 fromFront) ; -void Math3D_TriSetCoords(TriNorm* tri, Vec3f* pointA, Vec3f* pointB, Vec3f* pointC); -s32 Math3D_IsPointInSphere(Sphere16* sphere, Vec3f* point); -s32 Math3D_PointDistToLine2D(f32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f32* arg6, f32* arg7, f32* arg8); // returns boolean -s32 func_8017D7C0(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* lineLenSq); -s32 func_8017D814(f32 x0, f32 y0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); -s32 func_8017D91C(f32 y0, f32 z0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); -s32 func_8017DA24(f32 z0, f32 x0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); -s32 Math3D_LineVsSph(Sphere16* sphere, Linef* line); -void func_8017DD34(Sphere16* sphere, TriNorm* tri, Vec3f* pfParm3); -s32 Math3D_ColSphereTri(Sphere16* sphere, TriNorm* tri, Vec3f* uParm3); -s32 func_8017E294(Cylinder16* cyl, Vec3f* point); -s32 func_8017E350(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersectA, Vec3f* intersectB); -s32 Math3D_ColCylinderTri(Cylinder16* cylinder, TriNorm* tri, Vec3f* pzParm3); -// void func_8017F1A0(void); -s32 Math3D_SphVsSph(Sphere16* sphere1, Sphere16* sphere2); -s32 Math3D_ColSphereSphereIntersect(Sphere16* sphere1, Sphere16* sphere2, f32* intersectAmount); -s32 Math3D_ColSphereSphereIntersectAndDistance(Sphere16* sphere1, Sphere16* sphere2, f32* intersectAmount, f32* dist); -s32 Math3D_ColSphereCylinderDistance(Sphere16* sphere, Cylinder16* cylinder, f32* dist); -s32 Math3D_ColSphereCylinderDistanceAndAmount(Sphere16* sphere, Cylinder16* cylinder, f32* dist, f32* intersectAmount); -s32 Math3D_ColCylinderCylinderAmount(Cylinder16* cylinder1, Cylinder16* cylinder2, f32* intersectAmount); -s32 Math3D_ColCylinderCylinderAmountAndDistance(Cylinder16* cylinder1, Cylinder16* cylinder2, f32* intersectAmount, f32* dist); -s32 Math3d_ColTriTri(TriNorm* tri1, TriNorm* tri2, Vec3f* uParm3); -s32 Math3D_XZInSphere(Sphere16* sphere, f32 x, f32 z); -s32 Math3D_XYInSphere(Sphere16* sphere, f32 x, f32 y); -s32 Math3D_YZInSphere(Sphere16* sphere, f32 y, f32 z); -// void func_8017FB1C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11); -// void func_8017FD44(void); -u16 Math_GetAtan2Tbl(f32 opposite, f32 adjacent); -s16 Math_Atan2S(f32 opposite, f32 adjacent); -f32 Math_Atan2F(f32 opposite, f32 adjacent); -s16 Math_FAtan2F(f32 adjacent, f32 opposite); -f32 Math_Acot2F(f32 adjacent, f32 opposite); + void Matrix_StateAlloc(GameState* gameState); void Matrix_StatePush(void); void Matrix_StatePop(void); diff --git a/include/macros.h b/include/macros.h index 5e9c062c9..a10d1fe19 100644 --- a/include/macros.h +++ b/include/macros.h @@ -179,9 +179,6 @@ extern GraphicsContext* __gfxCtx; #define ALIGN64(val) (((val) + 0x3F) & ~0x3F) #define ALIGN256(val) (((val) + 0xFF) & ~0xFF) -#define SQ(x) ((x) * (x)) -#define ABS(x) ((x) >= 0 ? (x) : -(x)) -#define ABS_ALT(x) ((x) < 0 ? -(x) : (x)) #define DECR(x) ((x) == 0 ? 0 : --(x)) #define CLAMP(x, min, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x)) diff --git a/include/ultra64.h b/include/ultra64.h index 49323cc2b..b55536007 100644 --- a/include/ultra64.h +++ b/include/ultra64.h @@ -1,5 +1,5 @@ -#ifndef _ULTRA64_H_ -#define _ULTRA64_H_ +#ifndef ULTRA64_H +#define ULTRA64_H #include "PR/ultratypes.h" #include "PR/gbi.h" diff --git a/include/z64math.h b/include/z64math.h index 0c3b3b662..c33504ec3 100644 --- a/include/z64math.h +++ b/include/z64math.h @@ -1,7 +1,7 @@ -#ifndef _Z64MATH_H_ -#define _Z64MATH_H_ +#ifndef Z64MATH_H +#define Z64MATH_H -#include "ultra64.h" +#include "PR/ultratypes.h" #define VEC_SET(V,X,Y,Z) V.x=X;V.y=Y;V.z=Z @@ -105,6 +105,10 @@ typedef struct { #define IS_ZERO(f) (fabsf(f) < 0.008f) +#define SQ(x) ((x) * (x)) +#define ABS(x) ((x) >= 0 ? (x) : -(x)) +#define ABS_ALT(x) ((x) < 0 ? -(x) : (x)) + // Trig macros #define DEGF_TO_BINANG(degreesf) (s16)(degreesf * 182.04167f + .5f) #define RADF_TO_BINANG(radf) (s16)(radf * (32768.0f / M_PI)) @@ -123,4 +127,148 @@ typedef struct { #define SQXYZ(vec) ((vec.x) * (vec.x) + (vec.y) * (vec.y) + (vec.z) * (vec.z)) #define DOTXYZ(vec1, vec2) ((vec1.x) * (vec2.x) + (vec1.y) * (vec2.y) + (vec1.z) * (vec2.z)) + +f32 Math_CosS(s16 angle); +f32 Math_SinS(s16 angle); +s32 Math_StepToIImpl(s32 start, s32 target, s32 step); +void Math_StepToIGet(s32* pValue, s32 target, s32 step); +s32 Math_StepToI(s32* pValue, s32 target, s32 step); +s32 Math_ScaledStepToS(s16* pValue, s16 target, s16 step); +s32 Math_StepToS(s16* pValue, s16 target, s16 step); +s32 Math_StepToC(s8* pValue, s8 target, s8 step); +s32 Math_StepToF(f32* pValue, f32 target, f32 step); +s32 Math_StepUntilAngleS(s16* pValue, s16 target, s16 step); +s32 Math_StepToAngleS(s16* pValue, s16 target, s16 step); +s32 Math_AsymStepToS(s16* pValue, s16 target, s16 incrStep, s16 decrStep); +s32 Math_StepUntilF(f32* pValue, f32 limit, f32 step); +s32 Math_AsymStepToF(f32* pValue, f32 target, f32 incrStep, f32 decrStep); +void Math_Vec3f_Copy(Vec3f* dest, Vec3f* src); +void Math_Vec3s_Copy(Vec3s* dest, Vec3s* src); +void Math_Vec3s_ToVec3f(Vec3f* dest, Vec3s* src); +void Math_Vec3f_ToVec3s(Vec3s* dest, Vec3f* src); +void Math_Vec3f_Sum(Vec3f* l, Vec3f* r, Vec3f* dest); +void Math_Vec3f_Diff(Vec3f* l, Vec3f* r, Vec3f* dest); +void Math_Vec3s_DiffToVec3f(Vec3f* dest, Vec3s* l, Vec3s* r); +void Math_Vec3f_Scale(Vec3f* vec, f32 scale); +void Math_Vec3f_ScaleAndStore(Vec3f* vec, f32 scale, Vec3f* dest); +void Math_Vec3f_Lerp(Vec3f* a, Vec3f* b, f32 t, Vec3f* dest); +void Math_Vec3f_SumScaled(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dest); +void Math_Vec3f_AddRand(Vec3f* orig, f32 scale, Vec3f* dest); +void Math_Vec3f_DistXYZAndStoreNormDiff(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dest); +f32 Math_Vec3f_DistXYZ(Vec3f* a, Vec3f* b); +f32 Math_Vec3f_DistXYZAndStoreDiff(Vec3f* a, Vec3f* b, Vec3f* dest); +f32 Math_Vec3f_DistXZ(Vec3f* a, Vec3f* b); +f32 Math_Vec3f_DistXZAndStore(Vec3f* a, Vec3f* b, f32* dx, f32* dz); +f32 Math_Vec3f_StepToXZ(Vec3f* start, Vec3f* target, f32 speed); +f32 Math_Vec3f_DiffY(Vec3f* a, Vec3f* b); +s16 Math_Vec3f_Yaw(Vec3f* a, Vec3f* b); +s16 Math_Vec3f_Pitch(Vec3f* a, Vec3f* b); +f32 Math_SmoothStepToF(f32* pValue, f32 target, f32 fraction, f32 step, f32 minStep); +void Math_ApproachF(f32* pValue, f32 target, f32 scale, f32 maxStep); +void Math_ApproachZeroF(f32* pValue, f32 scale, f32 maxStep); +s16 Math_SmoothStepToS(s16* pValue, s16 target, s16 scale, s16 step, s16 minStep); +void Math_ApproachS(s16* pValue, s16 target, s16 scale, s16 maxStep); +f32 Math_Vec3f_StepTo(Vec3f* start, Vec3f* target, f32 speed); + +u16 Math_GetAtan2Tbl(f32 opposite, f32 adjacent); +s16 Math_Atan2S(f32 opposite, f32 adjacent); +f32 Math_Atan2F(f32 opposite, f32 adjacent); +s16 Math_FAtan2F(f32 adjacent, f32 opposite); +f32 Math_Acot2F(f32 adjacent, f32 opposite); + +f32 Math3D_Normalize(Vec3f* vec); +s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* closestPoint); +s32 func_80179798(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3, Vec3f* param_4, Vec3f* param_5, Vec3f* param_6); +// void func_80179A44(void); +void func_80179B34(float fParm1, f32 fParm2, f32 fParm5, f32 fParm6, f32 param_5, f32 param_6, f32 param_7, float* param_8, float* param_9); +s32 func_80179B94(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, InfiniteLine* intersect); +// void func_80179D74(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); +void Math3D_ScaleAndAdd(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dst); +void Math3D_Lerp(Vec3f* a, Vec3f* b, f32 t, Vec3f* dst); +f32 Math3D_Parallel(Vec3f* a, Vec3f* b); +s32 Math3D_AngleBetweenVectors(Vec3f* a, Vec3f* b, f32* angle); +void func_80179F64(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); +s32 Math3D_XZBoundCheck(f32 xMin, f32 xMax, f32 zMin, f32 zMax, f32 x, f32 z); +// void func_8017A09C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); +// void func_8017A1D0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); +s32 func_8017A304(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f32 chkDist); +// UNK_TYPE4 func_8017A438(Vec3f* pfParm1, Vec3f* pfParm2, Vec3f* pfParm3, Vec3f* pfParm4, f32 param_5); +f32 Math3D_XZLengthSquared(f32 x, f32 z); +f32 Math3D_XZLength(f32 x, f32 z); +f32 Math3D_XZDistanceSquared(f32 x1, f32 x2, f32 z1, f32 z2); +f32 Math3D_XZDistance(f32 x1, f32 x2, f32 z1, f32 z2); +f32 Math3D_LengthSquared(Vec3f* vec); +f32 Math3D_Vec3fMagnitude(Vec3f* vec); +f32 Math3D_Vec3fDistSq(Vec3f* a, Vec3f* b); +f32 Math3D_Distance(Vec3f* a, Vec3f* b); +f32 Math3D_DistanceS(Vec3s* s, Vec3f* f); +f32 Math3D_Vec3fDiff_CrossZ(Vec3f* a, Vec3f* b, f32 dx, f32 dy); +f32 Math3D_Vec3fDiff_CrossX(Vec3f* a, Vec3f* b, f32 dy, f32 dz); +f32 Math3D_Vec3fDiff_CrossY(Vec3f* a, Vec3f* b, f32 dz, f32 dx); +void Math3D_CrossProduct(Vec3f* a, Vec3f* b, Vec3f* res); +void Math3D_SurfaceNorm(Vec3f* a, Vec3f* b, Vec3f* c, Vec3f* res); +s32 Math3D_PointRelativeToCubeFaces(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); +s32 Math3D_PointRelativeToCubeEdges(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); +s32 Math3D_PointRelativeToCubeVertices(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); +s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b); +s32 Math3D_LineVsCubeShort(Vec3s* min, Vec3s* max, Vec3s* a, Vec3s* b); +void func_8017B7F8(Vec3f* arg0, s16 arg1, f32* arg2, f32* arg3, f32* arg4); +void Math3D_UnitNormalVector(Vec3f* a, Vec3f* b, Vec3f* c, f32* normX, f32* normY, f32* normZ, f32* param_7); +f32 Math3D_SignedDistanceFromPlane(f32 normX, f32 normY, f32 normZ, f32 d, Vec3f* position); +f32 func_8017B9D8(Plane* plane, Vec3f* pointOnPlane); +f32 Math3D_UDistPlaneToPos(f32 normX, f32 normY, f32 normZ, f32 d, Vec3f* position); +f32 Math3D_DistPlaneToPos(f32 normX, f32 normY, f32 normZ, f32 d, Vec3f* position); +s32 Math3D_TriChkPointParaYDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 unk, f32 chkDist, f32 ny); +// void func_8017BD98(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); +// void func_8017BDE0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); +s32 Math3D_TriChkPointParaYIntersectDist(Vec3f* a, Vec3f* b, Vec3f* c, f32 nx, f32 ny, f32 nz, f32 dist, f32 z, f32 x, f32* yIntersect, f32 chkDist); +s32 Math3D_TriChkPointParaYIntersectInsideTri(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 chkDist); +// void func_8017BF8C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); +s32 Math3D_TriChkLineSegParaYIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 y0, f32 y1); +// void func_8017C17C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); +// void func_8017C1F0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); +s32 Math3D_TriChkPointParaYIntersectInsideTri2(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 chkDist); +s32 Math3D_TriChkPointParaXDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 unk, f32 chkDist, f32 nx); +// void func_8017C808(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); +s32 Math3D_TriChkPointParaXIntersect(Vec3f* a, Vec3f* b, Vec3f* c, f32 nx, f32 ny, f32 nz, f32 dist, f32 y, f32 z, f32* xIntersect); +// void func_8017C904(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); +s32 Math3D_TriChkLineSegParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 y, f32 z, f32* xIntersect, f32 x0, f32 x1); +// void func_8017CB08(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); +s32 Math3D_TriChkLineSegParaZDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 unk, f32 chkDist, f32 nz); +// void func_8017CEA8(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); +s32 Math3D_TriChkPointParaZIntersect(Vec3f* a, Vec3f* b, Vec3f* c, f32 nx, f32 ny, f32 nz, f32 dist, f32 x, f32 y, f32* zIntersect); +// void func_8017CFA4(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); +s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, f32 y, f32* zIntersect, f32 z0, f32 z1); +// void func_8017D1AC(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); +// void func_8017D220(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); +s32 Math3D_LineSegVsPlane(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersect, s32 fromFront); +s32 func_8017D404(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersect, s32 fromFront) ; +void Math3D_TriSetCoords(TriNorm* tri, Vec3f* pointA, Vec3f* pointB, Vec3f* pointC); +s32 Math3D_IsPointInSphere(Sphere16* sphere, Vec3f* point); +s32 Math3D_PointDistToLine2D(f32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f32* arg6, f32* arg7, f32* arg8); // returns boolean +s32 func_8017D7C0(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* lineLenSq); +s32 func_8017D814(f32 x0, f32 y0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); +s32 func_8017D91C(f32 y0, f32 z0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); +s32 func_8017DA24(f32 z0, f32 x0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); +s32 Math3D_LineVsSph(Sphere16* sphere, Linef* line); +void func_8017DD34(Sphere16* sphere, TriNorm* tri, Vec3f* pfParm3); +s32 Math3D_ColSphereTri(Sphere16* sphere, TriNorm* tri, Vec3f* uParm3); +s32 func_8017E294(Cylinder16* cyl, Vec3f* point); +s32 func_8017E350(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersectA, Vec3f* intersectB); +s32 Math3D_ColCylinderTri(Cylinder16* cylinder, TriNorm* tri, Vec3f* pzParm3); +// void func_8017F1A0(void); +s32 Math3D_SphVsSph(Sphere16* sphere1, Sphere16* sphere2); +s32 Math3D_ColSphereSphereIntersect(Sphere16* sphere1, Sphere16* sphere2, f32* intersectAmount); +s32 Math3D_ColSphereSphereIntersectAndDistance(Sphere16* sphere1, Sphere16* sphere2, f32* intersectAmount, f32* dist); +s32 Math3D_ColSphereCylinderDistance(Sphere16* sphere, Cylinder16* cylinder, f32* dist); +s32 Math3D_ColSphereCylinderDistanceAndAmount(Sphere16* sphere, Cylinder16* cylinder, f32* dist, f32* intersectAmount); +s32 Math3D_ColCylinderCylinderAmount(Cylinder16* cylinder1, Cylinder16* cylinder2, f32* intersectAmount); +s32 Math3D_ColCylinderCylinderAmountAndDistance(Cylinder16* cylinder1, Cylinder16* cylinder2, f32* intersectAmount, f32* dist); +s32 Math3d_ColTriTri(TriNorm* tri1, TriNorm* tri2, Vec3f* uParm3); +s32 Math3D_XZInSphere(Sphere16* sphere, f32 x, f32 z); +s32 Math3D_XYInSphere(Sphere16* sphere, f32 x, f32 y); +s32 Math3D_YZInSphere(Sphere16* sphere, f32 y, f32 z); +// void func_8017FB1C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11); +// void func_8017FD44(void); + #endif diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 7d4c60cb1..b11288488 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -1,4 +1,6 @@ -#include "global.h" +#include "z64math.h" +#include "libc/stdbool.h" +#include "libc/math.h" #define Math3D_PlaneVsPlaneNewLine func_80179B94 #define Math3D_LineSegMakePerpLineSeg func_80179798 @@ -2221,7 +2223,6 @@ s32 Math3D_TriVsTriIntersect(TriNorm* ta, TriNorm* tb, Vec3f* intersect) { return false; } - s32 Math3D_XZInSphere(Sphere16* sphere, f32 x, f32 z) { f32 xDiff = sphere->center.x - x; f32 zDiff = sphere->center.z - z; diff --git a/tools/actorfixer.py b/tools/actorfixer.py index e5e125905..703d6d10e 100755 --- a/tools/actorfixer.py +++ b/tools/actorfixer.py @@ -58,7 +58,6 @@ animdict = { "Actor_IsActorFacingActor": "Actor_ActorAIsFacingActorB", "Actor_IsActorFacedByActor": "Actor_ActorBIsFacingActorA", "func_800B84D0": "Actor_ProcessTalkRequest", - "func_8017D668": "Math3D_PointDistToLine2D", "func_800BDFC0": "Gfx_DrawDListOpa", "func_800BE03C": "Gfx_DrawDListXlu", "func_800B6FC8": "Player_GetHeight", @@ -358,6 +357,7 @@ animdict = { "func_800CA1E8": "WaterBox_GetSurface1_2", "func_800CA22C": "WaterBox_GetSurface2", "func_800CA6D8": "WaterBox_GetLightSettingIndex", + "func_8017D668": "Math3D_PointDistToLine2D", "func_80179678": "Math3D_PlaneVsLineSegClosestPoint", "Math3D_DistanceSquared": "Math3D_Vec3fDistSq", "Math3D_NormalVector": "Math3D_SurfaceNorm", @@ -383,6 +383,7 @@ animdict = { "func_8017F9C0": "Math3D_XZInSphere", "func_8017FA34": "Math3D_XYInSphere", "func_8017FAA8": "Math3D_YZInSphere", + "func_8017D2FC": "Math3D_LineSegVsPlane", "func_800DFB14": "Camera_ChangeDataIdx", "func_800DFC68": "Camera_GetInputDirYaw", "func_800DFCB4": "Camera_GetCamDirPitch", @@ -409,7 +410,6 @@ animdict = { "func_80169E6C": "Play_SetupRespawnPoint", "func_8016A0AC": "Play_IsUnderwater", "func_801690CC": "Play_InCsMode", - "func_8017D2FC": "Math3D_LineSegVsPlane", "func_8013A7C0": "SubS_FindDoor", "func_8013E640": "SubS_FindActorCustom", "func_ActorCategoryIterateById": "SubS_FindActor", From 3dabee79dd60cf75f9d348a2ae54be8fb3ab3be5 Mon Sep 17 00:00:00 2001 From: angie Date: Sat, 2 Apr 2022 01:39:47 -0300 Subject: [PATCH 04/29] Rename some simple functions --- include/variables.h | 2 +- include/z64math.h | 22 +++---- src/code/sys_math3d.c | 58 ++++++++++++------- src/code/z_actor.c | 4 +- src/code/z_eff_blure.c | 4 +- src/code/z_fireobj.c | 2 +- src/code/z_sub_s.c | 4 +- .../z_bg_dblue_waterfall.c | 2 +- .../ovl_Bg_Hakugin_Post/z_bg_hakugin_post.c | 8 +-- src/overlays/actors/ovl_En_Arrow/z_en_arrow.c | 2 +- .../actors/ovl_En_Bigslime/z_en_bigslime.c | 2 +- .../actors/ovl_En_Bom_Chu/z_en_bom_chu.c | 4 +- src/overlays/actors/ovl_En_Butte/z_en_butte.c | 8 +-- .../actors/ovl_En_Goroiwa/z_en_goroiwa.c | 10 ++-- src/overlays/actors/ovl_En_Horse/z_en_horse.c | 24 ++++---- .../actors/ovl_En_Invadepoh/z_en_invadepoh.c | 10 ++-- src/overlays/actors/ovl_En_Ishi/z_en_ishi.c | 2 +- src/overlays/actors/ovl_En_Kusa2/z_en_kusa2.c | 6 +- .../actors/ovl_En_Mushi2/z_en_mushi2.c | 14 ++--- src/overlays/actors/ovl_En_Ot/z_en_ot.c | 2 +- .../actors/ovl_En_Pametfrog/z_en_pametfrog.c | 10 ++-- src/overlays/actors/ovl_En_Sw/z_en_sw.c | 6 +- src/overlays/actors/ovl_Mir_Ray/z_mir_ray.c | 4 +- .../actors/ovl_Obj_Iceblock/z_obj_iceblock.c | 4 +- .../ovl_Obj_Skateblock/z_obj_skateblock.c | 4 +- .../actors/ovl_Obj_Snowball/z_obj_snowball.c | 2 +- .../ovl_Obj_Spidertent/z_obj_spidertent.c | 12 ++-- .../ovl_Obj_Spinyroll/z_obj_spinyroll.c | 2 +- .../actors/ovl_Obj_Switch/z_obj_switch.c | 2 +- .../ovl_Obj_Vspinyroll/z_obj_vspinyroll.c | 2 +- tools/actorfixer.py | 14 +++++ tools/disasm/functions.txt | 22 +++---- tools/disasm/variables.txt | 2 +- tools/sizes/code_functions.csv | 22 +++---- 34 files changed, 165 insertions(+), 133 deletions(-) diff --git a/include/variables.h b/include/variables.h index 20af3294f..4074abc9f 100644 --- a/include/variables.h +++ b/include/variables.h @@ -2884,7 +2884,7 @@ extern f32 D_801E0134; extern f32 D_801E0138; extern f32 D_801E013C; extern f32 D_801E0140; -extern f32 Math3D_AngleBetweenVectors_min_length; +extern f32 Math3D_CosOut_min_length; extern f32 D_801E0148; extern f32 D_801E014C; extern f32 Math3D_UnitNormalVector_min_length; diff --git a/include/z64math.h b/include/z64math.h index c33504ec3..e0d23ec8f 100644 --- a/include/z64math.h +++ b/include/z64math.h @@ -179,33 +179,33 @@ f32 Math_Acot2F(f32 adjacent, f32 opposite); f32 Math3D_Normalize(Vec3f* vec); s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* closestPoint); s32 func_80179798(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3, Vec3f* param_4, Vec3f* param_5, Vec3f* param_6); -// void func_80179A44(void); +f32 Math3D_LineClosestToPoint(Linef* line, Vec3f* pos, Vec3f* closestPoint); void func_80179B34(float fParm1, f32 fParm2, f32 fParm5, f32 fParm6, f32 param_5, f32 param_6, f32 param_7, float* param_8, float* param_9); s32 func_80179B94(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, InfiniteLine* intersect); // void func_80179D74(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); void Math3D_ScaleAndAdd(Vec3f* a, Vec3f* b, f32 scale, Vec3f* dst); void Math3D_Lerp(Vec3f* a, Vec3f* b, f32 t, Vec3f* dst); -f32 Math3D_Parallel(Vec3f* a, Vec3f* b); -s32 Math3D_AngleBetweenVectors(Vec3f* a, Vec3f* b, f32* angle); +f32 Math3D_Cos(Vec3f* a, Vec3f* b); +s32 Math3D_CosOut(Vec3f* a, Vec3f* b, f32* angle); void func_80179F64(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); s32 Math3D_XZBoundCheck(f32 xMin, f32 xMax, f32 zMin, f32 zMax, f32 x, f32 z); // void func_8017A09C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); // void func_8017A1D0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); s32 func_8017A304(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f32 chkDist); // UNK_TYPE4 func_8017A438(Vec3f* pfParm1, Vec3f* pfParm2, Vec3f* pfParm3, Vec3f* pfParm4, f32 param_5); -f32 Math3D_XZLengthSquared(f32 x, f32 z); -f32 Math3D_XZLength(f32 x, f32 z); -f32 Math3D_XZDistanceSquared(f32 x1, f32 x2, f32 z1, f32 z2); -f32 Math3D_XZDistance(f32 x1, f32 x2, f32 z1, f32 z2); -f32 Math3D_LengthSquared(Vec3f* vec); +f32 Math3D_Dist1DSq(f32 x, f32 z); +f32 Math3D_Dist1D(f32 x, f32 z); +f32 Math3D_Dist2DSq(f32 x1, f32 x2, f32 z1, f32 z2); +f32 Math3D_Dist2D(f32 x1, f32 x2, f32 z1, f32 z2); +f32 Math3D_Vec3fMagnitudeSq(Vec3f* vec); f32 Math3D_Vec3fMagnitude(Vec3f* vec); f32 Math3D_Vec3fDistSq(Vec3f* a, Vec3f* b); -f32 Math3D_Distance(Vec3f* a, Vec3f* b); -f32 Math3D_DistanceS(Vec3s* s, Vec3f* f); +f32 Math3D_Vec3f_DistXYZ(Vec3f* a, Vec3f* b); +f32 Math3D_DistXYZ16toF(Vec3s* s, Vec3f* f); f32 Math3D_Vec3fDiff_CrossZ(Vec3f* a, Vec3f* b, f32 dx, f32 dy); f32 Math3D_Vec3fDiff_CrossX(Vec3f* a, Vec3f* b, f32 dy, f32 dz); f32 Math3D_Vec3fDiff_CrossY(Vec3f* a, Vec3f* b, f32 dz, f32 dx); -void Math3D_CrossProduct(Vec3f* a, Vec3f* b, Vec3f* res); +void Math3D_Vec3f_Cross(Vec3f* a, Vec3f* b, Vec3f* res); void Math3D_SurfaceNorm(Vec3f* a, Vec3f* b, Vec3f* c, Vec3f* res); s32 Math3D_PointRelativeToCubeFaces(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); s32 Math3D_PointRelativeToCubeEdges(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3); diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index b11288488..484987756 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -2,9 +2,9 @@ #include "libc/stdbool.h" #include "libc/math.h" +#define Math3D_FindPointOnPlaneIntersect func_80179B34 #define Math3D_PlaneVsPlaneNewLine func_80179B94 #define Math3D_LineSegMakePerpLineSeg func_80179798 -#define Math3D_Vec3f_Cross Math3D_CrossProduct #define Math3D_Plane func_8017B9D8 #define Math3D_TriLineIntersect func_8017D404 #define Math3D_CylOutsideCylDist Math3D_ColCylinderCylinderAmountAndDistance @@ -22,18 +22,8 @@ #define Math3D_LineSplitRatio Math3D_Lerp #define Math3D_PlaneVsPlaneVsLineClosestPoint func_80179D74 #define Math3D_PointInCyl func_8017E294 -#define Math3D_Cos Math3D_Parallel -#define Math3D_CosOut Math3D_AngleBetweenVectors #define Math3D_Vec3fReflect func_80179F64 #define Math3D_PointInSquare2D Math3D_XZBoundCheck -#define Math3D_Dist1DSq Math3D_XZLengthSquared -#define Math3D_Dist1D Math3D_XZLength -#define Math3D_Dist2DSq Math3D_XZDistanceSquared -#define Math3D_Dist2D Math3D_XZDistance -#define Math3D_Vec3fMagnitudeSq Math3D_LengthSquared -#define Math3D_Vec3fDistSq Math3D_Vec3fDistSq -#define Math3D_Vec3f_DistXYZ Math3D_Distance -#define Math3D_DistXYZ16toF Math3D_DistanceS #define Math3D_RotateXZPlane func_8017B7F8 #define Math3D_DefPlane Math3D_UnitNormalVector #define Math3D_PlaneF Math3D_SignedDistanceFromPlane @@ -59,8 +49,8 @@ #define Math3D_TriNorm Math3D_TriSetCoords #define Math3D_PointInSph Math3D_IsPointInSphere #define Math3D_PointDistToLine2D_ func_8017D814 -#define Math3D_Vec3fMagnitudeSq Math3D_LengthSquared -#define Math3D_LineClosestToPoint func_80179A44 +#define Math3D_TriVsTriIntersect Math3d_ColTriTri +#define Math3D_GetSphVsTriIntersectPoint func_8017DD34 f32 Math3D_Normalize(Vec3f* vec) { f32 magnitude = Math3D_Vec3fMagnitude(vec); @@ -82,7 +72,6 @@ s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 Vec3f* closestPoint) { static InfiniteLine planeIntersectLine; static Linef planeIntersectSeg; - Vec3f sp34; // unused if (!Math3D_PlaneVsPlaneNewLine(planeAA, planeAB, planeAC, planeADist, planeBA, planeBB, planeBC, planeBDist, @@ -175,12 +164,17 @@ s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_80179798.s") #endif +/** + * Determines the closest point on the line `line` to `pos`, by forming a line perpendicular from + * `point` to `line` closest point is placed in `closestPoint` + */ f32 Math3D_LineClosestToPoint(Linef* line, Vec3f* pos, Vec3f* closestPoint) { f32 dirVectorSize = Math3D_Vec3fMagnitudeSq(&line->b); f32 t; if (IS_ZERO(dirVectorSize)) { Math_Vec3f_Copy(closestPoint, pos); + //! @bug Missing early return } t = (((pos->x - line->a.x) * line->b.x) + ((pos->y - line->a.y) * line->b.y) + ((pos->z - line->a.z) * line->b.z)) / @@ -192,7 +186,6 @@ f32 Math3D_LineClosestToPoint(Linef* line, Vec3f* pos, Vec3f* closestPoint) { return t; } -#define Math3D_FindPointOnPlaneIntersect func_80179B34 void Math3D_FindPointOnPlaneIntersect(f32 planeAAxis1Norm, f32 planeAAxis2Norm, f32 planeBAxis1Norm, f32 planeBAxis2Norm, f32 axis3Direction, f32 planeADist, f32 planeBDist, f32* axis1Point, f32* axis2Point) { @@ -200,7 +193,6 @@ void Math3D_FindPointOnPlaneIntersect(f32 planeAAxis1Norm, f32 planeAAxis2Norm, *axis2Point = ((planeBAxis1Norm * planeADist) - (planeAAxis1Norm * planeBDist)) / axis3Direction; } -#define Math3D_PlaneVsPlaneNewLine func_80179B94 s32 Math3D_PlaneVsPlaneNewLine(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, InfiniteLine* intersect) { char pad[4]; @@ -510,30 +502,51 @@ s32 func_8017A438(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, f32 arg4) return 1; } +/** + * Returns the distance squared between `a` and `b` on a single axis + */ f32 Math3D_Dist1DSq(f32 a, f32 b) { return SQ(a) + SQ(b); } +/** + * Returns the distance between `a` and `b` on a single axis + */ f32 Math3D_Dist1D(f32 a, f32 b) { return sqrtf(Math3D_Dist1DSq(a, b)); } +/** + * Returns the distance squared between (`x0`,`y0`) and (`x1`,`x2`) + */ f32 Math3D_Dist2DSq(f32 x0, f32 y0, f32 x1, f32 y1) { return Math3D_Dist1DSq(x0 - x1, y0 - y1); } +/** + * Returns the distance between points (`x0`,`y0`) and (`x1`,`y1`) + */ f32 Math3D_Dist2D(f32 x0, f32 y0, f32 x1, f32 y1) { return sqrtf(Math3D_Dist2DSq(x0, y0, x1, y1)); } +/** + * Returns the magntiude (length) squared of `vec` + */ f32 Math3D_Vec3fMagnitudeSq(Vec3f* vec) { return SQ(vec->x) + SQ(vec->y) + SQ(vec->z); } +/** + * Returns the magnitude(length) of `vec` + */ f32 Math3D_Vec3fMagnitude(Vec3f* vec) { return sqrtf(Math3D_Vec3fMagnitudeSq(vec)); } +/** + * Returns the distance between `a` and `b` squared. + */ f32 Math3D_Vec3fDistSq(Vec3f* a, Vec3f* b) { Vec3f diff; @@ -542,10 +555,16 @@ f32 Math3D_Vec3fDistSq(Vec3f* a, Vec3f* b) { return Math3D_Vec3fMagnitudeSq(&diff); } +/* + * Calculates the distance between points `a` and `b` + */ f32 Math3D_Vec3f_DistXYZ(Vec3f* a, Vec3f* b) { return Math_Vec3f_DistXYZ(a, b); } +/* + * Calculates the distance between `a` and `b`. + */ f32 Math3D_DistXYZ16toF(Vec3s* a, Vec3f* b) { Vec3f diff; @@ -577,6 +596,9 @@ f32 Math3D_Vec3fDiff_CrossY(Vec3f* a, Vec3f* b, f32 dz, f32 dx) { return ((a->z - dz) * (b->x - dx)) - ((a->x - dx) * (b->z - dz)); } +/** + * Gets the Cross Product of vectors `a` and `b` and places the result in `ret` + */ void Math3D_Vec3f_Cross(Vec3f* a, Vec3f* b, Vec3f* ret) { ret->x = (a->y * b->z) - (a->z * b->y); ret->y = (a->z * b->x) - (a->x * b->z); @@ -1576,9 +1598,6 @@ s32 func_8017DA24(f32 z0, f32 x0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { return ret; } -#define Math3D_TriVsSphIntersect Math3D_ColSphereTri -#define Math3D_GetSphVsTriIntersectPoint func_8017DD34 - #ifdef NON_MATCHING // in-function static bss s32 Math3D_LineVsSph(Sphere16* sphere, Linef* line) { @@ -2176,7 +2195,6 @@ s32 Math3D_CylOutsideCylDist(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32 #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColCylinderCylinderAmountAndDistance.s") #endif -#define Math3D_TriVsTriIntersect Math3d_ColTriTri s32 Math3D_TriVsTriIntersect(TriNorm* ta, TriNorm* tb, Vec3f* intersect) { f32 dist0 = Math3D_Plane(&ta->plane, &tb->vtx[0]); f32 dist1 = Math3D_Plane(&ta->plane, &tb->vtx[1]); diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 93eeeddc7..f1a7e4b9c 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -3937,7 +3937,7 @@ void Actor_GetClosestPosOnPath(Vec3s* points, s32 numPoints, Vec3f* srcPos, Vec3 // Find the point closest to srcPos for (pointIndex = 0; pointIndex < numPoints; pointIndex++) { - distSq = Math3D_XZDistanceSquared(srcPos->x, srcPos->z, points[pointIndex].x, points[pointIndex].z); + distSq = Math3D_Dist2DSq(srcPos->x, srcPos->z, points[pointIndex].x, points[pointIndex].z); if (distSq < closestPointDistSq) { closestPointDistSq = distSq; closestPointIndex = pointIndex; @@ -3998,7 +3998,7 @@ void Actor_GetClosestPosOnPath(Vec3s* points, s32 numPoints, Vec3f* srcPos, Vec3 for (i = 0; i < ARRAY_COUNT(loopDistSq); i++) { if (useAdjacentLines[i]) { // Get distSq from srcPos to closestPos - loopDistSq[i] = Math3D_XZDistanceSquared(srcPos->x, srcPos->z, closestPos[i].x, closestPos[i].z); + loopDistSq[i] = Math3D_Dist2DSq(srcPos->x, srcPos->z, closestPos[i].x, closestPos[i].z); } else { // The closest Pos is not contained within the line-segment loopDistSq[i] = SQ(40000.0f); diff --git a/src/code/z_eff_blure.c b/src/code/z_eff_blure.c index b17799aff..c5560eb05 100644 --- a/src/code/z_eff_blure.c +++ b/src/code/z_eff_blure.c @@ -290,8 +290,8 @@ void EffectBlure_UpdateFlags(EffectBlureElement* elem) { Math_Vec3s_DiffToVec3f(&sp4C, &next->p1, &elem->p1); Math_Vec3s_DiffToVec3f(&sp40, &next->p2, &elem->p2); - if (Math3D_AngleBetweenVectors(&sp64, &sp4C, &sp34) || Math3D_AngleBetweenVectors(&sp58, &sp40, &sp30) || - Math3D_AngleBetweenVectors(&sp4C, &sp40, &sp2C)) { + if (Math3D_CosOut(&sp64, &sp4C, &sp34) || Math3D_CosOut(&sp58, &sp40, &sp30) || + Math3D_CosOut(&sp4C, &sp40, &sp2C)) { elem->flags &= ~3; elem->flags |= 0; } else if ((sp34 <= -0.5f) || (sp30 <= -0.5f) || (sp2C <= 0.7071f)) { diff --git a/src/code/z_fireobj.c b/src/code/z_fireobj.c index 379ebda1d..f9dfb635e 100644 --- a/src/code/z_fireobj.c +++ b/src/code/z_fireobj.c @@ -120,7 +120,7 @@ void FireObj_UpdateStateTransitions(GlobalContext* globalCtx, FireObj* fire) { } if ((fire->flags & 2) && (player->itemActionParam == PLAYER_AP_STICK)) { Math_Vec3f_Diff(&player->swordInfo[0].tip, &fire->position, &dist); - if (Math3D_LengthSquared(&dist) < 400.0f) { + if (Math3D_Vec3fMagnitudeSq(&dist) < 400.0f) { sp40 = true; } } diff --git a/src/code/z_sub_s.c b/src/code/z_sub_s.c index c36365d48..c0a5a3253 100644 --- a/src/code/z_sub_s.c +++ b/src/code/z_sub_s.c @@ -557,8 +557,8 @@ void SubS_ActorPathing_ComputePointInfo(GlobalContext* globalCtx, ActorPathing* diff.x = actorPath->curPoint.x - actorPath->worldPos->x; diff.y = actorPath->curPoint.y - actorPath->worldPos->y; diff.z = actorPath->curPoint.z - actorPath->worldPos->z; - actorPath->distSqToCurPointXZ = Math3D_XZLengthSquared(diff.x, diff.z); - actorPath->distSqToCurPoint = Math3D_LengthSquared(&diff); + actorPath->distSqToCurPointXZ = Math3D_Dist1DSq(diff.x, diff.z); + actorPath->distSqToCurPoint = Math3D_Vec3fMagnitudeSq(&diff); actorPath->rotToCurPoint.y = Math_FAtan2F(diff.z, diff.x); actorPath->rotToCurPoint.x = Math_FAtan2F(sqrtf(actorPath->distSqToCurPointXZ), -diff.y); actorPath->rotToCurPoint.z = 0; diff --git a/src/overlays/actors/ovl_Bg_Dblue_Waterfall/z_bg_dblue_waterfall.c b/src/overlays/actors/ovl_Bg_Dblue_Waterfall/z_bg_dblue_waterfall.c index cd3b8a9d6..aa9ee43db 100644 --- a/src/overlays/actors/ovl_Bg_Dblue_Waterfall/z_bg_dblue_waterfall.c +++ b/src/overlays/actors/ovl_Bg_Dblue_Waterfall/z_bg_dblue_waterfall.c @@ -61,7 +61,7 @@ Color_RGBA8 D_80B8539C = { 200, 255, 255, 255 }; Color_RGBA8 D_80B853A0 = { 200, 200, 200, 0 }; s32 func_80B83C80(Vec3f* arg0, Vec3f* arg1) { - f32 temp_f0 = Math3D_LengthSquared(arg0); + f32 temp_f0 = Math3D_Vec3fMagnitudeSq(arg0); f32 temp_f2; if (temp_f0 < 0.0000010000001f) { diff --git a/src/overlays/actors/ovl_Bg_Hakugin_Post/z_bg_hakugin_post.c b/src/overlays/actors/ovl_Bg_Hakugin_Post/z_bg_hakugin_post.c index 1ad88f3f8..cdf7acba9 100644 --- a/src/overlays/actors/ovl_Bg_Hakugin_Post/z_bg_hakugin_post.c +++ b/src/overlays/actors/ovl_Bg_Hakugin_Post/z_bg_hakugin_post.c @@ -484,12 +484,12 @@ void func_80A9BD24(BgHakuginPost* this, GlobalContext* globalCtx, BgHakuginPostU } if (unkStruct->unk_0000[i].unk_34 == 2) { - if (Math3D_XZLengthSquared(unkStruct->unk_0000[i].unk_14.x, unkStruct->unk_0000[i].unk_14.z) > + if (Math3D_Dist1DSq(unkStruct->unk_0000[i].unk_14.x, unkStruct->unk_0000[i].unk_14.z) > SQ(440.0f) + 0.02f) { unkStruct->unk_0000[i].unk_34 = 3; } } else if (unkStruct->unk_0000[i].unk_34 == 3) { - if (Math3D_XZLengthSquared(unkStruct->unk_0000[i].unk_14.x, unkStruct->unk_0000[i].unk_14.z) > 278784.03f) { + if (Math3D_Dist1DSq(unkStruct->unk_0000[i].unk_14.x, unkStruct->unk_0000[i].unk_14.z) > 278784.03f) { func_80A9B554(this, globalCtx, unkStruct, &unkStruct->unk_0000[i]); func_8019F128(NA_SE_EV_GLASSBROKEN_IMPACT); unkStruct->unk_0000[i].unk_34 = 4; @@ -540,7 +540,7 @@ void func_80A9C18C(BgHakuginPost* this, GlobalContext* globalCtx) { Camera* activeCam = GET_ACTIVE_CAM(globalCtx); s16 quake; - func_8013ECE0(Math3D_XZDistanceSquared(player->actor.world.pos.x, player->actor.world.pos.z, + func_8013ECE0(Math3D_Dist2DSq(player->actor.world.pos.x, player->actor.world.pos.z, this->dyna.actor.home.pos.x, this->dyna.actor.home.pos.z), 255, 20, 150); quake = Quake_Add(activeCam, 3); @@ -572,7 +572,7 @@ void func_80A9C228(BgHakuginPost* this, GlobalContext* globalCtx, BgHakuginPostU spB8.x = Math_SinS(temp_s0) * temp_f20 + spC8->unk_14.x; spB8.z = Math_CosS(temp_s0) * temp_f20 + spC8->unk_14.z; - if (Math3D_XZLengthSquared(spB8.x, spB8.z) < SQ(550.0f) + 0.03f) { + if (Math3D_Dist1DSq(spB8.x, spB8.z) < SQ(550.0f) + 0.03f) { spB8.x += this->dyna.actor.home.pos.x; spB8.y = spC8->unk_14.y + this->unk_16C + 20.0f; spB8.z += this->dyna.actor.home.pos.z; diff --git a/src/overlays/actors/ovl_En_Arrow/z_en_arrow.c b/src/overlays/actors/ovl_En_Arrow/z_en_arrow.c index d3286f545..36bbd0c9e 100644 --- a/src/overlays/actors/ovl_En_Arrow/z_en_arrow.c +++ b/src/overlays/actors/ovl_En_Arrow/z_en_arrow.c @@ -248,7 +248,7 @@ void func_8088A894(EnArrow* this, GlobalContext* globalCtx) { return; } - temp_f0 = Math3D_LengthSquared(&sp68); + temp_f0 = Math3D_Vec3fMagnitudeSq(&sp68); if (temp_f0 < 1.0f) { return; } diff --git a/src/overlays/actors/ovl_En_Bigslime/z_en_bigslime.c b/src/overlays/actors/ovl_En_Bigslime/z_en_bigslime.c index c0c1326a3..ad0e08f35 100644 --- a/src/overlays/actors/ovl_En_Bigslime/z_en_bigslime.c +++ b/src/overlays/actors/ovl_En_Bigslime/z_en_bigslime.c @@ -447,7 +447,7 @@ void EnBigslime_UpdateSurfaceNorm(EnBigslime* this) { vecTriEdge2.y = dynamicVtx12->n.ob[1] - dynamicVtx0->n.ob[1]; vecTriEdge2.z = dynamicVtx12->n.ob[2] - dynamicVtx0->n.ob[2]; - Math3D_CrossProduct(&vecTriEdge1, &vecTriEdge2, &vecTriNorm); + Math3D_Vec3f_Cross(&vecTriEdge1, &vecTriEdge2, &vecTriNorm); EnBigslime_Vec3fNormalize(&vecTriNorm); Math_Vec3f_Sum(&vtxNorm[sEnbigslimeTri[i].v[0]], &vecTriNorm, &vtxNorm[sEnbigslimeTri[i].v[0]]); diff --git a/src/overlays/actors/ovl_En_Bom_Chu/z_en_bom_chu.c b/src/overlays/actors/ovl_En_Bom_Chu/z_en_bom_chu.c index fc63795de..6a1976667 100644 --- a/src/overlays/actors/ovl_En_Bom_Chu/z_en_bom_chu.c +++ b/src/overlays/actors/ovl_En_Bom_Chu/z_en_bom_chu.c @@ -126,7 +126,7 @@ s32 EnBomChu_UpdateFloorPoly(EnBomChu* this, CollisionPoly* floorPoly, GlobalCon return false; } - Math3D_CrossProduct(&this->axisUp, &normal, &vec); + Math3D_Vec3f_Cross(&this->axisUp, &normal, &vec); magnitude = Math3D_Vec3fMagnitude(&vec); @@ -139,7 +139,7 @@ s32 EnBomChu_UpdateFloorPoly(EnBomChu* this, CollisionPoly* floorPoly, GlobalCon Matrix_InsertRotationAroundUnitVector_f(angle, &vec, MTXMODE_NEW); Matrix_MultiplyVector3fByState(&this->axisLeft, &vec); Math_Vec3f_Copy(&this->axisLeft, &vec); - Math3D_CrossProduct(&this->axisLeft, &normal, &this->axisForwards); + Math3D_Vec3f_Cross(&this->axisLeft, &normal, &this->axisForwards); magnitude = Math3D_Vec3fMagnitude(&this->axisForwards); if (magnitude < 0.001f) { diff --git a/src/overlays/actors/ovl_En_Butte/z_en_butte.c b/src/overlays/actors/ovl_En_Butte/z_en_butte.c index ea70a1480..f7d531013 100644 --- a/src/overlays/actors/ovl_En_Butte/z_en_butte.c +++ b/src/overlays/actors/ovl_En_Butte/z_en_butte.c @@ -229,7 +229,7 @@ void func_8091C794(EnButte* this, GlobalContext* globalCtx) { EnButteStruct* sp4C = &D_8091D324[this->unk_24E]; f32 distSq; Player* player = GET_PLAYER(globalCtx); - f32 distFromHomeSq = Math3D_XZDistanceSquared(this->actor.world.pos.x, this->actor.world.pos.z, + f32 distFromHomeSq = Math3D_Dist2DSq(this->actor.world.pos.x, this->actor.world.pos.z, this->actor.home.pos.x, this->actor.home.pos.z); f32 playSpeed; f32 sp38; @@ -285,7 +285,7 @@ void func_8091C794(EnButte* this, GlobalContext* globalCtx) { } if ((ENBUTTE_GET_1(&this->actor) == ENBUTTE_1) && (player->itemActionParam == 7) && (this->unk_252 <= 0) && - ((Math3D_XZDistanceSquared(player->actor.world.pos.x, player->actor.world.pos.z, this->actor.home.pos.x, + ((Math3D_Dist2DSq(player->actor.world.pos.x, player->actor.world.pos.z, this->actor.home.pos.x, this->actor.home.pos.z) < SQ(120.0f)) || (this->actor.xzDistToPlayer < 60.0f))) { func_8091CB68(this); @@ -350,13 +350,13 @@ void func_8091CBB4(EnButte* this, GlobalContext* globalCtx) { D_8091D3F0 = -D_8091D3F0; } - distSq = Math3D_XZDistanceSquared(this->actor.world.pos.x, this->actor.world.pos.z, this->actor.home.pos.x, + distSq = Math3D_Dist2DSq(this->actor.world.pos.x, this->actor.world.pos.z, this->actor.home.pos.x, this->actor.home.pos.z); if ((player->itemActionParam != 7) || !(fabsf(player->actor.speedXZ) < 1.8f) || (this->unk_252 > 0) || !(distSq < SQ(320.0f))) { func_8091C748(this); } else if ((distSq > SQ(240.0f)) && - (Math3D_XZDistanceSquared(player->swordInfo[0].tip.x, player->swordInfo[0].tip.z, + (Math3D_Dist2DSq(player->swordInfo[0].tip.x, player->swordInfo[0].tip.z, this->actor.world.pos.x, this->actor.world.pos.z) < SQ(60.0f))) { func_8091CF64(this); } diff --git a/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c b/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c index dd8d95c23..5f5f3093c 100644 --- a/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c +++ b/src/overlays/actors/ovl_En_Goroiwa/z_en_goroiwa.c @@ -199,7 +199,7 @@ f32 func_8093EB74(EnGoroiwa* this, GlobalContext* globalCtx) { for (i = 1; i < temp_s4; i++) { Math_Vec3f_Copy(&sp54, &sp48); Math_Vec3s_ToVec3f(&sp48, &this->unk_1D0[i]); - temp_f20 += Math3D_Distance(&sp54, &sp48); + temp_f20 += Math3D_Vec3f_DistXYZ(&sp54, &sp48); } return temp_f20; @@ -539,7 +539,7 @@ void func_8093FAA4(EnGoroiwa* this, GlobalContext* globalCtx) { if (this->unk_1E5 & 0x10) { sp7C = this->unk_1C0; } else { - temp = Math3D_Distance(&this->actor.world.pos, &this->actor.prevPos); + temp = Math3D_Vec3f_DistXYZ(&this->actor.world.pos, &this->actor.prevPos); tmp2 = temp / this->unk_1DC; this->unk_1C0 = tmp2; sp7C = this->unk_1C0; @@ -547,12 +547,12 @@ void func_8093FAA4(EnGoroiwa* this, GlobalContext* globalCtx) { sp7C *= this->unk_1C4; if (!(this->unk_1E5 & 0x10)) { - if (Math3D_LengthSquared(&this->actor.velocity) > 0.1f) { + if (Math3D_Vec3fMagnitudeSq(&this->actor.velocity) > 0.1f) { Math_Vec3f_Copy(&this->unk_1A8, &this->actor.velocity); } } - Math3D_CrossProduct(&D_80942E60, &this->unk_1A8, &sp70); + Math3D_Vec3f_Cross(&D_80942E60, &this->unk_1A8, &sp70); if (func_8093EAD4(&sp64, &sp70)) { this->unk_1B4 = sp64; @@ -1360,7 +1360,7 @@ void func_8094220C(EnGoroiwa* this, GlobalContext* globalCtx) { temp_f20 = this->unk_1DC * 0.9f; if (spB8.y > 0.0f) { - if (Math3D_AngleBetweenVectors(&D_80942E60, &spB8, &spAC)) { + if (Math3D_CosOut(&D_80942E60, &spB8, &spAC)) { phi_f12 = 1.0f; } else { phi_f12 = 1.0f - SQ(spAC); diff --git a/src/overlays/actors/ovl_En_Horse/z_en_horse.c b/src/overlays/actors/ovl_En_Horse/z_en_horse.c index 440ac3578..0de8e5e24 100644 --- a/src/overlays/actors/ovl_En_Horse/z_en_horse.c +++ b/src/overlays/actors/ovl_En_Horse/z_en_horse.c @@ -364,7 +364,7 @@ void func_8087B7C0(EnHorse* this, GlobalContext* globalCtx, Path* path) { for (i = sp68; i < sp60; i++) { Math_Vec3s_ToVec3f(&sp50, &spA0[i]); - temp_f0 = Math3D_Distance(&this->actor.world.pos, &sp50); + temp_f0 = Math3D_Vec3f_DistXYZ(&this->actor.world.pos, &sp50); if (temp_f0 < sp64) { sp64 = temp_f0; sp68 = i; @@ -537,7 +537,7 @@ s32 func_8087C38C(GlobalContext* globalCtx, EnHorse* this, Vec3f* arg2) { return false; } - eyeDist = Math3D_Distance(arg2, &globalCtx->view.eye); + eyeDist = Math3D_Vec3f_DistXYZ(arg2, &globalCtx->view.eye); return func_8087C2B8(globalCtx, this, &sp24, sp20) || (eyeDist < 100.0f); } @@ -588,7 +588,7 @@ s32 EnHorse_Spawn(EnHorse* this, GlobalContext* globalCtx) { spawnPos.x = pathPoints[i].x; spawnPos.y = pathPoints[i].y; spawnPos.z = pathPoints[i].z; - dist = Math3D_Distance(&player->actor.world.pos, &spawnPos); + dist = Math3D_Vec3f_DistXYZ(&player->actor.world.pos, &spawnPos); if ((minDist < dist) || func_8087C38C(globalCtx, this, &spawnPos)) { continue; @@ -614,7 +614,7 @@ s32 EnHorse_Spawn(EnHorse* this, GlobalContext* globalCtx) { spawnPos.x = pathPoints[i].x; spawnPos.y = pathPoints[i].y; spawnPos.z = pathPoints[i].z; - dist = Math3D_Distance(&player->actor.world.pos, &spawnPos); + dist = Math3D_Vec3f_DistXYZ(&player->actor.world.pos, &spawnPos); if (minDist < dist) { continue; @@ -2484,7 +2484,7 @@ void EnHorse_CsMoveToPoint(EnHorse* this, GlobalContext* globalCtx, CsCmdActorAc endPos.y = action->endPos.y; endPos.z = action->endPos.z; - if (Math3D_Distance(&endPos, &this->actor.world.pos) > 8.0f) { + if (Math3D_Vec3f_DistXYZ(&endPos, &this->actor.world.pos) > 8.0f) { EnHorse_RotateToPoint(this, globalCtx, &endPos, 0x320); this->actor.speedXZ = 8.0f; this->skin.skelAnime.playSpeed = this->actor.speedXZ * 0.3f; @@ -2665,7 +2665,7 @@ void EnHorse_CsWarpMoveToPoint(EnHorse* this, GlobalContext* globalCtx, CsCmdAct endPos.y = action->endPos.y; endPos.z = action->endPos.z; - if (Math3D_Distance(&endPos, &this->actor.world.pos) > 8.0f) { + if (Math3D_Vec3f_DistXYZ(&endPos, &this->actor.world.pos) > 8.0f) { EnHorse_RotateToPoint(this, globalCtx, &endPos, 0x320); this->actor.speedXZ = 8.0f; this->skin.skelAnime.playSpeed = this->actor.speedXZ * 0.3f; @@ -2801,7 +2801,7 @@ s32 EnHorse_UpdateHbaRaceInfo(EnHorse* this, GlobalContext* globalCtx, RaceInfo* func_8017B7F8(&pos, raceInfo->waypoints[this->curRaceWaypoint].angle, &px, &pz, &d); if ((this->curRaceWaypoint >= (raceInfo->numWaypoints - 1)) && - (Math3D_Distance(&pos, &this->actor.world.pos) < DREG(8))) { + (Math3D_Vec3f_DistXYZ(&pos, &this->actor.world.pos) < DREG(8))) { this->hbaFlags |= 2; } @@ -2971,9 +2971,9 @@ void EnHorse_FleePlayer(EnHorse* this, GlobalContext* globalCtx) { } } - distToHome = Math3D_Distance(&this->actor.home.pos, &this->actor.world.pos); - playerDistToHome = Math3D_Distance(&player->actor.world.pos, &this->actor.home.pos); - distToPlayer = Math3D_Distance(&player->actor.world.pos, &this->actor.world.pos); + distToHome = Math3D_Vec3f_DistXYZ(&this->actor.home.pos, &this->actor.world.pos); + playerDistToHome = Math3D_Vec3f_DistXYZ(&player->actor.world.pos, &this->actor.home.pos); + distToPlayer = Math3D_Vec3f_DistXYZ(&player->actor.world.pos, &this->actor.world.pos); if (playerDistToHome > 300.0f) { if (distToHome > 150.0f) { @@ -3330,7 +3330,7 @@ void func_808848C8(EnHorse* this, GlobalContext* globalCtx) { func_800F415C(&this->actor, &sp24, 2000); this->skin.skelAnime.playSpeed = this->actor.speedXZ * 0.75f; SkelAnime_Update(&this->skin.skelAnime); - if (Math3D_Distance(&sp24, &this->actor.world.pos) < 30.0f) { + if (Math3D_Vec3f_DistXYZ(&sp24, &this->actor.world.pos) < 30.0f) { this->stateFlags &= ~ENHORSE_UNRIDEABLE; EnHorse_StartIdleRidable(this); } @@ -3425,7 +3425,7 @@ void func_80884E0C(EnHorse* this, GlobalContext* globalCtx) { this->actor.world.pos.x = this->unk_570.x; this->actor.world.pos.z = this->unk_570.z; - this->unk_56C = Math3D_Distance(&this->actor.world.pos, &this->actor.prevPos); + this->unk_56C = Math3D_Vec3f_DistXYZ(&this->actor.world.pos, &this->actor.prevPos); if (((this->unk_550 == 5) || (this->unk_550 == 7)) && (Player_GetMask(globalCtx) != PLAYER_MASK_CIRCUS_LEADER)) { this->rider->unk488 = 7; } else { diff --git a/src/overlays/actors/ovl_En_Invadepoh/z_en_invadepoh.c b/src/overlays/actors/ovl_En_Invadepoh/z_en_invadepoh.c index 8d2f416a7..e821b912a 100644 --- a/src/overlays/actors/ovl_En_Invadepoh/z_en_invadepoh.c +++ b/src/overlays/actors/ovl_En_Invadepoh/z_en_invadepoh.c @@ -790,7 +790,7 @@ f32 EnInvadepoh_GetTotalPathLength(EnInvadepoh* this) { for (i = 1; i < temp_s4; i++) { Math_Vec3f_Copy(&sp54, &pathPointF); Math_Vec3s_ToVec3f(&pathPointF, pathPoint); - distance = Math3D_Distance(&sp54, &pathPointF); + distance = Math3D_Vec3f_DistXYZ(&sp54, &pathPointF); pathPoint++; totalDistance += distance; } @@ -841,7 +841,7 @@ s32 func_80B440B8(EnInvadepoh* this, f32 arg1, f32 arg2) { } temp_f12_2 = (sp2C * sp38) + (sp30 * sp34); - new_var = Math3D_XZLength(sp40, sp3C); + new_var = Math3D_Dist1D(sp40, sp3C); if ((temp_f12_2 < 0.0f) || (new_var < temp_f12_2)) { return false; @@ -913,7 +913,7 @@ void func_80B443A0(EnInvadepoh* this) { for (i = 1; i < temp_s5; i++, phi_s1++, phi_s0++) { Math_Vec3f_Copy(&sp70, &sp64); Math_Vec3s_ToVec3f(&sp64, phi_s1); - phi_f20 += Math3D_Distance(&sp70, &sp64); + phi_f20 += Math3D_Vec3f_DistXYZ(&sp70, &sp64); *phi_s0 = phi_f20 * pathTotalDistInv; if (*phi_s0 < 0.0f) { *phi_s0 = 0.0f; @@ -1153,7 +1153,7 @@ s32 func_80B44C80(EnInvadepoh* this, GlobalContext* globalCtx) { temp_f0_2 = temp_f2 - this->actor.world.pos.z; if (this->actor.speedXZ > 0.0f) { - if (Math3D_AngleBetweenVectors(&sp6C, &sp60, &sp44) != 0) { + if (Math3D_CosOut(&sp6C, &sp60, &sp44) != 0) { sp40 = 1; } else if (sp44 <= 0.0f) { sp40 = 1; @@ -1231,7 +1231,7 @@ void func_80B45080(void) { s32 func_80B450C0(f32* x1, f32* z1, f32 x2, f32 z2, f32 speed) { f32 deltaX = x2 - *x1; f32 deltaZ = z2 - *z1; - f32 temp_f0 = Math3D_XZLength(deltaX, deltaZ); + f32 temp_f0 = Math3D_Dist1D(deltaX, deltaZ); if (speed < temp_f0) { f32 temp_f2 = speed / temp_f0; diff --git a/src/overlays/actors/ovl_En_Ishi/z_en_ishi.c b/src/overlays/actors/ovl_En_Ishi/z_en_ishi.c index ac42d0c7a..68d19d1bd 100644 --- a/src/overlays/actors/ovl_En_Ishi/z_en_ishi.c +++ b/src/overlays/actors/ovl_En_Ishi/z_en_ishi.c @@ -314,7 +314,7 @@ void func_8095DFF0(EnIshi* this, GlobalContext* globalCtx) { Matrix_InsertXRotation_s(this->actor.shape.rot.x, MTXMODE_APPLY); Matrix_InsertZRotation_s(this->actor.shape.rot.z, MTXMODE_APPLY); Matrix_GetStateTranslationAndScaledY(1.0f, &sp30); - sp2C = Math3D_Parallel(&sp30, &D_8095F778); + sp2C = Math3D_Cos(&sp30, &D_8095F778); if (sp2C < 0.707f) { temp_v1_2 = Math_FAtan2F(sp30.z, sp30.x) - sp3C->world.rot.y; if (ABS_ALT(temp_v1_2) > 0x4000) { diff --git a/src/overlays/actors/ovl_En_Kusa2/z_en_kusa2.c b/src/overlays/actors/ovl_En_Kusa2/z_en_kusa2.c index 1b8d1ccbc..f68cfa9dd 100644 --- a/src/overlays/actors/ovl_En_Kusa2/z_en_kusa2.c +++ b/src/overlays/actors/ovl_En_Kusa2/z_en_kusa2.c @@ -511,7 +511,7 @@ void func_80A5C410(EnKusa2UnkBssStruct* arg0, EnKusa2UnkBssSubStruct2* arg1, Vec s32 phi_s2 = true; Math_Vec3f_Diff(&arg1->unk_04, &s->unk_00, &sp98); - temp_f0 = Math3D_LengthSquared(&sp98); + temp_f0 = Math3D_Vec3fMagnitudeSq(&sp98); phi_v0 = false; if (temp_f0 <= s->unk_4C) { @@ -917,7 +917,7 @@ void func_80A5D62C(EnKusa2* this, GlobalContext* globalCtx) { if (this->unk_1BE != 0) { func_80A5B490(this, globalCtx); func_80A5D754(this); - } else if (Math3D_XZLengthSquared(this->actor.projectedPos.x, this->actor.projectedPos.z) < SQ(1600.0f)) { + } else if (Math3D_Dist1DSq(this->actor.projectedPos.x, this->actor.projectedPos.z) < SQ(1600.0f)) { func_80A5B160(this, globalCtx); func_80A5D6B0(this); } @@ -932,7 +932,7 @@ void func_80A5D6C4(EnKusa2* this, GlobalContext* globalCtx) { if (this->unk_1BE != 0) { func_80A5B490(this, globalCtx); func_80A5D754(this); - } else if (Math3D_XZLengthSquared(this->actor.projectedPos.x, this->actor.projectedPos.z) > SQ(1750.0f)) { + } else if (Math3D_Dist1DSq(this->actor.projectedPos.x, this->actor.projectedPos.z) > SQ(1750.0f)) { func_80A5B334(this, globalCtx); func_80A5D618(this); } diff --git a/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.c b/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.c index 60de87422..45b657bbd 100644 --- a/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.c +++ b/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.c @@ -151,7 +151,7 @@ s32 func_80A68910(EnMushi2* this, GlobalContext* globalCtx) { params = OBJBEAN_GET_C000(bean); if (((params == ENOBJBEAN_GET_C000_1) || (params == ENOBJBEAN_GET_C000_2)) && (bean->room == this->actor.room)) { - temp_f0 = Math3D_XZDistanceSquared(this->actor.world.pos.x, this->actor.world.pos.z, bean->world.pos.x, + temp_f0 = Math3D_Dist2DSq(this->actor.world.pos.x, this->actor.world.pos.z, bean->world.pos.x, bean->world.pos.z); temp_f2 = bean->world.pos.y - this->actor.world.pos.y; if ((temp_f0 < minDistSq) && (temp_f2 < 100.0f) && (temp_f2 > -50.0f)) { @@ -234,7 +234,7 @@ s32 func_80A68CE4(Vec3f* arg0, Vec3f* arg1, f32 arg2) { f32 temp_f2; Math_Vec3f_Diff(arg1, arg0, &sp34); - temp_f0 = Math3D_LengthSquared(&sp34); + temp_f0 = Math3D_Vec3fMagnitudeSq(&sp34); temp_f2 = arg2 + 0.01f; if (temp_f0 <= SQ(temp_f2)) { Math_Vec3f_Copy(arg0, arg1); @@ -266,7 +266,7 @@ s32 func_80A68DD4(EnMushi2* this, GlobalContext* globalCtx) { player = GET_PLAYER(globalCtx); sp2E = BINANG_ROT180(this->actor.yawTowardsPlayer); sp24 = Math_SinS(sp2E); - if (Math3D_XZDistanceSquared((sp24 * 16.0f) + player->actor.world.pos.x, + if (Math3D_Dist2DSq((sp24 * 16.0f) + player->actor.world.pos.x, (Math_CosS(sp2E) * 16.0f) + player->actor.world.pos.z, this->actor.world.pos.x, this->actor.world.pos.z) < SQ(20.0f)) { return true; @@ -408,8 +408,8 @@ s32 func_80A691EC(EnMushi2* this, CollisionPoly* floorPoly, f32 arg2) { sp30 = 1; } - Math3D_CrossProduct(&this->unk_310, &sp4C, &sp40); - Math3D_CrossProduct(&sp4C, &sp40, &sp64); + Math3D_Vec3f_Cross(&this->unk_310, &sp4C, &sp40); + Math3D_Vec3f_Cross(&sp4C, &sp40, &sp64); if (func_80A68C5C(&sp64, &sp58) && func_80A68C5C(&sp40, &sp34)) { Math_Vec3f_Copy(&this->unk_31C, &sp4C); @@ -610,7 +610,7 @@ void func_80A69ADC(Actor* thisx) { this->unk_328.x, this->unk_328.y, this->unk_328.z, func_80A69AA8(this->unk_328.x, this->unk_328.y, this->unk_328.z, &this->actor.world.pos), &bean->dyna.actor.world.pos); - sp3C = Math3D_XZLength(sp44, sp40); + sp3C = Math3D_Dist1D(sp44, sp40); if (fabsf(sp3C) > 0.1f) { this->unk_360 = (Rand_ZeroOne() * 3000.0f * (this->unk_358 - 1.0f)) + (((sp40 / sp3C) - 1.0f) * -1500.0f); @@ -656,7 +656,7 @@ void func_80A69D3C(EnMushi2* this) { this->unk_328.x, this->unk_328.y, this->unk_328.z, func_80A69AA8(this->unk_328.x, this->unk_328.y, this->unk_328.z, &this->actor.world.pos), &this->unk_34C->dyna.actor.world.pos); - sp38 = Math3D_XZLengthSquared(sp40, sp3C); + sp38 = Math3D_Dist1DSq(sp40, sp3C); if (fabsf(sp38) > 0.010000001f) { s16 temp_v0 = Math_FAtan2F(sp3C, sp40); diff --git a/src/overlays/actors/ovl_En_Ot/z_en_ot.c b/src/overlays/actors/ovl_En_Ot/z_en_ot.c index 7573947e6..345bdc27b 100644 --- a/src/overlays/actors/ovl_En_Ot/z_en_ot.c +++ b/src/overlays/actors/ovl_En_Ot/z_en_ot.c @@ -856,7 +856,7 @@ s32 EnOt_ActorPathing_UpdateActorInfo(GlobalContext* globalCtx, ActorPathing* ac sp44.y = actorPath->curPoint.y - actorPath->prevPoint.y; sp44.z = actorPath->curPoint.z - actorPath->prevPoint.z; - temp = Math3D_Parallel(&sp50, &sp44); + temp = Math3D_Cos(&sp50, &sp44); if ((actorPath->distSqToCurPointXZ < SQ(thisx->speedXZ)) || (temp <= 0.0f)) { ret = true; } else { diff --git a/src/overlays/actors/ovl_En_Pametfrog/z_en_pametfrog.c b/src/overlays/actors/ovl_En_Pametfrog/z_en_pametfrog.c index 542238a17..54b6c538b 100644 --- a/src/overlays/actors/ovl_En_Pametfrog/z_en_pametfrog.c +++ b/src/overlays/actors/ovl_En_Pametfrog/z_en_pametfrog.c @@ -313,12 +313,12 @@ s32 func_8086A2CC(EnPametfrog* this, CollisionPoly* floorPoly) { return false; } - Math3D_CrossProduct(&this->unk_2DC, &floorNorm, &vec2); + Math3D_Vec3f_Cross(&this->unk_2DC, &floorNorm, &vec2); EnPametfrog_Vec3fNormalize(&vec2); Matrix_InsertRotationAroundUnitVector_f(rotation, &vec2, MTXMODE_NEW); Matrix_MultiplyVector3fByState(&this->unk_2E8, &vec2); Math_Vec3f_Copy(&this->unk_2E8, &vec2); - Math3D_CrossProduct(&this->unk_2E8, &floorNorm, &this->unk_2D0); + Math3D_Vec3f_Cross(&this->unk_2E8, &floorNorm, &this->unk_2D0); EnPametfrog_Vec3fNormalize(&this->unk_2D0); Math_Vec3f_Copy(&this->unk_2DC, &floorNorm); return true; @@ -570,9 +570,9 @@ void EnPametfrog_SetupWallCrawl(EnPametfrog* this) { this->unk_2DC.x = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.x); this->unk_2DC.y = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.y); this->unk_2DC.z = COLPOLY_GET_NORMAL(this->actor.wallPoly->normal.z); - Math3D_CrossProduct(&this->unk_2DC, &this->unk_2D0, &this->unk_2E8); + Math3D_Vec3f_Cross(&this->unk_2DC, &this->unk_2D0, &this->unk_2E8); EnPametfrog_Vec3fNormalize(&this->unk_2E8); - Math3D_CrossProduct(&this->unk_2E8, &this->unk_2DC, &this->unk_2D0); + Math3D_Vec3f_Cross(&this->unk_2E8, &this->unk_2DC, &this->unk_2D0); EnPametfrog_Vec3fNormalize(&this->unk_2D0); func_8086A238(this); this->actor.floorPoly = this->actor.wallPoly; @@ -686,7 +686,7 @@ void EnPametfrog_WallPause(EnPametfrog* this, GlobalContext* globalCtx) { Matrix_InsertRotationAroundUnitVector_f(this->wallRotation, &this->unk_2DC, MTXMODE_NEW); Matrix_MultiplyVector3fByState(&this->unk_2D0, &vec); Math_Vec3f_Copy(&this->unk_2D0, &vec); - Math3D_CrossProduct(&this->unk_2DC, &this->unk_2D0, &this->unk_2E8); + Math3D_Vec3f_Cross(&this->unk_2DC, &this->unk_2D0, &this->unk_2E8); func_8086A238(this); if (((globalCtx->gameplayFrames % 60) == 0) && (Rand_ZeroOne() < 0.8f)) { Actor_PlaySfxAtPos(&this->actor, NA_SE_EN_FROG_REAL); diff --git a/src/overlays/actors/ovl_En_Sw/z_en_sw.c b/src/overlays/actors/ovl_En_Sw/z_en_sw.c index f0d1a3aa7..47784f413 100644 --- a/src/overlays/actors/ovl_En_Sw/z_en_sw.c +++ b/src/overlays/actors/ovl_En_Sw/z_en_sw.c @@ -280,7 +280,7 @@ void func_808D90F0(EnSw* this, s32 arg1, s16 arg2) { Matrix_InsertRotationAroundUnitVector_f(BINANG_TO_RAD(temp), &this->unk_368, MTXMODE_NEW); Matrix_MultiplyVector3fByState(&this->unk_350, &sp2C); Math_Vec3f_Copy(&this->unk_350, &sp2C); - Math3D_CrossProduct(&this->unk_368, &this->unk_350, &this->unk_35C); + Math3D_Vec3f_Cross(&this->unk_368, &this->unk_350, &this->unk_35C); } s32 func_808D91C4(EnSw* this, CollisionPoly* arg1) { @@ -309,7 +309,7 @@ s32 func_808D91C4(EnSw* this, CollisionPoly* arg1) { return false; } - Math3D_CrossProduct(&this->unk_368, &sp38, &sp2C); + Math3D_Vec3f_Cross(&this->unk_368, &sp38, &sp2C); temp_f0 = Math3D_Vec3fMagnitude(&sp2C); if (temp_f0 < 0.001f) { return false; @@ -319,7 +319,7 @@ s32 func_808D91C4(EnSw* this, CollisionPoly* arg1) { Matrix_InsertRotationAroundUnitVector_f(sp4C, &sp2C, MTXMODE_NEW); Matrix_MultiplyVector3fByState(&this->unk_35C, &sp2C); Math_Vec3f_Copy(&this->unk_35C, &sp2C); - Math3D_CrossProduct(&this->unk_35C, &sp38, &this->unk_350); + Math3D_Vec3f_Cross(&this->unk_35C, &sp38, &this->unk_350); temp_f0 = Math3D_Vec3fMagnitude(&this->unk_350); if (temp_f0 < 0.001f) { diff --git a/src/overlays/actors/ovl_Mir_Ray/z_mir_ray.c b/src/overlays/actors/ovl_Mir_Ray/z_mir_ray.c index 18aafc07a..1f62b6447 100644 --- a/src/overlays/actors/ovl_Mir_Ray/z_mir_ray.c +++ b/src/overlays/actors/ovl_Mir_Ray/z_mir_ray.c @@ -704,7 +704,7 @@ s32 MirRay_CheckInFrustum(Vec3f* vecA, Vec3f* vecB, f32 pointx, f32 pointy, f32 sp50.y = pointy - vecA->y; sp50.z = pointz - vecA->z; - if (Math3D_Parallel(&sp5C, &sp50) < 0.0f) { + if (Math3D_Cos(&sp5C, &sp50) < 0.0f) { return false; } @@ -712,7 +712,7 @@ s32 MirRay_CheckInFrustum(Vec3f* vecA, Vec3f* vecB, f32 pointx, f32 pointy, f32 sp44.y = pointy - vecB->y; sp44.z = pointz - vecB->z; - if (Math3D_Parallel(&sp5C, &sp44) > 0.0f) { + if (Math3D_Cos(&sp5C, &sp44) > 0.0f) { return false; } return true; diff --git a/src/overlays/actors/ovl_Obj_Iceblock/z_obj_iceblock.c b/src/overlays/actors/ovl_Obj_Iceblock/z_obj_iceblock.c index 582c3a299..c0ecf96f0 100644 --- a/src/overlays/actors/ovl_Obj_Iceblock/z_obj_iceblock.c +++ b/src/overlays/actors/ovl_Obj_Iceblock/z_obj_iceblock.c @@ -437,7 +437,7 @@ s32 func_80A24118(ObjIceblock* this, GlobalContext* globalCtx, f32 arg2, Vec3f* spF0 = Math_SinS(sp9E); spEC = Math_CosS(sp9E); - temp_f20 = Math3D_Distance(&this->dyna.actor.world.pos, &this->dyna.actor.prevPos) + + temp_f20 = Math3D_Vec3f_DistXYZ(&this->dyna.actor.world.pos, &this->dyna.actor.prevPos) + (300.0f * this->dyna.actor.scale.z) + arg2; temp_f24 = temp_f20 * spF0; temp_f26 = temp_f20 * spEC; @@ -512,7 +512,7 @@ s32 func_80A243E0(ObjIceblock* this, GlobalContext* globalCtx, Vec3f* arg0) { sp100 = Math_SinS(temp_s6); spFC = Math_CosS(temp_s6); - temp_f0 = ((Math3D_Distance(&this->dyna.actor.world.pos, &this->dyna.actor.prevPos) + + temp_f0 = ((Math3D_Vec3f_DistXYZ(&this->dyna.actor.world.pos, &this->dyna.actor.prevPos) + (300.0f * this->dyna.actor.scale.z)) + 2.0f); temp_f12 = -temp_f0; diff --git a/src/overlays/actors/ovl_Obj_Skateblock/z_obj_skateblock.c b/src/overlays/actors/ovl_Obj_Skateblock/z_obj_skateblock.c index 1253747e4..e78e8f103 100644 --- a/src/overlays/actors/ovl_Obj_Skateblock/z_obj_skateblock.c +++ b/src/overlays/actors/ovl_Obj_Skateblock/z_obj_skateblock.c @@ -234,7 +234,7 @@ s32 func_80A216D4(ObjSkateblock* this, GlobalContext* globalCtx, f32 arg2, Vec3f spE8 = Math_SinS(sp96); spE4 = Math_CosS(sp96); - temp_f2 = Math3D_Distance(&this->dyna.actor.world.pos, &this->dyna.actor.prevPos) + + temp_f2 = Math3D_Vec3f_DistXYZ(&this->dyna.actor.world.pos, &this->dyna.actor.prevPos) + (300.0f * this->dyna.actor.scale.z) + arg2; temp_f24 = temp_f2 * spE8; temp_f26 = temp_f2 * spE4; @@ -307,7 +307,7 @@ s32 func_80A21990(ObjSkateblock* this, GlobalContext* globalCtx, Vec3f* arg2) { temp_f26 = Math_CosS(phi_s6); temp_f12 = - (300.0f * this->dyna.actor.scale.z + Math3D_Distance(&this->dyna.actor.world.pos, &this->dyna.actor.prevPos)) + + (300.0f * this->dyna.actor.scale.z + Math3D_Vec3f_DistXYZ(&this->dyna.actor.world.pos, &this->dyna.actor.prevPos)) + 2.0f; temp_f28 = -temp_f12 * sp100; temp_f30 = -temp_f12 * temp_f26; diff --git a/src/overlays/actors/ovl_Obj_Snowball/z_obj_snowball.c b/src/overlays/actors/ovl_Obj_Snowball/z_obj_snowball.c index 15a63746b..ed8876246 100644 --- a/src/overlays/actors/ovl_Obj_Snowball/z_obj_snowball.c +++ b/src/overlays/actors/ovl_Obj_Snowball/z_obj_snowball.c @@ -692,7 +692,7 @@ void func_80B047C0(ObjSnowball* this, GlobalContext* globalCtx) { sp84 = this->unk_20C * 60.0f * 0.9f; if (sp88.y > 0.0f) { - if (Math3D_AngleBetweenVectors(&D_80B04FD8, &sp88, &sp7C)) { + if (Math3D_CosOut(&D_80B04FD8, &sp88, &sp7C)) { phi_f2 = 1.0f; } else { phi_f2 = 1.0f - SQ(sp7C); diff --git a/src/overlays/actors/ovl_Obj_Spidertent/z_obj_spidertent.c b/src/overlays/actors/ovl_Obj_Spidertent/z_obj_spidertent.c index 1bc0f57b2..39c834577 100644 --- a/src/overlays/actors/ovl_Obj_Spidertent/z_obj_spidertent.c +++ b/src/overlays/actors/ovl_Obj_Spidertent/z_obj_spidertent.c @@ -328,7 +328,7 @@ static InitChainEntry sInitChain[] = { }; s32 func_80B2FB10(Vec3f* arg0, Vec3f* arg1) { - f32 temp_f0 = Math3D_LengthSquared(arg0); + f32 temp_f0 = Math3D_Vec3fMagnitudeSq(arg0); f32 temp_f2; if (temp_f0 < 9.999999e-9f) { @@ -396,7 +396,7 @@ s32 func_80B2FC98(TriNorm* triNorm, Vec3f* arg1) { sp78.y = vtx2->y - arg1->y; sp78.z = vtx2->z - arg1->z; - Math3D_CrossProduct(&sp84, &sp78, &sp4C[i]); + Math3D_Vec3f_Cross(&sp84, &sp78, &sp4C[i]); vtx2 = vtx; } @@ -416,7 +416,7 @@ s32 func_80B2FC98(TriNorm* triNorm, Vec3f* arg1) { sp78.y = 0.0f; sp78.z = vtx2->z - arg1->z; - Math3D_CrossProduct(&sp84, &sp78, &sp4C[i]); + Math3D_Vec3f_Cross(&sp84, &sp78, &sp4C[i]); vtx2 = vtx; } @@ -436,7 +436,7 @@ s32 func_80B2FC98(TriNorm* triNorm, Vec3f* arg1) { sp78.y = vtx2->y - arg1->y; sp78.z = 0.0f; - Math3D_CrossProduct(&sp84, &sp78, &sp4C[i]); + Math3D_Vec3f_Cross(&sp84, &sp78, &sp4C[i]); vtx2 = vtx; } @@ -467,9 +467,9 @@ void func_80B300F4(ObjSpidertent* thisx, GlobalContext* globalCtx, TriNorm* triN spAC.z = triNorm->plane.normal.z; if (triNorm->plane.normal.y < 0.5f) { - Math3D_CrossProduct(&spAC, &D_80B3140C, &sp88); + Math3D_Vec3f_Cross(&spAC, &D_80B3140C, &sp88); } else { - Math3D_CrossProduct(&spAC, &D_80B31400, &sp88); + Math3D_Vec3f_Cross(&spAC, &D_80B31400, &sp88); } if (func_80B2FB10(&sp88, &spA0)) { diff --git a/src/overlays/actors/ovl_Obj_Spinyroll/z_obj_spinyroll.c b/src/overlays/actors/ovl_Obj_Spinyroll/z_obj_spinyroll.c index 20f4a1c50..bcf8609e3 100644 --- a/src/overlays/actors/ovl_Obj_Spinyroll/z_obj_spinyroll.c +++ b/src/overlays/actors/ovl_Obj_Spinyroll/z_obj_spinyroll.c @@ -254,7 +254,7 @@ s32 func_80A1DEB8(ObjSpinyroll* this) { Math_Vec3f_Diff(&this->unk_4AC[sp30], &this->dyna.actor.world.pos, &sp24); - return Math3D_LengthSquared(&sp24) < (SQ(this->dyna.actor.speedXZ) + 0.05f); + return Math3D_Vec3fMagnitudeSq(&sp24) < (SQ(this->dyna.actor.speedXZ) + 0.05f); } void func_80A1DFA0(ObjSpinyroll* this) { diff --git a/src/overlays/actors/ovl_Obj_Switch/z_obj_switch.c b/src/overlays/actors/ovl_Obj_Switch/z_obj_switch.c index 7bea97826..992ede4b6 100644 --- a/src/overlays/actors/ovl_Obj_Switch/z_obj_switch.c +++ b/src/overlays/actors/ovl_Obj_Switch/z_obj_switch.c @@ -648,7 +648,7 @@ s32 ObjSwitch_IsEyeSwitchHit(ObjSwitch* this) { Matrix_InsertZRotation_s(actor->shape.rot.z, MTXMODE_APPLY); Matrix_GetStateTranslationAndScaledZ(1.0f, &sp20); Matrix_StatePop(); - if ((Math3D_Parallel(&sp2C, &sp20) < COS_OF_5_PI_DIV_8)) { + if ((Math3D_Cos(&sp2C, &sp20) < COS_OF_5_PI_DIV_8)) { return true; } } diff --git a/src/overlays/actors/ovl_Obj_Vspinyroll/z_obj_vspinyroll.c b/src/overlays/actors/ovl_Obj_Vspinyroll/z_obj_vspinyroll.c index 9c5d22bac..ba7e94024 100644 --- a/src/overlays/actors/ovl_Obj_Vspinyroll/z_obj_vspinyroll.c +++ b/src/overlays/actors/ovl_Obj_Vspinyroll/z_obj_vspinyroll.c @@ -130,7 +130,7 @@ s32 func_80A3C700(ObjVspinyroll* this) { this->dyna.actor.world.pos.z += this->dyna.actor.speedXZ * this->unk_3B4.z; Math_Vec3f_Diff(&this->unk_39C[sp30], &this->dyna.actor.world.pos, &sp24); - return Math3D_LengthSquared(&sp24) < (SQ(this->dyna.actor.speedXZ) + 0.05f); + return Math3D_Vec3fMagnitudeSq(&sp24) < (SQ(this->dyna.actor.speedXZ) + 0.05f); } void func_80A3C7E8(ObjVspinyroll* this) { diff --git a/tools/actorfixer.py b/tools/actorfixer.py index 703d6d10e..b9d3093ab 100755 --- a/tools/actorfixer.py +++ b/tools/actorfixer.py @@ -384,6 +384,20 @@ animdict = { "func_8017FA34": "Math3D_XYInSphere", "func_8017FAA8": "Math3D_YZInSphere", "func_8017D2FC": "Math3D_LineSegVsPlane", + + "Math3D_CrossProduct": "Math3D_Vec3f_Cross", + "Math3D_Parallel": "Math3D_Cos", + "Math3D_AngleBetweenVectors": "Math3D_CosOut", + "func_80179A44": "Math3D_LineClosestToPoint", + + "Math3D_XZLengthSquared": "Math3D_Dist1DSq", + "Math3D_XZLength": "Math3D_Dist1D", + "Math3D_XZDistanceSquared": "Math3D_Dist2DSq", + "Math3D_XZDistance": "Math3D_Dist2D", + "Math3D_LengthSquared": "Math3D_Vec3fMagnitudeSq", + "Math3D_Distance": "Math3D_Vec3f_DistXYZ", + "Math3D_DistanceS": "Math3D_DistXYZ16toF", + "func_800DFB14": "Camera_ChangeDataIdx", "func_800DFC68": "Camera_GetInputDirYaw", "func_800DFCB4": "Camera_GetCamDirPitch", diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index ec16f5d28..4e5d54c17 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -3258,33 +3258,33 @@ 0x801795F0:("Math3D_Normalize",), 0x80179678:("Math3D_PlaneVsLineSegClosestPoint",), 0x80179798:("func_80179798",), - 0x80179A44:("func_80179A44",), + 0x80179A44:("Math3D_LineClosestToPoint",), 0x80179B34:("func_80179B34",), 0x80179B94:("func_80179B94",), 0x80179D74:("func_80179D74",), 0x80179DF0:("Math3D_ScaleAndAdd",), 0x80179E3C:("Math3D_Lerp",), - 0x80179E88:("Math3D_Parallel",), - 0x80179EAC:("Math3D_AngleBetweenVectors",), + 0x80179E88:("Math3D_Cos",), + 0x80179EAC:("Math3D_CosOut",), 0x80179F64:("func_80179F64",), 0x8017A038:("Math3D_XZBoundCheck",), 0x8017A09C:("func_8017A09C",), 0x8017A1D0:("func_8017A1D0",), 0x8017A304:("func_8017A304",), 0x8017A438:("func_8017A438",), - 0x8017A5F8:("Math3D_XZLengthSquared",), - 0x8017A610:("Math3D_XZLength",), - 0x8017A634:("Math3D_XZDistanceSquared",), - 0x8017A678:("Math3D_XZDistance",), - 0x8017A6A8:("Math3D_LengthSquared",), + 0x8017A5F8:("Math3D_Dist1DSq",), + 0x8017A610:("Math3D_Dist1D",), + 0x8017A634:("Math3D_Dist2DSq",), + 0x8017A678:("Math3D_Dist2D",), + 0x8017A6A8:("Math3D_Vec3fMagnitudeSq",), 0x8017A6D4:("Math3D_Vec3fMagnitude",), 0x8017A6F8:("Math3D_Vec3fDistSq",), - 0x8017A720:("Math3D_Distance",), - 0x8017A740:("Math3D_DistanceS",), + 0x8017A720:("Math3D_Vec3f_DistXYZ",), + 0x8017A740:("Math3D_DistXYZ16toF",), 0x8017A7B8:("Math3D_Vec3fDiff_CrossZ",), 0x8017A7F8:("Math3D_Vec3fDiff_CrossX",), 0x8017A838:("Math3D_Vec3fDiff_CrossY",), - 0x8017A878:("Math3D_CrossProduct",), + 0x8017A878:("Math3D_Vec3f_Cross",), 0x8017A8EC:("Math3D_SurfaceNorm",), 0x8017A954:("Math3D_PointRelativeToCubeFaces",), 0x8017AA0C:("Math3D_PointRelativeToCubeEdges",), diff --git a/tools/disasm/variables.txt b/tools/disasm/variables.txt index 9b898c50d..d291f3b09 100644 --- a/tools/disasm/variables.txt +++ b/tools/disasm/variables.txt @@ -3672,7 +3672,7 @@ 0x801E0138:("D_801E0138","f32","",0x4), 0x801E013C:("D_801E013C","f32","",0x4), 0x801E0140:("D_801E0140","f32","",0x4), - 0x801E0144:("Math3D_AngleBetweenVectors_min_length","f32","",0x4), + 0x801E0144:("Math3D_CosOut_min_length","f32","",0x4), 0x801E0148:("D_801E0148","f32","",0x4), 0x801E014C:("D_801E014C","f32","",0x4), 0x801E0150:("Math3D_UnitNormalVector_min_length","f32","",0x4), diff --git a/tools/sizes/code_functions.csv b/tools/sizes/code_functions.csv index 5c02ab756..9715964fc 100644 --- a/tools/sizes/code_functions.csv +++ b/tools/sizes/code_functions.csv @@ -2772,33 +2772,33 @@ asm/non_matchings/code/sys_math/randPlusMinusPoint5Scaled.s,randPlusMinusPoint5S asm/non_matchings/code/sys_math3d/Math3D_Normalize.s,Math3D_Normalize,0x801795F0,0x22 asm/non_matchings/code/sys_math3d/Math3D_PlaneVsLineSegClosestPoint.s,Math3D_PlaneVsLineSegClosestPoint,0x80179678,0x48 asm/non_matchings/code/sys_math3d/func_80179798.s,func_80179798,0x80179798,0xAB -asm/non_matchings/code/sys_math3d/func_80179A44.s,func_80179A44,0x80179A44,0x3C +asm/non_matchings/code/sys_math3d/Math3D_LineClosestToPoint.s,Math3D_LineClosestToPoint,0x80179A44,0x3C asm/non_matchings/code/sys_math3d/func_80179B34.s,func_80179B34,0x80179B34,0x18 asm/non_matchings/code/sys_math3d/func_80179B94.s,func_80179B94,0x80179B94,0x78 asm/non_matchings/code/sys_math3d/func_80179D74.s,func_80179D74,0x80179D74,0x1F asm/non_matchings/code/sys_math3d/Math3D_ScaleAndAdd.s,Math3D_ScaleAndAdd,0x80179DF0,0x13 asm/non_matchings/code/sys_math3d/Math3D_Lerp.s,Math3D_Lerp,0x80179E3C,0x13 -asm/non_matchings/code/sys_math3d/Math3D_Parallel.s,Math3D_Parallel,0x80179E88,0x9 -asm/non_matchings/code/sys_math3d/Math3D_AngleBetweenVectors.s,Math3D_AngleBetweenVectors,0x80179EAC,0x2E +asm/non_matchings/code/sys_math3d/Math3D_Cos.s,Math3D_Cos,0x80179E88,0x9 +asm/non_matchings/code/sys_math3d/Math3D_CosOut.s,Math3D_CosOut,0x80179EAC,0x2E asm/non_matchings/code/sys_math3d/func_80179F64.s,func_80179F64,0x80179F64,0x35 asm/non_matchings/code/sys_math3d/Math3D_XZBoundCheck.s,Math3D_XZBoundCheck,0x8017A038,0x19 asm/non_matchings/code/sys_math3d/func_8017A09C.s,func_8017A09C,0x8017A09C,0x4D asm/non_matchings/code/sys_math3d/func_8017A1D0.s,func_8017A1D0,0x8017A1D0,0x4D asm/non_matchings/code/sys_math3d/func_8017A304.s,func_8017A304,0x8017A304,0x4D asm/non_matchings/code/sys_math3d/func_8017A438.s,func_8017A438,0x8017A438,0x70 -asm/non_matchings/code/sys_math3d/Math3D_XZLengthSquared.s,Math3D_XZLengthSquared,0x8017A5F8,0x6 -asm/non_matchings/code/sys_math3d/Math3D_XZLength.s,Math3D_XZLength,0x8017A610,0x9 -asm/non_matchings/code/sys_math3d/Math3D_XZDistanceSquared.s,Math3D_XZDistanceSquared,0x8017A634,0x11 -asm/non_matchings/code/sys_math3d/Math3D_XZDistance.s,Math3D_XZDistance,0x8017A678,0xC -asm/non_matchings/code/sys_math3d/Math3D_LengthSquared.s,Math3D_LengthSquared,0x8017A6A8,0xB +asm/non_matchings/code/sys_math3d/Math3D_Dist1DSq.s,Math3D_Dist1DSq,0x8017A5F8,0x6 +asm/non_matchings/code/sys_math3d/Math3D_Dist1D.s,Math3D_Dist1D,0x8017A610,0x9 +asm/non_matchings/code/sys_math3d/Math3D_Dist2DSq.s,Math3D_Dist2DSq,0x8017A634,0x11 +asm/non_matchings/code/sys_math3d/Math3D_Dist2D.s,Math3D_Dist2D,0x8017A678,0xC +asm/non_matchings/code/sys_math3d/Math3D_Vec3fMagnitudeSq.s,Math3D_Vec3fMagnitudeSq,0x8017A6A8,0xB asm/non_matchings/code/sys_math3d/Math3D_Vec3fMagnitude.s,Math3D_Vec3fMagnitude,0x8017A6D4,0x9 asm/non_matchings/code/sys_math3d/Math3D_Vec3fDistSq.s,Math3D_Vec3fDistSq,0x8017A6F8,0xA -asm/non_matchings/code/sys_math3d/Math3D_Distance.s,Math3D_Distance,0x8017A720,0x8 -asm/non_matchings/code/sys_math3d/Math3D_DistanceS.s,Math3D_DistanceS,0x8017A740,0x1E +asm/non_matchings/code/sys_math3d/Math3D_Vec3f_DistXYZ.s,Math3D_Vec3f_DistXYZ,0x8017A720,0x8 +asm/non_matchings/code/sys_math3d/Math3D_DistXYZ16toF.s,Math3D_DistXYZ16toF,0x8017A740,0x1E asm/non_matchings/code/sys_math3d/Math3D_Vec3fDiff_CrossZ.s,Math3D_Vec3fDiff_CrossZ,0x8017A7B8,0x10 asm/non_matchings/code/sys_math3d/Math3D_Vec3fDiff_CrossX.s,Math3D_Vec3fDiff_CrossX,0x8017A7F8,0x10 asm/non_matchings/code/sys_math3d/Math3D_Vec3fDiff_CrossY.s,Math3D_Vec3fDiff_CrossY,0x8017A838,0x10 -asm/non_matchings/code/sys_math3d/Math3D_CrossProduct.s,Math3D_CrossProduct,0x8017A878,0x1D +asm/non_matchings/code/sys_math3d/Math3D_Vec3f_Cross.s,Math3D_Vec3f_Cross,0x8017A878,0x1D asm/non_matchings/code/sys_math3d/Math3D_SurfaceNorm.s,Math3D_SurfaceNorm,0x8017A8EC,0x1A asm/non_matchings/code/sys_math3d/Math3D_PointRelativeToCubeFaces.s,Math3D_PointRelativeToCubeFaces,0x8017A954,0x2E asm/non_matchings/code/sys_math3d/Math3D_PointRelativeToCubeEdges.s,Math3D_PointRelativeToCubeEdges,0x8017AA0C,0x6C From 6891367506a5ec55de69f358a781e468b460b4e7 Mon Sep 17 00:00:00 2001 From: angie Date: Sat, 2 Apr 2022 19:20:29 -0300 Subject: [PATCH 05/29] Take matched Math3D_LineVsLineClosestTwoPoints from OoT --- include/z64math.h | 2 +- src/code/sys_math3d.c | 113 +++++++++++++++++---------------- src/code/z_eff_tire_mark.c | 4 +- tools/actorfixer.py | 1 + tools/disasm/functions.txt | 2 +- tools/sizes/code_functions.csv | 2 +- 6 files changed, 63 insertions(+), 61 deletions(-) diff --git a/include/z64math.h b/include/z64math.h index e0d23ec8f..cc45fe0dc 100644 --- a/include/z64math.h +++ b/include/z64math.h @@ -178,7 +178,7 @@ f32 Math_Acot2F(f32 adjacent, f32 opposite); f32 Math3D_Normalize(Vec3f* vec); s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* closestPoint); -s32 func_80179798(Vec3f* param_1, Vec3f* param_2, Vec3f* param_3, Vec3f* param_4, Vec3f* param_5, Vec3f* param_6); +s32 Math3D_LineVsLineClosestTwoPoints(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, Vec3f* lineAClosestToB, Vec3f* lineBClosestToA); f32 Math3D_LineClosestToPoint(Linef* line, Vec3f* pos, Vec3f* closestPoint); void func_80179B34(float fParm1, f32 fParm2, f32 fParm5, f32 fParm6, f32 param_5, f32 param_6, f32 param_7, float* param_8, float* param_9); s32 func_80179B94(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, InfiniteLine* intersect); diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 484987756..67f643e34 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -4,7 +4,7 @@ #define Math3D_FindPointOnPlaneIntersect func_80179B34 #define Math3D_PlaneVsPlaneNewLine func_80179B94 -#define Math3D_LineSegMakePerpLineSeg func_80179798 +#define Math3D_LineSegMakePerpLineSeg Math3D_LineVsLineClosestTwoPoints #define Math3D_Plane func_8017B9D8 #define Math3D_TriLineIntersect func_8017D404 #define Math3D_CylOutsideCylDist Math3D_ColCylinderCylinderAmountAndDistance @@ -99,70 +99,71 @@ s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PlaneVsLineSegClosestPoint.s") #endif -#ifdef NON_MATCHING -s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, - Vec3f* lineAIntersect, Vec3f* lineBIntersect) { - f32 sp5C; - f32 sp50; - f32 sp4C; - f32 sp30; - f32 temp_f0_4; - f32 temp_f18; - Vec3f lineADiff; - Vec3f lineBDiff; - Vec3f lineABPointADiff; - f32 t; - f32 t2; - f32 tempf2; - f32 tempf3; - f32 tempf4; - f32 tempf5; +/** + * Finds the two points on lines A and B where the lines are closest together. + */ +s32 Math3D_LineVsLineClosestTwoPoints(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, Vec3f* lineAClosestToB, Vec3f* lineBClosestToA) { + f32 sqMag; + f32 scaleB; + f32 lineAx; + f32 lineAy; + f32 lineAz; + f32 lineBx; + f32 lineBy; + f32 lineBz; + f32 compAAlongB; + f32 compBAAlongB; + Vec3f lineAPerpB; + Vec3f lineBAPerpB; + f32 tA; + f32 tB; - lineADiff.x = lineAPointB->x - lineAPointA->x; - lineADiff.y = lineAPointB->y - lineAPointA->y; - lineADiff.z = lineAPointB->z - lineAPointA->z; - lineBDiff.x = lineBPointB->x - lineBPointA->x; - lineBDiff.y = lineBPointB->y - lineBPointA->y; - lineBDiff.z = lineBPointB->z - lineBPointA->z; + lineAx = lineAPointB->x - lineAPointA->x; + lineAy = lineAPointB->y - lineAPointA->y; + lineAz = lineAPointB->z - lineAPointA->z; - if (IS_ZERO(SQXYZ(lineBDiff))) { - return false; - } - sp5C = DOTXYZ(lineADiff, lineBDiff) * (1.0f / SQXYZ(lineBDiff)); + lineBx = lineBPointB->x - lineBPointA->x; + lineBy = lineBPointB->y - lineBPointA->y; + lineBz = lineBPointB->z - lineBPointA->z; - lineABPointADiff.x = lineAPointA->x - lineBPointA->x; - lineABPointADiff.y = lineAPointA->y - lineBPointA->y; - lineABPointADiff.z = lineAPointA->z - lineBPointA->z; - - // most reordering is here. - temp_f18 = DOTXYZ(lineABPointADiff, lineBDiff) * (1.0f / SQXYZ(lineBDiff)); - - sp4C = lineADiff.x - (lineBDiff.x * sp5C); - sp50 = lineADiff.y - (lineBDiff.y * sp5C); - sp30 = lineADiff.z - (lineBDiff.z * sp5C); - - if (IS_ZERO(SQ(sp4C) + SQ(sp50) + SQ(sp30))) { + sqMag = SQ(lineBx) + SQ(lineBy) + SQ(lineBz); + if (IS_ZERO(sqMag)) { return false; } - t = SQ(sp4C) + SQ(sp50) + SQ(sp30); - temp_f0_4 = -((sp4C * (lineABPointADiff.x - (lineBDiff.x * temp_f18))) + - (sp50 * (lineABPointADiff.y - (lineBDiff.y * temp_f18))) + - (sp30 * (lineABPointADiff.z - (lineBDiff.z * temp_f18)))) / - t; + scaleB = 1.0f / sqMag; - lineAIntersect->x = lineAPointA->x + (lineADiff.x * temp_f0_4); - lineAIntersect->y = lineAPointA->y + (lineADiff.y * temp_f0_4); - lineAIntersect->z = lineAPointA->z + (lineADiff.z * temp_f0_4); + compAAlongB = ((lineAx * lineBx) + (lineAy * lineBy) + (lineAz * lineBz)) * scaleB; + + compBAAlongB = ((lineBx * (lineAPointA->x - lineBPointA->x)) + (lineBy * (lineAPointA->y - lineBPointA->y)) + + (lineBz * (lineAPointA->z - lineBPointA->z))) * + scaleB; + + lineAPerpB.x = lineAx - (lineBx * compAAlongB); + lineAPerpB.y = lineAy - (lineBy * compAAlongB); + lineAPerpB.z = lineAz - (lineBz * compAAlongB); + + sqMag = SQXYZ(lineAPerpB); + if (IS_ZERO(sqMag)) { + return false; + } + + lineBAPerpB.x = (lineAPointA->x - lineBPointA->x) - (lineBx * compBAAlongB); + lineBAPerpB.y = (lineAPointA->y - lineBPointA->y) - (lineBy * compBAAlongB); + lineBAPerpB.z = (lineAPointA->z - lineBPointA->z) - (lineBz * compBAAlongB); + + tA = -DOTXYZ(lineAPerpB, lineBAPerpB) / sqMag; + lineAClosestToB->x = (lineAx * tA) + lineAPointA->x; + lineAClosestToB->y = (lineAy * tA) + lineAPointA->y; + lineAClosestToB->z = (lineAz * tA) + lineAPointA->z; + + tB = (compAAlongB * tA) + compBAAlongB; + lineBClosestToA->x = (lineBx * tB) + lineBPointA->x; + lineBClosestToA->y = (lineBy * tB) + lineBPointA->y; + lineBClosestToA->z = (lineBz * tB) + lineBPointA->z; - lineBIntersect->x = (lineBDiff.x * (temp_f18 + (temp_f0_4 * sp5C))) + lineBPointA->x; - lineBIntersect->y = (lineBDiff.y * (temp_f18 + (temp_f0_4 * sp5C))) + lineBPointA->y; - lineBIntersect->z = (lineBDiff.z * (temp_f18 + (temp_f0_4 * sp5C))) + lineBPointA->z; return true; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_80179798.s") -#endif /** * Determines the closest point on the line `line` to `pos`, by forming a line perpendicular from @@ -195,7 +196,7 @@ void Math3D_FindPointOnPlaneIntersect(f32 planeAAxis1Norm, f32 planeAAxis2Norm, s32 Math3D_PlaneVsPlaneNewLine(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, InfiniteLine* intersect) { - char pad[4]; + s32 pad; Vec3f planeANormal; Vec3f planeBNormal; f32 dirX; diff --git a/src/code/z_eff_tire_mark.c b/src/code/z_eff_tire_mark.c index 532e8e2fb..e367ab6d3 100644 --- a/src/code/z_eff_tire_mark.c +++ b/src/code/z_eff_tire_mark.c @@ -57,8 +57,8 @@ void func_800AE930(CollisionContext* colCtx, EffectTireMark* this, Vec3f* pos, f sp48.y = spB8.y; sp48.z = spB8.z; - if ((func_80179798(&sp84, &sp90, &sp54, &sp60, &sp6C, &sp30) != 0) && - (func_80179798(&sp84, &sp90, &sp3C, &sp48, &sp78, &sp30) != 0)) { + if ((Math3D_LineVsLineClosestTwoPoints(&sp84, &sp90, &sp54, &sp60, &sp6C, &sp30) != 0) && + (Math3D_LineVsLineClosestTwoPoints(&sp84, &sp90, &sp3C, &sp48, &sp78, &sp30) != 0)) { if (!(spAC->flags & 2)) { spAC->flags |= 1; } diff --git a/tools/actorfixer.py b/tools/actorfixer.py index b9d3093ab..8935b2c69 100755 --- a/tools/actorfixer.py +++ b/tools/actorfixer.py @@ -397,6 +397,7 @@ animdict = { "Math3D_LengthSquared": "Math3D_Vec3fMagnitudeSq", "Math3D_Distance": "Math3D_Vec3f_DistXYZ", "Math3D_DistanceS": "Math3D_DistXYZ16toF", + "func_80179798": "Math3D_LineVsLineClosestTwoPoints", "func_800DFB14": "Camera_ChangeDataIdx", "func_800DFC68": "Camera_GetInputDirYaw", diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index 4e5d54c17..562372eaf 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -3257,7 +3257,7 @@ 0x801795C0:("randPlusMinusPoint5Scaled",), 0x801795F0:("Math3D_Normalize",), 0x80179678:("Math3D_PlaneVsLineSegClosestPoint",), - 0x80179798:("func_80179798",), + 0x80179798:("Math3D_LineVsLineClosestTwoPoints",), 0x80179A44:("Math3D_LineClosestToPoint",), 0x80179B34:("func_80179B34",), 0x80179B94:("func_80179B94",), diff --git a/tools/sizes/code_functions.csv b/tools/sizes/code_functions.csv index 9715964fc..fe3ab5f61 100644 --- a/tools/sizes/code_functions.csv +++ b/tools/sizes/code_functions.csv @@ -2771,7 +2771,7 @@ asm/non_matchings/code/sys_math/Rand_ZeroFloat.s,Rand_ZeroFloat,0x80179594,0xB asm/non_matchings/code/sys_math/randPlusMinusPoint5Scaled.s,randPlusMinusPoint5Scaled,0x801795C0,0xC asm/non_matchings/code/sys_math3d/Math3D_Normalize.s,Math3D_Normalize,0x801795F0,0x22 asm/non_matchings/code/sys_math3d/Math3D_PlaneVsLineSegClosestPoint.s,Math3D_PlaneVsLineSegClosestPoint,0x80179678,0x48 -asm/non_matchings/code/sys_math3d/func_80179798.s,func_80179798,0x80179798,0xAB +asm/non_matchings/code/sys_math3d/Math3D_LineVsLineClosestTwoPoints.s,Math3D_LineVsLineClosestTwoPoints,0x80179798,0xAB asm/non_matchings/code/sys_math3d/Math3D_LineClosestToPoint.s,Math3D_LineClosestToPoint,0x80179A44,0x3C asm/non_matchings/code/sys_math3d/func_80179B34.s,func_80179B34,0x80179B34,0x18 asm/non_matchings/code/sys_math3d/func_80179B94.s,func_80179B94,0x80179B94,0x78 From f62623a3348b0f00c80dce0fecba16e3db59b7fc Mon Sep 17 00:00:00 2001 From: angie Date: Sun, 3 Apr 2022 20:36:12 -0400 Subject: [PATCH 06/29] minor fixes to make stuff actually equivalent --- src/code/sys_math3d.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 67f643e34..f52440dc5 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -94,8 +94,6 @@ s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 return true; } #else -// static InfiniteLine planeIntersectLine; -// static Linef planeIntersectSeg; #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PlaneVsLineSegClosestPoint.s") #endif @@ -832,7 +830,7 @@ s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { } triVtx0.x = max->x; triVtx0.y = max->y; - triVtx0.z = max->z; + triVtx0.z = min->z; triVtx1.x = min->x; triVtx1.y = max->y; triVtx1.z = min->z; @@ -916,7 +914,7 @@ s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { /** * Checks if a line segment with endpoints `a` and `b` intersect a cube */ -// in-static bss +// in-function static bss s32 Math3D_LineVsCubeShort(Vec3s* min, Vec3s* max, Vec3s* a, Vec3s* b) { static Vec3f D_801FBD20; // minF static Vec3f D_801FBD30; // maxF @@ -1401,7 +1399,7 @@ s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, return false; } - if (Math3D_TriChkPointParaXImpl(v0, v1, v2, x, y, 300.0f, 1.0f, nz)) { + if (Math3D_TriChkPointParaZImpl(v0, v1, v2, x, y, 300.0f, 1.0f, nz)) { *zIntersect = (((-nx * x) - (ny * y)) - originDist) / nz; return true; } From 1a99793ab1041fe0788ba515f4e6b136a9812046 Mon Sep 17 00:00:00 2001 From: angie Date: Sun, 3 Apr 2022 21:06:21 -0400 Subject: [PATCH 07/29] func_8017FB1C --- src/code/sys_math3d.c | 50 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index f52440dc5..d9e8ed812 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -2270,7 +2270,55 @@ s32 Math3D_YZInSphere(Sphere16* sphere, f32 y, f32 z) { return false; } -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017FB1C.s") +s32 func_8017FB1C(f32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f32 arg6, f32* arg7, f32* arg8, f32* arg9, f32* argA) { + f32 temp_fa0; + f32 temp_fa1; + f32 temp_fs0; + f32 temp_fv0; + f32 temp_ft5; + f32 temp_fv1; + f32 temp_ft2; + s32 phi_a1; + + temp_fa1 = SQ(arg5) + SQ(arg6); + temp_fv1 = arg3 - arg0; + temp_fa0 = arg4 - arg1; + + if ((IS_ZERO(arg5) && IS_ZERO(arg6)) || IS_ZERO(temp_fa1)) { + *arg7 = 0.0f; + *arg8 = 0.0f; + *arg9 = 0.0f; + *argA = 0.0f; + return 0; + } + + temp_fs0 = 2.0f * ((arg5 * temp_fv1) + (arg6 * temp_fa0)); + temp_ft5 = SQ(temp_fs0) - (4.0f * temp_fa1 * ((SQ(temp_fv1) + SQ(temp_fa0)) - SQ(arg2))); + phi_a1 = 0; + + if (IS_ZERO(temp_ft5)) { + temp_fv0 = (-temp_fs0 / (2.0f * temp_fa1)); + *arg7 = (arg5 * temp_fv0) + arg3; + *arg8 = (arg6 * temp_fv0) + arg4; + *arg9 = 0.0f; + *argA = 0.0f; + } + + if (temp_ft5 > 0.0f) { + temp_fv0 = ((-temp_fs0 - sqrtf(temp_ft5)) / (2.0f * temp_fa1)); + temp_ft2 = ((sqrtf(temp_ft5) + -temp_fs0) / (2.0f * temp_fa1)); + *arg7 = (arg5 * temp_fv0) + arg3; + *arg8 = (arg6 * temp_fv0) + arg4; + *arg9 = (arg5 * temp_ft2) + arg3; + *argA = (arg6 * temp_ft2) + arg4; + phi_a1 = 2; + } else { + *arg7 = 0.0f; + *arg8 = 0.0f; + } + + return phi_a1; +} void func_8017FD44(Vec3f* arg0, Vec3f* arg1, Vec3f* dst, f32 arg3) { Vec3f sp2C; From 7a4adeabb3cf00c2f10d54d93d1b359ff3fd35e1 Mon Sep 17 00:00:00 2001 From: angie Date: Sun, 3 Apr 2022 21:22:33 -0400 Subject: [PATCH 08/29] format --- src/code/sys_math3d.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index d9e8ed812..620101a31 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -100,7 +100,8 @@ s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 /** * Finds the two points on lines A and B where the lines are closest together. */ -s32 Math3D_LineVsLineClosestTwoPoints(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, Vec3f* lineAClosestToB, Vec3f* lineBClosestToA) { +s32 Math3D_LineVsLineClosestTwoPoints(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, + Vec3f* lineAClosestToB, Vec3f* lineBClosestToA) { f32 sqMag; f32 scaleB; f32 lineAx; @@ -308,7 +309,6 @@ void Math3D_Vec3fReflect(Vec3f* vec, Vec3f* normal, Vec3f* reflVec) { reflVec->z = ((normScaleZ + vec->z) + (normScaleZ + vec->z)) + negVec.z; } - s32 Math3D_PointInSquare2D(f32 upperLeftX, f32 lowerRightX, f32 upperLeftY, f32 lowerRightY, f32 x, f32 y) { if (x >= upperLeftX && x <= lowerRightX && y >= upperLeftY && y <= lowerRightY) { return true; @@ -1063,7 +1063,6 @@ s32 Math3D_TriChkPointParaYIntersectDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx return false; } - s32 Math3D_TriChkPointParaYIntersectInsideTri(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 chkDist) { if (IS_ZERO(ny)) { @@ -1351,8 +1350,8 @@ s32 Math3D_TriChkPointParaZDeterminate(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f return Math3D_TriChkPointParaZImpl(v0, v1, v2, y, z, detMax, 1.0f, nx); } -s32 Math3D_TriChkPointParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, f32 y, - f32* zIntersect) { +s32 Math3D_TriChkPointParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, + f32 y, f32* zIntersect) { if (IS_ZERO(nz)) { return 0; } @@ -1491,7 +1490,8 @@ s32 Math3D_PointInSph(Sphere16* sphere, Vec3f* point) { return false; } -s32 Math3D_PointDistToLine2D(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* perpXOut, f32* perpYOut, f32* lineLenSq) { +s32 Math3D_PointDistToLine2D(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* perpXOut, f32* perpYOut, + f32* lineLenSq) { f32 perpendicularRatio; f32 xDiff = x2 - x1; f32 yDiff = y2 - y1; @@ -2270,7 +2270,8 @@ s32 Math3D_YZInSphere(Sphere16* sphere, f32 y, f32 z) { return false; } -s32 func_8017FB1C(f32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f32 arg6, f32* arg7, f32* arg8, f32* arg9, f32* argA) { +s32 func_8017FB1C(f32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f32 arg6, f32* arg7, f32* arg8, f32* arg9, + f32* argA) { f32 temp_fa0; f32 temp_fa1; f32 temp_fs0; From a65e1029542b513c490939149af9373258be149a Mon Sep 17 00:00:00 2001 From: angie Date: Sun, 3 Apr 2022 22:49:46 -0400 Subject: [PATCH 09/29] minor cleanup --- src/code/sys_math3d.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 620101a31..cb04f7412 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -2307,7 +2307,7 @@ s32 func_8017FB1C(f32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f3 if (temp_ft5 > 0.0f) { temp_fv0 = ((-temp_fs0 - sqrtf(temp_ft5)) / (2.0f * temp_fa1)); - temp_ft2 = ((sqrtf(temp_ft5) + -temp_fs0) / (2.0f * temp_fa1)); + temp_ft2 = ((-temp_fs0 + sqrtf(temp_ft5)) / (2.0f * temp_fa1)); *arg7 = (arg5 * temp_fv0) + arg3; *arg8 = (arg6 * temp_fv0) + arg4; *arg9 = (arg5 * temp_ft2) + arg3; From 9cd74ce16003b7cacfa8e8504fd5a8011f77de6e Mon Sep 17 00:00:00 2001 From: angie Date: Thu, 7 Apr 2022 20:39:36 -0400 Subject: [PATCH 10/29] Math3D_PointOnDirectedLine --- src/code/sys_math3d.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index cb04f7412..c510811df 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -18,7 +18,7 @@ #define Math3D_SphVsCylOverlapDist Math3D_ColSphereCylinderDistance #define Math3D_CylVsLineSeg func_8017E350 #define Math3D_TriVsSphIntersect Math3D_ColSphereTri -#define Math3D_PointOnInfiniteLine Math3D_ScaleAndAdd +#define Math3D_PointOnDirectedLine Math3D_ScaleAndAdd #define Math3D_LineSplitRatio Math3D_Lerp #define Math3D_PlaneVsPlaneVsLineClosestPoint func_80179D74 #define Math3D_PointInCyl func_8017E294 @@ -249,17 +249,20 @@ s32 Math3D_PlaneVsPlaneVsLineClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_80179D74.s") #endif -void Math3D_PointOnInfiniteLine(Vec3f* v0, Vec3f* dir, f32 dist, Vec3f* ret) { - ret->x = (dir->x * dist) + v0->x; - ret->y = (dir->y * dist) + v0->y; - ret->z = (dir->z * dist) + v0->z; +/** + * Calculates the point on the line from starting point `v0`, in the direction `dir` scaled by `scale`. Result is placed in `ret` + */ +void Math3D_PointOnDirectedLine(Vec3f* v0, Vec3f* dir, f32 scale, Vec3f* ret) { + ret->x = (dir->x * scale) + v0->x; + ret->y = (dir->y * scale) + v0->y; + ret->z = (dir->z * scale) + v0->z; } void Math3D_LineSplitRatio(Vec3f* v0, Vec3f* v1, f32 ratio, Vec3f* ret) { Vec3f diff; Math_Vec3f_Diff(v1, v0, &diff); - Math3D_PointOnInfiniteLine(v0, &diff, ratio, ret); + Math3D_PointOnDirectedLine(v0, &diff, ratio, ret); } /** @@ -2040,7 +2043,7 @@ s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect) { } radiusTodistFromCylYIntersectTov0v1 = cyl->radius / distFromCylYIntersectTov0v1; - Math3D_PointOnInfiniteLine(&cylIntersectCenter, &diffMidpointIntersect, radiusTodistFromCylYIntersectTov0v1, + Math3D_PointOnDirectedLine(&cylIntersectCenter, &diffMidpointIntersect, radiusTodistFromCylYIntersectTov0v1, intersect); return true; } From ef5e39fbd2b497b8d9054f59bbb3bb2995854519 Mon Sep 17 00:00:00 2001 From: angie Date: Mon, 11 Apr 2022 09:35:24 -0400 Subject: [PATCH 11/29] func_8017FB1C documentation Co-authored-by: EllipticEllipsis <73679967+EllipticEllipsis@users.noreply.github.com> --- src/code/sys_math3d.c | 99 ++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 39 deletions(-) diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index c510811df..f8c3e8cd6 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -2273,55 +2273,76 @@ s32 Math3D_YZInSphere(Sphere16* sphere, f32 y, f32 z) { return false; } -s32 func_8017FB1C(f32 arg0, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f32 arg6, f32* arg7, f32* arg8, f32* arg9, - f32* argA) { - f32 temp_fa0; - f32 temp_fa1; - f32 temp_fs0; - f32 temp_fv0; - f32 temp_ft5; - f32 temp_fv1; - f32 temp_ft2; - s32 phi_a1; - temp_fa1 = SQ(arg5) + SQ(arg6); - temp_fv1 = arg3 - arg0; - temp_fa0 = arg4 - arg1; +// Math3D_CircleLineIntersections? +/** + * @brief Computes the intersection points, if any, of the circle of radius radius, center (centerX, centerY) with the + * line through the point (pointX, pointY) in direction (dirX, dirY). + * + * @param[in] centreX x coordinate of centre of circle + * @param[in] centerY y coordinate of centre of circle + * @param[in] radius of circle + * @param[in] pointX x coordinate of point on line + * @param[in] pointY y coordinate of point on line + * @param[in] dirX x value of direction vector of line + * @param[in] dirY y value of direction vecotr of line + * @param[out] intersectAX x coordinate of first intersection + * @param[out] intersectAY y coordinate of first intersection + * @param[out] intersectBX x coordinate of second intersection + * @param[out] intersectBY y coordinate of second intersection + * @return number of intersections(ish) + */ +s32 func_8017FB1C(f32 centreX, f32 centerY, f32 radius, f32 pointX, f32 pointY, f32 dirX, f32 dirY, f32* intersectAX, + f32* intersectAY, f32* intersectBX, f32* intersectBY) { + f32 a = SQ(dirX) + SQ(dirY); // t^2 coefficient, |dir|^2 + f32 diffX = pointX - centreX; + f32 diffY = pointY - centerY; + f32 b; // t coefficient + f32 delta; // discriminant of quadratic + f32 rootP; // larger root of quadratic + f32 rootN; // smaller root of quadratic + s32 ret; - if ((IS_ZERO(arg5) && IS_ZERO(arg6)) || IS_ZERO(temp_fa1)) { - *arg7 = 0.0f; - *arg8 = 0.0f; - *arg9 = 0.0f; - *argA = 0.0f; + // if the direction vector's magnitude is too small, assume no intersections + if ((IS_ZERO(dirX) && IS_ZERO(dirY)) || IS_ZERO(a)) { + *intersectAX = 0.0f; + *intersectAY = 0.0f; + *intersectBX = 0.0f; + *intersectBY = 0.0f; return 0; } - temp_fs0 = 2.0f * ((arg5 * temp_fv1) + (arg6 * temp_fa0)); - temp_ft5 = SQ(temp_fs0) - (4.0f * temp_fa1 * ((SQ(temp_fv1) + SQ(temp_fa0)) - SQ(arg2))); - phi_a1 = 0; + b = 2.0f * (dirX * diffX + dirY * diffY); // 2 dir . (point - centre) + delta = SQ(b) - 4.0f * a * (SQ(diffX) + SQ(diffY) - SQ(radius)); + ret = 0; - if (IS_ZERO(temp_ft5)) { - temp_fv0 = (-temp_fs0 / (2.0f * temp_fa1)); - *arg7 = (arg5 * temp_fv0) + arg3; - *arg8 = (arg6 * temp_fv0) + arg4; - *arg9 = 0.0f; - *argA = 0.0f; + if (IS_ZERO(delta)) { // At most one root if discriminant is close to zero + // This root is always overwritten later. + rootN = -b / (2.0f * a); + *intersectAX = dirX * rootN + pointX; + *intersectAY = dirY * rootN + pointY; + + *intersectBX = 0.0f; + *intersectBY = 0.0f; } - if (temp_ft5 > 0.0f) { - temp_fv0 = ((-temp_fs0 - sqrtf(temp_ft5)) / (2.0f * temp_fa1)); - temp_ft2 = ((-temp_fs0 + sqrtf(temp_ft5)) / (2.0f * temp_fa1)); - *arg7 = (arg5 * temp_fv0) + arg3; - *arg8 = (arg6 * temp_fv0) + arg4; - *arg9 = (arg5 * temp_ft2) + arg3; - *argA = (arg6 * temp_ft2) + arg4; - phi_a1 = 2; - } else { - *arg7 = 0.0f; - *arg8 = 0.0f; + if (delta > 0.0f) { // Two roots if discriminant > 0 + rootN = (-b - sqrtf(delta)) / (2.0f * a); + *intersectAX = dirX * rootN + pointX; + *intersectAY = dirY * rootN + pointY; + + rootP = (-b + sqrtf(delta)) / (2.0f * a); + *intersectBX = dirX * rootP + pointX; + *intersectBY = dirY * rootP + pointY; + + ret = 2; + } else { // "No roots if discriminant <= 0.0f"* + //! @bug Should be one root if discriminant == 0, not zero (although this case is unlikely for floats) + *intersectAX = 0.0f; + *intersectAY = 0.0f; } - return phi_a1; + return ret; } void func_8017FD44(Vec3f* arg0, Vec3f* arg1, Vec3f* dst, f32 arg3) { From 4491f42b70e87516e75ae42ef05fec7c06b33a9c Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Sat, 18 Mar 2023 21:20:19 -0700 Subject: [PATCH 12/29] Remove actorfixer --- tools/actorfixer.py | 664 -------------------------------------------- 1 file changed, 664 deletions(-) delete mode 100755 tools/actorfixer.py diff --git a/tools/actorfixer.py b/tools/actorfixer.py deleted file mode 100755 index 8935b2c69..000000000 --- a/tools/actorfixer.py +++ /dev/null @@ -1,664 +0,0 @@ -#!/usr/bin/env python3 - -import argparse, os - -# There are a few commented out entries that would produce unexpected renames. -# They are left as a comment so people can just grab them. - -# "old": "new" -animdict = { - "Actor_GetSwitchFlag": "Flags_GetSwitch", - "atan_flip": "Math_Acot2F", - "atans": "Math_Atan2S", - "SysMatrix_StateAlloc": "Matrix_StateAlloc", - "SysMatrix_StatePush": "Matrix_StatePush", - "SysMatrix_CopyCurrentState": "Matrix_CopyCurrentState", - "SysMatrix_SetCurrentState": "Matrix_SetCurrentState", - "SysMatrix_InsertTranslation": "Matrix_InsertTranslation", - "SysMatrix_InsertMatrix": "Matrix_InsertMatrix", - "SysMatrix_Scale": "Matrix_Scale", - "SysMatrix_InsertXRotation_s": "Matrix_InsertXRotation_s", - "SysMatrix_InsertXRotation_f": "Matrix_InsertXRotation_f", - "SysMatrix_RotateStateAroundXAxis": "Matrix_RotateStateAroundXAxis", - "SysMatrix_SetStateXRotation": "Matrix_SetStateXRotation", - "SysMatrix_RotateY": "Matrix_RotateY", - "SysMatrix_InsertYRotation_f": "Matrix_InsertYRotation_f", - "SysMatrix_InsertZRotation_s": "Matrix_InsertZRotation_s", - "SysMatrix_InsertZRotation_f": "Matrix_InsertZRotation_f", - "SysMatrix_InsertRotation": "Matrix_InsertRotation", - "SysMatrix_JointPosition": "Matrix_JointPosition", - "SysMatrix_SetStateRotationAndTranslation": "Matrix_SetStateRotationAndTranslation", - "SysMatrix_ToRSPMatrix": "Matrix_ToRSPMatrix", - "SysMatrix_ToMtx": "Matrix_ToMtx", - "SysMatrix_NewMtx": "Matrix_NewMtx", - "SysMatrix_AppendToPolyOpaDisp": "Matrix_AppendToPolyOpaDisp", - "SysMatrix_MultiplyVector3fByState": "Matrix_MultiplyVector3fByState", - "SysMatrix_GetStateTranslation": "Matrix_GetStateTranslation", - "SysMatrix_GetStateTranslationAndScaledX": "Matrix_GetStateTranslationAndScaledX", - "SysMatrix_GetStateTranslationAndScaledY": "Matrix_GetStateTranslationAndScaledY", - "SysMatrix_GetStateTranslationAndScaledZ": "Matrix_GetStateTranslationAndScaledZ", - "SysMatrix_MultiplyVector3fXZByCurrentState": "Matrix_MultiplyVector3fXZByCurrentState", - "SysMatrix_MtxFCopy": "Matrix_MtxFCopy", - "SysMatrix_FromRSPMatrix": "Matrix_FromRSPMatrix", - "SysMatrix_MultiplyVector3fByMatrix": "Matrix_MultiplyVector3fByMatrix", - "SysMatrix_TransposeXYZ": "Matrix_TransposeXYZ", - "SysMatrix_NormalizeXYZ": "Matrix_NormalizeXYZ", - "SysMatrix_InsertRotationAroundUnitVector_f": "Matrix_InsertRotationAroundUnitVector_f", - "SysMatrix_InsertRotationAroundUnitVector_s": "Matrix_InsertRotationAroundUnitVector_s", - "SysMatrix_GetStateAsRSPMatrix": "Matrix_GetStateAsRSPMatrix", - "func_800B78B8": "Actor_UpdateBgCheckInfo", - "func_8012403C": "Player_GetMask", - "func_8012404c": "Player_RemoveMask", - "Actor_SpawnWithParentAndCutscene": "Actor_SpawnAsChildAndCutscene", - "Actor_SpawnWithParent": "Actor_SpawnAsChild", - "Actor_IsLinkFacingActor": "Player_IsFacingActor", - "Actor_IsActorFacingLink": "Actor_IsFacingPlayer", - "Actor_IsActorFacingLinkAndWithinRange": "Actor_IsFacingAndNearPlayer", - "Actor_IsActorFacingActorAndWithinRange": "Actor_ActorAIsFacingAndNearActorB", - "Actor_IsActorFacingActor": "Actor_ActorAIsFacingActorB", - "Actor_IsActorFacedByActor": "Actor_ActorBIsFacingActorA", - "func_800B84D0": "Actor_ProcessTalkRequest", - "func_800BDFC0": "Gfx_DrawDListOpa", - "func_800BE03C": "Gfx_DrawDListXlu", - "func_800B6FC8": "Player_GetHeight", - "Actor_InitCurrPosition": "Actor_SetWorldToHome", - "Actor_SetHeight": "Actor_SetFocus", - "Actor_SetRotationFromDrawRotation": "Actor_SetWorldRotToShape", - "Actor_InitDrawRotation": "Actor_SetShapeRotToWorld", - "Actor_CalcOffsetOrientedToDrawRotation": "Actor_OffsetOfPointInActorCoords", - "Actor_ApplyMovement": "Actor_UpdatePos", - "Actor_SetVelocityYRotationAndGravity": "Actor_UpdateVelocityWithGravity", - "Actor_SetVelocityAndMoveYRotationAndGravity": "Actor_MoveWithGravity", - "Actor_SetVelocityXYRotation": "Actor_UpdateVelocityWithoutGravity", - "Actor_SetVelocityAndMoveXYRotation": "Actor_MoveWithoutGravity", - "Actor_SetVelocityXYRotationReverse": "Actor_UpdateVelocityWithoutGravityReverse", - "Actor_SetVelocityAndMoveXYRotationReverse": "Actor_MoveWithoutGravityReverse", - "func_800B6C04": "Actor_SetSpeeds", - "func_800B81E0": "Actor_GetFocus", - "func_800B8214": "Actor_GetWorld", - "func_800B8248": "Actor_GetWorldPosShapeRot", - "func_800BE22C": "Actor_ApplyDamage", - "Audio_PlaySoundAtPosition": "SoundSource_PlaySfxAtFixedWorldPos", - "func_800F0590": "SoundSource_PlaySfxEachFrameAtFixedWorldPos", - "func_8016970C": "Play_CameraSetAtEye", - "func_800BBA88": "Enemy_StartFinishingBlow", - "ShrinkWindow_Step": "ShrinkWindow_Update", - "ShrinkWindow_Fini": "ShrinkWindow_Destroy", - "func_801A89A8": "Audio_QueueSeqCmd", - "func_8019F1C0": "Audio_PlaySfxAtPos", - "func_801A72CC": "Audio_StopSfxByPos", - "SkelAnime_LodDrawLimb(": "SkelAnime_DrawLimbLod(", - "SkelAnime_LodDraw(": "SkelAnime_DrawLod(", - "SkelAnime_LodDrawLimbSV(": "SkelAnime_DrawFlexLimbLod(", - "SkelAnime_LodDrawSV(": "SkelAnime_DrawFlexLod(", - #"SkelAnime_DrawLimb(": "SkelAnime_DrawLimbOpa(", - #"SkelAnime_Draw(": "SkelAnime_DrawOpa(", - "SkelAnime_DrawLimbSV(": "SkelAnime_DrawFlexLimbOpa(", - "SkelAnime_DrawSV(": "SkelAnime_DrawFlexOpa(", - #"SkelAnime_AnimateFrame(": "SkelAnime_GetFrameData(", - "SkelAnime_GetTotalFrames(": "Animation_GetLength(", - "SkelAnime_GetFrameCount(": "Animation_GetLastFrame(", - "SkelAnime_Draw2Limb(": "SkelAnime_DrawLimb(", - "SkelAnime_Draw2(": "SkelAnime_Draw(", - "SkelAnime_DrawLimbSV2(": "SkelAnime_DrawFlexLimb(", - "SkelAnime_DrawSV2(": "SkelAnime_DrawFlex(", - "func_80134FFC": "SkelAnime_GetFrameData2", - "func_801353D4": "Animation_GetLimbCount2", - "SkelAnime_GetTotalFrames2(": "Animation_GetLength2(", - "SkelAnime_GetFrameCount2(": "Animation_GetLastFrame2(", - "SkelAnime_InterpolateVec3s": "SkelAnime_InterpFrameTable", - "SkelAnime_AnimationCtxReset": "AnimationContext_Reset", - "func_801358D4": "AnimationContext_SetNextQueue", - "func_801358F4": "AnimationContext_DisableQueue", - "SkelAnime_NextEntry": "AnimationContext_AddEntry", - "SkelAnime_LoadLinkAnimetion": "AnimationContext_SetLoadFrame", - "SkelAnime_LoadAnimationType1": "AnimationContext_SetCopyAll", - "SkelAnime_LoadAnimationType2": "AnimationContext_SetInterp", - "SkelAnime_LoadAnimationType3": "AnimationContext_SetCopyTrue", - "SkelAnime_LoadAnimationType4": "AnimationContext_SetCopyFalse", - "SkelAnime_LoadAnimationType5": "AnimationContext_SetMoveActor", - "SkelAnime_LinkAnimetionLoaded": "AnimationContext_LoadFrame", - "SkelAnime_AnimationType1Loaded": "AnimationContext_CopyAll", - "SkelAnime_AnimationType2Loaded": "AnimationContext_CopyInterp", - "SkelAnime_AnimationType3Loaded": "AnimationContext_CopyTrue", - "SkelAnime_AnimationType4Loaded": "AnimationContext_CopyFalse", - "SkelAnime_AnimationType5Loaded": "AnimationContext_MoveActor", - "func_80135EE8": "AnimationContext_Update", - "SkelAnime_InitLinkAnimetion(": "SkelAnime_InitLink(", - "func_801360A8": "LinkAnimation_SetUpdateFunction", - "func_801360E0": "LinkAnimation_Update", - "func_80136104": "LinkAnimation_Morph", - "func_801361BC": "LinkAnimation_AnimateFrame", - "func_80136288": "LinkAnimation_Loop", - "func_8013631C": "LinkAnimation_Once", - "SkelAnime_SetTransition": "Animation_SetMorph", - "SkelAnime_ChangeLinkAnim": "LinkAnimation_Change", - "SkelAnime_ChangeLinkAnimDefaultStop": "LinkAnimation_PlayOnce", - "SkelAnime_ChangeLinkAnimPlaybackStop": "LinkAnimation_PlayOnceSetSpeed", - "SkelAnime_ChangeLinkAnimDefaultRepeat": "LinkAnimation_PlayLoop", - "SkelAnime_ChangeLinkAnimPlaybackRepeat": "LinkAnimation_PlayLoopSetSpeed", - "func_8013670C": "LinkAnimation_CopyJointToMorph", - "func_8013673C": "LinkAnimation_CopyMorphToJoint", - "func_8013676C": "LinkAnimation_LoadToMorph", - "func_801367B0": "LinkAnimation_LoadToJoint", - "func_801367F4": "LinkAnimation_InterpJointMorph", - "func_8013682C": "LinkAnimation_BlendToJoint", - "func_801368CC": "LinkAnimation_BlendToMorph", - "SkelAnime_SetModeStop": "LinkAnimation_EndLoop", - "func_80136990": "Animation_OnFrameImpl", - "func_80136A48": "LinkAnimation_OnFrame", - "SkelAnime_InitSV": "SkelAnime_InitFlex", - "func_80136C84": "SkelAnime_SetUpdate", - "SkelAnime_FrameUpdateMatrix": "SkelAnime_Update", - "func_80136CF4": "SkelAnime_Morph", - "func_80136D98": "SkelAnime_MorphTaper", - "func_80136F04": "SkelAnime_AnimateFrame", - "func_8013702C": "SkelAnime_LoopFull", - "func_801370B0": "SkelAnime_LoopPartial", - "func_8013713C": "SkelAnime_Once", - "SkelAnime_ChangeAnimImpl": "Animation_ChangeImpl", - "SkelAnime_ChangeAnim(": "Animation_Change(", - "SkelAnime_ChangeAnimDefaultStop": "Animation_PlayOnce", - "SkelAnime_ChangeAnimTransitionStop": "Animation_MorphToPlayOnce", - "SkelAnime_ChangeAnimPlaybackStop": "Animation_PlayOnceSetSpeed", - "SkelAnime_ChangeAnimDefaultRepeat": "Animation_PlayLoop", - "SkelAnime_ChangeAnimTransitionRepeat": "Animation_MorphToLoop", - "SkelAnime_ChangeAnimPlaybackRepeat": "Animation_PlayLoopSetSpeed", - "SkelAnime_AnimSetStop": "Animation_EndLoop", - "SkelAnime_AnimReverse": "Animation_Reverse", - "func_80137674": "SkelAnime_CopyFrameTableTrue", - "func_801376DC": "SkelAnime_CopyFrameTableFalse", - "func_80137748": "SkelAnime_UpdateTranslation", - "func_801378B8": "Animation_OnFrame", - "SkelAnime_CopyVec3s": "SkelAnime_CopyFrameTable", - "SysMatrix_StatePop": "Matrix_StatePop", - "SysMatrix_GetCurrentState": "Matrix_GetCurrentState", - "Actor_SetObjectSegment": "Actor_SetObjectDependency", - "func_800B3FC0": "ActorShadow_DrawCircle", - "func_800B4024": "ActorShadow_DrawSquare", - "func_800B4088": "ActorShadow_DrawWhiteCircle", - "func_800B40B8": "ActorShadow_DrawHorse", - "func_800B40E0": "ActorShadow_DrawFoot", - "func_800B42F8": "ActorShadow_DrawFeet", - "func_800B4A98": "Actor_SetFeetPos", - "Actor_SetSwitchFlag": "Flags_SetSwitch", - "Actor_UnsetSwitchFlag": "Flags_UnsetSwitch", - "Actor_GetChestFlag": "Flags_GetTreasure", - "Actor_SetChestFlag": "Flags_SetTreasure", - "Actor_SetAllChestFlag": "Flags_SetAllTreasure", - "Actor_GetAllChestFlag": "Flags_GetAllTreasure", - "Actor_GetRoomCleared(": "Flags_GetClear(", - "Actor_SetRoomCleared(": "Flags_SetClear(", - "Actor_UnsetRoomCleared(": "Flags_UnsetClear(", - "Actor_GetRoomClearedTemp(": "Flags_GetClearTemp(", - "Actor_SetRoomClearedTemp(": "Flags_SetClearTemp(", - "Actor_UnsetRoomClearedTemp(": "Flags_UnsetTempClear(", - "Actor_GetCollectibleFlag": "Flags_GetCollectible", - "Actor_SetCollectibleFlag": "Flags_SetCollectible", - "func_800B8A1C": "Actor_PickUp", - "func_800B8B84": "Actor_PickUpNearby", - "func_800B8BB0": "Actor_LiftActor", - "func_800B8BD0": "Actor_PickUpFar", - "func_801A5CFC": "Audio_PlaySfxGeneral", - "func_800BBDAC": "Actor_SpawnFloorDustRing", - "func_800B8708": "Player_GetExchangeItemId", - "func_801233E4": "Player_InCsMode", - "func_800BC4EC": "Actor_TestFloorInDirection", - "func_800BC5B8": "Actor_IsTargeted", - "func_800BC5EC": "Actor_OtherIsTargeted", - "func_800BCB70": "Actor_SetColorFilter", - "func_800BE0B8": "Actor_FindNearby", - "func_800BE258": "Actor_SetDropFlag", - "func_800BE2B8": "Actor_SetDropFlagJntSph", - "Actor_TitleCardCreate": "TitleCard_InitBossName", - "func_800B867C": "Actor_TextboxIsClosing", - "func_800BDC5C": "Actor_ChangeAnimationByInfo", - "Actor_ChangeAnimation(": "Actor_ChangeAnimationByInfo(", - "func_80152498": "Message_GetState", - "func_800B8898": "Actor_GetScreenPos", - "Audio_PlayActorSound2": "Actor_PlaySfxAtPos", - "func_800BF7CC": "Actor_SpawnIceEffects", - "Actor_IsFacingPlayerAndWithinRange": "Actor_IsFacingAndNearPlayer", - "func_800BC8B8": "Actor_DrawDoorLock", - "func_800B86C8": "Actor_ChangeFocus", - "zelda_malloc(": "ZeldaArena_Malloc(", - "zelda_mallocR(": "ZeldaArena_MallocR(", - "zelda_realloc": "ZeldaArena_Realloc", - "zelda_free": "ZeldaArena_Free", - "zelda_calloc": "ZeldaArena_Calloc", - "MainHeap_AnalyzeArena": "ZeldaArena_GetSizes", - "MainHeap_Check": "ZeldaArena_Check", - "MainHeap_Init": "ZeldaArena_Init", - "MainHeap_Cleanup": "ZeldaArena_Cleanup", - "MainHeap_IsInitialized": "ZeldaArena_IsInitialized", - "func_80138300": "Skin_GetLimbPos", - "func_8013835C": "Skin_GetVertexPos", - # "BgCheck_RelocateMeshHeader": "CollisionHeader_GetVirtual", - # "BgCheck_AddActorMesh": "DynaPoly_SetBgActor", - # "BgCheck_RemoveActorMesh": "DynaPoly_DeleteBgActor", - "BgCheck_PolygonLinkedListNodeInit": "SSNode_SetValue", - "BgCheck_PolygonLinkedListResetHead": "SSList_SetNull", - "BgCheck_ScenePolygonListsNodeInsert": "SSNodeList_SetSSListHead", - "BgCheck_PolygonLinkedListNodeInsert": "DynaSSNodeList_SetSSListHead", - "BgCheck_PolygonLinkedListInit": "DynaSSNodeList_Init", - "BgCheck_PolygonLinkedListAlloc": "DynaSSNodeList_Alloc", - "BgCheck_PolygonLinkedListReset": "DynaSSNodeList_ResetCount", - "BgCheck_AllocPolygonLinkedListNode": "DynaSSNodeList_GetNextNodeIdx", - "BgCheck_CreateVec3fFromVertex": "BgCheck_Vec3sToVec3f", - "BgCheck_CreateVertexFromVec3f": "BgCheck_Vec3fToVec3s", - "BgCheck_PolygonGetMinY": "CollisionPoly_GetMinY", - "BgCheck_PolygonGetNormal": "CollisionPoly_GetNormalF", - "BcCheck3_BgActorInit": "DynaPolyActor_Init", - "BgCheck3_LoadMesh": "DynaPolyActor_LoadMesh", - "func_800C01B8": "CollisionPoly_GetPointDistanceFromPlane", - "BgCheck_CreateTriNormFromPolygon": "CollisionPoly_GetVertices", - "func_800C02C0": "CollisionPoly_GetVerticesByBgId", - "BgCheck_PolygonCollidesWithSphere": "CollisionPoly_SphVsPoly", - "BgCheck_ScenePolygonListsInsertSorted": "StaticLookup_AddPolyToSSList", - "BgCheck_ScenePolygonListsInsert": "StaticLookup_AddPoly", - "BgCheck_GetPolyMinSubdivisions": "BgCheck_GetSubdivisionMinBounds", - "BgCheck_GetPolyMaxSubdivisions": "BgCheck_GetSubdivisionMaxBounds", - "BgCheck_GetPolyMinMaxSubdivisions": "BgCheck_GetPolySubdivisionBounds", - "func_800C2BE0": "BgCheck_PolyIntersectsSubdivision", - "BgCheck_SplitScenePolygonsIntoSubdivisions": "BgCheck_InitStaticLookup", - "BgCheck_GetIsDefaultSpecialScene": "BgCheck_IsSmallMemScene", - "BgCheck_GetSpecialSceneMaxMemory": "BgCheck_TryGetCustomMemsize", - "BgCheck_CalcSubdivisionSize": "BgCheck_SetSubdivisionDimension", - "BgCheck_Init(": "BgCheck_Allocate(", - "func_800C3C00": "BgCheck_SetContextFlags", - "func_800C3C14": "BgCheck_UnsetContextFlags", - "BgCheck_GetActorMeshHeader": "BgCheck_GetCollisionHeader", - "func_800C3D50": "BgCheck_RaycastFloorImpl", - "func_800C3F40": "BgCheck_CameraRaycastFloor1", - "func_800C3FA0": "BgCheck_EntityRaycastFloor1", - "func_800C4000": "BgCheck_EntityRaycastFloor2", - "func_800C4058": "BgCheck_EntityRaycastFloor2_1", - "func_800C40B4": "BgCheck_EntityRaycastFloor3", - "func_800C411C": "BgCheck_EntityRaycastFloor5", - "func_800C4188": "BgCheck_EntityRaycastFloor5_2", - "func_800C41E4": "BgCheck_EntityRaycastFloor5_3", - "func_800C4240": "BgCheck_EntityRaycastFloor6", - "func_800C42A8": "BgCheck_EntityRaycastFloor7", - "func_800C4314": "BgCheck_AnyRaycastFloor1", - "func_800C43CC": "BgCheck_AnyRaycastFloor2", - "func_800C4488": "BgCheck_CameraRaycastFloor2", - "func_800C44F0": "BgCheck_EntityRaycastFloor8", - "func_800C455C": "BgCheck_EntityRaycastFloor9", - "func_800C45C4": "BgCheck_CheckWallImpl", - "func_800C4C74": "BgCheck_EntitySphVsWall1", - "func_800C4CD8": "BgCheck_EntitySphVsWall2", - "func_800C4D3C": "BgCheck_EntitySphVsWall3", - "func_800C4DA4": "BgCheck_EntitySphVsWall4", - "func_800C4E10": "BgCheck_CheckCeilingImpl", - "func_800C4F38": "BgCheck_AnyCheckCeiling", - "func_800C4F84": "BgCheck_EntityCheckCeiling", - "func_800C54AC": "BgCheck_CameraLineTest1", - "func_800C5538": "BgCheck_CameraLineTest2", - "func_800C55C4": "BgCheck_EntityLineTest1", - "func_800C5650": "BgCheck_EntityLineTest2", - "func_800C56E0": "BgCheck_EntityLineTest3", - "func_800C576C": "BgCheck_ProjectileLineTest", - "func_800C57F8": "BgCheck_AnyLineTest1", - "func_800C583C": "BgCheck_AnyLineTest2", - "func_800C58C8": "BgCheck_AnyLineTest3", - "func_800C5954": "BgCheck_SphVsFirstPolyImpl", - "func_800C5A20": "BgCheck_SphVsFirstPoly", - "func_800C5A64": "BgCheck_SphVsFirstWall", - "BgCheck_ScenePolygonListsInit": "SSNodeList_Init", - "BgCheck_ScenePolygonListsAlloc": "SSNodeList_Alloc", - "func_800C5B80": "SSNodeList_GetNextNode", - "BgCheck_ScenePolygonListsReserveNode": "SSNodeList_GetNextNodeIdx", - "BgCheck_ActorMeshParamsInit": "ScaleRotPos_Init", - "BgCheck_SetActorMeshParams": "ScaleRotPos_SetValue", - "BgCheck_ActorMeshPolyListsHeadsInit": "DynaLookup_ResetLists", - "BgCheck_ActorMeshPolyListsInit": "DynaLookup_Reset", - "BgCheck_ActorMeshVerticesIndexInit": "DynaLookup_ResetVtxStartIndex", - "BgCheck_ActorMeshWaterboxesIndexInit": "DynaLookup_ResetWaterBoxStartIndex", - "BgCheck_ActorMeshInit": "BgActor_Init", - "BgCheck_ActorMeshInitFromActor": "BgActor_SetActor", - "BgCheck_HasActorMeshChanged": "BgActor_IsTransformUnchanged", - "BgCheck_PolygonsInit": "DynaPoly_NullPolyList", - "BgCheck_PolygonsAlloc": "DynaPoly_AllocPolyList", - "BgCheck_VerticesInit": "DynaPoly_NullVtxList", - "BgCheck_VerticesListAlloc": "DynaPoly_AllocVtxList", - "BgCheck_WaterboxListInit": "DynaPoly_InitWaterBoxList", - "BgCheck_WaterboxListAlloc": "DynaPoly_AllocWaterBoxList", - "BgCheck_ActorMeshUpdateParams": "DynaPoly_SetBgActorPrevTransform", - "BgCheck_IsActorMeshIndexValid": "DynaPoly_IsBgIdBgActor", - "BgCheck_DynaInit": "DynaPoly_Init", - "BgCheck_DynaAlloc": "DynaPoly_Alloc", - "BgCheck_AddActorMesh": "DynaPoly_SetBgActor", - "BgCheck_GetActorOfMesh": "DynaPoly_GetActor", - "BgCheck_RemoveActorMesh": "DynaPoly_DeleteBgActor", - "BgCheck_AddActorMeshToLists": "DynaPoly_ExpandSRT", - "BgCheck_Update": "DynaPoly_Setup", - "BgCheck_UpdateAllActorMeshes": "DynaPoly_UpdateBgActorTransforms", - "BgCheck_RelocateMeshHeaderPointers": "CollisionHeader_SegmentedToVirtual", - "BgCheck_RelocateMeshHeader": "CollisionHeader_GetVirtual", - "BgCheck_RelocateAllMeshHeaders": "BgCheck_InitCollisionHeaders", - "BgCheck_GetPolygonAttributes": "SurfaceType_GetData", - "func_800C9704": "SurfaceType_GetCamDataIndex", - "func_800C9924": "SurfaceType_GetCamPosData", - "func_800C99AC": "SurfaceType_GetSceneExitIndex", - "func_800C9B90": "SurfaceType_IsHorseBlocked", - "func_800C9BDC": "SurfaceType_GetSfx", - "func_800C9C74": "SurfaceType_GetSlope", - "func_800C9C9C": "SurfaceType_GetLightSettingIndex", - "func_800C9CC4": "SurfaceType_GetEcho", - "func_800C9CEC": "SurfaceType_IsHookshotSurface", - "func_800C9D14": "SurfaceType_IsIgnoredByEntities", - "func_800C9D50": "SurfaceType_IsIgnoredByProjectiles", - "func_800C9D8C": "SurfaceType_GetConveyorType", - "func_800C9E18": "SurfaceType_GetConveyorSpeed", - "func_800C9E40": "SurfaceType_GetConveyorDirection", - "func_800C9E88": "SurfaceType_IsWallDamage", - "func_800C9EBC": "WaterBox_GetSurfaceImpl", - "func_800CA1AC": "WaterBox_GetSurface1", - "func_800CA1E8": "WaterBox_GetSurface1_2", - "func_800CA22C": "WaterBox_GetSurface2", - "func_800CA6D8": "WaterBox_GetLightSettingIndex", - "func_8017D668": "Math3D_PointDistToLine2D", - "func_80179678": "Math3D_PlaneVsLineSegClosestPoint", - "Math3D_DistanceSquared": "Math3D_Vec3fDistSq", - "Math3D_NormalVector": "Math3D_SurfaceNorm", - "func_8017A954": "Math3D_PointRelativeToCubeFaces", - "func_8017AA0C": "Math3D_PointRelativeToCubeEdges", - "func_8017ABBC": "Math3D_PointRelativeToCubeVertices", - "func_8017AD38": "Math3D_LineVsCube", - "Math3D_NormalizedDistanceFromPlane": "Math3D_UDistPlaneToPos", - "Math3D_NormalizedSignedDistanceFromPlane": "Math3D_DistPlaneToPos", - "func_8017BAD0": "Math3D_TriChkPointParaYDist", - "func_8017BE30": "Math3D_TriChkPointParaYIntersectDist", - "func_8017BEE0": "Math3D_TriChkPointParaYIntersectInsideTri", - "func_8017C008": "Math3D_TriChkLineSegParaYIntersect", - "func_8017C494": "Math3D_TriChkPointParaYIntersectInsideTri2", - "func_8017C540": "Math3D_TriChkPointParaXDist", - "func_8017C850": "Math3D_TriChkPointParaXIntersect", - "func_8017C980": "Math3D_TriChkLineSegParaXIntersect", - "func_8017CB7C": "Math3D_TriChkLineSegParaZDist", - "func_8017CEF0": "Math3D_TriChkPointParaZIntersect", - "func_8017D020": "Math3D_TriChkLineSegParaZIntersect", - "Math3D_ColSphereLineSeg": "Math3D_LineVsSph", - "Math3D_ColSphereSphere(": "Math3D_SphVsSph(", - "func_8017F9C0": "Math3D_XZInSphere", - "func_8017FA34": "Math3D_XYInSphere", - "func_8017FAA8": "Math3D_YZInSphere", - "func_8017D2FC": "Math3D_LineSegVsPlane", - - "Math3D_CrossProduct": "Math3D_Vec3f_Cross", - "Math3D_Parallel": "Math3D_Cos", - "Math3D_AngleBetweenVectors": "Math3D_CosOut", - "func_80179A44": "Math3D_LineClosestToPoint", - - "Math3D_XZLengthSquared": "Math3D_Dist1DSq", - "Math3D_XZLength": "Math3D_Dist1D", - "Math3D_XZDistanceSquared": "Math3D_Dist2DSq", - "Math3D_XZDistance": "Math3D_Dist2D", - "Math3D_LengthSquared": "Math3D_Vec3fMagnitudeSq", - "Math3D_Distance": "Math3D_Vec3f_DistXYZ", - "Math3D_DistanceS": "Math3D_DistXYZ16toF", - "func_80179798": "Math3D_LineVsLineClosestTwoPoints", - - "func_800DFB14": "Camera_ChangeDataIdx", - "func_800DFC68": "Camera_GetInputDirYaw", - "func_800DFCB4": "Camera_GetCamDirPitch", - "func_800DFCDC": "Camera_GetCamDirYaw", - "func_800E0308": "Camera_SetTargetActor", - "func_800E031C": "Camera_GetWaterYPos", - "func_800E02AC": "Camera_SetToTrackActor", - "func_801694DC": "Play_CreateSubCamera", - "Play_GetActiveCameraIndex": "Play_GetActiveCamId", - "func_80169590": "Play_CameraChangeStatus", - "func_80169600": "Play_ClearCamera", - "func_80169668": "Play_ClearAllSubCameras", - "func_8016981C": "Play_CameraSetAtEyeUp", - "func_80169940": "Play_CameraSetFov", - "func_80169988": "Play_CameraSetRoll", - "func_801699D4": "Play_CopyCamera", - "func_80169AC0": "Play_CameraChangeSetting", - "func_80169BC4": "Play_CameraGetUID", - "func_80169C64": "Play_GetCsCamDataSetting", - "func_80169C84": "Play_GetCsCamDataVec3s", - "convert_scene_number_among_shared_scenes": "Play_GetOriginalSceneNumber", - "func_80169D40": "Play_SaveCycleSceneFlags", - "func_80169DCC": "Play_SetRespawnData", - "func_80169E6C": "Play_SetupRespawnPoint", - "func_8016A0AC": "Play_IsUnderwater", - "func_801690CC": "Play_InCsMode", - "func_8013A7C0": "SubS_FindDoor", - "func_8013E640": "SubS_FindActorCustom", - "func_ActorCategoryIterateById": "SubS_FindActor", - "func_8013BB7C": "SubS_FindNearestActor", - "func_800A81F0": "EffectBlure_AddVertex", - "func_800A8514": "EffectBlure_AddSpace", - "Effect_GetParams": "Effect_GetByIndex", - "func_800F5A8C": "Environment_LerpWeight", - "func_801A3F54": "Audio_SetCutsceneFlag", - "func_800EA0D4": "Cutscene_Start", - "func_800EA0EC": "Cutscene_End", - "func_800EDE34": "Cutscene_ActorTranslate", - "func_800EDF24": "Cutscene_ActorTranslateAndYaw", - "func_800EDF78": "Cutscene_ActorTranslateAndYawSmooth", - "func_800EE0CC": "Cutscene_ActorTranslateXZAndYawSmooth", - "func_800EE1D8": "Cutscene_GetSceneSetupIndex", - "func_800EE200": "Cutscene_GetActorActionIndex", - "func_800EE29C": "Cutscene_CheckActorAction", - "func_800EE2F4": "Cutscene_IsPlaying", - "func_801343C0": "SkelAnime_DrawTransformFlexOpa", - "func_80134148": "SkelAnime_DrawTransformFlexLimbOpa", - "func_8013AB00": "SubS_DrawTransformFlex", - "func_8013A860": "SubS_DrawTransformFlexLimb", - "func_8013BC6C": "SubS_ChangeAnimationByInfoS", - "func_8013E1C8": "SubS_ChangeAnimationBySpeedInfo", - "func_8013D9C8": "SubS_FillLimbRotTables", - "func_80114E90": "Interface_HasEmptyBottle", - "func_80114F2C": "Interface_HasItemInBottle", - "func_80123C90": "Player_SetEquipmentData", - "func_800BE680": "Actor_DrawDamageEffects", - "func_8013E2D4": "SubS_StartActorCutscene", - "func_8013E3B8": "SubS_FillCutscenesList", - "func_8013AED4": "SubS_UpdateFlags", - "func_8013D8DC": "SubS_IsObjectLoaded", - "func_8013D924": "SubS_GetObjectIndex", - "func_8013D5E8": "SubS_AngleDiffLessEqual", - "func_8012F22C": "Inventory_GetSkullTokenCount", - "func_8013DCE0": "SubS_ActorPathing_Init", - "func_8013DE04": "SubS_ActorPathing_Update", - "func_8013DF3C": "SubS_ActorPathing_ComputePointInfo", - "func_8013E054": "SubS_ActorPathing_MoveWithGravity", - "func_8013E07C": "SubS_ActorPathing_MoveWithoutGravityReverse", - "func_8013E0A4": "SubS_ActorPathing_SetNextPoint", - "func_8013BB34": "SubS_GetAdditionalPath", - "func_8013BD40": "SubS_HasReachedPoint", - "func_8013BEDC": "SubS_GetDayDependentPath", - "func_8013C8B8": "SubS_CopyPointFromPathCheckBounds", - "func_8013D648": "SubS_GetPathByIndex", - "func_8013D68C": "SubS_CopyPointFromPath", - "func_8013D720": "SubS_GetDistSqAndOrientPoints", - "func_8013D768": "SubS_MoveActorToPoint", - "func_8013D83C": "SubS_GetDistSqAndOrientPath", - "func_8013DB90": "SubS_IsFloorAbove", - "func_8013DC40": "SubS_CopyPointFromPathList", - "func_8013DCCC": "SubS_GetPathCount", - - "func_80147624": "Message_ShouldAdvance", - "func_80147734": "Message_ShouldAdvanceSilent", - "func_80149EBC": "Message_FindMessage", - "func_8014CC14": "Message_LoadChar", - "func_801518B0": "Message_StartTextbox", - "func_801588D0": "Message_FindMessageNES", - "func_80158988": "Message_LoadCharNES", - "func_80158A24": "Message_LoadPluralRupeesNES", - "func_80158C04": "Message_LoadLocalizedRupeesNES", - "func_80158D98": "Message_LoadRupeesNES", - "func_80158FB0": "Message_LoadTimeNES", - "func_8015926C": "Message_LoadAreaTextNES", - "func_8015E750": "Message_FindCreditsMessage", - - - # Structs members - "skelAnime.unk03": "skelAnime.taper", - "skelAnime.animCurrentSeg": "skelAnime.animation", - "skelAnime.initialFrame": "skelAnime.startFrame", - "skelAnime.animFrameCount": "skelAnime.endFrame", - "skelAnime.totalFrames": "skelAnime.animLength", - "skelAnime.animCurrentFrame": "skelAnime.curFrame", - "skelAnime.animPlaybackSpeed": "skelAnime.playSpeed", - "skelAnime.limbDrawTbl": "skelAnime.jointTable", - "skelAnime.transitionDrawTbl": "skelAnime.morphTable", - "skelAnime.transCurrentFrame": "skelAnime.morphWeight", - "skelAnime.transitionStep": "skelAnime.morphRate", - "skelAnime.animUpdate": "skelAnime.update", - "skelAnime.flags": "skelAnime.moveFlags", - "skelAnime.prevFrameRot": "skelAnime.prevRot", - "skelAnime.prevFramePos": "skelAnime.prevTransl", - "skelAnime.unk3E": "skelAnime.baseTransl", - - "actor.minVelocityY": "actor.terminalVelocity", - "actor.yDistToWater": "actor.depthInWater", - "actor.yDistToPlayer": "actor.playerHeightRel", - "gSaveContext.weekEventReg": "gSaveContext.save.weekEventReg", - "gSaveContext.playerForm": "gSaveContext.save.playerForm", - "gSaveContext.day": "gSaveContext.save.day", - "gSaveContext.isNight": "gSaveContext.save.isNight", - "gSaveContext.naviTimer": "gSaveContext.save.playerData.tatlTimer", - "gSaveContext.tatlTimer": "gSaveContext.save.playerData.tatlTimer", - "gSaveContext.rupees": "gSaveContext.save.playerData.rupees", - "gSaveContext.magicAcquired": "gSaveContext.save.playerData.magicAcquired", - "gSaveContext.doubleMagic": "gSaveContext.save.playerData.doubleMagic", - "gSaveContext.doubleDefense": "gSaveContext.save.playerData.doubleDefense", - "gSaveContext.playerName": "gSaveContext.save.playerData.playerName", - "gSaveContext.inventory": "gSaveContext.save.inventory", - "gSaveContext.equippedMask": "gSaveContext.save.equippedMask", - "gSaveContext.entranceIndex": "gSaveContext.save.entranceIndex", - "gSaveContext.time": "gSaveContext.save.time", - "gSaveContext.unk_14": "gSaveContext.save.daySpeed", - "gSaveContext.unk_FE6": "gSaveContext.save.bombersCaughtNum", - "gSaveContext.unk_FE7": "gSaveContext.save.bombersCaughtOrder", - "gSaveContext.linkAge": "gSaveContext.save.linkAge", - "gSaveContext.dekuPlaygroundHighScores": "gSaveContext.save.dekuPlaygroundHighScores", - "gSaveContext.lotteryCodeGuess": "gSaveContext.save.lotteryCodeGuess", - "gSaveContext.permanentSceneFlags": "gSaveContext.save.permanentSceneFlags", - "gSaveContext.bomberCode": "gSaveContext.save.bomberCode", - "gSaveContext.skullTokenCount": "gSaveContext.save.skullTokenCount", - "player->unk_A87": "player->exchangeItemId", - "player->leftHandActor": "player->heldActor", - "player->unk_384": "player->getItemId", - "player->unk_386": "player->getItemDirection", - "player->unk_388": "player->interactRangeActor", - "player->unk_38C": "player->mountSide", - "player->unk_394": "player->csMode", - "csCtx.npcActions": "csCtx.actorActions", - "csCtx->npcActions": "csCtx->actorActions", - "csCtx.unk_12": "csCtx.currentCsIndex", - "globalCtx->mf_187FC": "globalCtx->billboardMtxF", - "globalCtx->projectionMatrix": "globalCtx->viewProjectionMtxF", - "globalCtx->actorCtx.actorList[": "globalCtx->actorCtx.actorLists[", - "globalCtx->envCtx.unk_8C": "globalCtx->envCtx.lightSettings", - "globalCtx->envCtx.unk_E5": "globalCtx->envCtx.fillScreen", - "globalCtx->envCtx.unk_E6": "globalCtx->envCtx.screenFillColor", - "globalCtx->envCtx.unk_C3": "globalCtx->envCtx.lightSettingOverride", - "globalCtx->envCtx.unk_DC": "globalCtx->envCtx.lightBlend", - "gSaveContext.unk_1016": "gSaveContext.jinxTimer", - "gSaveContext.unk_3F58": "gSaveContext.sunsSongState", - "globalCtx->msgCtx.unk1202A": "globalCtx->msgCtx.ocarinaMode", - "globalCtx->msgCtx.unk1202C": "globalCtx->msgCtx.ocarinaAction", - "globalCtx->msgCtx.unk11F22": "globalCtx->msgCtx.msgMode", - "globalCtx->msgCtx.unk11F04": "globalCtx->msgCtx.currentTextId", - - "D_801D15B0" : "gZeroVec3f", - "D_801D15BC" : "gZeroVec3s", - "D_801D1DE0" : "gIdentityMtx", - "D_801D1E20" : "gIdentityMtxF", - "D_04020658" : "gameplay_keep_Anim_020658", - "D_04022B28" : "gDoorSkel", - "D_04023100" : "gDoorCol", - - # Structs - "ActorAnimationEntry": "AnimationInfo", - "ActorAnimationEntryS": "AnimationInfoS", - "struct_80B8E1A8": "AnimationSpeedInfo", - - # Macros - "CUR_EQUIP_VALUE_VOID": "GET_CUR_EQUIP_VALUE", - "CUR_UPG_VALUE_VOID": "GET_CUR_UPG_VALUE", - "ICHAIN_F32_DIV1000(minVelocityY,": "ICHAIN_F32_DIV1000(terminalVelocity,", - "ICHAIN_F32(minVelocityY,": "ICHAIN_F32(terminalVelocity,", -} - -def replace_anim(file): - with open(file, 'r', encoding='utf-8') as infile: - srcdata = infile.read() - - funcs = list(animdict.keys()) - fixes = 0 - for func in funcs: - newfunc = animdict.get(func) - if(newfunc is None): - print("How did this happen?") - return -1 - if(func in srcdata): - fixes += 1 - print(func) - srcdata = srcdata.replace(func, newfunc) - - if(fixes > 0): - print('Changed', fixes,'entr' + ('y' if fixes == 1 else 'ies') + ' in',file) - with open(file, 'w', encoding = 'utf-8', newline = '\n') as outfile: - outfile.write(srcdata) - return 1 - -def replace_anim_all(repo): - for subdir, dirs, files in os.walk(repo + os.sep + 'src'): - for filename in files: - if(filename.endswith('.c')): - file = subdir + os.sep + filename - replace_anim(file) - - for subdir, dirs, files in os.walk(repo + os.sep + 'asm'): - for filename in files: - if(filename.endswith('.s')): - file = subdir + os.sep + filename - replace_anim(file) - - for subdir, dirs, files in os.walk(repo + os.sep + 'data'): - for filename in files: - if(filename.endswith('.s')): - file = subdir + os.sep + filename - replace_anim(file) - - for subdir, dirs, files in os.walk(repo + os.sep + 'docs'): - for filename in files: - if(filename.endswith('.md')): - file = subdir + os.sep + filename - replace_anim(file) - - for subdir, dirs, files in os.walk(repo + os.sep + 'tools' + os.sep + 'sizes'): - for filename in files: - if(filename.endswith('.csv')): - file = subdir + os.sep + filename - replace_anim(file) - return 1 - -def dictSanityCheck(): - keys = animdict.keys() - values = animdict.values() - for k in keys: - if k in values: - print(f"Key '{k}' found in values") - print(f"This would produce unintended renames") - print(f"Fix this by removing said key from the dictionary") - exit(-1) - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Update to the new animation names') - parser.add_argument('file', help="source file to be processed. use . to process the whole repo", default = None) - - args = parser.parse_args() - - dictSanityCheck() - - if(args.file == '.'): - replace_anim_all(os.curdir) - else: - replace_anim(args.file) From b1e87f7838aeec12a83251a89b486b993cfec0f0 Mon Sep 17 00:00:00 2001 From: angie Date: Tue, 23 May 2023 23:14:00 -0400 Subject: [PATCH 13/29] fix merge --- include/z64camera.h | 4 ++-- src/code/z_camera.c | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/z64camera.h b/include/z64camera.h index 54cf748ac..7232b3da2 100644 --- a/include/z64camera.h +++ b/include/z64camera.h @@ -2,6 +2,7 @@ #define Z64CAMERA_H #include "ultra64.h" +#include "z64math.h" #include "z64save.h" // these two angle conversion macros are slightly inaccurate @@ -1189,8 +1190,7 @@ typedef struct { /* 0x00 */ Vec3f unk_00; /* 0x0C */ Vec3f unk_0C; /* 0x18 */ f32 unk_18; - /* 0x1C */ Vec3f unk_1C; - /* 0x28 */ Vec3f unk_28; + /* 0x1C */ Linef unk_1C; /* 0x34 */ Vec3s unk_34; /* 0x3A */ s16 unk_3A; /* 0x3C */ s16 timer; diff --git a/src/code/z_camera.c b/src/code/z_camera.c index ea600b30e..c0bb26430 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -1255,7 +1255,7 @@ s32 func_800CD44C(Camera* camera, VecGeo* diffGeo, CameraCollision* camEyeCollis // different bgIds for at->eye[Next] and eye[Next]->at ret = 3; } else { - cosEyeAt = Math3D_Parallel(&camEyeCollision->norm, &camAtCollision->norm); + cosEyeAt = Math3D_Cos(&camEyeCollision->norm, &camAtCollision->norm); if (cosEyeAt < -0.5f) { ret = 6; } else if ((cosEyeAt > 0.5f) || (checkEye & 2)) { @@ -1860,7 +1860,7 @@ void Camera_CalcDefaultSwing(Camera* camera, VecGeo* arg1, VecGeo* arg2, f32 arg } else if (swing->atEyeColChk.norm.y > 0.50f) { swing->unk_64 = 0; } else { - Math3D_AngleBetweenVectors(&camera->unk_0F0, &swing->eyeAtColChk.norm, &sp88); + Math3D_CosOut(&camera->unk_0F0, &swing->eyeAtColChk.norm, &sp88); if (sp88 > 0.0f) { swing->unk_64 = 0; } @@ -5565,8 +5565,8 @@ s32 Camera_Unique0(Camera* camera) { switch (camera->animState) { case 0: bgCamFuncData = (BgCamFuncData*)Camera_GetBgCamOrActorCsCamFuncData(camera, camera->bgCamIndex); - Camera_Vec3sToVec3f(&rwData->unk_1C, &bgCamFuncData->pos); - camera->eye = camera->eyeNext = rwData->unk_1C; + Camera_Vec3sToVec3f(&rwData->unk_1C.a, &bgCamFuncData->pos); + camera->eye = camera->eyeNext = rwData->unk_1C.a; rwData->unk_34 = bgCamFuncData->rot; temp_v1 = bgCamFuncData->fov; @@ -5597,7 +5597,7 @@ s32 Camera_Unique0(Camera* camera) { } rwData->unk_3A = camera->focalActor->world.rot.y; rwData->unk_3E = 0; - camera->eye = camera->eyeNext = rwData->unk_1C; + camera->eye = camera->eyeNext = rwData->unk_1C.a; Camera_UnsetStateFlag(camera, CAM_STATE_2); camera->animState++; // fallthrough @@ -5605,8 +5605,8 @@ s32 Camera_Unique0(Camera* camera) { sp84.r = OLib_Vec3fDist(&sp8C, &camera->eye); sp84.yaw = rwData->unk_34.y; sp84.pitch = -rwData->unk_34.x; - OLib_VecGeoToVec3f(&rwData->unk_28, &sp84); - func_80179A44(&rwData->unk_1C, focalActorPosRot, &rwData->unk_0C); + OLib_VecGeoToVec3f(&rwData->unk_1C.b, &sp84); + Math3D_LineClosestToPoint(&rwData->unk_1C, &focalActorPosRot->pos, &rwData->unk_0C); camera->at = rwData->unk_0C; if (player->stateFlags1 & PLAYER_STATE1_20000000) { From 61f71acccd96f0f6dca1feadfdf89e4b076cedc2 Mon Sep 17 00:00:00 2001 From: angie Date: Wed, 24 May 2023 10:14:19 -0400 Subject: [PATCH 14/29] Apply renames --- include/z64math.h | 88 ++++++------- src/code/sys_math3d.c | 71 ++-------- src/code/z_bgcheck.c | 12 +- src/code/z_camera.c | 4 +- src/code/z_collision_check.c | 124 +++++++++--------- src/code/z_eff_tire_mark.c | 4 +- src/code/z_sub_s.c | 2 +- .../ovl_En_Akindonuts/z_en_akindonuts.c | 2 +- .../actors/ovl_En_Bubble/z_en_bubble.c | 2 +- src/overlays/actors/ovl_En_Dg/z_en_dg.c | 2 +- src/overlays/actors/ovl_En_Gg2/z_en_gg2.c | 2 +- src/overlays/actors/ovl_En_Gk/z_en_gk.c | 2 +- src/overlays/actors/ovl_En_Horse/z_en_horse.c | 4 +- .../z_en_horse_game_check.c | 18 +-- src/overlays/actors/ovl_En_Jg/z_en_jg.c | 2 +- .../actors/ovl_En_Mt_tag/z_en_mt_tag.c | 6 +- .../actors/ovl_En_Mushi2/z_en_mushi2.c | 8 +- src/overlays/actors/ovl_En_Rg/z_en_rg.c | 2 +- .../actors/ovl_En_Ruppecrow/z_en_ruppecrow.c | 4 +- .../actors/ovl_En_Scopecrow/z_en_scopecrow.c | 2 +- .../actors/ovl_En_Scopenuts/z_en_scopenuts.c | 2 +- .../actors/ovl_En_Sellnuts/z_en_sellnuts.c | 2 +- .../actors/ovl_En_Suttari/z_en_suttari.c | 4 +- src/overlays/actors/ovl_En_Trt2/z_en_trt2.c | 2 +- .../actors/ovl_En_Tru_Mt/z_en_tru_mt.c | 2 +- src/overlays/actors/ovl_Obj_Um/z_obj_um.c | 6 +- tools/disasm/functions.txt | 88 ++++++------- tools/namefixer.py | 60 +++++++-- tools/sizes/code_functions.csv | 88 ++++++------- 29 files changed, 305 insertions(+), 310 deletions(-) diff --git a/include/z64math.h b/include/z64math.h index 5bf72296f..7e1d990b5 100644 --- a/include/z64math.h +++ b/include/z64math.h @@ -222,17 +222,17 @@ f32 Math_Atan2F_XY(f32 x, f32 y); f32 Math3D_Normalize(Vec3f* vec); s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* closestPoint); -s32 Math3D_LineVsLineClosestTwoPoints(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, Vec3f* lineAClosestToB, Vec3f* lineBClosestToA); +s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, Vec3f* lineAClosestToB, Vec3f* lineBClosestToA); f32 Math3D_LineClosestToPoint(Linef* line, Vec3f* pos, Vec3f* closestPoint); -void func_80179B34(float planeAAxis1Norm, f32 planeAAxis2Norm, f32 planeBAxis1Norm, f32 planeBAxis2Norm, f32 axis3Direction, f32 planeADist, f32 planeBDist, float* axis1Point, float* axis2Point); -s32 func_80179B94(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, InfiniteLine* intersect); -// void func_80179D74(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); -void Math3D_ScaleAndAdd(Vec3f* v0, Vec3f* dir, f32 scale, Vec3f* ret); -void Math3D_Lerp(Vec3f* v0, Vec3f* v1, f32 ratio, Vec3f* ret); +void Math3D_FindPointOnPlaneIntersect(float planeAAxis1Norm, f32 planeAAxis2Norm, f32 planeBAxis1Norm, f32 planeBAxis2Norm, f32 axis3Direction, f32 planeADist, f32 planeBDist, float* axis1Point, float* axis2Point); +s32 Math3D_PlaneVsPlaneNewLine(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, InfiniteLine* intersect); +// void Math3D_PlaneVsPlaneVsLineClosestPoint(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); +void Math3D_PointOnDirectedLine(Vec3f* v0, Vec3f* dir, f32 scale, Vec3f* ret); +void Math3D_LineSplitRatio(Vec3f* v0, Vec3f* v1, f32 ratio, Vec3f* ret); f32 Math3D_Cos(Vec3f* a, Vec3f* b); s32 Math3D_CosOut(Vec3f* a, Vec3f* b, f32* dst); -void func_80179F64(Vec3f* vec, Vec3f* normal, Vec3f* reflVec); -s32 Math3D_XZBoundCheck(f32 upperLeftX, f32 lowerRightX, f32 upperLeftY, f32 lowerRightY, f32 x, f32 y); +void Math3D_Vec3fReflect(Vec3f* vec, Vec3f* normal, Vec3f* reflVec); +s32 Math3D_PointInSquare2D(f32 upperLeftX, f32 lowerRightX, f32 upperLeftY, f32 lowerRightY, f32 x, f32 y); // void func_8017A09C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); // void func_8017A1D0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); s32 func_8017A304(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 arg5); @@ -256,59 +256,59 @@ s32 Math3D_PointRelativeToCubeEdges(Vec3f* point, Vec3f* min, Vec3f* max); s32 Math3D_PointRelativeToCubeVertices(Vec3f* point, Vec3f* min, Vec3f* max); s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b); s32 Math3D_LineVsCubeShort(Vec3s* min, Vec3s* max, Vec3s* a, Vec3s* b); -void func_8017B7F8(Vec3f* pointOnPlane, s16 angle, f32* a, f32* c, f32* d); -void Math3D_UnitNormalVector(Vec3f* va, Vec3f* vb, Vec3f* vc, f32* nx, f32* ny, f32* nz, f32* originDist); -f32 Math3D_SignedDistanceFromPlane(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* pointOnPlane); -f32 func_8017B9D8(Plane* plane, Vec3f* pointOnPlane); +void Math3D_RotateXZPlane(Vec3f* pointOnPlane, s16 angle, f32* a, f32* c, f32* d); +void Math3D_DefPlane(Vec3f* va, Vec3f* vb, Vec3f* vc, f32* nx, f32* ny, f32* nz, f32* originDist); +f32 Math3D_PlaneF(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* pointOnPlane); +f32 Math3D_Plane(Plane* plane, Vec3f* pointOnPlane); f32 Math3D_UDistPlaneToPos(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* p); f32 Math3D_DistPlaneToPos(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* p); -s32 Math3D_TriChkPointParaYDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f32 detMax, f32 chkDist, f32 ny); -// void func_8017BD98(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void func_8017BDE0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); +s32 Math3D_TriChkPointParaYImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f32 detMax, f32 chkDist, f32 ny); +// void Math3D_TriChkPointParaYDeterminate(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); +// void Math3D_TriChkPointParaYSlopedY(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); s32 Math3D_TriChkPointParaYIntersectDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 chkDist); s32 Math3D_TriChkPointParaYIntersectInsideTri(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 chkDist); -// void func_8017BF8C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); +// void Math3D_TriChkPointParaY(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); s32 Math3D_TriChkLineSegParaYIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 y0, f32 y1); -// void func_8017C17C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void func_8017C1F0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); -s32 Math3D_TriChkPointParaYIntersectInsideTri2(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 chkDist); -s32 Math3D_TriChkPointParaXDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 detMax, f32 chkDist, f32 ny); -// void func_8017C808(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); +// void Math3D_TriChkPointParaYDist(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); +// void Math3D_TriChkPointParaYImplNoCheckRange(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); +s32 Math3D_TriChkPointParaYNoRangeCheckIntersectInsideTri(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 chkDist); +s32 Math3D_TriChkPointParaXImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 detMax, f32 chkDist, f32 ny); +// void Math3D_TriChkPointParaXDeterminate(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); s32 Math3D_TriChkPointParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 y, f32 z, f32* xIntersect); -// void func_8017C904(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); +// void Math3D_TriChkPointParaX(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); s32 Math3D_TriChkLineSegParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 y, f32 z, f32* xIntersect, f32 x0, f32 x1); -// void func_8017CB08(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -s32 Math3D_TriChkLineSegParaZDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 x, f32 y, f32 detMax, f32 chkDist, f32 nz); -// void func_8017CEA8(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); +// void Math3D_TriChkLineSegParaXDist(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); +s32 Math3D_TriChkPointParaZImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 x, f32 y, f32 detMax, f32 chkDist, f32 nz); +// void Math3D_TriChkPointParaZDeterminate(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); s32 Math3D_TriChkPointParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, f32 y, f32* zIntersect); -// void func_8017CFA4(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); +// void Math3D_TriChkPointParaZ(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, f32 y, f32* zIntersect, f32 z0, f32 z1); -// void func_8017D1AC(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void func_8017D220(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); +// void Math3D_TriChkLineSegParaZDist(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); +// void Math3D_LineSegFindPlaneIntersect(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); s32 Math3D_LineSegVsPlane(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersect, s32 fromFront); -s32 func_8017D404(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersect, s32 fromFront) ; -void Math3D_TriSetCoords(TriNorm* tri, Vec3f* va, Vec3f* vb, Vec3f* vc); -s32 Math3D_IsPointInSphere(Sphere16* sphere, Vec3f* point); +s32 Math3D_TriLineIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersect, s32 fromFront) ; +void Math3D_TriNorm(TriNorm* tri, Vec3f* va, Vec3f* vb, Vec3f* vc); +s32 Math3D_PointInSph(Sphere16* sphere, Vec3f* point); s32 Math3D_PointDistToLine2D(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* perpXOut, f32* perpYOut, f32* lineLenSq); // returns boolean s32 func_8017D7C0(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* lineLenSq); s32 func_8017D814(f32 x0, f32 y0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); s32 func_8017D91C(f32 y0, f32 z0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); s32 func_8017DA24(f32 z0, f32 x0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); s32 Math3D_LineVsSph(Sphere16* sphere, Linef* line); -void func_8017DD34(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoint); -s32 Math3D_ColSphereTri(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoint); -s32 func_8017E294(Cylinder16* cyl, Vec3f* point); -s32 func_8017E350(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersectA, Vec3f* intersectB); -s32 Math3D_ColCylinderTri(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect); -// void func_8017F1A0(void); +void Math3D_GetSphVsTriIntersectPoint(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoint); +s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoint); +s32 Math3D_PointInCyl(Cylinder16* cyl, Vec3f* point); +s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersectA, Vec3f* intersectB); +s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect); +// void Math3D_CylVsTri(void); s32 Math3D_SphVsSph(Sphere16* sphereA, Sphere16* sphereB); -s32 Math3D_ColSphereSphereIntersect(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize); -s32 Math3D_ColSphereSphereIntersectAndDistance(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize, f32* centerDist); -s32 Math3D_ColSphereCylinderDistance(Sphere16* sph, Cylinder16* cyl, f32* overlapSize); -s32 Math3D_ColSphereCylinderDistanceAndAmount(Sphere16* sph, Cylinder16* cyl, f32* overlapSize, f32* centerDist); -s32 Math3D_ColCylinderCylinderAmount(Cylinder16* ca, Cylinder16* cb, f32* deadSpace); -s32 Math3D_ColCylinderCylinderAmountAndDistance(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32* xzDist); -s32 Math3d_ColTriTri(TriNorm* ta, TriNorm* tb, Vec3f* intersect); +s32 Math3D_SphVsSphOverlap(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize); +s32 Math3D_SphVsSphOverlapCenter(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize, f32* centerDist); +s32 Math3D_SphVsCylOverlapDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize); +s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize, f32* centerDist); +s32 Math3D_CylOutsideCyl(Cylinder16* ca, Cylinder16* cb, f32* deadSpace); +s32 Math3D_CylOutsideCylDist(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32* xzDist); +s32 Math3D_TriVsTriIntersect(TriNorm* ta, TriNorm* tb, Vec3f* intersect); s32 Math3D_XZInSphere(Sphere16* sphere, f32 x, f32 z); s32 Math3D_XYInSphere(Sphere16* sphere, f32 x, f32 y); s32 Math3D_YZInSphere(Sphere16* sphere, f32 y, f32 z); diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index f3234a053..8a8656d4e 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -2,56 +2,6 @@ #include "libc/stdbool.h" #include "libc/math.h" -#define Math3D_FindPointOnPlaneIntersect func_80179B34 -#define Math3D_PlaneVsPlaneNewLine func_80179B94 -#define Math3D_LineSegMakePerpLineSeg Math3D_LineVsLineClosestTwoPoints -#define Math3D_Plane func_8017B9D8 -#define Math3D_TriLineIntersect func_8017D404 -#define Math3D_CylOutsideCylDist Math3D_ColCylinderCylinderAmountAndDistance -#define Math3D_CylOutsideCyl Math3D_ColCylinderCylinderAmount -#define Math3D_SphVsCylOverlapCenterDist Math3D_ColSphereCylinderDistanceAndAmount -#define Math3D_CylTriVsIntersect Math3D_ColCylinderTri -#define Math3D_CylVsTri func_8017F1A0 -#define Math3D_SphVsSph Math3D_SphVsSph -#define Math3D_SphVsSphOverlap Math3D_ColSphereSphereIntersect -#define Math3D_SphVsSphOverlapCenter Math3D_ColSphereSphereIntersectAndDistance -#define Math3D_SphVsCylOverlapDist Math3D_ColSphereCylinderDistance -#define Math3D_CylVsLineSeg func_8017E350 -#define Math3D_TriVsSphIntersect Math3D_ColSphereTri -#define Math3D_PointOnDirectedLine Math3D_ScaleAndAdd -#define Math3D_LineSplitRatio Math3D_Lerp -#define Math3D_PlaneVsPlaneVsLineClosestPoint func_80179D74 -#define Math3D_PointInCyl func_8017E294 -#define Math3D_Vec3fReflect func_80179F64 -#define Math3D_PointInSquare2D Math3D_XZBoundCheck -#define Math3D_RotateXZPlane func_8017B7F8 -#define Math3D_DefPlane Math3D_UnitNormalVector -#define Math3D_PlaneF Math3D_SignedDistanceFromPlane -#define Math3D_Plane func_8017B9D8 -#define Math3D_DistPlaneToPos Math3D_DistPlaneToPos -#define Math3D_TriChkPointParaYImpl Math3D_TriChkPointParaYDist -#define Math3D_TriChkPointParaYDeterminate func_8017BD98 -#define Math3D_TriChkPointParaYSlopedY func_8017BDE0 -#define Math3D_TriChkPointParaY func_8017BF8C -#define Math3D_TriChkPointParaYDist_ func_8017C17C -#define Math3D_TriChkPointParaYImplNoCheckRange func_8017C1F0 -#define Math3D_TriChkPointParaYNoRangeCheckIntersectInsideTri Math3D_TriChkPointParaYIntersectInsideTri2 -#define Math3D_TriChkPointParaXImpl Math3D_TriChkPointParaXDist -#define Math3D_TriChkPointParaXDeterminate func_8017C808 -#define Math3D_TriChkPointParaX func_8017C904 -#define Math3D_TriChkLineSegParaXDist func_8017CB08 -#define Math3D_TriChkPointParaZImpl Math3D_TriChkLineSegParaZDist -#define Math3D_TriChkPointParaZDeterminate func_8017CEA8 -#define Math3D_TriChkPointParaZ func_8017CFA4 -#define Math3D_TriChkLineSegParaZDist_ func_8017D1AC -#define Math3D_LineSegFindPlaneIntersect func_8017D220 -#define Math3D_TriLineIntersect func_8017D404 -#define Math3D_TriNorm Math3D_TriSetCoords -#define Math3D_PointInSph Math3D_IsPointInSphere -#define Math3D_PointDistToLine2D_ func_8017D814 -#define Math3D_TriVsTriIntersect Math3d_ColTriTri -#define Math3D_GetSphVsTriIntersectPoint func_8017DD34 - f32 Math3D_Normalize(Vec3f* vec) { f32 magnitude = Math3D_Vec3fMagnitude(vec); @@ -100,7 +50,7 @@ s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 /** * Finds the two points on lines A and B where the lines are closest together. */ -s32 Math3D_LineVsLineClosestTwoPoints(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, +s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, Vec3f* lineAClosestToB, Vec3f* lineBClosestToA) { f32 sqMag; f32 scaleB; @@ -246,7 +196,7 @@ s32 Math3D_PlaneVsPlaneVsLineClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, return true; } #else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_80179D74.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PlaneVsPlaneVsLineClosestPoint.s") #endif /** @@ -974,7 +924,7 @@ void Math3D_DefPlane(Vec3f* va, Vec3f* vb, Vec3f* vc, f32* nx, f32* ny, f32* nz, } } #else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_UnitNormalVector.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_DefPlane.s") #endif f32 Math3D_PlaneF(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* pointOnPlane) { @@ -1526,7 +1476,8 @@ s32 func_8017D7C0(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* lineLenSq return Math3D_PointDistToLine2D(x0, y0, x1, y1, x2, y2, &perpX, &perpY, lineLenSq); } -s32 Math3D_PointDistToLine2D_(f32 x0, f32 y0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { +// Math3D_PointDistToLine2D_ +s32 func_8017D814(f32 x0, f32 y0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { f32 perpendicularRatio; f32 xDiff = p2->x - p1->x; f32 yDiff = p2->y - p1->y; @@ -1672,7 +1623,7 @@ void Math3D_GetSphVsTriIntersectPoint(Sphere16* sphere, TriNorm* tri, Vec3f* int Math3D_LineSplitRatio(&sphereCenter, &v0v1Center, splitRatio, intersectPoint); } #else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017DD34.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_GetSphVsTriIntersectPoint.s") #endif #ifdef NON_MATCHING @@ -1762,7 +1713,7 @@ s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoi return false; } #else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColSphereTri.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriVsSphIntersect.s") #endif s32 Math3D_PointInCyl(Cylinder16* cyl, Vec3f* point) { @@ -1964,7 +1915,7 @@ s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, V return count; } #else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017E350.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_CylVsLineSeg.s") #endif #ifdef NON_MATCHING @@ -2062,7 +2013,7 @@ s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect) { return false; } #else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColCylinderTri.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_CylTriVsIntersect.s") #endif s32 Math3D_CylVsTri(Cylinder16* cyl, TriNorm* tri) { @@ -2153,7 +2104,7 @@ s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overla return false; } #else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColSphereCylinderDistanceAndAmount.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_SphVsCylOverlapCenterDist.s") #endif s32 Math3D_CylOutsideCyl(Cylinder16* ca, Cylinder16* cb, f32* deadSpace) { @@ -2195,7 +2146,7 @@ s32 Math3D_CylOutsideCylDist(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32 return true; } #else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_ColCylinderCylinderAmountAndDistance.s") +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_CylOutsideCylDist.s") #endif s32 Math3D_TriVsTriIntersect(TriNorm* ta, TriNorm* tb, Vec3f* intersect) { diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c index 2ce46459e..c35842022 100644 --- a/src/code/z_bgcheck.c +++ b/src/code/z_bgcheck.c @@ -363,7 +363,7 @@ s32 CollisionPoly_CheckYIntersect(CollisionPoly* poly, Vec3s* vtxList, f32 x, f3 nx = COLPOLY_GET_NORMAL(poly->normal.x); ny = COLPOLY_GET_NORMAL(poly->normal.y); nz = COLPOLY_GET_NORMAL(poly->normal.z); - return Math3D_TriChkPointParaYIntersectInsideTri2(&D_801EDA18[0], &D_801EDA18[1], &D_801EDA18[2], nx, ny, nz, + return Math3D_TriChkPointParaYNoRangeCheckIntersectInsideTri(&D_801EDA18[0], &D_801EDA18[1], &D_801EDA18[2], nx, ny, nz, poly->dist, z, x, yIntersect, checkDist); } @@ -429,16 +429,16 @@ s32 CollisionPoly_LineVsPoly(BgLineVsPolyTest* a0) { CollisionPoly_GetNormalF(a0->poly, &sPlane.normal.x, &sPlane.normal.y, &sPlane.normal.z); CollisionPoly_GetVertices(a0->poly, a0->vtxList, sPolyVerts); - Math3D_Lerp(a0->posA, a0->posB, planeDistA / (planeDistA - planeDistB), a0->planeIntersect); + Math3D_LineSplitRatio(a0->posA, a0->posB, planeDistA / (planeDistA - planeDistB), a0->planeIntersect); if (((fabsf(sPlane.normal.x) > 0.5f) && - Math3D_TriChkPointParaXDist(&sPolyVerts[0], &sPolyVerts[1], &sPolyVerts[2], a0->planeIntersect->y, + Math3D_TriChkPointParaXImpl(&sPolyVerts[0], &sPolyVerts[1], &sPolyVerts[2], a0->planeIntersect->y, a0->planeIntersect->z, 0.0f, a0->checkDist, sPlane.normal.x)) || ((fabsf(sPlane.normal.y) > 0.5f) && - Math3D_TriChkPointParaYDist(&sPolyVerts[0], &sPolyVerts[1], &sPolyVerts[2], a0->planeIntersect->z, + Math3D_TriChkPointParaYImpl(&sPolyVerts[0], &sPolyVerts[1], &sPolyVerts[2], a0->planeIntersect->z, a0->planeIntersect->x, 0.0f, a0->checkDist, sPlane.normal.y)) || ((fabsf(sPlane.normal.z) > 0.5f) && - Math3D_TriChkLineSegParaZDist(&sPolyVerts[0], &sPolyVerts[1], &sPolyVerts[2], a0->planeIntersect->x, + Math3D_TriChkPointParaZImpl(&sPolyVerts[0], &sPolyVerts[1], &sPolyVerts[2], a0->planeIntersect->x, a0->planeIntersect->y, 0.0f, a0->checkDist, sPlane.normal.z))) { return true; } @@ -463,7 +463,7 @@ s32 CollisionPoly_SphVsPoly(CollisionPoly* poly, Vec3s* vtxList, Vec3f* center, sSphere.center.y = center->y; sSphere.center.z = center->z; sSphere.radius = radius; - return Math3D_ColSphereTri(&sSphere, &sTri, &intersect); + return Math3D_TriVsSphIntersect(&sSphere, &sTri, &intersect); } #else s32 CollisionPoly_SphVsPoly(CollisionPoly* poly, Vec3s* vtxList, Vec3f* center, f32 radius); diff --git a/src/code/z_camera.c b/src/code/z_camera.c index c0bb26430..b6a829b71 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -1847,13 +1847,13 @@ void Camera_CalcDefaultSwing(Camera* camera, VecGeo* arg1, VecGeo* arg2, f32 arg //! FAKE: dummy:; swing->unk_64 = 0; - } else if ((sp88 = Math3D_SignedDistanceFromPlane(swing->eyeAtColChk.norm.x, swing->eyeAtColChk.norm.y, + } else if ((sp88 = Math3D_PlaneF(swing->eyeAtColChk.norm.x, swing->eyeAtColChk.norm.y, swing->eyeAtColChk.norm.z, swing->eyeAtColChk.poly->dist, at)) > 0.0f) { swing->unk_64 = 0; } else if ((sp88 = OLib_Vec3fDist(eye, &swing->eyeAtColChk.pos)) < 10.0f) { swing->unk_64 = 0; - } else if ((sp88 = Math3D_SignedDistanceFromPlane(swing->atEyeColChk.norm.x, swing->atEyeColChk.norm.y, + } else if ((sp88 = Math3D_PlaneF(swing->atEyeColChk.norm.x, swing->atEyeColChk.norm.y, swing->atEyeColChk.norm.z, swing->atEyeColChk.poly->dist, eye)) > 0.0f) { swing->unk_64 = 0; diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c index 50045a278..0e44356b8 100644 --- a/src/code/z_collision_check.c +++ b/src/code/z_collision_check.c @@ -619,7 +619,7 @@ s32 Collider_SetTrisElementDim(PlayState* play, TriNorm* dim, ColliderTrisElemen *destVtx = *srcVtx; } - Math3D_UnitNormalVector(&src->vtx[0], &src->vtx[1], &src->vtx[2], &nx, &ny, &nz, &originDist); + Math3D_DefPlane(&src->vtx[0], &src->vtx[1], &src->vtx[2], &nx, &ny, &nz, &originDist); dim->plane.normal.x = nx; dim->plane.normal.y = ny; @@ -1733,7 +1733,7 @@ void CollisionCheck_AC_JntSphVsJntSph(PlayState* play, CollisionCheckContext* co continue; } - if (Math3D_ColSphereSphereIntersectAndDistance(&atElem->dim.worldSphere, &acElem->dim.worldSphere, + if (Math3D_SphVsSphOverlapCenter(&atElem->dim.worldSphere, &acElem->dim.worldSphere, &overlapSize, ¢erDist) != 0) { f32 acToHit; Vec3f hitPos; @@ -1784,7 +1784,7 @@ void CollisionCheck_AC_JntSphVsCyl(PlayState* play, CollisionCheckContext* colCt if (CollisionCheck_NoSharedFlags(&atElem->info, &ac->info)) { continue; } - if (Math3D_ColSphereCylinderDistanceAndAmount(&atElem->dim.worldSphere, &ac->dim, &overlapSize, + if (Math3D_SphVsCylOverlapCenterDist(&atElem->dim.worldSphere, &ac->dim, &overlapSize, ¢erDist)) { Vec3f hitPos; Vec3f atPos; @@ -1834,7 +1834,7 @@ void CollisionCheck_AC_JntSphVsTris(PlayState* play, CollisionCheckContext* colC if (CollisionCheck_NoSharedFlags(&atElem->info, &acElem->info)) { continue; } - if (Math3D_ColSphereTri(&atElem->dim.worldSphere, &acElem->dim, &hitPos) != 0) { + if (Math3D_TriVsSphIntersect(&atElem->dim.worldSphere, &acElem->dim, &hitPos) != 0) { Vec3f atPos; Vec3f acPos; @@ -1862,8 +1862,8 @@ void CollisionCheck_AC_JntSphVsQuad(PlayState* play, CollisionCheckContext* colC if (CollisionCheck_SkipBump(&ac->info)) { return; } - Math3D_TriSetCoords(&D_801EF590, &ac->dim.quad[2], &ac->dim.quad[3], &ac->dim.quad[1]); - Math3D_TriSetCoords(&D_801EF5C8, &ac->dim.quad[1], &ac->dim.quad[0], &ac->dim.quad[2]); + Math3D_TriNorm(&D_801EF590, &ac->dim.quad[2], &ac->dim.quad[3], &ac->dim.quad[1]); + Math3D_TriNorm(&D_801EF5C8, &ac->dim.quad[1], &ac->dim.quad[0], &ac->dim.quad[2]); for (sphElem = at->elements; sphElem < &at->elements[at->count]; sphElem++) { if (CollisionCheck_SkipTouch(&sphElem->info)) { @@ -1872,8 +1872,8 @@ void CollisionCheck_AC_JntSphVsQuad(PlayState* play, CollisionCheckContext* colC if (CollisionCheck_NoSharedFlags(&sphElem->info, &ac->info)) { continue; } - if (Math3D_ColSphereTri(&sphElem->dim.worldSphere, &D_801EF590, &hitPos) != 0 || - Math3D_ColSphereTri(&sphElem->dim.worldSphere, &D_801EF5C8, &hitPos) != 0) { + if (Math3D_TriVsSphIntersect(&sphElem->dim.worldSphere, &D_801EF590, &hitPos) != 0 || + Math3D_TriVsSphIntersect(&sphElem->dim.worldSphere, &D_801EF5C8, &hitPos) != 0) { Vec3f atPos; Vec3f acPos; @@ -1909,7 +1909,7 @@ void CollisionCheck_AC_JntSphVsSphere(PlayState* play, CollisionCheckContext* co if (CollisionCheck_NoSharedFlags(&sphElem->info, &ac->info)) { continue; } - if (Math3D_ColSphereSphereIntersectAndDistance(&sphElem->dim.worldSphere, &ac->dim.worldSphere, + if (Math3D_SphVsSphOverlapCenter(&sphElem->dim.worldSphere, &ac->dim.worldSphere, &overlapSize, ¢erDist) != 0) { f32 acToHit; Vec3f hitPos; @@ -1954,7 +1954,7 @@ void CollisionCheck_AC_CylVsJntSph(PlayState* play, CollisionCheckContext* colCt if (CollisionCheck_NoSharedFlags(&at->info, &sphElem->info)) { continue; } - if (Math3D_ColSphereCylinderDistanceAndAmount(&sphElem->dim.worldSphere, &at->dim, &overlapSize, + if (Math3D_SphVsCylOverlapCenterDist(&sphElem->dim.worldSphere, &at->dim, &overlapSize, ¢erDist) != 0) { Vec3f hitPos; Vec3f atPos; @@ -2005,7 +2005,7 @@ void CollisionCheck_AC_CylVsCyl(PlayState* play, CollisionCheckContext* colCtxt, return; } - if (Math3D_ColCylinderCylinderAmountAndDistance(&at->dim, &ac->dim, &overlapSize, ¢erDist) != 0) { + if (Math3D_CylOutsideCylDist(&at->dim, &ac->dim, &overlapSize, ¢erDist) != 0) { Vec3f hitPos; Vec3f atPos; Vec3f acPos; @@ -2059,7 +2059,7 @@ void CollisionCheck_AC_CylVsTris(PlayState* play, CollisionCheckContext* colCtxt continue; } - if (Math3D_ColCylinderTri(&at->dim, &acElem->dim, &hitPos) != 0) { + if (Math3D_CylTriVsIntersect(&at->dim, &acElem->dim, &hitPos) != 0) { Vec3f atPos; Vec3f acPos; @@ -2089,17 +2089,17 @@ void CollisionCheck_AC_CylVsQuad(PlayState* play, CollisionCheckContext* colCtxt if (CollisionCheck_NoSharedFlags(&at->info, &ac->info)) { return; } - Math3D_TriSetCoords(&D_801EF600, &ac->dim.quad[2], &ac->dim.quad[3], &ac->dim.quad[1]); - Math3D_TriSetCoords(&D_801EF638, &ac->dim.quad[1], &ac->dim.quad[0], &ac->dim.quad[2]); + Math3D_TriNorm(&D_801EF600, &ac->dim.quad[2], &ac->dim.quad[3], &ac->dim.quad[1]); + Math3D_TriNorm(&D_801EF638, &ac->dim.quad[1], &ac->dim.quad[0], &ac->dim.quad[2]); - if (Math3D_ColCylinderTri(&at->dim, &D_801EF600, &D_801EDE00) != 0) { + if (Math3D_CylTriVsIntersect(&at->dim, &D_801EF600, &D_801EDE00) != 0) { Vec3f atPos; Vec3f acPos; Math_Vec3s_ToVec3f(&atPos, &at->dim.pos); CollisionCheck_QuadAvgPoint(ac, &acPos); CollisionCheck_SetATvsAC(play, &at->base, &at->info, &atPos, &ac->base, &ac->info, &acPos, &D_801EDE00); - } else if (Math3D_ColCylinderTri(&at->dim, &D_801EF638, &D_801EDE00) != 0) { + } else if (Math3D_CylTriVsIntersect(&at->dim, &D_801EF638, &D_801EDE00) != 0) { Vec3f atPos; Vec3f acPos; @@ -2130,7 +2130,7 @@ void CollisionCheck_AC_CylVsSphere(PlayState* play, CollisionCheckContext* colCt return; } - if (Math3D_ColSphereCylinderDistanceAndAmount(&ac->dim.worldSphere, &at->dim, &overlapSize, ¢erDist) != 0) { + if (Math3D_SphVsCylOverlapCenterDist(&ac->dim.worldSphere, &at->dim, &overlapSize, ¢erDist) != 0) { Vec3f hitPos; Vec3f atPos; Vec3f acPos; @@ -2178,7 +2178,7 @@ void CollisionCheck_AC_TrisVsJntSph(PlayState* play, CollisionCheckContext* colC if (CollisionCheck_NoSharedFlags(&atElem->info, &acElem->info)) { continue; } - if (Math3D_ColSphereTri(&acElem->dim.worldSphere, &atElem->dim, &hitPos)) { + if (Math3D_TriVsSphIntersect(&acElem->dim.worldSphere, &atElem->dim, &hitPos)) { Vec3f atPos; Vec3f acPos; @@ -2215,7 +2215,7 @@ void CollisionCheck_AC_TrisVsCyl(PlayState* play, CollisionCheckContext* colCtxt if (CollisionCheck_NoSharedFlags(&atElem->info, &ac->info)) { continue; } - if (Math3D_ColCylinderTri(&ac->dim, &atElem->dim, &D_801EDE10) != 0) { + if (Math3D_CylTriVsIntersect(&ac->dim, &atElem->dim, &D_801EDE10) != 0) { Vec3f atPos; Vec3f acPos; @@ -2250,7 +2250,7 @@ void CollisionCheck_AC_TrisVsTris(PlayState* play, CollisionCheckContext* colCtx if (CollisionCheck_NoSharedFlags(&atElem->info, &acElem->info)) { continue; } - if (Math3d_ColTriTri(&atElem->dim, &acElem->dim, &D_801EDE20) != 0) { + if (Math3D_TriVsTriIntersect(&atElem->dim, &acElem->dim, &D_801EDE20) != 0) { Vec3f atPos; Vec3f acPos; @@ -2278,8 +2278,8 @@ void CollisionCheck_AC_TrisVsQuad(PlayState* play, CollisionCheckContext* colCtx return; } - Math3D_TriSetCoords(&D_801EDE40, &ac->dim.quad[2], &ac->dim.quad[3], &ac->dim.quad[1]); - Math3D_TriSetCoords(&D_801EDE78, &ac->dim.quad[1], &ac->dim.quad[0], &ac->dim.quad[2]); + Math3D_TriNorm(&D_801EDE40, &ac->dim.quad[2], &ac->dim.quad[3], &ac->dim.quad[1]); + Math3D_TriNorm(&D_801EDE78, &ac->dim.quad[1], &ac->dim.quad[0], &ac->dim.quad[2]); for (atElem = at->elements; atElem < &at->elements[at->count]; atElem++) { if (CollisionCheck_SkipTouch(&atElem->info)) { @@ -2288,8 +2288,8 @@ void CollisionCheck_AC_TrisVsQuad(PlayState* play, CollisionCheckContext* colCtx if (CollisionCheck_NoSharedFlags(&atElem->info, &ac->info)) { continue; } - if (Math3d_ColTriTri(&D_801EDE40, &atElem->dim, &D_801EDE30) != 0 || - Math3d_ColTriTri(&D_801EDE78, &atElem->dim, &D_801EDE30) != 0) { + if (Math3D_TriVsTriIntersect(&D_801EDE40, &atElem->dim, &D_801EDE30) != 0 || + Math3D_TriVsTriIntersect(&D_801EDE78, &atElem->dim, &D_801EDE30) != 0) { Vec3f atPos; Vec3f acPos; @@ -2323,7 +2323,7 @@ void CollisionCheck_AC_TrisVsSphere(PlayState* play, CollisionCheckContext* colC if (CollisionCheck_NoSharedFlags(&atElem->info, &ac->info)) { continue; } - if (Math3D_ColSphereTri(&ac->dim.worldSphere, &atElem->dim, &hitPos) != 0) { + if (Math3D_TriVsSphIntersect(&ac->dim.worldSphere, &atElem->dim, &hitPos) != 0) { Vec3f atPos; Vec3f acPos; @@ -2348,8 +2348,8 @@ void CollisionCheck_AC_QuadVsJntSph(PlayState* play, CollisionCheckContext* colC if (CollisionCheck_SkipTouch(&at->info)) { return; } - Math3D_TriSetCoords(&D_801EDEC8, &at->dim.quad[2], &at->dim.quad[3], &at->dim.quad[1]); - Math3D_TriSetCoords(&D_801EDF00, &at->dim.quad[2], &at->dim.quad[1], &at->dim.quad[0]); + Math3D_TriNorm(&D_801EDEC8, &at->dim.quad[2], &at->dim.quad[3], &at->dim.quad[1]); + Math3D_TriNorm(&D_801EDF00, &at->dim.quad[2], &at->dim.quad[1], &at->dim.quad[0]); for (acElem = ac->elements; acElem < &ac->elements[ac->count]; acElem++) { if (CollisionCheck_SkipBump(&acElem->info)) { @@ -2358,8 +2358,8 @@ void CollisionCheck_AC_QuadVsJntSph(PlayState* play, CollisionCheckContext* colC if (CollisionCheck_NoSharedFlags(&at->info, &acElem->info)) { continue; } - if (Math3D_ColSphereTri(&acElem->dim.worldSphere, &D_801EDEC8, &hitPos) != 0 || - Math3D_ColSphereTri(&acElem->dim.worldSphere, &D_801EDF00, &hitPos) != 0) { + if (Math3D_TriVsSphIntersect(&acElem->dim.worldSphere, &D_801EDEC8, &hitPos) != 0 || + Math3D_TriVsSphIntersect(&acElem->dim.worldSphere, &D_801EDF00, &hitPos) != 0) { Vec3f atPos; Vec3f acPos; @@ -2396,10 +2396,10 @@ void CollisionCheck_AC_QuadVsCyl(PlayState* play, CollisionCheckContext* colCtxt return; } - Math3D_TriSetCoords(&D_801EDF58, &at->dim.quad[2], &at->dim.quad[3], &at->dim.quad[1]); - Math3D_TriSetCoords(&D_801EDF90, &at->dim.quad[2], &at->dim.quad[1], &at->dim.quad[0]); + Math3D_TriNorm(&D_801EDF58, &at->dim.quad[2], &at->dim.quad[3], &at->dim.quad[1]); + Math3D_TriNorm(&D_801EDF90, &at->dim.quad[2], &at->dim.quad[1], &at->dim.quad[0]); - if (Math3D_ColCylinderTri(&ac->dim, &D_801EDF58, &D_801EDFE0) != 0) { + if (Math3D_CylTriVsIntersect(&ac->dim, &D_801EDF58, &D_801EDFE0) != 0) { if (Collider_QuadSetNearestAC(play, at, &D_801EDFE0)) { Vec3f atPos; Vec3f acPos; @@ -2410,7 +2410,7 @@ void CollisionCheck_AC_QuadVsCyl(PlayState* play, CollisionCheckContext* colCtxt return; } } - if (Math3D_ColCylinderTri(&ac->dim, &D_801EDF90, &D_801EDFE0) != 0) { + if (Math3D_CylTriVsIntersect(&ac->dim, &D_801EDF90, &D_801EDFE0) != 0) { if (Collider_QuadSetNearestAC(play, at, &D_801EDFE0)) { Vec3f atPos; Vec3f acPos; @@ -2436,8 +2436,8 @@ void CollisionCheck_AC_QuadVsTris(PlayState* play, CollisionCheckContext* colCtx return; } - Math3D_TriSetCoords(&D_801EE000, &at->dim.quad[2], &at->dim.quad[3], &at->dim.quad[1]); - Math3D_TriSetCoords(&D_801EE038, &at->dim.quad[1], &at->dim.quad[0], &at->dim.quad[2]); + Math3D_TriNorm(&D_801EE000, &at->dim.quad[2], &at->dim.quad[3], &at->dim.quad[1]); + Math3D_TriNorm(&D_801EE038, &at->dim.quad[1], &at->dim.quad[0], &at->dim.quad[2]); for (acElem = ac->elements; acElem < &ac->elements[ac->count]; acElem++) { if (CollisionCheck_SkipBump(&acElem->info)) { @@ -2447,8 +2447,8 @@ void CollisionCheck_AC_QuadVsTris(PlayState* play, CollisionCheckContext* colCtx continue; } - if ((Math3d_ColTriTri(&D_801EE000, &acElem->dim, &D_801EDFF0) != 0) || - (Math3d_ColTriTri(&D_801EE038, &acElem->dim, &D_801EDFF0) != 0)) { + if ((Math3D_TriVsTriIntersect(&D_801EE000, &acElem->dim, &D_801EDFF0) != 0) || + (Math3D_TriVsTriIntersect(&D_801EE038, &acElem->dim, &D_801EDFF0) != 0)) { if (Collider_QuadSetNearestAC(play, at, &D_801EDFF0)) { Vec3f atPos; Vec3f acPos; @@ -2483,14 +2483,14 @@ void CollisionCheck_AC_QuadVsQuad(PlayState* play, CollisionCheckContext* colCtx return; } - Math3D_TriSetCoords(&D_801EE0E8[0], &at->dim.quad[2], &at->dim.quad[3], &at->dim.quad[1]); - Math3D_TriSetCoords(&D_801EE0E8[1], &at->dim.quad[2], &at->dim.quad[1], &at->dim.quad[0]); - Math3D_TriSetCoords(&D_801EE070[0], &ac->dim.quad[2], &ac->dim.quad[3], &ac->dim.quad[1]); - Math3D_TriSetCoords(&D_801EE070[1], &ac->dim.quad[2], &ac->dim.quad[1], &ac->dim.quad[0]); + Math3D_TriNorm(&D_801EE0E8[0], &at->dim.quad[2], &at->dim.quad[3], &at->dim.quad[1]); + Math3D_TriNorm(&D_801EE0E8[1], &at->dim.quad[2], &at->dim.quad[1], &at->dim.quad[0]); + Math3D_TriNorm(&D_801EE070[0], &ac->dim.quad[2], &ac->dim.quad[3], &ac->dim.quad[1]); + Math3D_TriNorm(&D_801EE070[1], &ac->dim.quad[2], &ac->dim.quad[1], &ac->dim.quad[0]); for (i = 0; i < 2; i++) { for (j = 0; j < 2; j++) { - if (Math3d_ColTriTri(&D_801EE0E8[j], &D_801EE070[i], &D_801EE0D8) != 0 && + if (Math3D_TriVsTriIntersect(&D_801EE0E8[j], &D_801EE070[i], &D_801EE0D8) != 0 && Collider_QuadSetNearestAC(play, at, &D_801EE0D8) != 0) { Vec3f atPos; Vec3f acPos; @@ -2519,11 +2519,11 @@ void CollisionCheck_AC_QuadVsSphere(PlayState* play, CollisionCheckContext* colC return; } - Math3D_TriSetCoords(&D_801EE150, &at->dim.quad[2], &at->dim.quad[3], &at->dim.quad[1]); - Math3D_TriSetCoords(&D_801EE188, &at->dim.quad[2], &at->dim.quad[1], &at->dim.quad[0]); + Math3D_TriNorm(&D_801EE150, &at->dim.quad[2], &at->dim.quad[3], &at->dim.quad[1]); + Math3D_TriNorm(&D_801EE188, &at->dim.quad[2], &at->dim.quad[1], &at->dim.quad[0]); - if ((Math3D_ColSphereTri(&ac->dim.worldSphere, &D_801EE150, &hitPos) != 0) || - (Math3D_ColSphereTri(&ac->dim.worldSphere, &D_801EE188, &hitPos) != 0)) { + if ((Math3D_TriVsSphIntersect(&ac->dim.worldSphere, &D_801EE150, &hitPos) != 0) || + (Math3D_TriVsSphIntersect(&ac->dim.worldSphere, &D_801EE188, &hitPos) != 0)) { if (Collider_QuadSetNearestAC(play, at, &hitPos)) { Vec3f atPos; Vec3f acPos; @@ -2559,7 +2559,7 @@ void CollisionCheck_AC_SphereVsJntSph(PlayState* play, CollisionCheckContext* co continue; } - if (Math3D_ColSphereSphereIntersectAndDistance(&at->dim.worldSphere, &acElem->dim.worldSphere, &overlapSize, + if (Math3D_SphVsSphOverlapCenter(&at->dim.worldSphere, &acElem->dim.worldSphere, &overlapSize, ¢erDist) != 0) { f32 acToHit; Vec3f hitPos; @@ -2602,7 +2602,7 @@ void CollisionCheck_AC_SphereVsCylinder(PlayState* play, CollisionCheckContext* return; } - if (Math3D_ColSphereCylinderDistanceAndAmount(&at->dim.worldSphere, &ac->dim, &overlapSize, ¢erDist) != 0) { + if (Math3D_SphVsCylOverlapCenterDist(&at->dim.worldSphere, &ac->dim, &overlapSize, ¢erDist) != 0) { Vec3f hitPos; Vec3f atPos; Vec3f acPos; @@ -2649,7 +2649,7 @@ void CollisionCheck_AC_SphereVsTris(PlayState* play, CollisionCheckContext* colC if (CollisionCheck_NoSharedFlags(&at->info, &acElem->info)) { continue; } - if (Math3D_ColSphereTri(&at->dim.worldSphere, &acElem->dim, &hitPos) != 0) { + if (Math3D_TriVsSphIntersect(&at->dim.worldSphere, &acElem->dim, &hitPos) != 0) { Vec3f atPos; Vec3f acPos; @@ -2676,11 +2676,11 @@ void CollisionCheck_AC_SphereVsQuad(PlayState* play, CollisionCheckContext* colC return; } - Math3D_TriSetCoords(&D_801EE6C8, &ac->dim.quad[2], &ac->dim.quad[3], &ac->dim.quad[1]); - Math3D_TriSetCoords(&D_801EE700, &ac->dim.quad[1], &ac->dim.quad[0], &ac->dim.quad[2]); + Math3D_TriNorm(&D_801EE6C8, &ac->dim.quad[2], &ac->dim.quad[3], &ac->dim.quad[1]); + Math3D_TriNorm(&D_801EE700, &ac->dim.quad[1], &ac->dim.quad[0], &ac->dim.quad[2]); - if (Math3D_ColSphereTri(&at->dim.worldSphere, &D_801EE6C8, &hitPos) != 0 || - Math3D_ColSphereTri(&at->dim.worldSphere, &D_801EE700, &hitPos) != 0) { + if (Math3D_TriVsSphIntersect(&at->dim.worldSphere, &D_801EE6C8, &hitPos) != 0 || + Math3D_TriVsSphIntersect(&at->dim.worldSphere, &D_801EE700, &hitPos) != 0) { Vec3f atPos; Vec3f acPos; @@ -2710,7 +2710,7 @@ void CollisionCheck_AC_SphereVsSphere(PlayState* play, CollisionCheckContext* co return; } - if (Math3D_ColSphereSphereIntersectAndDistance(&at->dim.worldSphere, &ac->dim.worldSphere, &overlapSize, + if (Math3D_SphVsSphOverlapCenter(&at->dim.worldSphere, &ac->dim.worldSphere, &overlapSize, ¢erDist) != 0) { f32 acToHit; Vec3f hitPos; @@ -3043,7 +3043,7 @@ void CollisionCheck_OC_JntSphVsJntSph(PlayState* play, CollisionCheckContext* co if (!(rightElem->info.ocElemFlags & OCELEM_ON)) { continue; } - if (Math3D_ColSphereSphereIntersect(&leftElem->dim.worldSphere, &rightElem->dim.worldSphere, + if (Math3D_SphVsSphOverlap(&leftElem->dim.worldSphere, &rightElem->dim.worldSphere, &overlap) != 0) { Vec3f leftPos; Vec3f rightPos; @@ -3074,7 +3074,7 @@ void CollisionCheck_OC_JntSphVsCyl(PlayState* play, CollisionCheckContext* colCt if (!(leftElem->info.ocElemFlags & OCELEM_ON)) { continue; } - if (Math3D_ColSphereCylinderDistance(&leftElem->dim.worldSphere, &right->dim, &overlap) != 0) { + if (Math3D_SphVsCylOverlapDist(&leftElem->dim.worldSphere, &right->dim, &overlap) != 0) { Vec3f leftPos; Vec3f rightPos; @@ -3103,7 +3103,7 @@ void CollisionCheck_OC_JntSphVsSphere(PlayState* play, CollisionCheckContext* co if (!(leftElem->info.ocElemFlags & OCELEM_ON)) { continue; } - if (Math3D_ColSphereSphereIntersect(&leftElem->dim.worldSphere, &right->dim.worldSphere, &overlap) != 0) { + if (Math3D_SphVsSphOverlap(&leftElem->dim.worldSphere, &right->dim.worldSphere, &overlap) != 0) { Vec3f leftPos; Vec3f rightPos; @@ -3133,7 +3133,7 @@ void CollisionCheck_OC_CylVsCyl(PlayState* play, CollisionCheckContext* colCtxt, if ((left->base.ocFlags1 & OCELEM_ON) && (right->base.ocFlags1 & OCELEM_ON) && (left->info.ocElemFlags & OCELEM_ON) && (right->info.ocElemFlags & OCELEM_ON)) { - if (Math3D_ColCylinderCylinderAmount(&left->dim, &right->dim, &overlap) != 0) { + if (Math3D_CylOutsideCyl(&left->dim, &right->dim, &overlap) != 0) { Vec3f leftPos; Vec3f rightPos; @@ -3155,7 +3155,7 @@ void CollisionCheck_OC_CylVsSphere(PlayState* play, CollisionCheckContext* colCt if ((left->base.ocFlags1 & OCELEM_ON) && (left->info.ocElemFlags & OCELEM_ON) && (right->base.ocFlags1 & OCELEM_ON) && (right->info.ocElemFlags & OCELEM_ON)) { - if (Math3D_ColSphereCylinderDistance(&right->dim.worldSphere, &left->dim, &overlap) != 0) { + if (Math3D_SphVsCylOverlapDist(&right->dim.worldSphere, &left->dim, &overlap) != 0) { Vec3f leftPos; Vec3f rightPos; @@ -3191,7 +3191,7 @@ void CollisionCheck_OC_SphereVsSphere(PlayState* play, CollisionCheckContext* co if ((left->base.ocFlags1 & OCELEM_ON) && (left->info.ocElemFlags & OCELEM_ON) && (right->base.ocFlags1 & OCELEM_ON) && (right->info.ocElemFlags & OCELEM_ON)) { - if (Math3D_ColSphereSphereIntersect(&left->dim.worldSphere, &right->dim.worldSphere, &overlap) != 0) { + if (Math3D_SphVsSphOverlap(&left->dim.worldSphere, &right->dim.worldSphere, &overlap) != 0) { Vec3f leftPos; Vec3f rightPos; @@ -3496,7 +3496,7 @@ s32 CollisionCheck_LineOC_Cyl(PlayState* play, CollisionCheckContext* colChkCtx, return 0; } - if (func_8017E350(&cylinder->dim, a, b, &D_801EDF38, &D_801EDF48) != 0) { + if (Math3D_CylVsLineSeg(&cylinder->dim, a, b, &D_801EDF38, &D_801EDF48) != 0) { return 1; } @@ -3627,7 +3627,7 @@ void Collider_SetTrisVertices(ColliderTris* collider, s32 index, Vec3f* a, Vec3f Math_Vec3f_Copy(&element->dim.vtx[0], a); Math_Vec3f_Copy(&element->dim.vtx[1], b); Math_Vec3f_Copy(&element->dim.vtx[2], c); - Math3D_UnitNormalVector(a, b, c, &nx, &ny, &nz, &originDist); + Math3D_DefPlane(a, b, c, &nx, &ny, &nz, &originDist); element->dim.plane.normal.x = nx; element->dim.plane.normal.y = ny; element->dim.plane.normal.z = nz; diff --git a/src/code/z_eff_tire_mark.c b/src/code/z_eff_tire_mark.c index 66e01b6f8..10b3d9fa2 100644 --- a/src/code/z_eff_tire_mark.c +++ b/src/code/z_eff_tire_mark.c @@ -57,8 +57,8 @@ void func_800AE930(CollisionContext* colCtx, EffectTireMark* this, Vec3f* pos, f sp48.y = spB8.y; sp48.z = spB8.z; - if ((Math3D_LineVsLineClosestTwoPoints(&sp84, &sp90, &sp54, &sp60, &sp6C, &sp30) != 0) && - (Math3D_LineVsLineClosestTwoPoints(&sp84, &sp90, &sp3C, &sp48, &sp78, &sp30) != 0)) { + if ((Math3D_LineSegMakePerpLineSeg(&sp84, &sp90, &sp54, &sp60, &sp6C, &sp30) != 0) && + (Math3D_LineSegMakePerpLineSeg(&sp84, &sp90, &sp3C, &sp48, &sp78, &sp30) != 0)) { if (!(spAC->flags & 2)) { spAC->flags |= 1; } diff --git a/src/code/z_sub_s.c b/src/code/z_sub_s.c index eea4feca2..1dd35ab84 100644 --- a/src/code/z_sub_s.c +++ b/src/code/z_sub_s.c @@ -577,7 +577,7 @@ s32 SubS_HasReachedPoint(Actor* actor, Path* path, s32 pointIndex) { diffZ = points[index + 1].z - points[index - 1].z; } - func_8017B7F8(&point, RAD_TO_BINANG(func_80086B30(diffX, diffZ)), &px, &pz, &d); + Math3D_RotateXZPlane(&point, RAD_TO_BINANG(func_80086B30(diffX, diffZ)), &px, &pz, &d); if (((px * actor->world.pos.x) + (pz * actor->world.pos.z) + d) > 0.0f) { reached = true; } diff --git a/src/overlays/actors/ovl_En_Akindonuts/z_en_akindonuts.c b/src/overlays/actors/ovl_En_Akindonuts/z_en_akindonuts.c index 41dba0aab..bd8840785 100644 --- a/src/overlays/actors/ovl_En_Akindonuts/z_en_akindonuts.c +++ b/src/overlays/actors/ovl_En_Akindonuts/z_en_akindonuts.c @@ -179,7 +179,7 @@ s32 func_80BECD10(EnAkindonuts* this, Path* path, s32 arg2) { phi_f14 = sp5C[idx + 1].z - sp5C[idx - 1].z; } - func_8017B7F8(&sp30, RAD_TO_BINANG(func_80086B30(phi_f12, phi_f14)), &sp44, &sp40, &sp3C); + Math3D_RotateXZPlane(&sp30, RAD_TO_BINANG(func_80086B30(phi_f12, phi_f14)), &sp44, &sp40, &sp3C); if (((this->actor.world.pos.x * sp44) + (sp40 * this->actor.world.pos.z) + sp3C) > 0.0f) { sp50 = true; } diff --git a/src/overlays/actors/ovl_En_Bubble/z_en_bubble.c b/src/overlays/actors/ovl_En_Bubble/z_en_bubble.c index 1c0c2cfc4..b1062343e 100644 --- a/src/overlays/actors/ovl_En_Bubble/z_en_bubble.c +++ b/src/overlays/actors/ovl_En_Bubble/z_en_bubble.c @@ -170,7 +170,7 @@ s32 func_8089F908(EnBubble* this) { void EnBubble_Vec3fNormalizedReflect(Vec3f* vec1, Vec3f* vec2, Vec3f* dest) { f32 norm; - func_80179F64(vec1, vec2, dest); + Math3D_Vec3fReflect(vec1, vec2, dest); norm = sqrtf(SQ(dest->x) + SQ(dest->y) + SQ(dest->z)); if (norm != 0.0f) { dest->x /= norm; diff --git a/src/overlays/actors/ovl_En_Dg/z_en_dg.c b/src/overlays/actors/ovl_En_Dg/z_en_dg.c index 8a6ae63e8..f1ebb07e3 100644 --- a/src/overlays/actors/ovl_En_Dg/z_en_dg.c +++ b/src/overlays/actors/ovl_En_Dg/z_en_dg.c @@ -280,7 +280,7 @@ s32 EnDg_HasReachedPoint(EnDg* this, Path* path, s32 pointIndex) { diffZ = points[currentPoint + 1].z - points[currentPoint - 1].z; } - func_8017B7F8(&point, RAD_TO_BINANG(func_80086B30(diffX, diffZ)), &px, &pz, &d); + Math3D_RotateXZPlane(&point, RAD_TO_BINANG(func_80086B30(diffX, diffZ)), &px, &pz, &d); if (((this->actor.world.pos.x * px) + (pz * this->actor.world.pos.z) + d) > 0.0f) { reached = true; diff --git a/src/overlays/actors/ovl_En_Gg2/z_en_gg2.c b/src/overlays/actors/ovl_En_Gg2/z_en_gg2.c index fdd099fff..a12afdcb5 100644 --- a/src/overlays/actors/ovl_En_Gg2/z_en_gg2.c +++ b/src/overlays/actors/ovl_En_Gg2/z_en_gg2.c @@ -310,7 +310,7 @@ s32 func_80B3B648(EnGg2* this, Path* path, s32 arg2_) { phi_f14 = points[arg2 + 1].z - points[arg2 - 1].z; } - func_8017B7F8(&sp30, RAD_TO_BINANG(func_80086B30(phi_f12, phi_f14)), &sp44, &sp40, &sp3C); + Math3D_RotateXZPlane(&sp30, RAD_TO_BINANG(func_80086B30(phi_f12, phi_f14)), &sp44, &sp40, &sp3C); if (((this->actor.world.pos.x * sp44) + (sp40 * this->actor.world.pos.z) + sp3C) > 0.0f) { ret = true; diff --git a/src/overlays/actors/ovl_En_Gk/z_en_gk.c b/src/overlays/actors/ovl_En_Gk/z_en_gk.c index 40cf72a98..617b36377 100644 --- a/src/overlays/actors/ovl_En_Gk/z_en_gk.c +++ b/src/overlays/actors/ovl_En_Gk/z_en_gk.c @@ -374,7 +374,7 @@ s32 func_80B50C78(EnGk* this, Path* path, s32 arg2_) { phi_f14 = sp5C[arg2 + 1].z - sp5C[arg2 - 1].z; } - func_8017B7F8(&sp30, RAD_TO_BINANG(func_80086B30(phi_f12, phi_f14)), &sp44, &sp40, &sp3C); + Math3D_RotateXZPlane(&sp30, RAD_TO_BINANG(func_80086B30(phi_f12, phi_f14)), &sp44, &sp40, &sp3C); if (((this->actor.world.pos.x * sp44) + (sp40 * this->actor.world.pos.z) + sp3C) > 0.0f) { ret = true; diff --git a/src/overlays/actors/ovl_En_Horse/z_en_horse.c b/src/overlays/actors/ovl_En_Horse/z_en_horse.c index 6ca711a2b..a3c2bce4a 100644 --- a/src/overlays/actors/ovl_En_Horse/z_en_horse.c +++ b/src/overlays/actors/ovl_En_Horse/z_en_horse.c @@ -327,7 +327,7 @@ void func_8087B7C0(EnHorse* this, PlayState* play, Path* path) { phi_f14 = spA0[this->curRaceWaypoint + 1].z - spA0[this->curRaceWaypoint - 1].z; } - func_8017B7F8(&sp8C, Math_Atan2S(phi_f12, phi_f14), &sp7C, &sp78, &sp74); + Math3D_RotateXZPlane(&sp8C, Math_Atan2S(phi_f12, phi_f14), &sp7C, &sp78, &sp74); if (((this->actor.world.pos.x * sp7C) + (sp78 * this->actor.world.pos.z) + sp74) > 0.0f) { this->curRaceWaypoint++; @@ -2809,7 +2809,7 @@ s32 EnHorse_UpdateHbaRaceInfo(EnHorse* this, PlayState* play, RaceInfo* raceInfo f32 d; EnHorse_RaceWaypointPos(raceInfo->waypoints, this->curRaceWaypoint, &pos); - func_8017B7F8(&pos, raceInfo->waypoints[this->curRaceWaypoint].angle, &px, &pz, &d); + Math3D_RotateXZPlane(&pos, raceInfo->waypoints[this->curRaceWaypoint].angle, &px, &pz, &d); if ((this->curRaceWaypoint >= (raceInfo->numWaypoints - 1)) && (Math3D_Vec3f_DistXYZ(&pos, &this->actor.world.pos) < DREG(8))) { diff --git a/src/overlays/actors/ovl_En_Horse_Game_Check/z_en_horse_game_check.c b/src/overlays/actors/ovl_En_Horse_Game_Check/z_en_horse_game_check.c index d37fb8f23..da421f47f 100644 --- a/src/overlays/actors/ovl_En_Horse_Game_Check/z_en_horse_game_check.c +++ b/src/overlays/actors/ovl_En_Horse_Game_Check/z_en_horse_game_check.c @@ -257,21 +257,21 @@ s32 func_808F8FAC(EnHorseGameCheck* this, PlayState* play) { } if (!(this->unk_164 & 0x1000)) { - if (Math3D_XZBoundCheck(D_808F9BAC[0], D_808F9BAC[1], D_808F9BAC[2], D_808F9BAC[3], + if (Math3D_PointInSquare2D(D_808F9BAC[0], D_808F9BAC[1], D_808F9BAC[2], D_808F9BAC[3], this->horse1->actor.world.pos.x, this->horse1->actor.world.pos.z)) { this->unk_164 |= 0x1000; } } if (!(this->unk_164 & 0x2000) && (this->unk_164 & 0x1000)) { - if (Math3D_XZBoundCheck(D_808F9BBC[0], D_808F9BBC[1], D_808F9BBC[2], D_808F9BBC[3], + if (Math3D_PointInSquare2D(D_808F9BBC[0], D_808F9BBC[1], D_808F9BBC[2], D_808F9BBC[3], this->horse1->actor.world.pos.x, this->horse1->actor.world.pos.z)) { this->unk_164 |= 0x2000; } } if (!(this->unk_164 & 0x4000) && (this->unk_164 & 0x2000)) { - if (Math3D_XZBoundCheck(D_808F9BCC[0], D_808F9BCC[1], D_808F9BCC[2], D_808F9BCC[3], + if (Math3D_PointInSquare2D(D_808F9BCC[0], D_808F9BCC[1], D_808F9BCC[2], D_808F9BCC[3], this->horse1->actor.world.pos.x, this->horse1->actor.world.pos.z)) { this->unk_164 |= 0x4000; } @@ -290,21 +290,21 @@ s32 func_808F8FAC(EnHorseGameCheck* this, PlayState* play) { } if (!(this->unk_164 & 0x80000)) { - if (Math3D_XZBoundCheck(D_808F9BAC[0], D_808F9BAC[1], D_808F9BAC[2], D_808F9BAC[3], + if (Math3D_PointInSquare2D(D_808F9BAC[0], D_808F9BAC[1], D_808F9BAC[2], D_808F9BAC[3], this->horse2->actor.world.pos.x, this->horse2->actor.world.pos.z)) { this->unk_164 |= 0x80000; } } if (!(this->unk_164 & 0x100000) && (this->unk_164 & 0x80000)) { - if (Math3D_XZBoundCheck(D_808F9BBC[0], D_808F9BBC[1], D_808F9BBC[2], D_808F9BBC[3], + if (Math3D_PointInSquare2D(D_808F9BBC[0], D_808F9BBC[1], D_808F9BBC[2], D_808F9BBC[3], this->horse2->actor.world.pos.x, this->horse2->actor.world.pos.z)) { this->unk_164 |= 0x100000; } } if (!(this->unk_164 & 0x200000) && (this->unk_164 & 0x100000)) { - if (Math3D_XZBoundCheck(D_808F9BCC[0], D_808F9BCC[1], D_808F9BCC[2], D_808F9BCC[3], + if (Math3D_PointInSquare2D(D_808F9BCC[0], D_808F9BCC[1], D_808F9BCC[2], D_808F9BCC[3], this->horse2->actor.world.pos.x, this->horse2->actor.world.pos.z)) { this->unk_164 |= 0x200000; } @@ -322,19 +322,19 @@ s32 func_808F8FAC(EnHorseGameCheck* this, PlayState* play) { this->unk_174 = 60; } - if (!(this->unk_164 & 0x20) && Math3D_XZBoundCheck(D_808F9BAC[0], D_808F9BAC[1], D_808F9BAC[2], D_808F9BAC[3], + if (!(this->unk_164 & 0x20) && Math3D_PointInSquare2D(D_808F9BAC[0], D_808F9BAC[1], D_808F9BAC[2], D_808F9BAC[3], horse->actor.world.pos.x, horse->actor.world.pos.z)) { this->unk_164 |= 0x20; } if (!(this->unk_164 & 0x40) && (this->unk_164 & 0x20) && - Math3D_XZBoundCheck(D_808F9BBC[0], D_808F9BBC[1], D_808F9BBC[2], D_808F9BBC[3], horse->actor.world.pos.x, + Math3D_PointInSquare2D(D_808F9BBC[0], D_808F9BBC[1], D_808F9BBC[2], D_808F9BBC[3], horse->actor.world.pos.x, horse->actor.world.pos.z)) { this->unk_164 |= 0x40; } if (!(this->unk_164 & 0x80) && (this->unk_164 & 0x40) && - Math3D_XZBoundCheck(D_808F9BCC[0], D_808F9BCC[1], D_808F9BCC[2], D_808F9BCC[3], horse->actor.world.pos.x, + Math3D_PointInSquare2D(D_808F9BCC[0], D_808F9BCC[1], D_808F9BCC[2], D_808F9BCC[3], horse->actor.world.pos.x, horse->actor.world.pos.z)) { this->unk_164 |= 0x80; } diff --git a/src/overlays/actors/ovl_En_Jg/z_en_jg.c b/src/overlays/actors/ovl_En_Jg/z_en_jg.c index 451b9e553..cf24f698a 100644 --- a/src/overlays/actors/ovl_En_Jg/z_en_jg.c +++ b/src/overlays/actors/ovl_En_Jg/z_en_jg.c @@ -242,7 +242,7 @@ s32 EnJg_ReachedPoint(EnJg* this, Path* path, s32 pointIndex) { diffZ = points[currentPoint + 1].z - points[currentPoint - 1].z; } - func_8017B7F8(&point, RAD_TO_BINANG(func_80086B30(diffX, diffZ)), &px, &pz, &d); + Math3D_RotateXZPlane(&point, RAD_TO_BINANG(func_80086B30(diffX, diffZ)), &px, &pz, &d); if (((this->actor.world.pos.x * px) + (pz * this->actor.world.pos.z) + d) > 0.0f) { reached = true; diff --git a/src/overlays/actors/ovl_En_Mt_tag/z_en_mt_tag.c b/src/overlays/actors/ovl_En_Mt_tag/z_en_mt_tag.c index c94a94b12..605729f22 100644 --- a/src/overlays/actors/ovl_En_Mt_tag/z_en_mt_tag.c +++ b/src/overlays/actors/ovl_En_Mt_tag/z_en_mt_tag.c @@ -69,7 +69,7 @@ static Vec3f sCheckpointPositions[] = { * The range extends a little bit beyond the finish line's in-game visual. */ s32 EnMttag_IsInFinishLine(Vec3f* pos) { - return Math3D_XZBoundCheck(-1261.0f, -901.0f, -1600.0f, -1520.0f, pos->x, pos->z); + return Math3D_PointInSquare2D(-1261.0f, -901.0f, -1600.0f, -1520.0f, pos->x, pos->z); } /** @@ -78,11 +78,11 @@ s32 EnMttag_IsInFinishLine(Vec3f* pos) { */ s32 EnMttag_CheckPlayerCheatStatus(Vec3f* pos) { if (!CHECK_EVENTINF(EVENTINF_10)) { - if (Math3D_XZBoundCheck(-466.0f, -386.0f, -687.0f, 193.0f, pos->x, pos->z)) { + if (Math3D_PointInSquare2D(-466.0f, -386.0f, -687.0f, 193.0f, pos->x, pos->z)) { // The race hasn't started yet, but the player is beyond the starting line. return GORON_RACE_CHEAT_FALSE_START; } - } else if (Math3D_XZBoundCheck(-1127.0f, -1007.0f, -867.0f, -787.0f, pos->x, pos->z)) { + } else if (Math3D_PointInSquare2D(-1127.0f, -1007.0f, -867.0f, -787.0f, pos->x, pos->z)) { // The goal is actually quite close to the start, just behind a large wall. // This checks if the player is in an area "behind" the goal that is not accessible // in normal play; it can only be reached by climbing the wall somehow. Perhaps they diff --git a/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.c b/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.c index ee6c61a43..a14daa318 100644 --- a/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.c +++ b/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.c @@ -602,11 +602,11 @@ void func_80A69ADC(Actor* thisx) { s32 pad2; if (this->unk_358 < 1.0f) { - sp44 = Math3D_SignedDistanceFromPlane( + sp44 = Math3D_PlaneF( this->unk_310.x, this->unk_310.y, this->unk_310.z, func_80A69AA8(this->unk_310.x, this->unk_310.y, this->unk_310.z, &this->actor.world.pos), &bean->dyna.actor.world.pos); - sp40 = Math3D_SignedDistanceFromPlane( + sp40 = Math3D_PlaneF( this->unk_328.x, this->unk_328.y, this->unk_328.z, func_80A69AA8(this->unk_328.x, this->unk_328.y, this->unk_328.z, &this->actor.world.pos), &bean->dyna.actor.world.pos); @@ -648,11 +648,11 @@ void func_80A69D3C(EnMushi2* this) { f32 sp38; if ((this->unk_34C != NULL) && (this->unk_358 > 0.999f)) { - sp40 = Math3D_SignedDistanceFromPlane( + sp40 = Math3D_PlaneF( this->unk_310.x, this->unk_310.y, this->unk_310.z, func_80A69AA8(this->unk_310.x, this->unk_310.y, this->unk_310.z, &this->actor.world.pos), &this->unk_34C->dyna.actor.world.pos); - sp3C = Math3D_SignedDistanceFromPlane( + sp3C = Math3D_PlaneF( this->unk_328.x, this->unk_328.y, this->unk_328.z, func_80A69AA8(this->unk_328.x, this->unk_328.y, this->unk_328.z, &this->actor.world.pos), &this->unk_34C->dyna.actor.world.pos); diff --git a/src/overlays/actors/ovl_En_Rg/z_en_rg.c b/src/overlays/actors/ovl_En_Rg/z_en_rg.c index d552c5605..ea108d457 100644 --- a/src/overlays/actors/ovl_En_Rg/z_en_rg.c +++ b/src/overlays/actors/ovl_En_Rg/z_en_rg.c @@ -614,7 +614,7 @@ void func_80BF4AB8(EnRg* this, PlayState* play) { } s32 func_80BF4D64(Vec3f* arg0) { - return Math3D_XZBoundCheck(-1261.0f, -901.0f, -1600.0f, -1520.0f, arg0->x, arg0->z); + return Math3D_PointInSquare2D(-1261.0f, -901.0f, -1600.0f, -1520.0f, arg0->x, arg0->z); } s32 func_80BF4DA8(EnRg* this) { diff --git a/src/overlays/actors/ovl_En_Ruppecrow/z_en_ruppecrow.c b/src/overlays/actors/ovl_En_Ruppecrow/z_en_ruppecrow.c index e270f1515..e60c773d0 100644 --- a/src/overlays/actors/ovl_En_Ruppecrow/z_en_ruppecrow.c +++ b/src/overlays/actors/ovl_En_Ruppecrow/z_en_ruppecrow.c @@ -163,7 +163,7 @@ s32 EnRuppecrow_ReachedPointClockwise(EnRuppecrow* this, Path* path, s32 pointIn } } - func_8017B7F8(&point, RAD_TO_BINANG(func_80086B30(diffX, diffZ)), &px, &pz, &d); + Math3D_RotateXZPlane(&point, RAD_TO_BINANG(func_80086B30(diffX, diffZ)), &px, &pz, &d); if (((this->actor.world.pos.x * px) + (pz * this->actor.world.pos.z) + d) > 0.0f) { reached = true; } @@ -198,7 +198,7 @@ s32 EnRuppecrow_ReachedPointCounterClockwise(EnRuppecrow* this, Path* path, s32 } } - func_8017B7F8(&point, RAD_TO_BINANG(func_80086B30(diffX, diffZ)), &px, &pz, &d); + Math3D_RotateXZPlane(&point, RAD_TO_BINANG(func_80086B30(diffX, diffZ)), &px, &pz, &d); if (((this->actor.world.pos.x * px) + (pz * this->actor.world.pos.z) + d) > 0.0f) { reached = true; } diff --git a/src/overlays/actors/ovl_En_Scopecrow/z_en_scopecrow.c b/src/overlays/actors/ovl_En_Scopecrow/z_en_scopecrow.c index 321c790d1..c7a2863f6 100644 --- a/src/overlays/actors/ovl_En_Scopecrow/z_en_scopecrow.c +++ b/src/overlays/actors/ovl_En_Scopecrow/z_en_scopecrow.c @@ -192,7 +192,7 @@ s32 func_80BCD334(EnScopecrow* this, Path* path, s32 pointIndex) { phi_fa1 = points[index + 1].z - points[index - 1].z; } - func_8017B7F8(&sp30, RAD_TO_BINANG(func_80086B30(phi_fa0, phi_fa1)), &sp3C.z, &sp3C.y, &sp3C.x); + Math3D_RotateXZPlane(&sp30, RAD_TO_BINANG(func_80086B30(phi_fa0, phi_fa1)), &sp3C.z, &sp3C.y, &sp3C.x); if (((this->actor.world.pos.x * sp3C.z) + (sp3C.y * this->actor.world.pos.z) + sp3C.x) > 0.0f) { ret = true; diff --git a/src/overlays/actors/ovl_En_Scopenuts/z_en_scopenuts.c b/src/overlays/actors/ovl_En_Scopenuts/z_en_scopenuts.c index 07e2646a0..d9ef2b83e 100644 --- a/src/overlays/actors/ovl_En_Scopenuts/z_en_scopenuts.c +++ b/src/overlays/actors/ovl_En_Scopenuts/z_en_scopenuts.c @@ -654,7 +654,7 @@ s32 func_80BCC2AC(EnScopenuts* this, Path* path, s32 arg2_) { phi_f14 = sp5C[arg2 + 1].z - sp5C[arg2 - 1].z; } - func_8017B7F8(&sp30, RAD_TO_BINANG(func_80086B30(phi_f12, phi_f14)), &sp44, &sp40, &sp3C); + Math3D_RotateXZPlane(&sp30, RAD_TO_BINANG(func_80086B30(phi_f12, phi_f14)), &sp44, &sp40, &sp3C); if (((this->actor.world.pos.x * sp44) + (sp40 * this->actor.world.pos.z) + sp3C) > 0.0f) { sp50 = true; diff --git a/src/overlays/actors/ovl_En_Sellnuts/z_en_sellnuts.c b/src/overlays/actors/ovl_En_Sellnuts/z_en_sellnuts.c index 871bb85a8..04daf8095 100644 --- a/src/overlays/actors/ovl_En_Sellnuts/z_en_sellnuts.c +++ b/src/overlays/actors/ovl_En_Sellnuts/z_en_sellnuts.c @@ -916,7 +916,7 @@ s32 func_80ADCE4C(EnSellnuts* this, Path* path, s32 arg2) { pointY = points[var + 1].z - points[var - 1].z; } - func_8017B7F8(&sp30, RAD_TO_BINANG(func_80086B30(pointX, pointY)), &sp44, &sp40, &sp3C); + Math3D_RotateXZPlane(&sp30, RAD_TO_BINANG(func_80086B30(pointX, pointY)), &sp44, &sp40, &sp3C); if (((this->actor.world.pos.x * sp44) + (sp40 * this->actor.world.pos.z) + sp3C) > 0.0f) { ret = true; } diff --git a/src/overlays/actors/ovl_En_Suttari/z_en_suttari.c b/src/overlays/actors/ovl_En_Suttari/z_en_suttari.c index 196b29263..2c3ee319c 100644 --- a/src/overlays/actors/ovl_En_Suttari/z_en_suttari.c +++ b/src/overlays/actors/ovl_En_Suttari/z_en_suttari.c @@ -589,7 +589,7 @@ s32 func_80BAB758(EnSuttari* this, Path* path, s32 arg2) { sp54 = sp5C[index + 1].x - sp5C[index - 1].x; sp48 = sp5C[index + 1].z - sp5C[index - 1].z; } - func_8017B7F8(&sp30, RAD_TO_BINANG(func_80086B30(sp54, sp48)), &sp44, &sp40, &sp3C); + Math3D_RotateXZPlane(&sp30, RAD_TO_BINANG(func_80086B30(sp54, sp48)), &sp44, &sp40, &sp3C); if (((sp44 * this->actor.world.pos.x) + (sp40 * this->actor.world.pos.z) + sp3C) > 0.0f) { ret = true; } @@ -619,7 +619,7 @@ s32 func_80BAB8F4(EnSuttari* this, Path* path, s32 arg2) { sp54 = sp5C[index - 1].x - sp5C[index + 1].x; sp48 = sp5C[index - 1].z - sp5C[index + 1].z; } - func_8017B7F8(&sp30, RAD_TO_BINANG(func_80086B30(sp54, sp48)), &sp44, &sp40, &sp3C); + Math3D_RotateXZPlane(&sp30, RAD_TO_BINANG(func_80086B30(sp54, sp48)), &sp44, &sp40, &sp3C); if (((sp44 * this->actor.world.pos.x) + (sp40 * this->actor.world.pos.z) + sp3C) > 0.0f) { ret = true; } diff --git a/src/overlays/actors/ovl_En_Trt2/z_en_trt2.c b/src/overlays/actors/ovl_En_Trt2/z_en_trt2.c index 67f52e064..5dc1b749d 100644 --- a/src/overlays/actors/ovl_En_Trt2/z_en_trt2.c +++ b/src/overlays/actors/ovl_En_Trt2/z_en_trt2.c @@ -592,7 +592,7 @@ s32 func_80AD475C(EnTrt2* this, Path* path, s32 arg2) { phi_f14 = points[arg + 1].z - points[arg - 1].z; } - func_8017B7F8(&sp30, RAD_TO_BINANG(func_80086B30(phi_f12, phi_f14)), &sp44, &sp40, &sp3C); + Math3D_RotateXZPlane(&sp30, RAD_TO_BINANG(func_80086B30(phi_f12, phi_f14)), &sp44, &sp40, &sp3C); if (((this->actor.world.pos.x * sp44) + (sp40 * this->actor.world.pos.z) + sp3C) > 0.0f) { ret = true; diff --git a/src/overlays/actors/ovl_En_Tru_Mt/z_en_tru_mt.c b/src/overlays/actors/ovl_En_Tru_Mt/z_en_tru_mt.c index 09ec80172..fd279df36 100644 --- a/src/overlays/actors/ovl_En_Tru_Mt/z_en_tru_mt.c +++ b/src/overlays/actors/ovl_En_Tru_Mt/z_en_tru_mt.c @@ -301,7 +301,7 @@ s32 func_80B76600(EnTruMt* this, Path* path, s32 arg2) { phi_f14 = sp5C[idx + 1].z - sp5C[idx - 1].z; } - func_8017B7F8(&sp30, RAD_TO_BINANG(func_80086B30(phi_f12, phi_f14)), &sp44, &sp40, &sp3C); + Math3D_RotateXZPlane(&sp30, RAD_TO_BINANG(func_80086B30(phi_f12, phi_f14)), &sp44, &sp40, &sp3C); if (((this->actor.world.pos.x * sp44) + (sp40 * this->actor.world.pos.z) + sp3C) > 0.0f) { sp50 = true; } diff --git a/src/overlays/actors/ovl_Obj_Um/z_obj_um.c b/src/overlays/actors/ovl_Obj_Um/z_obj_um.c index bd43c4679..7128d57a0 100644 --- a/src/overlays/actors/ovl_Obj_Um/z_obj_um.c +++ b/src/overlays/actors/ovl_Obj_Um/z_obj_um.c @@ -400,7 +400,7 @@ s32 func_80B783E0(ObjUm* this, PlayState* play, s32 banditIndex, EnHorse* bandit temp_a1 = Math_Atan2S(phi_f12, phi_f14); - func_8017B7F8(&sp50, temp_a1, &sp4C, &sp48, &sp44); + Math3D_RotateXZPlane(&sp50, temp_a1, &sp4C, &sp48, &sp44); if (((bandit->actor.world.pos.x * sp4C) + (sp48 * bandit->actor.world.pos.z) + sp44) > 0.0f) { bandit->curRaceWaypoint++; if (bandit->curRaceWaypoint >= sp68) { @@ -483,7 +483,7 @@ s32 func_80B78764(ObjUm* this, PlayState* play, EnHorse* bandit1, EnHorse* bandi func_80B781DC(this, bandit1, bandit2, play); } - Math3D_Lerp(&bandit1->unk_540, &this->unk_360[bandit1->unk_550], 1.0f - ((f32)bandit1->unk_55C / bandit1->unk_560), + Math3D_LineSplitRatio(&bandit1->unk_540, &this->unk_360[bandit1->unk_550], 1.0f - ((f32)bandit1->unk_55C / bandit1->unk_560), &sp30); bandit1->banditPosition = sp30; bandit1->unk_588 = this->dyna.actor.shape.rot.y; @@ -1070,7 +1070,7 @@ ObjUmPathState ObjUm_UpdatePath(ObjUm* this, PlayState* play) { angle = Math_Atan2S(xDiff, zDiff); - func_8017B7F8(&sp50, angle, &sp4C, &sp48, &sp44); + Math3D_RotateXZPlane(&sp50, angle, &sp4C, &sp48, &sp44); if (((this->dyna.actor.world.pos.x * sp4C) + (sp48 * this->dyna.actor.world.pos.z) + sp44) > 0.0f) { this->pointIndex++; diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index 5041005a1..876c51dc1 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -3257,17 +3257,17 @@ 0x801795C0:("randPlusMinusPoint5Scaled",), 0x801795F0:("Math3D_Normalize",), 0x80179678:("Math3D_PlaneVsLineSegClosestPoint",), - 0x80179798:("Math3D_LineVsLineClosestTwoPoints",), + 0x80179798:("Math3D_LineSegMakePerpLineSeg",), 0x80179A44:("Math3D_LineClosestToPoint",), - 0x80179B34:("func_80179B34",), - 0x80179B94:("func_80179B94",), - 0x80179D74:("func_80179D74",), - 0x80179DF0:("Math3D_ScaleAndAdd",), - 0x80179E3C:("Math3D_Lerp",), + 0x80179B34:("Math3D_FindPointOnPlaneIntersect",), + 0x80179B94:("Math3D_PlaneVsPlaneNewLine",), + 0x80179D74:("Math3D_PlaneVsPlaneVsLineClosestPoint",), + 0x80179DF0:("Math3D_PointOnDirectedLine",), + 0x80179E3C:("Math3D_LineSplitRatio",), 0x80179E88:("Math3D_Cos",), 0x80179EAC:("Math3D_CosOut",), - 0x80179F64:("func_80179F64",), - 0x8017A038:("Math3D_XZBoundCheck",), + 0x80179F64:("Math3D_Vec3fReflect",), + 0x8017A038:("Math3D_PointInSquare2D",), 0x8017A09C:("func_8017A09C",), 0x8017A1D0:("func_8017A1D0",), 0x8017A304:("func_8017A304",), @@ -3291,59 +3291,59 @@ 0x8017ABBC:("Math3D_PointRelativeToCubeVertices",), 0x8017AD38:("Math3D_LineVsCube",), 0x8017B68C:("Math3D_LineVsCubeShort",), - 0x8017B7F8:("func_8017B7F8",), - 0x8017B884:("Math3D_UnitNormalVector",), - 0x8017B998:("Math3D_SignedDistanceFromPlane",), - 0x8017B9D8:("func_8017B9D8",), + 0x8017B7F8:("Math3D_RotateXZPlane",), + 0x8017B884:("Math3D_DefPlane",), + 0x8017B998:("Math3D_PlaneF",), + 0x8017B9D8:("Math3D_Plane",), 0x8017BA14:("Math3D_UDistPlaneToPos",), 0x8017BA4C:("Math3D_DistPlaneToPos",), - 0x8017BAD0:("Math3D_TriChkPointParaYDist",), - 0x8017BD98:("func_8017BD98",), - 0x8017BDE0:("func_8017BDE0",), + 0x8017BAD0:("Math3D_TriChkPointParaYImpl",), + 0x8017BD98:("Math3D_TriChkPointParaYDeterminate",), + 0x8017BDE0:("Math3D_TriChkPointParaYSlopedY",), 0x8017BE30:("Math3D_TriChkPointParaYIntersectDist",), 0x8017BEE0:("Math3D_TriChkPointParaYIntersectInsideTri",), - 0x8017BF8C:("func_8017BF8C",), + 0x8017BF8C:("Math3D_TriChkPointParaY",), 0x8017C008:("Math3D_TriChkLineSegParaYIntersect",), - 0x8017C17C:("func_8017C17C",), - 0x8017C1F0:("func_8017C1F0",), - 0x8017C494:("Math3D_TriChkPointParaYIntersectInsideTri2",), - 0x8017C540:("Math3D_TriChkPointParaXDist",), - 0x8017C808:("func_8017C808",), + 0x8017C17C:("Math3D_TriChkPointParaYDist",), + 0x8017C1F0:("Math3D_TriChkPointParaYImplNoCheckRange",), + 0x8017C494:("Math3D_TriChkPointParaYNoRangeCheckIntersectInsideTri",), + 0x8017C540:("Math3D_TriChkPointParaXImpl",), + 0x8017C808:("Math3D_TriChkPointParaXDeterminate",), 0x8017C850:("Math3D_TriChkPointParaXIntersect",), - 0x8017C904:("func_8017C904",), + 0x8017C904:("Math3D_TriChkPointParaX",), 0x8017C980:("Math3D_TriChkLineSegParaXIntersect",), - 0x8017CB08:("func_8017CB08",), - 0x8017CB7C:("Math3D_TriChkLineSegParaZDist",), - 0x8017CEA8:("func_8017CEA8",), + 0x8017CB08:("Math3D_TriChkLineSegParaXDist",), + 0x8017CB7C:("Math3D_TriChkPointParaZImpl",), + 0x8017CEA8:("Math3D_TriChkPointParaZDeterminate",), 0x8017CEF0:("Math3D_TriChkPointParaZIntersect",), - 0x8017CFA4:("func_8017CFA4",), + 0x8017CFA4:("Math3D_TriChkPointParaZ",), 0x8017D020:("Math3D_TriChkLineSegParaZIntersect",), - 0x8017D1AC:("func_8017D1AC",), - 0x8017D220:("func_8017D220",), + 0x8017D1AC:("Math3D_TriChkLineSegParaZDist",), + 0x8017D220:("Math3D_LineSegFindPlaneIntersect",), 0x8017D2FC:("Math3D_LineSegVsPlane",), - 0x8017D404:("func_8017D404",), - 0x8017D568:("Math3D_TriSetCoords",), - 0x8017D618:("Math3D_IsPointInSphere",), + 0x8017D404:("Math3D_TriLineIntersect",), + 0x8017D568:("Math3D_TriNorm",), + 0x8017D618:("Math3D_PointInSph",), 0x8017D668:("Math3D_PointDistToLine2D",), 0x8017D7C0:("func_8017D7C0",), 0x8017D814:("func_8017D814",), 0x8017D91C:("func_8017D91C",), 0x8017DA24:("func_8017DA24",), 0x8017DB2C:("Math3D_LineVsSph",), - 0x8017DD34:("func_8017DD34",), - 0x8017DE74:("Math3D_ColSphereTri",), - 0x8017E294:("func_8017E294",), - 0x8017E350:("func_8017E350",), - 0x8017ED20:("Math3D_ColCylinderTri",), - 0x8017F1A0:("func_8017F1A0",), + 0x8017DD34:("Math3D_GetSphVsTriIntersectPoint",), + 0x8017DE74:("Math3D_TriVsSphIntersect",), + 0x8017E294:("Math3D_PointInCyl",), + 0x8017E350:("Math3D_CylVsLineSeg",), + 0x8017ED20:("Math3D_CylTriVsIntersect",), + 0x8017F1A0:("Math3D_CylVsTri",), 0x8017F1C0:("Math3D_SphVsSph",), - 0x8017F1E0:("Math3D_ColSphereSphereIntersect",), - 0x8017F200:("Math3D_ColSphereSphereIntersectAndDistance",), - 0x8017F2CC:("Math3D_ColSphereCylinderDistance",), - 0x8017F2EC:("Math3D_ColSphereCylinderDistanceAndAmount",), - 0x8017F45C:("Math3D_ColCylinderCylinderAmount",), - 0x8017F47C:("Math3D_ColCylinderCylinderAmountAndDistance",), - 0x8017F64C:("Math3d_ColTriTri",), + 0x8017F1E0:("Math3D_SphVsSphOverlap",), + 0x8017F200:("Math3D_SphVsSphOverlapCenter",), + 0x8017F2CC:("Math3D_SphVsCylOverlapDist",), + 0x8017F2EC:("Math3D_SphVsCylOverlapCenterDist",), + 0x8017F45C:("Math3D_CylOutsideCyl",), + 0x8017F47C:("Math3D_CylOutsideCylDist",), + 0x8017F64C:("Math3D_TriVsTriIntersect",), 0x8017F9C0:("Math3D_XZInSphere",), 0x8017FA34:("Math3D_XYInSphere",), 0x8017FAA8:("Math3D_YZInSphere",), diff --git a/tools/namefixer.py b/tools/namefixer.py index eefefac57..130c3f07b 100755 --- a/tools/namefixer.py +++ b/tools/namefixer.py @@ -116,7 +116,6 @@ wordReplace = { "Actor_IsActorFacedByActor": "Actor_ActorBIsFacingActorA", "Actor_MarkForDeath": "Actor_Kill", "func_800B84D0": "Actor_ProcessTalkRequest", - "func_8017D668": "Math3D_PointDistToLine2D", "THGA_GetSize": "THGA_GetRemaining", "THGA_AllocStartArray8": "THGA_AllocDisplayList", @@ -493,6 +492,8 @@ wordReplace = { "func_800CA1E8": "WaterBox_GetSurface1_2", "func_800CA22C": "WaterBox_GetSurface2", "func_800CA6D8": "WaterBox_GetLightSettingIndex", + + "func_8017D668": "Math3D_PointDistToLine2D", "func_80179678": "Math3D_PlaneVsLineSegClosestPoint", "Math3D_DistanceSquared": "Math3D_Vec3fDistSq", "Math3D_NormalVector": "Math3D_SurfaceNorm", @@ -502,15 +503,16 @@ wordReplace = { "func_8017AD38": "Math3D_LineVsCube", "Math3D_NormalizedDistanceFromPlane": "Math3D_UDistPlaneToPos", "Math3D_NormalizedSignedDistanceFromPlane": "Math3D_DistPlaneToPos", - "func_8017BAD0": "Math3D_TriChkPointParaYDist", + "func_8017BAD0": "Math3D_TriChkPointParaYImpl", + # "Math3D_TriChkPointParaYDist": "Math3D_TriChkPointParaYImpl", "func_8017BE30": "Math3D_TriChkPointParaYIntersectDist", "func_8017BEE0": "Math3D_TriChkPointParaYIntersectInsideTri", "func_8017C008": "Math3D_TriChkLineSegParaYIntersect", - "func_8017C494": "Math3D_TriChkPointParaYIntersectInsideTri2", - "func_8017C540": "Math3D_TriChkPointParaXDist", + "func_8017C494": "Math3D_TriChkPointParaYNoRangeCheckIntersectInsideTri", + "func_8017C540": "Math3D_TriChkPointParaXImpl", "func_8017C850": "Math3D_TriChkPointParaXIntersect", "func_8017C980": "Math3D_TriChkLineSegParaXIntersect", - "func_8017CB7C": "Math3D_TriChkLineSegParaZDist", + "func_8017CB7C": "Math3D_TriChkPointParaZImpl", "func_8017CEF0": "Math3D_TriChkPointParaZIntersect", "func_8017D020": "Math3D_TriChkLineSegParaZIntersect", "Math3D_ColSphereLineSeg": "Math3D_LineVsSph", @@ -519,7 +521,6 @@ wordReplace = { "Math3D_Parallel": "Math3D_Cos", "Math3D_AngleBetweenVectors": "Math3D_CosOut", "func_80179A44": "Math3D_LineClosestToPoint", - "Math3D_XZLengthSquared": "Math3D_Dist1DSq", "Math3D_XZLength": "Math3D_Dist1D", "Math3D_XZDistanceSquared": "Math3D_Dist2DSq", @@ -527,11 +528,54 @@ wordReplace = { "Math3D_LengthSquared": "Math3D_Vec3fMagnitudeSq", "Math3D_Distance": "Math3D_Vec3f_DistXYZ", "Math3D_DistanceS": "Math3D_DistXYZ16toF", - "func_80179798": "Math3D_LineVsLineClosestTwoPoints", - + "func_80179798": "Math3D_LineSegMakePerpLineSeg", + "Math3D_LineVsLineClosestTwoPoints": "Math3D_LineSegMakePerpLineSeg", + "func_80179B34": "Math3D_FindPointOnPlaneIntersect", + "func_80179B94": "Math3D_PlaneVsPlaneNewLine", + "func_8017B9D8": "Math3D_Plane", + "func_8017D404": "Math3D_TriLineIntersect", + "Math3D_ColCylinderCylinderAmountAndDistance": "Math3D_CylOutsideCylDist", + "Math3D_ColCylinderCylinderAmount": "Math3D_CylOutsideCyl", + "Math3D_ColSphereCylinderDistanceAndAmount": "Math3D_SphVsCylOverlapCenterDist", + "Math3D_ColCylinderTri": "Math3D_CylTriVsIntersect", + "func_8017F1A0": "Math3D_CylVsTri", + "Math3D_ColSphereSphereIntersect": "Math3D_SphVsSphOverlap", + "Math3D_ColSphereSphereIntersectAndDistance": "Math3D_SphVsSphOverlapCenter", + "Math3D_ColSphereCylinderDistance": "Math3D_SphVsCylOverlapDist", + "func_8017E350": "Math3D_CylVsLineSeg", + "Math3D_ColSphereTri": "Math3D_TriVsSphIntersect", + "Math3D_ScaleAndAdd": "Math3D_PointOnDirectedLine", + "Math3D_Lerp": "Math3D_LineSplitRatio", + "func_80179D74": "Math3D_PlaneVsPlaneVsLineClosestPoint", + "func_8017E294": "Math3D_PointInCyl", + "func_80179F64": "Math3D_Vec3fReflect", + "Math3D_XZBoundCheck": "Math3D_PointInSquare2D", + "func_8017B7F8": "Math3D_RotateXZPlane", + "Math3D_UnitNormalVector": "Math3D_DefPlane", + "Math3D_SignedDistanceFromPlane": "Math3D_PlaneF", + "func_8017BD98": "Math3D_TriChkPointParaYDeterminate", + "func_8017BDE0": "Math3D_TriChkPointParaYSlopedY", + "func_8017BF8C": "Math3D_TriChkPointParaY", + # "func_8017C17C": "Math3D_TriChkPointParaYDist", + "func_8017C1F0": "Math3D_TriChkPointParaYImplNoCheckRange", + "Math3D_TriChkPointParaYIntersectInsideTri2": "Math3D_TriChkPointParaYNoRangeCheckIntersectInsideTri", + "Math3D_TriChkPointParaXDist": "Math3D_TriChkPointParaXImpl", + "func_8017C808": "Math3D_TriChkPointParaXDeterminate", + "func_8017C904": "Math3D_TriChkPointParaX", + "func_8017CB08": "Math3D_TriChkLineSegParaXDist", + # "Math3D_TriChkLineSegParaZDist": "Math3D_TriChkPointParaZImpl", + "func_8017CEA8": "Math3D_TriChkPointParaZDeterminate", + "func_8017CFA4": "Math3D_TriChkPointParaZ", + # "func_8017D1AC": "Math3D_TriChkLineSegParaZDist", + "func_8017D220": "Math3D_LineSegFindPlaneIntersect", + "Math3D_TriSetCoords": "Math3D_TriNorm", + "Math3D_IsPointInSphere": "Math3D_PointInSph", + "Math3d_ColTriTri": "Math3D_TriVsTriIntersect", + "func_8017DD34": "Math3D_GetSphVsTriIntersectPoint", "func_8017F9C0": "Math3D_XZInSphere", "func_8017FA34": "Math3D_XYInSphere", "func_8017FAA8": "Math3D_YZInSphere", + "func_800DFB14": "Camera_ChangeActorCsCamIndex", "func_800DFC68": "Camera_GetInputDirYaw", "func_800DFCB4": "Camera_GetCamDirPitch", diff --git a/tools/sizes/code_functions.csv b/tools/sizes/code_functions.csv index 144678765..fe47a815c 100644 --- a/tools/sizes/code_functions.csv +++ b/tools/sizes/code_functions.csv @@ -2771,17 +2771,17 @@ asm/non_matchings/code/sys_math/Rand_ZeroFloat.s,Rand_ZeroFloat,0x80179594,0xB asm/non_matchings/code/sys_math/randPlusMinusPoint5Scaled.s,randPlusMinusPoint5Scaled,0x801795C0,0xC asm/non_matchings/code/sys_math3d/Math3D_Normalize.s,Math3D_Normalize,0x801795F0,0x22 asm/non_matchings/code/sys_math3d/Math3D_PlaneVsLineSegClosestPoint.s,Math3D_PlaneVsLineSegClosestPoint,0x80179678,0x48 -asm/non_matchings/code/sys_math3d/Math3D_LineVsLineClosestTwoPoints.s,Math3D_LineVsLineClosestTwoPoints,0x80179798,0xAB +asm/non_matchings/code/sys_math3d/Math3D_LineSegMakePerpLineSeg.s,Math3D_LineSegMakePerpLineSeg,0x80179798,0xAB asm/non_matchings/code/sys_math3d/Math3D_LineClosestToPoint.s,Math3D_LineClosestToPoint,0x80179A44,0x3C -asm/non_matchings/code/sys_math3d/func_80179B34.s,func_80179B34,0x80179B34,0x18 -asm/non_matchings/code/sys_math3d/func_80179B94.s,func_80179B94,0x80179B94,0x78 -asm/non_matchings/code/sys_math3d/func_80179D74.s,func_80179D74,0x80179D74,0x1F -asm/non_matchings/code/sys_math3d/Math3D_ScaleAndAdd.s,Math3D_ScaleAndAdd,0x80179DF0,0x13 -asm/non_matchings/code/sys_math3d/Math3D_Lerp.s,Math3D_Lerp,0x80179E3C,0x13 +asm/non_matchings/code/sys_math3d/Math3D_FindPointOnPlaneIntersect.s,Math3D_FindPointOnPlaneIntersect,0x80179B34,0x18 +asm/non_matchings/code/sys_math3d/Math3D_PlaneVsPlaneNewLine.s,Math3D_PlaneVsPlaneNewLine,0x80179B94,0x78 +asm/non_matchings/code/sys_math3d/Math3D_PlaneVsPlaneVsLineClosestPoint.s,Math3D_PlaneVsPlaneVsLineClosestPoint,0x80179D74,0x1F +asm/non_matchings/code/sys_math3d/Math3D_PointOnDirectedLine.s,Math3D_PointOnDirectedLine,0x80179DF0,0x13 +asm/non_matchings/code/sys_math3d/Math3D_LineSplitRatio.s,Math3D_LineSplitRatio,0x80179E3C,0x13 asm/non_matchings/code/sys_math3d/Math3D_Cos.s,Math3D_Cos,0x80179E88,0x9 asm/non_matchings/code/sys_math3d/Math3D_CosOut.s,Math3D_CosOut,0x80179EAC,0x2E -asm/non_matchings/code/sys_math3d/func_80179F64.s,func_80179F64,0x80179F64,0x35 -asm/non_matchings/code/sys_math3d/Math3D_XZBoundCheck.s,Math3D_XZBoundCheck,0x8017A038,0x19 +asm/non_matchings/code/sys_math3d/Math3D_Vec3fReflect.s,Math3D_Vec3fReflect,0x80179F64,0x35 +asm/non_matchings/code/sys_math3d/Math3D_PointInSquare2D.s,Math3D_PointInSquare2D,0x8017A038,0x19 asm/non_matchings/code/sys_math3d/func_8017A09C.s,func_8017A09C,0x8017A09C,0x4D asm/non_matchings/code/sys_math3d/func_8017A1D0.s,func_8017A1D0,0x8017A1D0,0x4D asm/non_matchings/code/sys_math3d/func_8017A304.s,func_8017A304,0x8017A304,0x4D @@ -2805,59 +2805,59 @@ asm/non_matchings/code/sys_math3d/Math3D_PointRelativeToCubeEdges.s,Math3D_Point asm/non_matchings/code/sys_math3d/Math3D_PointRelativeToCubeVertices.s,Math3D_PointRelativeToCubeVertices,0x8017ABBC,0x5F asm/non_matchings/code/sys_math3d/Math3D_LineVsCube.s,Math3D_LineVsCube,0x8017AD38,0x255 asm/non_matchings/code/sys_math3d/Math3D_LineVsCubeShort.s,Math3D_LineVsCubeShort,0x8017B68C,0x5B -asm/non_matchings/code/sys_math3d/func_8017B7F8.s,func_8017B7F8,0x8017B7F8,0x23 -asm/non_matchings/code/sys_math3d/Math3D_UnitNormalVector.s,Math3D_UnitNormalVector,0x8017B884,0x45 -asm/non_matchings/code/sys_math3d/Math3D_SignedDistanceFromPlane.s,Math3D_SignedDistanceFromPlane,0x8017B998,0x10 -asm/non_matchings/code/sys_math3d/func_8017B9D8.s,func_8017B9D8,0x8017B9D8,0xF +asm/non_matchings/code/sys_math3d/Math3D_RotateXZPlane.s,Math3D_RotateXZPlane,0x8017B7F8,0x23 +asm/non_matchings/code/sys_math3d/Math3D_DefPlane.s,Math3D_DefPlane,0x8017B884,0x45 +asm/non_matchings/code/sys_math3d/Math3D_PlaneF.s,Math3D_PlaneF,0x8017B998,0x10 +asm/non_matchings/code/sys_math3d/Math3D_Plane.s,Math3D_Plane,0x8017B9D8,0xF asm/non_matchings/code/sys_math3d/Math3D_UDistPlaneToPos.s,Math3D_UDistPlaneToPos,0x8017BA14,0xE asm/non_matchings/code/sys_math3d/Math3D_DistPlaneToPos.s,Math3D_DistPlaneToPos,0x8017BA4C,0x21 -asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYDist.s,Math3D_TriChkPointParaYDist,0x8017BAD0,0xB2 -asm/non_matchings/code/sys_math3d/func_8017BD98.s,func_8017BD98,0x8017BD98,0x12 -asm/non_matchings/code/sys_math3d/func_8017BDE0.s,func_8017BDE0,0x8017BDE0,0x14 +asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYImpl.s,Math3D_TriChkPointParaYImpl,0x8017BAD0,0xB2 +asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYDeterminate.s,Math3D_TriChkPointParaYDeterminate,0x8017BD98,0x12 +asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYSlopedY.s,Math3D_TriChkPointParaYSlopedY,0x8017BDE0,0x14 asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYIntersectDist.s,Math3D_TriChkPointParaYIntersectDist,0x8017BE30,0x2C asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYIntersectInsideTri.s,Math3D_TriChkPointParaYIntersectInsideTri,0x8017BEE0,0x2B -asm/non_matchings/code/sys_math3d/func_8017BF8C.s,func_8017BF8C,0x8017BF8C,0x1F +asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaY.s,Math3D_TriChkPointParaY,0x8017BF8C,0x1F asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaYIntersect.s,Math3D_TriChkLineSegParaYIntersect,0x8017C008,0x5D -asm/non_matchings/code/sys_math3d/func_8017C17C.s,func_8017C17C,0x8017C17C,0x1D -asm/non_matchings/code/sys_math3d/func_8017C1F0.s,func_8017C1F0,0x8017C1F0,0xA9 -asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYIntersectInsideTri2.s,Math3D_TriChkPointParaYIntersectInsideTri2,0x8017C494,0x2B -asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaXDist.s,Math3D_TriChkPointParaXDist,0x8017C540,0xB2 -asm/non_matchings/code/sys_math3d/func_8017C808.s,func_8017C808,0x8017C808,0x12 +asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYDist.s,Math3D_TriChkPointParaYDist,0x8017C17C,0x1D +asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYImplNoCheckRange.s,Math3D_TriChkPointParaYImplNoCheckRange,0x8017C1F0,0xA9 +asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaYNoRangeCheckIntersectInsideTri.s,Math3D_TriChkPointParaYNoRangeCheckIntersectInsideTri,0x8017C494,0x2B +asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaXImpl.s,Math3D_TriChkPointParaXImpl,0x8017C540,0xB2 +asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaXDeterminate.s,Math3D_TriChkPointParaXDeterminate,0x8017C808,0x12 asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaXIntersect.s,Math3D_TriChkPointParaXIntersect,0x8017C850,0x2D -asm/non_matchings/code/sys_math3d/func_8017C904.s,func_8017C904,0x8017C904,0x1F +asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaX.s,Math3D_TriChkPointParaX,0x8017C904,0x1F asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaXIntersect.s,Math3D_TriChkLineSegParaXIntersect,0x8017C980,0x62 -asm/non_matchings/code/sys_math3d/func_8017CB08.s,func_8017CB08,0x8017CB08,0x1D -asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaZDist.s,Math3D_TriChkLineSegParaZDist,0x8017CB7C,0xCB -asm/non_matchings/code/sys_math3d/func_8017CEA8.s,func_8017CEA8,0x8017CEA8,0x12 +asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaXDist.s,Math3D_TriChkLineSegParaXDist,0x8017CB08,0x1D +asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaZImpl.s,Math3D_TriChkPointParaZImpl,0x8017CB7C,0xCB +asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaZDeterminate.s,Math3D_TriChkPointParaZDeterminate,0x8017CEA8,0x12 asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaZIntersect.s,Math3D_TriChkPointParaZIntersect,0x8017CEF0,0x2D -asm/non_matchings/code/sys_math3d/func_8017CFA4.s,func_8017CFA4,0x8017CFA4,0x1F +asm/non_matchings/code/sys_math3d/Math3D_TriChkPointParaZ.s,Math3D_TriChkPointParaZ,0x8017CFA4,0x1F asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaZIntersect.s,Math3D_TriChkLineSegParaZIntersect,0x8017D020,0x63 -asm/non_matchings/code/sys_math3d/func_8017D1AC.s,func_8017D1AC,0x8017D1AC,0x1D -asm/non_matchings/code/sys_math3d/func_8017D220.s,func_8017D220,0x8017D220,0x37 +asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaZDist.s,Math3D_TriChkLineSegParaZDist,0x8017D1AC,0x1D +asm/non_matchings/code/sys_math3d/Math3D_LineSegFindPlaneIntersect.s,Math3D_LineSegFindPlaneIntersect,0x8017D220,0x37 asm/non_matchings/code/sys_math3d/Math3D_LineSegVsPlane.s,Math3D_LineSegVsPlane,0x8017D2FC,0x42 -asm/non_matchings/code/sys_math3d/func_8017D404.s,func_8017D404,0x8017D404,0x59 -asm/non_matchings/code/sys_math3d/Math3D_TriSetCoords.s,Math3D_TriSetCoords,0x8017D568,0x2C -asm/non_matchings/code/sys_math3d/Math3D_IsPointInSphere.s,Math3D_IsPointInSphere,0x8017D618,0x14 +asm/non_matchings/code/sys_math3d/Math3D_TriLineIntersect.s,Math3D_TriLineIntersect,0x8017D404,0x59 +asm/non_matchings/code/sys_math3d/Math3D_TriNorm.s,Math3D_TriNorm,0x8017D568,0x2C +asm/non_matchings/code/sys_math3d/Math3D_PointInSph.s,Math3D_PointInSph,0x8017D618,0x14 asm/non_matchings/code/sys_math3d/Math3D_PointDistToLine2D.s,Math3D_PointDistToLine2D,0x8017D668,0x56 asm/non_matchings/code/sys_math3d/func_8017D7C0.s,func_8017D7C0,0x8017D7C0,0x15 asm/non_matchings/code/sys_math3d/func_8017D814.s,func_8017D814,0x8017D814,0x42 asm/non_matchings/code/sys_math3d/func_8017D91C.s,func_8017D91C,0x8017D91C,0x42 asm/non_matchings/code/sys_math3d/func_8017DA24.s,func_8017DA24,0x8017DA24,0x42 asm/non_matchings/code/sys_math3d/Math3D_LineVsSph.s,Math3D_LineVsSph,0x8017DB2C,0x82 -asm/non_matchings/code/sys_math3d/func_8017DD34.s,func_8017DD34,0x8017DD34,0x50 -asm/non_matchings/code/sys_math3d/Math3D_ColSphereTri.s,Math3D_ColSphereTri,0x8017DE74,0x108 -asm/non_matchings/code/sys_math3d/func_8017E294.s,func_8017E294,0x8017E294,0x2F -asm/non_matchings/code/sys_math3d/func_8017E350.s,func_8017E350,0x8017E350,0x274 -asm/non_matchings/code/sys_math3d/Math3D_ColCylinderTri.s,Math3D_ColCylinderTri,0x8017ED20,0x120 -asm/non_matchings/code/sys_math3d/func_8017F1A0.s,func_8017F1A0,0x8017F1A0,0x8 +asm/non_matchings/code/sys_math3d/Math3D_GetSphVsTriIntersectPoint.s,Math3D_GetSphVsTriIntersectPoint,0x8017DD34,0x50 +asm/non_matchings/code/sys_math3d/Math3D_TriVsSphIntersect.s,Math3D_TriVsSphIntersect,0x8017DE74,0x108 +asm/non_matchings/code/sys_math3d/Math3D_PointInCyl.s,Math3D_PointInCyl,0x8017E294,0x2F +asm/non_matchings/code/sys_math3d/Math3D_CylVsLineSeg.s,Math3D_CylVsLineSeg,0x8017E350,0x274 +asm/non_matchings/code/sys_math3d/Math3D_CylTriVsIntersect.s,Math3D_CylTriVsIntersect,0x8017ED20,0x120 +asm/non_matchings/code/sys_math3d/Math3D_CylVsTri.s,Math3D_CylVsTri,0x8017F1A0,0x8 asm/non_matchings/code/sys_math3d/Math3D_ColSphereSphere.s,Math3D_ColSphereSphere,0x8017F1C0,0x8 -asm/non_matchings/code/sys_math3d/Math3D_ColSphereSphereIntersect.s,Math3D_ColSphereSphereIntersect,0x8017F1E0,0x8 -asm/non_matchings/code/sys_math3d/Math3D_ColSphereSphereIntersectAndDistance.s,Math3D_ColSphereSphereIntersectAndDistance,0x8017F200,0x33 -asm/non_matchings/code/sys_math3d/Math3D_ColSphereCylinderDistance.s,Math3D_ColSphereCylinderDistance,0x8017F2CC,0x8 -asm/non_matchings/code/sys_math3d/Math3D_ColSphereCylinderDistanceAndAmount.s,Math3D_ColSphereCylinderDistanceAndAmount,0x8017F2EC,0x5C -asm/non_matchings/code/sys_math3d/Math3D_ColCylinderCylinderAmount.s,Math3D_ColCylinderCylinderAmount,0x8017F45C,0x8 -asm/non_matchings/code/sys_math3d/Math3D_ColCylinderCylinderAmountAndDistance.s,Math3D_ColCylinderCylinderAmountAndDistance,0x8017F47C,0x74 -asm/non_matchings/code/sys_math3d/Math3d_ColTriTri.s,Math3d_ColTriTri,0x8017F64C,0xDD +asm/non_matchings/code/sys_math3d/Math3D_SphVsSphOverlap.s,Math3D_SphVsSphOverlap,0x8017F1E0,0x8 +asm/non_matchings/code/sys_math3d/Math3D_SphVsSphOverlapCenter.s,Math3D_SphVsSphOverlapCenter,0x8017F200,0x33 +asm/non_matchings/code/sys_math3d/Math3D_SphVsCylOverlapDist.s,Math3D_SphVsCylOverlapDist,0x8017F2CC,0x8 +asm/non_matchings/code/sys_math3d/Math3D_SphVsCylOverlapCenterDist.s,Math3D_SphVsCylOverlapCenterDist,0x8017F2EC,0x5C +asm/non_matchings/code/sys_math3d/Math3D_CylOutsideCyl.s,Math3D_CylOutsideCyl,0x8017F45C,0x8 +asm/non_matchings/code/sys_math3d/Math3D_CylOutsideCylDist.s,Math3D_CylOutsideCylDist,0x8017F47C,0x74 +asm/non_matchings/code/sys_math3d/Math3D_TriVsTriIntersect.s,Math3D_TriVsTriIntersect,0x8017F64C,0xDD asm/non_matchings/code/sys_math3d/Math3D_XZInSphere.s,Math3D_XZInSphere,0x8017F9C0,0x1D asm/non_matchings/code/sys_math3d/Math3D_XYInSphere.s,Math3D_XYInSphere,0x8017FA34,0x1D asm/non_matchings/code/sys_math3d/Math3D_YZInSphere.s,Math3D_YZInSphere,0x8017FAA8,0x1D From 45b37e01a32c4d2a2efec87184a8571fcdc8731d Mon Sep 17 00:00:00 2001 From: angie Date: Wed, 24 May 2023 11:06:08 -0400 Subject: [PATCH 15/29] more cleanup --- include/z64camera.h | 2 +- include/z64math.h | 40 ++--- src/code/sys_math3d.c | 144 ++++++++++-------- src/code/z_bgcheck.c | 6 +- src/code/z_camera.c | 14 +- src/code/z_collision_check.c | 22 ++- .../z_en_horse_game_check.c | 18 +-- .../actors/ovl_En_Mushi2/z_en_mushi2.c | 28 ++-- src/overlays/actors/ovl_Obj_Um/z_obj_um.c | 4 +- tools/disasm/functions.txt | 4 +- tools/namefixer.py | 1 + tools/sizes/code_functions.csv | 4 +- 12 files changed, 150 insertions(+), 137 deletions(-) diff --git a/include/z64camera.h b/include/z64camera.h index 7232b3da2..00409e89a 100644 --- a/include/z64camera.h +++ b/include/z64camera.h @@ -1190,7 +1190,7 @@ typedef struct { /* 0x00 */ Vec3f unk_00; /* 0x0C */ Vec3f unk_0C; /* 0x18 */ f32 unk_18; - /* 0x1C */ Linef unk_1C; + /* 0x1C */ InfiniteLine unk_1C; /* 0x34 */ Vec3s unk_34; /* 0x3A */ s16 unk_3A; /* 0x3C */ s16 timer; diff --git a/include/z64math.h b/include/z64math.h index 7e1d990b5..3de1ce159 100644 --- a/include/z64math.h +++ b/include/z64math.h @@ -223,20 +223,20 @@ f32 Math_Atan2F_XY(f32 x, f32 y); f32 Math3D_Normalize(Vec3f* vec); s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* closestPoint); s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, Vec3f* lineAClosestToB, Vec3f* lineBClosestToA); -f32 Math3D_LineClosestToPoint(Linef* line, Vec3f* pos, Vec3f* closestPoint); +f32 Math3D_LineClosestToPoint(InfiniteLine* line, Vec3f* pos, Vec3f* closestPoint); void Math3D_FindPointOnPlaneIntersect(float planeAAxis1Norm, f32 planeAAxis2Norm, f32 planeBAxis1Norm, f32 planeBAxis2Norm, f32 axis3Direction, f32 planeADist, f32 planeBDist, float* axis1Point, float* axis2Point); s32 Math3D_PlaneVsPlaneNewLine(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, InfiniteLine* intersect); -// void Math3D_PlaneVsPlaneVsLineClosestPoint(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); +s32 Math3D_PlaneVsPlaneVsLineClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* point, Vec3f* closestPoint); void Math3D_PointOnDirectedLine(Vec3f* v0, Vec3f* dir, f32 scale, Vec3f* ret); void Math3D_LineSplitRatio(Vec3f* v0, Vec3f* v1, f32 ratio, Vec3f* ret); f32 Math3D_Cos(Vec3f* a, Vec3f* b); s32 Math3D_CosOut(Vec3f* a, Vec3f* b, f32* dst); void Math3D_Vec3fReflect(Vec3f* vec, Vec3f* normal, Vec3f* reflVec); s32 Math3D_PointInSquare2D(f32 upperLeftX, f32 lowerRightX, f32 upperLeftY, f32 lowerRightY, f32 x, f32 y); -// void func_8017A09C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); -// void func_8017A1D0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); +s32 func_8017A09C(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 arg5); +s32 func_8017A1D0(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 arg5); s32 func_8017A304(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 arg5); -// UNK_TYPE4 func_8017A438(Vec3f* pfParm1, Vec3f* pfParm2, Vec3f* pfParm3, Vec3f* pfParm4, f32 param_5); +s32 Math3D_SphCubeVsTriCube(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, f32 arg4); f32 Math3D_Dist1DSq(f32 a, f32 b); f32 Math3D_Dist1D(f32 a, f32 b); f32 Math3D_Dist2DSq(f32 x0, f32 y0, f32 x1, f32 y1); @@ -263,28 +263,28 @@ f32 Math3D_Plane(Plane* plane, Vec3f* pointOnPlane); f32 Math3D_UDistPlaneToPos(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* p); f32 Math3D_DistPlaneToPos(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* p); s32 Math3D_TriChkPointParaYImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f32 detMax, f32 chkDist, f32 ny); -// void Math3D_TriChkPointParaYDeterminate(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void Math3D_TriChkPointParaYSlopedY(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); +s32 Math3D_TriChkPointParaYDeterminate(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f32 detMax, f32 ny); +s32 Math3D_TriChkPointParaYSlopedY(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x); s32 Math3D_TriChkPointParaYIntersectDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 chkDist); s32 Math3D_TriChkPointParaYIntersectInsideTri(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 chkDist); -// void Math3D_TriChkPointParaY(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); +s32 Math3D_TriChkPointParaY(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 ny, f32 z, f32 x); s32 Math3D_TriChkLineSegParaYIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 y0, f32 y1); -// void Math3D_TriChkPointParaYDist(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void Math3D_TriChkPointParaYImplNoCheckRange(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8); +s32 Math3D_TriChkPointParaYDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 z, f32 x, f32 chkDist); +s32 Math3D_TriChkPointParaYImplNoCheckRange(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f32 detMax, f32 chkDist, f32 ny); s32 Math3D_TriChkPointParaYNoRangeCheckIntersectInsideTri(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 chkDist); s32 Math3D_TriChkPointParaXImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 detMax, f32 chkDist, f32 ny); -// void Math3D_TriChkPointParaXDeterminate(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); +s32 Math3D_TriChkPointParaXDeterminate(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 detMax, f32 nx); s32 Math3D_TriChkPointParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 y, f32 z, f32* xIntersect); -// void Math3D_TriChkPointParaX(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); +s32 Math3D_TriChkPointParaX(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 y, f32 z); s32 Math3D_TriChkLineSegParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 y, f32 z, f32* xIntersect, f32 x0, f32 x1); -// void Math3D_TriChkLineSegParaXDist(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); +s32 Math3D_TriChkLineSegParaXDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 y, f32 z, f32 chkDist); s32 Math3D_TriChkPointParaZImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 x, f32 y, f32 detMax, f32 chkDist, f32 nz); -// void Math3D_TriChkPointParaZDeterminate(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); +s32 Math3D_TriChkPointParaZDeterminate(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 detMax, f32 nx); s32 Math3D_TriChkPointParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, f32 y, f32* zIntersect); -// void Math3D_TriChkPointParaZ(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); +s32 Math3D_TriChkPointParaZ(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 y, f32 z); s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, f32 y, f32* zIntersect, f32 z0, f32 z1); -// void Math3D_TriChkLineSegParaZDist(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -// void Math3D_LineSegFindPlaneIntersect(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); +s32 Math3D_TriChkLineSegParaZDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 x, f32 y, f32 chkDist); +s32 Math3D_LineSegFindPlaneIntersect(f32 pointADist, f32 pointBDist, Vec3f* pointA, Vec3f* pointB, Vec3f* intersect); s32 Math3D_LineSegVsPlane(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersect, s32 fromFront); s32 Math3D_TriLineIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersect, s32 fromFront) ; void Math3D_TriNorm(TriNorm* tri, Vec3f* va, Vec3f* vb, Vec3f* vc); @@ -300,7 +300,7 @@ s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoi s32 Math3D_PointInCyl(Cylinder16* cyl, Vec3f* point); s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersectA, Vec3f* intersectB); s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect); -// void Math3D_CylVsTri(void); +s32 Math3D_CylVsTri(Cylinder16* cyl, TriNorm* tri); s32 Math3D_SphVsSph(Sphere16* sphereA, Sphere16* sphereB); s32 Math3D_SphVsSphOverlap(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize); s32 Math3D_SphVsSphOverlapCenter(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize, f32* centerDist); @@ -312,7 +312,7 @@ s32 Math3D_TriVsTriIntersect(TriNorm* ta, TriNorm* tb, Vec3f* intersect); s32 Math3D_XZInSphere(Sphere16* sphere, f32 x, f32 z); s32 Math3D_XYInSphere(Sphere16* sphere, f32 x, f32 y); s32 Math3D_YZInSphere(Sphere16* sphere, f32 y, f32 z); -// void func_8017FB1C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11); -// void func_8017FD44(void); +s32 Math3D_CircleLineIntersections(f32 centreX, f32 centerY, f32 radius, f32 pointX, f32 pointY, f32 dirX, f32 dirY, f32* intersectAX, f32* intersectAY, f32* intersectBX, f32* intersectBY); +void func_8017FD44(Vec3f* arg0, Vec3f* arg1, Vec3f* dst, f32 arg3); #endif diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 8a8656d4e..6d7cdc68c 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -1,6 +1,7 @@ #include "z64math.h" #include "libc/stdbool.h" #include "libc/math.h" +#include "macros.h" f32 Math3D_Normalize(Vec3f* vec) { f32 magnitude = Math3D_Vec3fMagnitude(vec); @@ -51,15 +52,15 @@ s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 * Finds the two points on lines A and B where the lines are closest together. */ s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, - Vec3f* lineAClosestToB, Vec3f* lineBClosestToA) { + Vec3f* lineAClosestToB, Vec3f* lineBClosestToA) { f32 sqMag; f32 scaleB; - f32 lineAx; - f32 lineAy; - f32 lineAz; - f32 lineBx; - f32 lineBy; - f32 lineBz; + f32 lineAx = lineAPointB->x - lineAPointA->x; + f32 lineAy = lineAPointB->y - lineAPointA->y; + f32 lineAz = lineAPointB->z - lineAPointA->z; + f32 lineBx = lineBPointB->x - lineBPointA->x; + f32 lineBy = lineBPointB->y - lineBPointA->y; + f32 lineBz = lineBPointB->z - lineBPointA->z; f32 compAAlongB; f32 compBAAlongB; Vec3f lineAPerpB; @@ -67,14 +68,6 @@ s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* f32 tA; f32 tB; - lineAx = lineAPointB->x - lineAPointA->x; - lineAy = lineAPointB->y - lineAPointA->y; - lineAz = lineAPointB->z - lineAPointA->z; - - lineBx = lineBPointB->x - lineBPointA->x; - lineBy = lineBPointB->y - lineBPointA->y; - lineBz = lineBPointB->z - lineBPointA->z; - sqMag = SQ(lineBx) + SQ(lineBy) + SQ(lineBz); if (IS_ZERO(sqMag)) { return false; @@ -118,8 +111,8 @@ s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* * Determines the closest point on the line `line` to `pos`, by forming a line perpendicular from * `point` to `line` closest point is placed in `closestPoint` */ -f32 Math3D_LineClosestToPoint(Linef* line, Vec3f* pos, Vec3f* closestPoint) { - f32 dirVectorSize = Math3D_Vec3fMagnitudeSq(&line->b); +f32 Math3D_LineClosestToPoint(InfiniteLine* line, Vec3f* pos, Vec3f* closestPoint) { + f32 dirVectorSize = Math3D_Vec3fMagnitudeSq(&line->dir); f32 t; if (IS_ZERO(dirVectorSize)) { @@ -127,11 +120,12 @@ f32 Math3D_LineClosestToPoint(Linef* line, Vec3f* pos, Vec3f* closestPoint) { //! @bug Missing early return } - t = (((pos->x - line->a.x) * line->b.x) + ((pos->y - line->a.y) * line->b.y) + ((pos->z - line->a.z) * line->b.z)) / + t = (((pos->x - line->point.x) * line->dir.x) + ((pos->y - line->point.y) * line->dir.y) + + ((pos->z - line->point.z) * line->dir.z)) / dirVectorSize; - closestPoint->x = (line->b.x * t) + line->a.x; - closestPoint->y = (line->b.y * t) + line->a.y; - closestPoint->z = (line->b.z * t) + line->a.z; + closestPoint->x = (line->dir.x * t) + line->point.x; + closestPoint->y = (line->dir.y * t) + line->point.y; + closestPoint->z = (line->dir.z * t) + line->point.z; return t; } @@ -186,10 +180,10 @@ s32 Math3D_PlaneVsPlaneNewLine(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeA // in-function static bss s32 Math3D_PlaneVsPlaneVsLineClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* point, Vec3f* closestPoint) { - static Linef planeIntersect; + static InfiniteLine planeIntersect; if (!Math3D_PlaneVsPlaneNewLine(planeAA, planeAB, planeAC, planeADist, planeBA, planeBB, planeBC, planeBDist, - (InfiniteLine*)&planeIntersect)) { + &planeIntersect)) { return false; } Math3D_LineClosestToPoint(&planeIntersect, point, closestPoint); @@ -264,7 +258,7 @@ void Math3D_Vec3fReflect(Vec3f* vec, Vec3f* normal, Vec3f* reflVec) { } s32 Math3D_PointInSquare2D(f32 upperLeftX, f32 lowerRightX, f32 upperLeftY, f32 lowerRightY, f32 x, f32 y) { - if (x >= upperLeftX && x <= lowerRightX && y >= upperLeftY && y <= lowerRightY) { + if ((x >= upperLeftX) && (x <= lowerRightX) && (y >= upperLeftY) && (y <= lowerRightY)) { return true; } return false; @@ -394,8 +388,7 @@ s32 func_8017A304(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 return 1; } -// Math3D_SphCubeVsTriCube -s32 func_8017A438(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, f32 arg4) { +s32 Math3D_SphCubeVsTriCube(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, f32 arg4) { f32 phi_f0; f32 phi_f2; @@ -895,8 +888,8 @@ s32 Math3D_LineVsCubeShort(Vec3s* min, Vec3s* max, Vec3s* a, Vec3s* b) { #endif void Math3D_RotateXZPlane(Vec3f* pointOnPlane, s16 angle, f32* a, f32* c, f32* d) { - *a = Math_SinS(angle) * 32767.0f; - *c = Math_CosS(angle) * 32767.0f; + *a = Math_SinS(angle) * 0x7FFF; + *c = Math_CosS(angle) * 0x7FFF; *d = -((*a * pointOnPlane->x) + (*c * pointOnPlane->z)); } @@ -1010,10 +1003,12 @@ s32 Math3D_TriChkPointParaYIntersectDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx if (IS_ZERO(ny)) { return false; } + if (Math3D_TriChkPointParaYImpl(v0, v1, v2, z, x, 300.0f, chkDist, ny)) { - *yIntersect = (f32)((((-nx * x) - (nz * z)) - originDist) / ny); + *yIntersect = (((-nx * x) - (nz * z)) - originDist) / ny; return true; } + return false; } @@ -1022,10 +1017,12 @@ s32 Math3D_TriChkPointParaYIntersectInsideTri(Vec3f* v0, Vec3f* v1, Vec3f* v2, f if (IS_ZERO(ny)) { return false; } + if (Math3D_TriChkPointParaYImpl(v0, v1, v2, z, x, 0.0f, chkDist, ny)) { - *yIntersect = (f32)((((-nx * x) - (nz * z)) - originDist) / ny); + *yIntersect = (((-nx * x) - (nz * z)) - originDist) / ny; return true; } + return false; } @@ -1033,9 +1030,11 @@ s32 Math3D_TriChkPointParaY(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 ny, f32 z, f32 if (IS_ZERO(ny)) { return false; } + if (Math3D_TriChkPointParaYImpl(v0, v1, v2, z, x, 300.0f, 1.0f, ny)) { return true; } + return false; } @@ -1060,20 +1059,24 @@ s32 Math3D_TriChkLineSegParaYIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, if (((pointADist > 0.0f) && (pointBDist > 0.0f)) || ((pointADist < 0.0f) && (pointBDist < 0.0f))) { return false; } + if (Math3D_TriChkPointParaYImpl(v0, v1, v2, z, x, 300.0f, 1.0f, ny)) { *yIntersect = (((-nx * x) - (nz * z)) - originDist) / ny; return true; } + return false; } -s32 Math3D_TriChkPointParaYDist_(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 z, f32 x, f32 chkDist) { +s32 Math3D_TriChkPointParaYDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 z, f32 x, f32 chkDist) { if (IS_ZERO(plane->normal.y)) { return false; } + if (Math3D_TriChkPointParaYImpl(v0, v1, v2, z, x, 0.0f, chkDist, plane->normal.y)) { return true; } + return false; } @@ -1097,7 +1100,7 @@ s32 Math3D_TriChkPointParaYImplNoCheckRange(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 if (((detMax >= (detv0v1 = ((v0->z - z) * (v1->x - x)) - ((v0->x - x) * (v1->z - z)))) && (detMax >= (detv1v2 = ((v1->z - z) * (v2->x - x)) - ((v1->x - x) * (v2->z - z)))) && (detMax >= (detv2v0 = ((v2->z - z) * (v0->x - x)) - ((v2->x - x) * (v0->z - z)))))) { - return 1; + return true; } if (((-detMax <= (detv0v1 = ((v0->z - z) * (v1->x - x)) - ((v0->x - x) * (v1->z - z)))) && (-detMax <= (detv1v2 = ((v1->z - z) * (v2->x - x)) - ((v1->x - x) * (v2->z - z)))) && @@ -1108,16 +1111,17 @@ s32 Math3D_TriChkPointParaYImplNoCheckRange(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 if (fabsf(ny) > 0.5f && chkDistSq > 0.0f) { // Do a check on each face of the triangle, if the point is within `chkDist` units return true. if ((func_8017DA24(z, x, v0, v1, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { - return 1; + return true; } if ((func_8017DA24(z, x, v1, v2, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { - return 1; + return true; } if ((func_8017DA24(z, x, v2, v0, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { - return 1; + return true; } } - return 0; + + return false; } s32 Math3D_TriChkPointParaYNoRangeCheckIntersectInsideTri(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, @@ -1125,10 +1129,12 @@ s32 Math3D_TriChkPointParaYNoRangeCheckIntersectInsideTri(Vec3f* v0, Vec3f* v1, if (IS_ZERO(ny)) { return false; } + if (Math3D_TriChkPointParaYImplNoCheckRange(v0, v1, v2, z, x, 0.0f, chkDist, ny)) { - *yIntersect = (f32)((((-nx * x) - (nz * z)) - originDist) / ny); + *yIntersect = (((-nx * x) - (nz * z)) - originDist) / ny; return true; } + return false; } @@ -1156,7 +1162,7 @@ s32 Math3D_TriChkPointParaXImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f if (((detMax >= (detv0v1 = ((v0->y - y) * (v1->z - z)) - ((v0->z - z) * (v1->y - y)))) && (detMax >= (detv1v2 = ((v1->y - y) * (v2->z - z)) - ((v1->z - z) * (v2->y - y)))) && (detMax >= (detv2v0 = ((v2->y - y) * (v0->z - z)) - ((v2->z - z) * (v0->y - y)))))) { - return 1; + return true; } if (((-detMax <= (detv0v1 = ((v0->y - y) * (v1->z - z)) - ((v0->z - z) * (v1->y - y)))) && (-detMax <= (detv1v2 = ((v1->y - y) * (v2->z - z)) - ((v1->z - z) * (v2->y - y)))) && @@ -1164,19 +1170,19 @@ s32 Math3D_TriChkPointParaXImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f return true; } - if (fabsf(ny) > 0.5f && chkDistSq > 0.0f) { + if ((fabsf(ny) > 0.5f) && (chkDistSq > 0.0f)) { // Do a check on each face of the triangle, if the point is within `chkDist` units return true. if ((func_8017D91C(y, z, v0, v1, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { - return 1; + return true; } if ((func_8017D91C(y, z, v1, v2, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { - return 1; + return true; } if ((func_8017D91C(y, z, v2, v0, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { - return 1; + return true; } } - return 0; + return false; } s32 Math3D_TriChkPointParaXDeterminate(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f32 detMax, f32 nx) { @@ -1193,6 +1199,7 @@ s32 Math3D_TriChkPointParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f3 *xIntersect = (((-ny * y) - (nz * z)) - originDist) / nx; return true; } + return false; } @@ -1200,9 +1207,11 @@ s32 Math3D_TriChkPointParaX(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 y, f32 if (IS_ZERO(nx)) { return false; } + if (Math3D_TriChkPointParaXImpl(v0, v1, v2, y, z, 300.0f, 1.0f, nx)) { return true; } + return false; } @@ -1245,9 +1254,11 @@ s32 Math3D_TriChkLineSegParaXDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, if (IS_ZERO(plane->normal.x)) { return false; } + if (Math3D_TriChkPointParaXImpl(v0, v1, v2, y, z, 0.0f, chkDist, plane->normal.x)) { return true; } + return false; } @@ -1307,24 +1318,26 @@ s32 Math3D_TriChkPointParaZDeterminate(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f s32 Math3D_TriChkPointParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, f32 y, f32* zIntersect) { if (IS_ZERO(nz)) { - return 0; + return false; } if (Math3D_TriChkPointParaZImpl(v0, v1, v2, x, y, 300.0f, 1.0f, nz)) { *zIntersect = (((-nx * x) - (ny * y)) - originDist) / nz; - return 1; + return true; } - return 0; + return false; } s32 Math3D_TriChkPointParaZ(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 y, f32 z) { if (IS_ZERO(nx)) { return false; } + if (Math3D_TriChkPointParaZImpl(v0, v1, v2, y, z, 300.0f, 1.0f, nx)) { return true; } + return false; } @@ -1362,13 +1375,15 @@ s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaZIntersect.s") #endif -s32 Math3D_TriChkLineSegParaZDist_(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 x, f32 y, f32 chkDist) { +s32 Math3D_TriChkLineSegParaZDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 x, f32 y, f32 chkDist) { if (IS_ZERO(plane->normal.z)) { return false; } + if (Math3D_TriChkPointParaZImpl(v0, v1, v2, x, y, 0.0f, chkDist, plane->normal.z)) { return true; } + return false; } @@ -1433,6 +1448,7 @@ void Math3D_TriNorm(TriNorm* tri, Vec3f* va, Vec3f* vb, Vec3f* vc) { tri->vtx[0] = *va; tri->vtx[1] = *vb; tri->vtx[2] = *vc; + Math3D_DefPlane(va, vb, vc, &tri->plane.normal.x, &tri->plane.normal.y, &tri->plane.normal.z, &tri->plane.originDist); } @@ -1441,6 +1457,7 @@ s32 Math3D_PointInSph(Sphere16* sphere, Vec3f* point) { if (Math3D_DistXYZ16toF(&sphere->center, point) < sphere->radius) { return true; } + return false; } @@ -1644,7 +1661,7 @@ s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoi sphereCenter.z = sphere->center.z; radius = sphere->radius; - if (!func_8017A438(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], &sphereCenter, radius)) { + if (!Math3D_SphCubeVsTriCube(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], &sphereCenter, radius)) { return false; } @@ -1805,6 +1822,7 @@ s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, V } } } + /** * This section finds the points of intersection of the infinite line containing AB with the side of the infinite * cylinder containing cyl. Intersection points beyond the bounds of the segment and cylinder are filtered out @@ -1841,6 +1859,7 @@ s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, V } else { return 0; } + // checks for intersection points outside the bounds of the segment if (!sideIntB) { if (fracA < 0.0f || 1.0f < fracA) { @@ -1859,6 +1878,7 @@ s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, V sideIntB = 0; } } + // checks for intersection points outside the bounds of the cylinder if ((sideIntA != 0) && ((fracA * ptAToPtB.y + cylToPtA.y) < 0.0f || cyl->height < (fracA * ptAToPtB.y + cylToPtA.y))) { @@ -1871,6 +1891,7 @@ s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, V if (sideIntA == 0 && sideIntB == 0) { return 0; } + // Adds intersection points to intPts and sets side A and side B flags if (sideIntA != 0 && sideIntB != 0) { intPts[2].x = (fracA * ptAToPtB.x + cylToPtA.x) + cyl->pos.x; @@ -1896,7 +1917,7 @@ s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, V /** * Places the found intersection points into intersectA and intersectB. IntersectA is always closer to point A */ - for (count = 0, i = 0; i < 4; i++) { + for (count = 0, i = 0; i < ARRAY_COUNT(intPts); i++) { if (intFlags & (1 << i)) { if (count == 0) { *intersectA = intPts[i]; @@ -2072,7 +2093,7 @@ s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overla f32 sphBottom; f32 sphTop; - if (sph->radius <= 0 || cyl->radius <= 0) { + if ((sph->radius <= 0) || (cyl->radius <= 0)) { // either radius is 0 return false; } @@ -2225,7 +2246,6 @@ s32 Math3D_YZInSphere(Sphere16* sphere, f32 y, f32 z) { return false; } -// Math3D_CircleLineIntersections? /** * @brief Computes the intersection points, if any, of the circle of radius radius, center (centerX, centerY) with the * line through the point (pointX, pointY) in direction (dirX, dirY). @@ -2243,8 +2263,8 @@ s32 Math3D_YZInSphere(Sphere16* sphere, f32 y, f32 z) { * @param[out] intersectBY y coordinate of second intersection * @return number of intersections(ish) */ -s32 func_8017FB1C(f32 centreX, f32 centerY, f32 radius, f32 pointX, f32 pointY, f32 dirX, f32 dirY, f32* intersectAX, - f32* intersectAY, f32* intersectBX, f32* intersectBY) { +s32 Math3D_CircleLineIntersections(f32 centreX, f32 centerY, f32 radius, f32 pointX, f32 pointY, f32 dirX, f32 dirY, + f32* intersectAX, f32* intersectAY, f32* intersectBX, f32* intersectBY) { f32 a = SQ(dirX) + SQ(dirY); // t^2 coefficient, |dir|^2 f32 diffX = pointX - centreX; f32 diffY = pointY - centerY; @@ -2301,13 +2321,15 @@ void func_8017FD44(Vec3f* arg0, Vec3f* arg1, Vec3f* dst, f32 arg3) { s16 sp2A; f32 sp24; - if (!(arg3 < -1.0f) || !(arg3 > 1.0f)) { - sp2C.x = (arg0->x + arg1->x) * 0.5f; - sp2C.z = (arg0->z + arg1->z) * 0.5f; - sp24 = sqrtf(SQ(sp2C.x - arg0->x) + SQ(sp2C.z - arg0->z)); - dst->y = (arg1->y - arg0->y) * arg3 + arg0->y; - sp2A = Math_Vec3f_Yaw(&sp2C, arg0); - dst->x = Math_SinS((s16)(32767.0f * arg3) + sp2A) * sp24 + sp2C.x; - dst->z = Math_CosS((s16)(32767.0f * arg3) + sp2A) * sp24 + sp2C.z; + if ((arg3 < -1.0f) && (arg3 > 1.0f)) { + return; } + + sp2C.x = (arg0->x + arg1->x) / 2.0f; + sp2C.z = (arg0->z + arg1->z) / 2.0f; + sp24 = sqrtf(SQ(sp2C.x - arg0->x) + SQ(sp2C.z - arg0->z)); + dst->y = (arg1->y - arg0->y) * arg3 + arg0->y; + sp2A = Math_Vec3f_Yaw(&sp2C, arg0); + dst->x = Math_SinS(TRUNCF_BINANG(0x7FFF * arg3) + sp2A) * sp24 + sp2C.x; + dst->z = Math_CosS(TRUNCF_BINANG(0x7FFF * arg3) + sp2A) * sp24 + sp2C.z; } diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c index c35842022..ff6f7a676 100644 --- a/src/code/z_bgcheck.c +++ b/src/code/z_bgcheck.c @@ -363,8 +363,8 @@ s32 CollisionPoly_CheckYIntersect(CollisionPoly* poly, Vec3s* vtxList, f32 x, f3 nx = COLPOLY_GET_NORMAL(poly->normal.x); ny = COLPOLY_GET_NORMAL(poly->normal.y); nz = COLPOLY_GET_NORMAL(poly->normal.z); - return Math3D_TriChkPointParaYNoRangeCheckIntersectInsideTri(&D_801EDA18[0], &D_801EDA18[1], &D_801EDA18[2], nx, ny, nz, - poly->dist, z, x, yIntersect, checkDist); + return Math3D_TriChkPointParaYNoRangeCheckIntersectInsideTri(&D_801EDA18[0], &D_801EDA18[1], &D_801EDA18[2], nx, ny, + nz, poly->dist, z, x, yIntersect, checkDist); } s32 CollisionPoly_CheckYIntersectApprox2(CollisionPoly* poly, Vec3s* vtxList, f32 x, f32 z, f32* yIntersect) { @@ -439,7 +439,7 @@ s32 CollisionPoly_LineVsPoly(BgLineVsPolyTest* a0) { a0->planeIntersect->x, 0.0f, a0->checkDist, sPlane.normal.y)) || ((fabsf(sPlane.normal.z) > 0.5f) && Math3D_TriChkPointParaZImpl(&sPolyVerts[0], &sPolyVerts[1], &sPolyVerts[2], a0->planeIntersect->x, - a0->planeIntersect->y, 0.0f, a0->checkDist, sPlane.normal.z))) { + a0->planeIntersect->y, 0.0f, a0->checkDist, sPlane.normal.z))) { return true; } return false; diff --git a/src/code/z_camera.c b/src/code/z_camera.c index b6a829b71..9c5ef3041 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -1848,14 +1848,12 @@ void Camera_CalcDefaultSwing(Camera* camera, VecGeo* arg1, VecGeo* arg2, f32 arg dummy:; swing->unk_64 = 0; } else if ((sp88 = Math3D_PlaneF(swing->eyeAtColChk.norm.x, swing->eyeAtColChk.norm.y, - swing->eyeAtColChk.norm.z, swing->eyeAtColChk.poly->dist, - at)) > 0.0f) { + swing->eyeAtColChk.norm.z, swing->eyeAtColChk.poly->dist, at)) > 0.0f) { swing->unk_64 = 0; } else if ((sp88 = OLib_Vec3fDist(eye, &swing->eyeAtColChk.pos)) < 10.0f) { swing->unk_64 = 0; } else if ((sp88 = Math3D_PlaneF(swing->atEyeColChk.norm.x, swing->atEyeColChk.norm.y, - swing->atEyeColChk.norm.z, swing->atEyeColChk.poly->dist, - eye)) > 0.0f) { + swing->atEyeColChk.norm.z, swing->atEyeColChk.poly->dist, eye)) > 0.0f) { swing->unk_64 = 0; } else if (swing->atEyeColChk.norm.y > 0.50f) { swing->unk_64 = 0; @@ -5565,8 +5563,8 @@ s32 Camera_Unique0(Camera* camera) { switch (camera->animState) { case 0: bgCamFuncData = (BgCamFuncData*)Camera_GetBgCamOrActorCsCamFuncData(camera, camera->bgCamIndex); - Camera_Vec3sToVec3f(&rwData->unk_1C.a, &bgCamFuncData->pos); - camera->eye = camera->eyeNext = rwData->unk_1C.a; + Camera_Vec3sToVec3f(&rwData->unk_1C.point, &bgCamFuncData->pos); + camera->eye = camera->eyeNext = rwData->unk_1C.point; rwData->unk_34 = bgCamFuncData->rot; temp_v1 = bgCamFuncData->fov; @@ -5597,7 +5595,7 @@ s32 Camera_Unique0(Camera* camera) { } rwData->unk_3A = camera->focalActor->world.rot.y; rwData->unk_3E = 0; - camera->eye = camera->eyeNext = rwData->unk_1C.a; + camera->eye = camera->eyeNext = rwData->unk_1C.point; Camera_UnsetStateFlag(camera, CAM_STATE_2); camera->animState++; // fallthrough @@ -5605,7 +5603,7 @@ s32 Camera_Unique0(Camera* camera) { sp84.r = OLib_Vec3fDist(&sp8C, &camera->eye); sp84.yaw = rwData->unk_34.y; sp84.pitch = -rwData->unk_34.x; - OLib_VecGeoToVec3f(&rwData->unk_1C.b, &sp84); + OLib_VecGeoToVec3f(&rwData->unk_1C.dir, &sp84); Math3D_LineClosestToPoint(&rwData->unk_1C, &focalActorPosRot->pos, &rwData->unk_0C); camera->at = rwData->unk_0C; diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c index 0e44356b8..3d794a366 100644 --- a/src/code/z_collision_check.c +++ b/src/code/z_collision_check.c @@ -1733,8 +1733,8 @@ void CollisionCheck_AC_JntSphVsJntSph(PlayState* play, CollisionCheckContext* co continue; } - if (Math3D_SphVsSphOverlapCenter(&atElem->dim.worldSphere, &acElem->dim.worldSphere, - &overlapSize, ¢erDist) != 0) { + if (Math3D_SphVsSphOverlapCenter(&atElem->dim.worldSphere, &acElem->dim.worldSphere, &overlapSize, + ¢erDist) != 0) { f32 acToHit; Vec3f hitPos; Vec3f atPos; @@ -1784,8 +1784,7 @@ void CollisionCheck_AC_JntSphVsCyl(PlayState* play, CollisionCheckContext* colCt if (CollisionCheck_NoSharedFlags(&atElem->info, &ac->info)) { continue; } - if (Math3D_SphVsCylOverlapCenterDist(&atElem->dim.worldSphere, &ac->dim, &overlapSize, - ¢erDist)) { + if (Math3D_SphVsCylOverlapCenterDist(&atElem->dim.worldSphere, &ac->dim, &overlapSize, ¢erDist)) { Vec3f hitPos; Vec3f atPos; Vec3f acPos; @@ -1909,8 +1908,8 @@ void CollisionCheck_AC_JntSphVsSphere(PlayState* play, CollisionCheckContext* co if (CollisionCheck_NoSharedFlags(&sphElem->info, &ac->info)) { continue; } - if (Math3D_SphVsSphOverlapCenter(&sphElem->dim.worldSphere, &ac->dim.worldSphere, - &overlapSize, ¢erDist) != 0) { + if (Math3D_SphVsSphOverlapCenter(&sphElem->dim.worldSphere, &ac->dim.worldSphere, &overlapSize, + ¢erDist) != 0) { f32 acToHit; Vec3f hitPos; Vec3f atPos; @@ -1954,8 +1953,7 @@ void CollisionCheck_AC_CylVsJntSph(PlayState* play, CollisionCheckContext* colCt if (CollisionCheck_NoSharedFlags(&at->info, &sphElem->info)) { continue; } - if (Math3D_SphVsCylOverlapCenterDist(&sphElem->dim.worldSphere, &at->dim, &overlapSize, - ¢erDist) != 0) { + if (Math3D_SphVsCylOverlapCenterDist(&sphElem->dim.worldSphere, &at->dim, &overlapSize, ¢erDist) != 0) { Vec3f hitPos; Vec3f atPos; Vec3f acPos; @@ -2560,7 +2558,7 @@ void CollisionCheck_AC_SphereVsJntSph(PlayState* play, CollisionCheckContext* co } if (Math3D_SphVsSphOverlapCenter(&at->dim.worldSphere, &acElem->dim.worldSphere, &overlapSize, - ¢erDist) != 0) { + ¢erDist) != 0) { f32 acToHit; Vec3f hitPos; Vec3f atPos; @@ -2710,8 +2708,7 @@ void CollisionCheck_AC_SphereVsSphere(PlayState* play, CollisionCheckContext* co return; } - if (Math3D_SphVsSphOverlapCenter(&at->dim.worldSphere, &ac->dim.worldSphere, &overlapSize, - ¢erDist) != 0) { + if (Math3D_SphVsSphOverlapCenter(&at->dim.worldSphere, &ac->dim.worldSphere, &overlapSize, ¢erDist) != 0) { f32 acToHit; Vec3f hitPos; Vec3f atPos; @@ -3043,8 +3040,7 @@ void CollisionCheck_OC_JntSphVsJntSph(PlayState* play, CollisionCheckContext* co if (!(rightElem->info.ocElemFlags & OCELEM_ON)) { continue; } - if (Math3D_SphVsSphOverlap(&leftElem->dim.worldSphere, &rightElem->dim.worldSphere, - &overlap) != 0) { + if (Math3D_SphVsSphOverlap(&leftElem->dim.worldSphere, &rightElem->dim.worldSphere, &overlap) != 0) { Vec3f leftPos; Vec3f rightPos; diff --git a/src/overlays/actors/ovl_En_Horse_Game_Check/z_en_horse_game_check.c b/src/overlays/actors/ovl_En_Horse_Game_Check/z_en_horse_game_check.c index da421f47f..936f177ed 100644 --- a/src/overlays/actors/ovl_En_Horse_Game_Check/z_en_horse_game_check.c +++ b/src/overlays/actors/ovl_En_Horse_Game_Check/z_en_horse_game_check.c @@ -258,21 +258,21 @@ s32 func_808F8FAC(EnHorseGameCheck* this, PlayState* play) { if (!(this->unk_164 & 0x1000)) { if (Math3D_PointInSquare2D(D_808F9BAC[0], D_808F9BAC[1], D_808F9BAC[2], D_808F9BAC[3], - this->horse1->actor.world.pos.x, this->horse1->actor.world.pos.z)) { + this->horse1->actor.world.pos.x, this->horse1->actor.world.pos.z)) { this->unk_164 |= 0x1000; } } if (!(this->unk_164 & 0x2000) && (this->unk_164 & 0x1000)) { if (Math3D_PointInSquare2D(D_808F9BBC[0], D_808F9BBC[1], D_808F9BBC[2], D_808F9BBC[3], - this->horse1->actor.world.pos.x, this->horse1->actor.world.pos.z)) { + this->horse1->actor.world.pos.x, this->horse1->actor.world.pos.z)) { this->unk_164 |= 0x2000; } } if (!(this->unk_164 & 0x4000) && (this->unk_164 & 0x2000)) { if (Math3D_PointInSquare2D(D_808F9BCC[0], D_808F9BCC[1], D_808F9BCC[2], D_808F9BCC[3], - this->horse1->actor.world.pos.x, this->horse1->actor.world.pos.z)) { + this->horse1->actor.world.pos.x, this->horse1->actor.world.pos.z)) { this->unk_164 |= 0x4000; } } @@ -291,21 +291,21 @@ s32 func_808F8FAC(EnHorseGameCheck* this, PlayState* play) { if (!(this->unk_164 & 0x80000)) { if (Math3D_PointInSquare2D(D_808F9BAC[0], D_808F9BAC[1], D_808F9BAC[2], D_808F9BAC[3], - this->horse2->actor.world.pos.x, this->horse2->actor.world.pos.z)) { + this->horse2->actor.world.pos.x, this->horse2->actor.world.pos.z)) { this->unk_164 |= 0x80000; } } if (!(this->unk_164 & 0x100000) && (this->unk_164 & 0x80000)) { if (Math3D_PointInSquare2D(D_808F9BBC[0], D_808F9BBC[1], D_808F9BBC[2], D_808F9BBC[3], - this->horse2->actor.world.pos.x, this->horse2->actor.world.pos.z)) { + this->horse2->actor.world.pos.x, this->horse2->actor.world.pos.z)) { this->unk_164 |= 0x100000; } } if (!(this->unk_164 & 0x200000) && (this->unk_164 & 0x100000)) { if (Math3D_PointInSquare2D(D_808F9BCC[0], D_808F9BCC[1], D_808F9BCC[2], D_808F9BCC[3], - this->horse2->actor.world.pos.x, this->horse2->actor.world.pos.z)) { + this->horse2->actor.world.pos.x, this->horse2->actor.world.pos.z)) { this->unk_164 |= 0x200000; } } @@ -323,19 +323,19 @@ s32 func_808F8FAC(EnHorseGameCheck* this, PlayState* play) { } if (!(this->unk_164 & 0x20) && Math3D_PointInSquare2D(D_808F9BAC[0], D_808F9BAC[1], D_808F9BAC[2], D_808F9BAC[3], - horse->actor.world.pos.x, horse->actor.world.pos.z)) { + horse->actor.world.pos.x, horse->actor.world.pos.z)) { this->unk_164 |= 0x20; } if (!(this->unk_164 & 0x40) && (this->unk_164 & 0x20) && Math3D_PointInSquare2D(D_808F9BBC[0], D_808F9BBC[1], D_808F9BBC[2], D_808F9BBC[3], horse->actor.world.pos.x, - horse->actor.world.pos.z)) { + horse->actor.world.pos.z)) { this->unk_164 |= 0x40; } if (!(this->unk_164 & 0x80) && (this->unk_164 & 0x40) && Math3D_PointInSquare2D(D_808F9BCC[0], D_808F9BCC[1], D_808F9BCC[2], D_808F9BCC[3], horse->actor.world.pos.x, - horse->actor.world.pos.z)) { + horse->actor.world.pos.z)) { this->unk_164 |= 0x80; } diff --git a/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.c b/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.c index a14daa318..7b4f84ab5 100644 --- a/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.c +++ b/src/overlays/actors/ovl_En_Mushi2/z_en_mushi2.c @@ -602,14 +602,12 @@ void func_80A69ADC(Actor* thisx) { s32 pad2; if (this->unk_358 < 1.0f) { - sp44 = Math3D_PlaneF( - this->unk_310.x, this->unk_310.y, this->unk_310.z, - func_80A69AA8(this->unk_310.x, this->unk_310.y, this->unk_310.z, &this->actor.world.pos), - &bean->dyna.actor.world.pos); - sp40 = Math3D_PlaneF( - this->unk_328.x, this->unk_328.y, this->unk_328.z, - func_80A69AA8(this->unk_328.x, this->unk_328.y, this->unk_328.z, &this->actor.world.pos), - &bean->dyna.actor.world.pos); + sp44 = Math3D_PlaneF(this->unk_310.x, this->unk_310.y, this->unk_310.z, + func_80A69AA8(this->unk_310.x, this->unk_310.y, this->unk_310.z, &this->actor.world.pos), + &bean->dyna.actor.world.pos); + sp40 = Math3D_PlaneF(this->unk_328.x, this->unk_328.y, this->unk_328.z, + func_80A69AA8(this->unk_328.x, this->unk_328.y, this->unk_328.z, &this->actor.world.pos), + &bean->dyna.actor.world.pos); sp3C = Math3D_Dist1D(sp44, sp40); if (fabsf(sp3C) > 0.1f) { @@ -648,14 +646,12 @@ void func_80A69D3C(EnMushi2* this) { f32 sp38; if ((this->unk_34C != NULL) && (this->unk_358 > 0.999f)) { - sp40 = Math3D_PlaneF( - this->unk_310.x, this->unk_310.y, this->unk_310.z, - func_80A69AA8(this->unk_310.x, this->unk_310.y, this->unk_310.z, &this->actor.world.pos), - &this->unk_34C->dyna.actor.world.pos); - sp3C = Math3D_PlaneF( - this->unk_328.x, this->unk_328.y, this->unk_328.z, - func_80A69AA8(this->unk_328.x, this->unk_328.y, this->unk_328.z, &this->actor.world.pos), - &this->unk_34C->dyna.actor.world.pos); + sp40 = Math3D_PlaneF(this->unk_310.x, this->unk_310.y, this->unk_310.z, + func_80A69AA8(this->unk_310.x, this->unk_310.y, this->unk_310.z, &this->actor.world.pos), + &this->unk_34C->dyna.actor.world.pos); + sp3C = Math3D_PlaneF(this->unk_328.x, this->unk_328.y, this->unk_328.z, + func_80A69AA8(this->unk_328.x, this->unk_328.y, this->unk_328.z, &this->actor.world.pos), + &this->unk_34C->dyna.actor.world.pos); sp38 = Math3D_Dist1DSq(sp40, sp3C); if (fabsf(sp38) > 0.010000001f) { diff --git a/src/overlays/actors/ovl_Obj_Um/z_obj_um.c b/src/overlays/actors/ovl_Obj_Um/z_obj_um.c index 7128d57a0..684db4e35 100644 --- a/src/overlays/actors/ovl_Obj_Um/z_obj_um.c +++ b/src/overlays/actors/ovl_Obj_Um/z_obj_um.c @@ -483,8 +483,8 @@ s32 func_80B78764(ObjUm* this, PlayState* play, EnHorse* bandit1, EnHorse* bandi func_80B781DC(this, bandit1, bandit2, play); } - Math3D_LineSplitRatio(&bandit1->unk_540, &this->unk_360[bandit1->unk_550], 1.0f - ((f32)bandit1->unk_55C / bandit1->unk_560), - &sp30); + Math3D_LineSplitRatio(&bandit1->unk_540, &this->unk_360[bandit1->unk_550], + 1.0f - ((f32)bandit1->unk_55C / bandit1->unk_560), &sp30); bandit1->banditPosition = sp30; bandit1->unk_588 = this->dyna.actor.shape.rot.y; diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index 876c51dc1..b79d1326e 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -3271,7 +3271,7 @@ 0x8017A09C:("func_8017A09C",), 0x8017A1D0:("func_8017A1D0",), 0x8017A304:("func_8017A304",), - 0x8017A438:("func_8017A438",), + 0x8017A438:("Math3D_SphCubeVsTriCube",), 0x8017A5F8:("Math3D_Dist1DSq",), 0x8017A610:("Math3D_Dist1D",), 0x8017A634:("Math3D_Dist2DSq",), @@ -3347,7 +3347,7 @@ 0x8017F9C0:("Math3D_XZInSphere",), 0x8017FA34:("Math3D_XYInSphere",), 0x8017FAA8:("Math3D_YZInSphere",), - 0x8017FB1C:("func_8017FB1C",), + 0x8017FB1C:("Math3D_CircleLineIntersections",), 0x8017FD44:("func_8017FD44",), 0x8017FEB0:("Math_GetAtan2Tbl",), 0x8017FEE4:("Math_Atan2S",), diff --git a/tools/namefixer.py b/tools/namefixer.py index 130c3f07b..146c814e2 100755 --- a/tools/namefixer.py +++ b/tools/namefixer.py @@ -521,6 +521,7 @@ wordReplace = { "Math3D_Parallel": "Math3D_Cos", "Math3D_AngleBetweenVectors": "Math3D_CosOut", "func_80179A44": "Math3D_LineClosestToPoint", + "func_8017A438": "Math3D_SphCubeVsTriCube", "Math3D_XZLengthSquared": "Math3D_Dist1DSq", "Math3D_XZLength": "Math3D_Dist1D", "Math3D_XZDistanceSquared": "Math3D_Dist2DSq", diff --git a/tools/sizes/code_functions.csv b/tools/sizes/code_functions.csv index fe47a815c..f8780277b 100644 --- a/tools/sizes/code_functions.csv +++ b/tools/sizes/code_functions.csv @@ -2785,7 +2785,7 @@ asm/non_matchings/code/sys_math3d/Math3D_PointInSquare2D.s,Math3D_PointInSquare2 asm/non_matchings/code/sys_math3d/func_8017A09C.s,func_8017A09C,0x8017A09C,0x4D asm/non_matchings/code/sys_math3d/func_8017A1D0.s,func_8017A1D0,0x8017A1D0,0x4D asm/non_matchings/code/sys_math3d/func_8017A304.s,func_8017A304,0x8017A304,0x4D -asm/non_matchings/code/sys_math3d/func_8017A438.s,func_8017A438,0x8017A438,0x70 +asm/non_matchings/code/sys_math3d/Math3D_SphCubeVsTriCube.s,Math3D_SphCubeVsTriCube,0x8017A438,0x70 asm/non_matchings/code/sys_math3d/Math3D_Dist1DSq.s,Math3D_Dist1DSq,0x8017A5F8,0x6 asm/non_matchings/code/sys_math3d/Math3D_Dist1D.s,Math3D_Dist1D,0x8017A610,0x9 asm/non_matchings/code/sys_math3d/Math3D_Dist2DSq.s,Math3D_Dist2DSq,0x8017A634,0x11 @@ -2861,7 +2861,7 @@ asm/non_matchings/code/sys_math3d/Math3D_TriVsTriIntersect.s,Math3D_TriVsTriInte asm/non_matchings/code/sys_math3d/Math3D_XZInSphere.s,Math3D_XZInSphere,0x8017F9C0,0x1D asm/non_matchings/code/sys_math3d/Math3D_XYInSphere.s,Math3D_XYInSphere,0x8017FA34,0x1D asm/non_matchings/code/sys_math3d/Math3D_YZInSphere.s,Math3D_YZInSphere,0x8017FAA8,0x1D -asm/non_matchings/code/sys_math3d/func_8017FB1C.s,func_8017FB1C,0x8017FB1C,0x8A +asm/non_matchings/code/sys_math3d/Math3D_CircleLineIntersections.s,Math3D_CircleLineIntersections,0x8017FB1C,0x8A asm/non_matchings/code/sys_math3d/func_8017FD44.s,func_8017FD44,0x8017FD44,0x5B asm/non_matchings/code/sys_math_atan/Math_GetAtan2Tbl.s,Math_GetAtan2Tbl,0x8017FEB0,0xD asm/non_matchings/code/sys_math_atan/Math_Atan2S.s,Math_Atan2S,0x8017FEE4,0x7A From f80186e79e8664c7383ec07e5e4e31f0eaec6716 Mon Sep 17 00:00:00 2001 From: angie Date: Wed, 24 May 2023 12:45:58 -0400 Subject: [PATCH 16/29] bss cleanup --- include/variables.h | 73 +------------------------- src/code/sys_math3d.c | 31 +++++++++++ src/code/z_camera.c | 2 + tools/disasm/variables.txt | 102 +++++++++++-------------------------- 4 files changed, 64 insertions(+), 144 deletions(-) diff --git a/include/variables.h b/include/variables.h index 935a96076..2b63bab8a 100644 --- a/include/variables.h +++ b/include/variables.h @@ -2453,78 +2453,7 @@ extern UNK_TYPE2 D_801FBBCE; // extern UNK_TYPE1 D_801FBBD0; // extern UNK_TYPE1 D_801FBBD2; extern u8 D_801FBBD4; -extern Vec3f D_801FBBF0; -extern Linef Math3D_ColSphereTri_line; -extern Vec3f Math3D_ColSphereTri_point; -// extern UNK_TYPE1 D_801FBC28; -// extern UNK_TYPE1 D_801FBC2C; -// extern UNK_TYPE1 D_801FBC30; -// extern UNK_TYPE1 D_801FBC38; -// extern UNK_TYPE1 D_801FBC3A; -// extern UNK_TYPE1 D_801FBC3C; -// extern UNK_TYPE1 D_801FBC3E; -// extern UNK_TYPE1 D_801FBC40; -// extern UNK_TYPE1 D_801FBC42; -// extern UNK_TYPE1 D_801FBC44; -// extern UNK_TYPE1 D_801FBC46; -// extern UNK_TYPE1 D_801FBC48; -// extern UNK_TYPE1 D_801FBC58; -extern Vec3f Math3D_NormalVector_temp1; -extern Vec3f Math3D_NormalVector_temp2; -extern f32 D_801FBC8C; -extern f32 D_801FBC90; -extern f32 D_801FBC98; -extern f32 D_801FBCA4; -extern f32 D_801FBCAC; -extern f32 D_801FBCB0; -extern f32 D_801FBCB4; -extern f32 D_801FBCB8; -extern f32 D_801FBCBC; -extern f32 D_801FBCC0; -extern f32 D_801FBCC4; -extern f32 D_801FBCC8; -extern f32 D_801FBCCC; -extern f32 D_801FBCD0; -extern f32 D_801FBCD4; -extern f32 D_801FBCD8; -extern f32 D_801FBCDC; -// extern UNK_TYPE1 D_801FBCE0; -// extern UNK_TYPE1 D_801FBCE4; -// extern UNK_TYPE1 D_801FBCE8; -// extern UNK_TYPE1 D_801FBCF0; -// extern UNK_TYPE1 D_801FBCF4; -// extern UNK_TYPE1 D_801FBCF8; -// extern UNK_TYPE1 D_801FBD00; -// extern UNK_TYPE1 D_801FBD04; -// extern UNK_TYPE1 D_801FBD08; -// extern UNK_TYPE1 D_801FBD10; -// extern UNK_TYPE1 D_801FBD20; -// extern UNK_TYPE1 D_801FBD24; -// extern UNK_TYPE1 D_801FBD28; -// extern UNK_TYPE1 D_801FBD30; -// extern UNK_TYPE1 D_801FBD34; -// extern UNK_TYPE1 D_801FBD38; -// extern UNK_TYPE1 D_801FBD40; -// extern UNK_TYPE1 D_801FBD44; -// extern UNK_TYPE1 D_801FBD48; -// extern UNK_TYPE1 D_801FBD50; -// extern UNK_TYPE1 D_801FBD54; -// extern UNK_TYPE1 D_801FBD58; -extern Vec3f Math3D_UnitNormalVector_temp; -// extern UNK_TYPE1 D_801FBD70; -// extern UNK_TYPE1 D_801FBD74; -// extern UNK_TYPE1 D_801FBD78; -extern Vec3f D_801FBD80[2]; -extern Vec3f D_801FBD98; -extern Vec3f D_801FBDA4; -// extern UNK_TYPE1 D_801FBDB0; -// extern UNK_TYPE1 D_801FBDB4; -// extern UNK_TYPE1 D_801FBDB8; -// extern UNK_TYPE1 D_801FBDC0; -// extern UNK_TYPE1 D_801FBDD8; -// extern UNK_TYPE1 D_801FBDDC; -// extern UNK_TYPE1 D_801FBDE0; -extern Vec3f D_801FBDE8; + extern MtxF* sMatrixStack; extern MtxF* sCurrentMatrix; diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 6d7cdc68c..18cf53631 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -3,6 +3,37 @@ #include "libc/math.h" #include "macros.h" +extern Vec3f Math3D_GetSphVsTriIntersectPoint_sphereCenter; +extern Linef Math3D_TriVsSphIntersect_triTestLine; +extern Vec3f Math3D_TriVsSphIntersect_sphereCenter; +extern Vec3f Math3D_TriVsSphIntersect_sphPlanePos; +extern Sphere16 topSphere; +extern Sphere16 bottomSphere; +extern Vec3f cylIntersectA; +extern Vec3f cylIntersectB; +extern Vec3f abDiff; +extern Vec3f acDiff; +extern Cylinderf cylf; +extern Spheref sphf; +extern Cylinderf caf; +extern Cylinderf cbf; +extern Vec3f triVtx0; +extern Vec3f triVtx1; +extern Vec3f triVtx2; +extern Vec3f Math3D_LineVsCube_intersectPoint; +extern Vec3f D_801FBD20; +extern Vec3f D_801FBD30; +extern Vec3f D_801FBD40; +extern Vec3f D_801FBD50; +extern Vec3f Math3D_DefPlane_normal; +extern Vec3f Math3D_TriChkLineSegParaXIntersect_planePos; +extern InfiniteLine planeIntersectLine; +extern Linef planeIntersectSeg; +extern Vec3f Math3D_TriChkLineSegParaZIntersect_planePos; +extern InfiniteLine Math3D_PlaneVsPlaneVsLineClosestPoint_planeIntersect; +extern Vec3f sphLinePerpendicularPoint; +extern Vec3f v0v1Center; + f32 Math3D_Normalize(Vec3f* vec) { f32 magnitude = Math3D_Vec3fMagnitude(vec); diff --git a/src/code/z_camera.c b/src/code/z_camera.c index 9c5ef3041..ff885b544 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -42,6 +42,8 @@ * -Y +Z -Y * */ + +#include "prevent_bss_reordering.h" #include "global.h" #include "z64quake.h" #include "z64shrink_window.h" diff --git a/tools/disasm/variables.txt b/tools/disasm/variables.txt index f26cabc06..b5ae0f138 100644 --- a/tools/disasm/variables.txt +++ b/tools/disasm/variables.txt @@ -4119,78 +4119,36 @@ 0x801FBBD2:("D_801FBBD2","UNK_TYPE1","",0x1), 0x801FBBD4:("D_801FBBD4","UNK_TYPE1","",0x1), 0x801FBBE0:("sDmaBuffer","u32","[2]",0x8), - 0x801FBBF0:("D_801FBBF0","Vec3f","",0xc), - 0x801FBC00:("Math3D_ColSphereTri_line","Linef","",0x18), - 0x801FBC18:("Math3D_ColSphereTri_point","Vec3f","",0xc), - 0x801FBC28:("D_801FBC28","UNK_TYPE1","",0x1), - 0x801FBC2C:("D_801FBC2C","UNK_TYPE1","",0x1), - 0x801FBC30:("D_801FBC30","UNK_TYPE1","",0x1), - 0x801FBC38:("D_801FBC38","UNK_TYPE1","",0x1), - 0x801FBC3A:("D_801FBC3A","UNK_TYPE1","",0x1), - 0x801FBC3C:("D_801FBC3C","UNK_TYPE1","",0x1), - 0x801FBC3E:("D_801FBC3E","UNK_TYPE1","",0x1), - 0x801FBC40:("D_801FBC40","UNK_TYPE1","",0x1), - 0x801FBC42:("D_801FBC42","UNK_TYPE1","",0x1), - 0x801FBC44:("D_801FBC44","UNK_TYPE1","",0x1), - 0x801FBC46:("D_801FBC46","UNK_TYPE1","",0x1), - 0x801FBC48:("D_801FBC48","UNK_TYPE1","",0x1), - 0x801FBC58:("D_801FBC58","UNK_TYPE1","",0x1), - 0x801FBC68:("Math3D_SurfaceNorm_temp1","Vec3f","",0xc), - 0x801FBC78:("Math3D_SurfaceNorm_temp2","Vec3f","",0xc), - 0x801FBC8C:("D_801FBC8C","f32","",0x4), - 0x801FBC90:("D_801FBC90","f32","",0x4), - 0x801FBC98:("D_801FBC98","f32","",0x4), - 0x801FBCA4:("D_801FBCA4","f32","",0x4), - 0x801FBCAC:("D_801FBCAC","f32","",0x4), - 0x801FBCB0:("D_801FBCB0","f32","",0x4), - 0x801FBCB4:("D_801FBCB4","f32","",0x4), - 0x801FBCB8:("D_801FBCB8","f32","",0x4), - 0x801FBCBC:("D_801FBCBC","f32","",0x4), - 0x801FBCC0:("D_801FBCC0","f32","",0x4), - 0x801FBCC4:("D_801FBCC4","f32","",0x4), - 0x801FBCC8:("D_801FBCC8","f32","",0x4), - 0x801FBCCC:("D_801FBCCC","f32","",0x4), - 0x801FBCD0:("D_801FBCD0","f32","",0x4), - 0x801FBCD4:("D_801FBCD4","f32","",0x4), - 0x801FBCD8:("D_801FBCD8","f32","",0x4), - 0x801FBCDC:("D_801FBCDC","f32","",0x4), - 0x801FBCE0:("D_801FBCE0","UNK_TYPE1","",0x1), - 0x801FBCE4:("D_801FBCE4","UNK_TYPE1","",0x1), - 0x801FBCE8:("D_801FBCE8","UNK_TYPE1","",0x1), - 0x801FBCF0:("D_801FBCF0","UNK_TYPE1","",0x1), - 0x801FBCF4:("D_801FBCF4","UNK_TYPE1","",0x1), - 0x801FBCF8:("D_801FBCF8","UNK_TYPE1","",0x1), - 0x801FBD00:("D_801FBD00","UNK_TYPE1","",0x1), - 0x801FBD04:("D_801FBD04","UNK_TYPE1","",0x1), - 0x801FBD08:("D_801FBD08","UNK_TYPE1","",0x1), - 0x801FBD10:("D_801FBD10","UNK_TYPE1","",0x1), - 0x801FBD20:("D_801FBD20","UNK_TYPE1","",0x1), - 0x801FBD24:("D_801FBD24","UNK_TYPE1","",0x1), - 0x801FBD28:("D_801FBD28","UNK_TYPE1","",0x1), - 0x801FBD30:("D_801FBD30","UNK_TYPE1","",0x1), - 0x801FBD34:("D_801FBD34","UNK_TYPE1","",0x1), - 0x801FBD38:("D_801FBD38","UNK_TYPE1","",0x1), - 0x801FBD40:("D_801FBD40","UNK_TYPE1","",0x1), - 0x801FBD44:("D_801FBD44","UNK_TYPE1","",0x1), - 0x801FBD48:("D_801FBD48","UNK_TYPE1","",0x1), - 0x801FBD50:("D_801FBD50","UNK_TYPE1","",0x1), - 0x801FBD54:("D_801FBD54","UNK_TYPE1","",0x1), - 0x801FBD58:("D_801FBD58","UNK_TYPE1","",0x1), - 0x801FBD60:("Math3D_UnitNormalVector_temp","Vec3f","",0xc), - 0x801FBD70:("D_801FBD70","UNK_TYPE1","",0x1), - 0x801FBD74:("D_801FBD74","UNK_TYPE1","",0x1), - 0x801FBD78:("D_801FBD78","UNK_TYPE1","",0x1), - 0x801FBD80:("D_801FBD80","Vec3f","[2]",0x18), - 0x801FBD98:("D_801FBD98","Vec3f","",0xc), - 0x801FBDA4:("D_801FBDA4","Vec3f","",0xc), - 0x801FBDB0:("D_801FBDB0","UNK_TYPE1","",0x1), - 0x801FBDB4:("D_801FBDB4","UNK_TYPE1","",0x1), - 0x801FBDB8:("D_801FBDB8","UNK_TYPE1","",0x1), - 0x801FBDC0:("D_801FBDC0","UNK_TYPE1","",0x1), - 0x801FBDD8:("D_801FBDD8","UNK_TYPE1","",0x1), - 0x801FBDDC:("D_801FBDDC","UNK_TYPE1","",0x1), - 0x801FBDE0:("D_801FBDE0","UNK_TYPE1","",0x1), - 0x801FBDE8:("D_801FBDE8","Vec3f","",0xc), + 0x801FBBF0:("Math3D_GetSphVsTriIntersectPoint_sphereCenter","Vec3f","",0xc), + 0x801FBC00:("Math3D_TriVsSphIntersect_triTestLine","Linef","",0x18), + 0x801FBC18:("Math3D_TriVsSphIntersect_sphereCenter","Vec3f","",0xc), + 0x801FBC28:("Math3D_TriVsSphIntersect_sphPlanePos","Vec3f","",0xC), + 0x801FBC38:("topSphere","Sphere16","",0x8), + 0x801FBC40:("bottomSphere","Sphere16","",0x8), + 0x801FBC48:("cylIntersectA","Vec3f","",0xC), + 0x801FBC58:("cylIntersectB","Vec3f","",0xC), + 0x801FBC68:("abDiff","Vec3f","",0xc), + 0x801FBC78:("acDiff","Vec3f","",0xc), + 0x801FBC88:("cylf","Cylinderf","",0x18), + 0x801FBCA0:("sphf","Spheref","",0x10), + 0x801FBCB0:("caf","Cylinderf","",0x18), + 0x801FBCC8:("cbf","Cylinderf","",0x18), + 0x801FBCE0:("triVtx0","Vec3f","",0xC), + 0x801FBCF0:("triVtx1","Vec3f","",0xC), + 0x801FBD00:("triVtx2","Vec3f","",0xC), + 0x801FBD10:("Math3D_LineVsCube_intersectPoint","Vec3f","",0xC), + 0x801FBD20:("D_801FBD20","Vec3f","",0xC), + 0x801FBD30:("D_801FBD30","Vec3f","",0xC), + 0x801FBD40:("D_801FBD40","Vec3f","",0xC), + 0x801FBD50:("D_801FBD50","Vec3f","",0xC), + 0x801FBD60:("Math3D_DefPlane_normal","Vec3f","",0xC), + 0x801FBD70:("Math3D_TriChkLineSegParaXIntersect_planePos","Vec3f","",0xC), + 0x801FBD80:("planeIntersectLine","InfiniteLine","",0x18), + 0x801FBD98:("planeIntersectSeg","Linef","",0x18), + 0x801FBDB0:("Math3D_TriChkLineSegParaZIntersect_planePos","Vec3f","",0xC), + 0x801FBDC0:("Math3D_PlaneVsPlaneVsLineClosestPoint_planeIntersect","InfiniteLine","",0x18), + 0x801FBDD8:("sphLinePerpendicularPoint","Vec3f","",0xC), + 0x801FBDE8:("v0v1Center","Vec3f","",0xC), 0x801FBE00:("sMatrixStack","MtxF*","",0x4), 0x801FBE04:("sCurrentMatrix","MtxF*","",0x4), 0x801FBE10:("D_801FBE10","UNK_TYPE1","",0x1), From f0aa038426296baafa9858bd855a56b52536f7f4 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Fri, 26 May 2023 17:52:38 +1000 Subject: [PATCH 17/29] match Math3D_CylVsLineSeg --- src/code/sys_math3d.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 18cf53631..2b4cf7324 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -1780,8 +1780,6 @@ s32 Math3D_PointInCyl(Cylinder16* cyl, Vec3f* point) { } } -#ifdef NON_MATCHING -// fracA and fracB are init to 0 but this causes problems everywhere s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersectA, Vec3f* intersectB) { Vec3f cylToPtA; Vec3f cylToPtB; @@ -1789,7 +1787,7 @@ s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, V f32 fracA; f32 fracB; f32 fracBase; - f32 zero = 0.0f; + f32 zero; f32 pad; f32 cylRadiusSq; f32 radSqDiff; @@ -1799,11 +1797,20 @@ s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, V s32 sideIntB; s32 intBeyondA; s32 intBeyondB; - s32 intFlags = 0; + s32 intFlags; Vec3f intPts[4]; s32 count; s32 i; + fracA = 0.0f; + fracB = 0.0f; + +//! FAKE: +dummy:; + + zero = 0.0f; + intFlags = 0; + if (Math3D_PointInCyl(cyl, linePointA) && Math3D_PointInCyl(cyl, linePointB)) { // both points are in the cylinder *intersectA = *linePointA; @@ -1966,9 +1973,6 @@ s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, V } return count; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_CylVsLineSeg.s") -#endif #ifdef NON_MATCHING // in-function static bss From 8c7fb9384427656a09f9bc43346ac803a2418000 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Fri, 26 May 2023 18:50:27 +1000 Subject: [PATCH 18/29] WIP --- spec | 1 - src/code/sys_math3d.c | 671 +++++++++++++++++++------------------ tools/disasm/variables.txt | 52 +-- 3 files changed, 380 insertions(+), 344 deletions(-) diff --git a/spec b/spec index 57fca6cda..2c330decf 100644 --- a/spec +++ b/spec @@ -579,7 +579,6 @@ beginseg include "build/src/code/sys_initial_check.o" include "build/src/code/sys_math.o" include "build/src/code/sys_math3d.o" - include "build/data/code/sys_math3d.bss.o" include "build/data/code/code_801D15B0.data.o" include "build/src/code/sys_math_atan.o" include "build/src/code/sys_matrix.o" diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 2b4cf7324..93f0475ba 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -1,39 +1,76 @@ +// #include "prevent_bss_reordering.h" #include "z64math.h" #include "libc/stdbool.h" #include "libc/math.h" #include "macros.h" -extern Vec3f Math3D_GetSphVsTriIntersectPoint_sphereCenter; -extern Linef Math3D_TriVsSphIntersect_triTestLine; -extern Vec3f Math3D_TriVsSphIntersect_sphereCenter; -extern Vec3f Math3D_TriVsSphIntersect_sphPlanePos; -extern Sphere16 topSphere; -extern Sphere16 bottomSphere; -extern Vec3f cylIntersectA; -extern Vec3f cylIntersectB; -extern Vec3f abDiff; -extern Vec3f acDiff; -extern Cylinderf cylf; -extern Spheref sphf; -extern Cylinderf caf; -extern Cylinderf cbf; -extern Vec3f triVtx0; -extern Vec3f triVtx1; -extern Vec3f triVtx2; -extern Vec3f Math3D_LineVsCube_intersectPoint; -extern Vec3f D_801FBD20; -extern Vec3f D_801FBD30; -extern Vec3f D_801FBD40; -extern Vec3f D_801FBD50; -extern Vec3f Math3D_DefPlane_normal; -extern Vec3f Math3D_TriChkLineSegParaXIntersect_planePos; -extern InfiniteLine planeIntersectLine; -extern Linef planeIntersectSeg; -extern Vec3f Math3D_TriChkLineSegParaZIntersect_planePos; -extern InfiniteLine Math3D_PlaneVsPlaneVsLineClosestPoint_planeIntersect; -extern Vec3f sphLinePerpendicularPoint; -extern Vec3f v0v1Center; +// extern Vec3f D_801FBBF0; +// extern Linef D_801FBC00; +// extern Vec3f D_801FBC18; +// extern Vec3f D_801FBC28; +// extern Sphere16 D_801FBC38; +// extern Sphere16 D_801FBC40; +// extern Vec3f D_801FBC48; +// extern Vec3f D_801FBC58; +// extern Vec3f D_801FBC68; // can be global +// extern Vec3f D_801FBC78; // can be global +// extern Cylinderf D_801FBC88; +// extern Spheref D_801FBCA0; +// extern Cylinderf D_801FBCB0; +// extern Cylinderf D_801FBCC8; +// extern Vec3f D_801FBCE0; +// extern Vec3f D_801FBCF0; +// extern Vec3f D_801FBD00; +// extern Vec3f D_801FBD10; +// extern Vec3f D_801FBD20; +// extern Vec3f D_801FBD30; +// extern Vec3f D_801FBD40; +// extern Vec3f D_801FBD50; +// extern Vec3f D_801FBD60; +// extern Vec3f D_801FBD70; +// extern InfiniteLine D_801FBD80; +// extern Linef D_801FBD98; +// extern Vec3f D_801FBDB0; +// extern InfiniteLine D_801FBDC0; // can be global +// extern Vec3f D_801FBDD8; +// extern Vec3f D_801FBDE8; +static Vec3f D_801FBC68; +static Vec3f D_801FBC78; + + +// extern Vec3f dummy0; +// extern Vec3f dummy1; +// extern Vec3f dummy2; +// extern Vec3f dummy3; +// extern Vec3f dummy4; +// extern Vec3f dummy5; +// extern Vec3f dummy6; +// extern Vec3f dummy7; +// extern Vec3f dummy8; +// extern Vec3f dummy9; +// extern Vec3f dummy10; +// extern Vec3f dummy11; +// extern Vec3f dummy12; +// extern Vec3f dummy13; +// extern Vec3f dummy14; +// extern Vec3f dummy15; +// extern Vec3f dummy16; +// extern Vec3f dummy17; +// extern Vec3f dummy18; +// extern Vec3f dummy19; +// extern Vec3f dummy20; +// extern Vec3f dummy21; +// extern Vec3f dummy22; +// extern Vec3f dummy23; +// extern Vec3f dummy24; +// extern Vec3f dummy25; +// extern Vec3f dummy26; +// extern Vec3f dummy27; +// extern Vec3f dummy28; +// extern Vec3f dummy29; + +#ifdef NON_MATCHING f32 Math3D_Normalize(Vec3f* vec) { f32 magnitude = Math3D_Vec3fMagnitude(vec); @@ -46,38 +83,41 @@ f32 Math3D_Normalize(Vec3f* vec) { vec->z *= 1.0f / magnitude; return magnitude; } +#else +#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_Normalize.s") +#endif -#ifdef NON_MATCHING +// #ifdef NON_MATCHING // in-function static bss s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* closestPoint) { - static InfiniteLine planeIntersectLine; - static Linef planeIntersectSeg; + static InfiniteLine D_801FBD80; + static Linef D_801FBD98; Vec3f sp34; // unused if (!Math3D_PlaneVsPlaneNewLine(planeAA, planeAB, planeAC, planeADist, planeBA, planeBB, planeBC, planeBDist, - &planeIntersectLine)) { + &D_801FBD80)) { // The planes are parallel return false; } // create a line segment on the plane. - Math_Vec3f_Copy(&planeIntersectSeg.a, &planeIntersectLine.point); - planeIntersectSeg.b.x = (planeIntersectLine.dir.x * 100.0f) + planeIntersectLine.point.x; - planeIntersectSeg.b.y = (planeIntersectLine.dir.y * 100.0f) + planeIntersectLine.point.y; - planeIntersectSeg.b.z = (planeIntersectLine.dir.z * 100.0f) + planeIntersectLine.point.z; + Math_Vec3f_Copy(&D_801FBD98.a, &D_801FBD80.point); + D_801FBD98.b.x = (D_801FBD80.dir.x * 100.0f) + D_801FBD80.point.x; + D_801FBD98.b.y = (D_801FBD80.dir.y * 100.0f) + D_801FBD80.point.y; + D_801FBD98.b.z = (D_801FBD80.dir.z * 100.0f) + D_801FBD80.point.z; // closestPoint is a point on planeIntersect, sp34 is a point on linePointA, linePointB - if (!Math3D_LineSegMakePerpLineSeg(&planeIntersectSeg.a, &planeIntersectSeg.b, linePointA, linePointB, closestPoint, + if (!Math3D_LineSegMakePerpLineSeg(&D_801FBD98.a, &D_801FBD98.b, linePointA, linePointB, closestPoint, &sp34)) { return false; } return true; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PlaneVsLineSegClosestPoint.s") -#endif +// #else +// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PlaneVsLineSegClosestPoint.s") +// #endif /** * Finds the two points on lines A and B where the lines are closest together. @@ -207,22 +247,22 @@ s32 Math3D_PlaneVsPlaneNewLine(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeA return true; } -#ifdef NON_MATCHING +// #ifdef NON_MATCHING // in-function static bss s32 Math3D_PlaneVsPlaneVsLineClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* point, Vec3f* closestPoint) { - static InfiniteLine planeIntersect; + static InfiniteLine D_801FBDC0; if (!Math3D_PlaneVsPlaneNewLine(planeAA, planeAB, planeAC, planeADist, planeBA, planeBB, planeBC, planeBDist, - &planeIntersect)) { + &D_801FBDC0)) { return false; } - Math3D_LineClosestToPoint(&planeIntersect, point, closestPoint); + Math3D_LineClosestToPoint(&D_801FBDC0, point, closestPoint); return true; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PlaneVsPlaneVsLineClosestPoint.s") -#endif +// #else +// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PlaneVsPlaneVsLineClosestPoint.s") +// #endif /** * Calculates the point on the line from starting point `v0`, in the direction `dir` scaled by `scale`. Result is placed @@ -582,19 +622,16 @@ void Math3D_Vec3f_Cross(Vec3f* a, Vec3f* b, Vec3f* ret) { ret->z = (a->x * b->y) - (a->y * b->x); } -#ifdef NON_MATCHING +// #ifdef NON_MATCHING // in-function static bss void Math3D_SurfaceNorm(Vec3f* va, Vec3f* vb, Vec3f* vc, Vec3f* normal) { - static Vec3f abDiff; - static Vec3f acDiff; - - Math_Vec3f_Diff(vb, va, &abDiff); - Math_Vec3f_Diff(vc, va, &acDiff); - Math3D_Vec3f_Cross(&abDiff, &acDiff, normal); + Math_Vec3f_Diff(vb, va, &D_801FBC68); + Math_Vec3f_Diff(vc, va, &D_801FBC78); + Math3D_Vec3f_Cross(&D_801FBC68, &D_801FBC78, normal); } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_SurfaceNorm.s") -#endif +// #else +// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_SurfaceNorm.s") +// #endif s32 Math3D_PointRelativeToCubeFaces(Vec3f* point, Vec3f* min, Vec3f* max) { s32 ret = 0; @@ -711,13 +748,13 @@ s32 Math3D_PointRelativeToCubeVertices(Vec3f* point, Vec3f* min, Vec3f* max) { return ret; } -#ifdef NON_MATCHING +// #ifdef NON_MATCHING // in-function static bss s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { - static Vec3f triVtx0; - static Vec3f triVtx1; - static Vec3f triVtx2; - static Vec3f intersectPoint; + static Vec3f D_801FBCE0; + static Vec3f D_801FBCF0; + static Vec3f D_801FBD00; + static Vec3f D_801FBD10; s32 flags[2]; @@ -749,146 +786,146 @@ s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { } // face 1 - triVtx0.x = min->x; - triVtx0.y = min->y; - triVtx0.z = min->z; - triVtx1.x = min->x; - triVtx1.y = min->y; - triVtx1.z = max->z; - triVtx2.x = min->x; - triVtx2.y = max->y; - triVtx2.z = max->z; - if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, -1.0f, 0.0f, 0.0f, min->x, a, b, &intersectPoint, 0)) { + D_801FBCE0.x = min->x; + D_801FBCE0.y = min->y; + D_801FBCE0.z = min->z; + D_801FBCF0.x = min->x; + D_801FBCF0.y = min->y; + D_801FBCF0.z = max->z; + D_801FBD00.x = min->x; + D_801FBD00.y = max->y; + D_801FBD00.z = max->z; + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, -1.0f, 0.0f, 0.0f, min->x, a, b, &D_801FBD10, 0)) { return true; } - triVtx1.x = min->x; - triVtx1.y = max->y; - triVtx1.z = max->z; - triVtx2.x = min->x; - triVtx2.y = max->y; - triVtx2.z = min->z; - if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, -1.0f, 0.0f, 0.0f, min->x, a, b, &intersectPoint, 0)) { + D_801FBCF0.x = min->x; + D_801FBCF0.y = max->y; + D_801FBCF0.z = max->z; + D_801FBD00.x = min->x; + D_801FBD00.y = max->y; + D_801FBD00.z = min->z; + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, -1.0f, 0.0f, 0.0f, min->x, a, b, &D_801FBD10, 0)) { return true; } // face 2 - triVtx0.x = min->x; - triVtx0.y = max->y; - triVtx0.z = max->z; - triVtx1.x = min->x; - triVtx1.y = min->y; - triVtx1.z = max->z; - triVtx2.x = max->x; - triVtx2.y = max->y; - triVtx2.z = max->z; - if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 0.0f, 0.0f, 1.0f, -max->z, a, b, &intersectPoint, 0)) { + D_801FBCE0.x = min->x; + D_801FBCE0.y = max->y; + D_801FBCE0.z = max->z; + D_801FBCF0.x = min->x; + D_801FBCF0.y = min->y; + D_801FBCF0.z = max->z; + D_801FBD00.x = max->x; + D_801FBD00.y = max->y; + D_801FBD00.z = max->z; + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 0.0f, 1.0f, -max->z, a, b, &D_801FBD10, 0)) { return true; } - triVtx0.x = max->x; - triVtx0.y = max->y; - triVtx0.z = max->z; - triVtx2.x = max->x; - //! @bug trVtx1.y should be triVtx2.y, prevents a tri on the cube from being checked. - triVtx1.y = min->y; - triVtx2.z = max->z; - if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 0.0f, 0.0f, 1.0f, -max->z, a, b, &intersectPoint, 0)) { + D_801FBCE0.x = max->x; + D_801FBCE0.y = max->y; + D_801FBCE0.z = max->z; + D_801FBD00.x = max->x; + //! @bug trVtx1.y should be D_801FBD00.y, prevents a tri on the cube from being checked. + D_801FBCF0.y = min->y; + D_801FBD00.z = max->z; + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 0.0f, 1.0f, -max->z, a, b, &D_801FBD10, 0)) { return true; } // face 3 - triVtx0.x = min->x; - triVtx0.y = max->y; - triVtx0.z = min->z; - triVtx2.x = min->x; - triVtx2.y = max->y; - triVtx2.z = max->z; - if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 0.0f, 1.0f, 0.0f, -max->y, a, b, &intersectPoint, 0)) { + D_801FBCE0.x = min->x; + D_801FBCE0.y = max->y; + D_801FBCE0.z = min->z; + D_801FBD00.x = min->x; + D_801FBD00.y = max->y; + D_801FBD00.z = max->z; + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 1.0f, 0.0f, -max->y, a, b, &D_801FBD10, 0)) { return true; } - triVtx0.x = max->x; - triVtx0.y = max->y; - triVtx0.z = min->z; - triVtx1.x = min->x; - triVtx1.y = max->y; - triVtx1.z = min->z; - if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 0.0f, 1.0f, 0.0f, -max->y, a, b, &intersectPoint, 0)) { + D_801FBCE0.x = max->x; + D_801FBCE0.y = max->y; + D_801FBCE0.z = min->z; + D_801FBCF0.x = min->x; + D_801FBCF0.y = max->y; + D_801FBCF0.z = min->z; + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 1.0f, 0.0f, -max->y, a, b, &D_801FBD10, 0)) { return true; } // face 4 - triVtx0.x = min->x; - triVtx0.y = min->y; - triVtx0.z = min->z; - triVtx1.x = min->x; - triVtx1.y = max->y; - triVtx1.z = min->z; - triVtx2.x = max->x; - triVtx2.y = max->y; - triVtx2.z = min->z; - if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 0.0f, 0.0f, -1.0f, min->z, a, b, &intersectPoint, 0)) { + D_801FBCE0.x = min->x; + D_801FBCE0.y = min->y; + D_801FBCE0.z = min->z; + D_801FBCF0.x = min->x; + D_801FBCF0.y = max->y; + D_801FBCF0.z = min->z; + D_801FBD00.x = max->x; + D_801FBD00.y = max->y; + D_801FBD00.z = min->z; + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 0.0f, -1.0f, min->z, a, b, &D_801FBD10, 0)) { return true; } - triVtx0.x = max->x; - triVtx0.y = max->y; - triVtx0.z = min->z; - triVtx1.x = max->x; - triVtx1.y = min->y; - triVtx1.z = min->z; + D_801FBCE0.x = max->x; + D_801FBCE0.y = max->y; + D_801FBCE0.z = min->z; + D_801FBCF0.x = max->x; + D_801FBCF0.y = min->y; + D_801FBCF0.z = min->z; // face 5 - if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 0.0f, 0.0f, -1.0f, min->z, a, b, &intersectPoint, 0)) { + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 0.0f, -1.0f, min->z, a, b, &D_801FBD10, 0)) { return true; } - triVtx0.x = max->x; - triVtx0.y = min->y; - triVtx0.z = min->z; - triVtx1.x = max->x; - triVtx1.y = min->y; - triVtx1.z = max->z; - if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 0.0f, -1.0f, 0.0f, min->y, a, b, &intersectPoint, 0)) { + D_801FBCE0.x = max->x; + D_801FBCE0.y = min->y; + D_801FBCE0.z = min->z; + D_801FBCF0.x = max->x; + D_801FBCF0.y = min->y; + D_801FBCF0.z = max->z; + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, -1.0f, 0.0f, min->y, a, b, &D_801FBD10, 0)) { return true; } - triVtx0.x = max->x; - triVtx0.y = min->y; - triVtx0.z = max->z; - triVtx1.x = min->x; - triVtx1.y = min->y; - triVtx1.z = max->z; + D_801FBCE0.x = max->x; + D_801FBCE0.y = min->y; + D_801FBCE0.z = max->z; + D_801FBCF0.x = min->x; + D_801FBCF0.y = min->y; + D_801FBCF0.z = max->z; // face 6 - if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 0.0f, -1.0f, 0.0f, min->y, a, b, &intersectPoint, 0)) { + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, -1.0f, 0.0f, min->y, a, b, &D_801FBD10, 0)) { return true; } - triVtx0.x = max->x; - triVtx0.y = max->y; - triVtx0.z = max->z; - triVtx1.x = max->x; - triVtx1.y = min->y; - triVtx1.z = min->z; - triVtx2.x = max->x; - triVtx2.y = max->y; - triVtx2.z = min->z; - if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 1.0f, 0.0f, 0.0f, -max->x, a, b, &intersectPoint, 0)) { + D_801FBCE0.x = max->x; + D_801FBCE0.y = max->y; + D_801FBCE0.z = max->z; + D_801FBCF0.x = max->x; + D_801FBCF0.y = min->y; + D_801FBCF0.z = min->z; + D_801FBD00.x = max->x; + D_801FBD00.y = max->y; + D_801FBD00.z = min->z; + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 1.0f, 0.0f, 0.0f, -max->x, a, b, &D_801FBD10, 0)) { return true; } - triVtx0.x = max->x; - triVtx0.y = min->y; - triVtx0.z = max->z; - triVtx1.x = max->x; - triVtx1.y = min->y; - triVtx1.z = min->z; - if (Math3D_TriLineIntersect(&triVtx0, &triVtx1, &triVtx2, 1.0f, 0.0f, 0.0f, -max->x, a, b, &intersectPoint, 0)) { + D_801FBCE0.x = max->x; + D_801FBCE0.y = min->y; + D_801FBCE0.z = max->z; + D_801FBCF0.x = max->x; + D_801FBCF0.y = min->y; + D_801FBCF0.z = min->z; + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 1.0f, 0.0f, 0.0f, -max->x, a, b, &D_801FBD10, 0)) { return true; } return false; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_LineVsCube.s") -#endif +// #else +// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_LineVsCube.s") +// #endif -#ifdef NON_MATCHING +// #ifdef NON_MATCHING /** * Checks if a line segment with endpoints `a` and `b` intersect a cube */ @@ -914,9 +951,9 @@ s32 Math3D_LineVsCubeShort(Vec3s* min, Vec3s* max, Vec3s* a, Vec3s* b) { return Math3D_LineVsCube(&D_801FBD20, &D_801FBD30, &D_801FBD40, &D_801FBD50); } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_LineVsCubeShort.s") -#endif +// #else +// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_LineVsCubeShort.s") +// #endif void Math3D_RotateXZPlane(Vec3f* pointOnPlane, s16 angle, f32* a, f32* c, f32* d) { *a = Math_SinS(angle) * 0x7FFF; @@ -924,21 +961,21 @@ void Math3D_RotateXZPlane(Vec3f* pointOnPlane, s16 angle, f32* a, f32* c, f32* d *d = -((*a * pointOnPlane->x) + (*c * pointOnPlane->z)); } -#ifdef NON_MATCHING +// #ifdef NON_MATCHING // in-function static bss void Math3D_DefPlane(Vec3f* va, Vec3f* vb, Vec3f* vc, f32* nx, f32* ny, f32* nz, f32* originDist) { - static Vec3f normal; + static Vec3f D_801FBD60; f32 normMagnitude; f32 normMagInv; - Math3D_SurfaceNorm(va, vb, vc, &normal); - normMagnitude = sqrtf(SQ(normal.x) + SQ(normal.y) + SQ(normal.z)); + Math3D_SurfaceNorm(va, vb, vc, &D_801FBD60); + normMagnitude = sqrtf(SQ(D_801FBD60.x) + SQ(D_801FBD60.y) + SQ(D_801FBD60.z)); if (!IS_ZERO(normMagnitude)) { normMagInv = 1.0f / normMagnitude; - *nx = normal.x * normMagInv; - *ny = normal.y * normMagInv; - *nz = normal.z * normMagInv; + *nx = D_801FBD60.x * normMagInv; + *ny = D_801FBD60.y * normMagInv; + *nz = D_801FBD60.z * normMagInv; *originDist = -((*nx * va->x) + (*ny * va->y) + (*nz * va->z)); } else { *originDist = 0.0f; @@ -947,9 +984,9 @@ void Math3D_DefPlane(Vec3f* va, Vec3f* vb, Vec3f* vc, f32* nx, f32* ny, f32* nz, *nx = 0.0f; } } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_DefPlane.s") -#endif +// #else +// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_DefPlane.s") +// #endif f32 Math3D_PlaneF(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* pointOnPlane) { return (nx * pointOnPlane->x) + (ny * pointOnPlane->y) + (nz * pointOnPlane->z) + originDist; @@ -1246,11 +1283,11 @@ s32 Math3D_TriChkPointParaX(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 y, f32 return false; } -#ifdef NON_MATCHING +// #ifdef NON_MATCHING // in-function static bss s32 Math3D_TriChkLineSegParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 y, f32 z, f32* xIntersect, f32 x0, f32 x1) { - static Vec3f planePos; + static Vec3f D_801FBD70; f32 pointADist; f32 pointBDist; @@ -1259,13 +1296,13 @@ s32 Math3D_TriChkLineSegParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, return false; } - planePos.x = x0; - planePos.y = y; - planePos.z = z; - pointADist = Math3D_PlaneF(nx, ny, nz, originDist, &planePos); + D_801FBD70.x = x0; + D_801FBD70.y = y; + D_801FBD70.z = z; + pointADist = Math3D_PlaneF(nx, ny, nz, originDist, &D_801FBD70); - planePos.x = x1; - pointBDist = Math3D_PlaneF(nx, ny, nz, originDist, &planePos); + D_801FBD70.x = x1; + pointBDist = Math3D_PlaneF(nx, ny, nz, originDist, &D_801FBD70); if (((pointADist > 0.0f) && (pointBDist > 0.0f)) || ((pointADist < 0.0f) && (pointBDist < 0.0f))) { return false; @@ -1277,9 +1314,9 @@ s32 Math3D_TriChkLineSegParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, } return false; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaXIntersect.s") -#endif +// #else +// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaXIntersect.s") +// #endif s32 Math3D_TriChkLineSegParaXDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 y, f32 z, f32 chkDist) { if (IS_ZERO(plane->normal.x)) { @@ -1372,11 +1409,11 @@ s32 Math3D_TriChkPointParaZ(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 y, f32 return false; } -#ifdef NON_MATCHING +// #ifdef NON_MATCHING // in-function static bss s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, f32 y, f32* zIntersect, f32 z0, f32 z1) { - static Vec3f planePos; + static Vec3f D_801FBDB0; f32 pointADist; f32 pointBDist; @@ -1384,13 +1421,13 @@ s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, if (IS_ZERO(nz)) { return false; } - planePos.x = x; - planePos.y = y; - planePos.z = z0; - pointADist = Math3D_PlaneF(nx, ny, nz, originDist, &planePos); + D_801FBDB0.x = x; + D_801FBDB0.y = y; + D_801FBDB0.z = z0; + pointADist = Math3D_PlaneF(nx, ny, nz, originDist, &D_801FBDB0); - planePos.z = z1; - pointBDist = Math3D_PlaneF(nx, ny, nz, originDist, &planePos); + D_801FBDB0.z = z1; + pointBDist = Math3D_PlaneF(nx, ny, nz, originDist, &D_801FBDB0); if (((pointADist > 0.0f) && (pointBDist > 0.0f)) || ((pointADist < 0.0f) && (pointBDist < 0.0f))) { // points on the line segment are on the same side of the plane return false; @@ -1402,9 +1439,9 @@ s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, } return false; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaZIntersect.s") -#endif +// #else +// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaZIntersect.s") +// #endif s32 Math3D_TriChkLineSegParaZDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 x, f32 y, f32 chkDist) { if (IS_ZERO(plane->normal.z)) { @@ -1600,10 +1637,10 @@ s32 func_8017DA24(f32 z0, f32 x0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { return ret; } -#ifdef NON_MATCHING +// #ifdef NON_MATCHING // in-function static bss s32 Math3D_LineVsSph(Sphere16* sphere, Linef* line) { - static Vec3f sphLinePerpendicularPoint; + static Vec3f D_801FBDD8; Vec3f lineDiff; f32 temp_f0_2; @@ -1629,57 +1666,57 @@ s32 Math3D_LineVsSph(Sphere16* sphere, Linef* line) { return false; } - sphLinePerpendicularPoint.x = (lineDiff.x * temp_f0_2) + line->a.x; - sphLinePerpendicularPoint.y = (lineDiff.y * temp_f0_2) + line->a.y; - sphLinePerpendicularPoint.z = (lineDiff.z * temp_f0_2) + line->a.z; + D_801FBDD8.x = (lineDiff.x * temp_f0_2) + line->a.x; + D_801FBDD8.y = (lineDiff.y * temp_f0_2) + line->a.y; + D_801FBDD8.z = (lineDiff.z * temp_f0_2) + line->a.z; - if (SQ(sphLinePerpendicularPoint.x - sphere->center.x) + SQ(sphLinePerpendicularPoint.y - sphere->center.y) + - SQ(sphLinePerpendicularPoint.z - sphere->center.z) <= + if (SQ(D_801FBDD8.x - sphere->center.x) + SQ(D_801FBDD8.y - sphere->center.y) + + SQ(D_801FBDD8.z - sphere->center.z) <= SQ((f32)sphere->radius)) { return true; } return false; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_LineVsSph.s") -#endif +// #else +// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_LineVsSph.s") +// #endif -#ifdef NON_MATCHING +// #ifdef NON_MATCHING // in-function static bss void Math3D_GetSphVsTriIntersectPoint(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoint) { - static Vec3f v0v1Center; - static Vec3f sphereCenter; + static Vec3f D_801FBDE8; + static Vec3f D_801FBBF0; f32 dist; f32 splitRatio; - v0v1Center.x = ((tri->vtx[0].x + tri->vtx[1].x) * 0.5f); - v0v1Center.y = ((tri->vtx[0].y + tri->vtx[1].y) * 0.5f); - v0v1Center.z = ((tri->vtx[0].z + tri->vtx[1].z) * 0.5f); - sphereCenter.x = sphere->center.x; - sphereCenter.y = sphere->center.y; - sphereCenter.z = sphere->center.z; - dist = Math3D_Vec3f_DistXYZ(&v0v1Center, &sphereCenter); + D_801FBDE8.x = ((tri->vtx[0].x + tri->vtx[1].x) * 0.5f); + D_801FBDE8.y = ((tri->vtx[0].y + tri->vtx[1].y) * 0.5f); + D_801FBDE8.z = ((tri->vtx[0].z + tri->vtx[1].z) * 0.5f); + D_801FBBF0.x = sphere->center.x; + D_801FBBF0.y = sphere->center.y; + D_801FBBF0.z = sphere->center.z; + dist = Math3D_Vec3f_DistXYZ(&D_801FBDE8, &D_801FBBF0); // Distance from the sphere's center to the center of the line formed from v0->v1 if (IS_ZERO(dist)) { - intersectPoint->x = sphereCenter.x; - intersectPoint->y = sphereCenter.y; - intersectPoint->z = sphereCenter.z; + intersectPoint->x = D_801FBBF0.x; + intersectPoint->y = D_801FBBF0.y; + intersectPoint->z = D_801FBBF0.z; return; } splitRatio = sphere->radius / dist; - Math3D_LineSplitRatio(&sphereCenter, &v0v1Center, splitRatio, intersectPoint); + Math3D_LineSplitRatio(&D_801FBBF0, &D_801FBDE8, splitRatio, intersectPoint); } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_GetSphVsTriIntersectPoint.s") -#endif +// #else +// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_GetSphVsTriIntersectPoint.s") +// #endif -#ifdef NON_MATCHING +// #ifdef NON_MATCHING // in-function static bss s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoint) { - static Linef triTestLine; - static Vec3f sphereCenter; - static Vec3f sphPlanePos; + static Linef D_801FBC00; + static Vec3f D_801FBC18; + static Vec3f D_801FBC28; f32 radius; f32 nx; @@ -1687,17 +1724,17 @@ s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoi f32 nz; f32 planeDist; - sphereCenter.x = sphere->center.x; - sphereCenter.y = sphere->center.y; - sphereCenter.z = sphere->center.z; + D_801FBC18.x = sphere->center.x; + D_801FBC18.y = sphere->center.y; + D_801FBC18.z = sphere->center.z; radius = sphere->radius; - if (!Math3D_SphCubeVsTriCube(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], &sphereCenter, radius)) { + if (!Math3D_SphCubeVsTriCube(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], &D_801FBC18, radius)) { return false; } planeDist = Math3D_UDistPlaneToPos(tri->plane.normal.x, tri->plane.normal.y, tri->plane.normal.z, - tri->plane.originDist, &sphereCenter); + tri->plane.originDist, &D_801FBC18); if (radius < planeDist) { // the point that lies within the plane of the triangle which is perpendicular to the sphere's center is more // than the radius of the sphere, the plane never crosses the sphere. @@ -1705,23 +1742,23 @@ s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoi } // tests if any of the edges of the triangle are intersecting the sphere - triTestLine.a = tri->vtx[0]; - triTestLine.b = tri->vtx[1]; - if (Math3D_LineVsSph(sphere, &triTestLine)) { + D_801FBC00.a = tri->vtx[0]; + D_801FBC00.b = tri->vtx[1]; + if (Math3D_LineVsSph(sphere, &D_801FBC00)) { Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); return true; } - triTestLine.a = tri->vtx[1]; - triTestLine.b = tri->vtx[2]; - if (Math3D_LineVsSph(sphere, &triTestLine)) { + D_801FBC00.a = tri->vtx[1]; + D_801FBC00.b = tri->vtx[2]; + if (Math3D_LineVsSph(sphere, &D_801FBC00)) { Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); return true; } - triTestLine.a = tri->vtx[2]; - triTestLine.b = tri->vtx[0]; - if (Math3D_LineVsSph(sphere, &triTestLine)) { + D_801FBC00.a = tri->vtx[2]; + D_801FBC00.b = tri->vtx[0]; + if (Math3D_LineVsSph(sphere, &D_801FBC00)) { Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); return true; } @@ -1731,38 +1768,38 @@ s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoi nz = tri->plane.normal.z * planeDist; if (Math3D_PlaneF(tri->plane.normal.x, tri->plane.normal.y, tri->plane.normal.z, tri->plane.originDist, - &sphereCenter) > 0.0f) { - sphPlanePos.x = sphereCenter.x - nx; - sphPlanePos.y = sphereCenter.y - ny; - sphPlanePos.z = sphereCenter.z - nz; + &D_801FBC18) > 0.0f) { + D_801FBC28.x = D_801FBC18.x - nx; + D_801FBC28.y = D_801FBC18.y - ny; + D_801FBC28.z = D_801FBC18.z - nz; } else { - sphPlanePos.x = sphereCenter.x + nx; - sphPlanePos.y = sphereCenter.y + ny; - sphPlanePos.z = sphereCenter.z + nz; + D_801FBC28.x = D_801FBC18.x + nx; + D_801FBC28.y = D_801FBC18.y + ny; + D_801FBC28.z = D_801FBC18.z + nz; } if (fabsf(tri->plane.normal.y) > 0.5f) { - if (Math3D_TriChkPointParaYDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], sphPlanePos.z, sphPlanePos.x, + if (Math3D_TriChkPointParaYDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], D_801FBC28.z, D_801FBC28.x, 0.0f, tri->plane.normal.y)) { Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); return true; } } else if (fabsf(tri->plane.normal.x) > 0.5f) { - if (Math3D_TriChkPointParaXDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], sphPlanePos.y, sphPlanePos.z, + if (Math3D_TriChkPointParaXDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], D_801FBC28.y, D_801FBC28.z, 0.0f, tri->plane.normal.x)) { Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); return true; } - } else if (Math3D_TriChkPointParaZDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], sphPlanePos.x, - sphPlanePos.y, 0.0f, tri->plane.normal.z)) { + } else if (Math3D_TriChkPointParaZDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], D_801FBC28.x, + D_801FBC28.y, 0.0f, tri->plane.normal.z)) { Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); return true; } return false; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriVsSphIntersect.s") -#endif +// #else +// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriVsSphIntersect.s") +// #endif s32 Math3D_PointInCyl(Cylinder16* cyl, Vec3f* point) { f32 bottom; @@ -1974,13 +2011,13 @@ dummy:; return count; } -#ifdef NON_MATCHING +// #ifdef NON_MATCHING // in-function static bss s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect) { - static Sphere16 topSphere; - static Sphere16 bottomSphere; - static Vec3f cylIntersectA; - static Vec3f cylIntersectB; + static Sphere16 D_801FBC38; + static Sphere16 D_801FBC40; + static Vec3f D_801FBC48; + static Vec3f D_801FBC58; f32 yIntersect; f32 cylTop; @@ -2000,24 +2037,24 @@ s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect) { } minDistSq = 1.e38f; - if (Math3D_CylVsLineSeg(cyl, &tri->vtx[0], &tri->vtx[1], &cylIntersectA, &cylIntersectB)) { - distFromPointAToIntersectASq = Math3D_Vec3fDistSq(&cylIntersectA, &tri->vtx[0]); + if (Math3D_CylVsLineSeg(cyl, &tri->vtx[0], &tri->vtx[1], &D_801FBC48, &D_801FBC58)) { + distFromPointAToIntersectASq = Math3D_Vec3fDistSq(&D_801FBC48, &tri->vtx[0]); minDistSq = distFromPointAToIntersectASq; - *intersect = cylIntersectA; + *intersect = D_801FBC48; } - if (Math3D_CylVsLineSeg(cyl, &tri->vtx[2], &tri->vtx[1], &cylIntersectA, &cylIntersectB)) { - distFromPointAToIntersectASq = Math3D_Vec3fDistSq(&cylIntersectA, &tri->vtx[2]); + if (Math3D_CylVsLineSeg(cyl, &tri->vtx[2], &tri->vtx[1], &D_801FBC48, &D_801FBC58)) { + distFromPointAToIntersectASq = Math3D_Vec3fDistSq(&D_801FBC48, &tri->vtx[2]); if (distFromPointAToIntersectASq < minDistSq) { - *intersect = cylIntersectA; + *intersect = D_801FBC48; minDistSq = distFromPointAToIntersectASq; } } - if (Math3D_CylVsLineSeg(cyl, &tri->vtx[0], &tri->vtx[2], &cylIntersectA, &cylIntersectB)) { - distFromPointAToIntersectASq = Math3D_Vec3fDistSq(&cylIntersectA, &tri->vtx[0]); + if (Math3D_CylVsLineSeg(cyl, &tri->vtx[0], &tri->vtx[2], &D_801FBC48, &D_801FBC58)) { + distFromPointAToIntersectASq = Math3D_Vec3fDistSq(&D_801FBC48, &tri->vtx[0]); if (distFromPointAToIntersectASq < minDistSq) { - *intersect = cylIntersectA; + *intersect = D_801FBC48; minDistSq = distFromPointAToIntersectASq; } } @@ -2056,21 +2093,21 @@ s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect) { return true; } - topSphere.center.x = bottomSphere.center.x = cyl->pos.x; - topSphere.center.z = bottomSphere.center.z = cyl->pos.z; - topSphere.center.y = cylTop; - bottomSphere.center.y = cylBottom; - topSphere.radius = bottomSphere.radius = cyl->radius; + D_801FBC38.center.x = D_801FBC40.center.x = cyl->pos.x; + D_801FBC38.center.z = D_801FBC40.center.z = cyl->pos.z; + D_801FBC38.center.y = cylTop; + D_801FBC40.center.y = cylBottom; + D_801FBC38.radius = D_801FBC40.radius = cyl->radius; - if ((Math3D_TriVsSphIntersect(&topSphere, tri, intersect)) || - (Math3D_TriVsSphIntersect(&bottomSphere, tri, intersect))) { + if ((Math3D_TriVsSphIntersect(&D_801FBC38, tri, intersect)) || + (Math3D_TriVsSphIntersect(&D_801FBC40, tri, intersect))) { return true; } return false; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_CylTriVsIntersect.s") -#endif +// #else +// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_CylTriVsIntersect.s") +// #endif s32 Math3D_CylVsTri(Cylinder16* cyl, TriNorm* tri) { Vec3f intersect; @@ -2114,11 +2151,11 @@ s32 Math3D_SphVsCylOverlapDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize) return Math3D_SphVsCylOverlapCenterDist(sph, cyl, overlapSize, ¢erDist); } -#ifdef NON_MATCHING +// #ifdef NON_MATCHING // in-function static bss s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize, f32* centerDist) { - static Cylinderf cylf; - static Spheref sphf; + static Cylinderf D_801FBC88; + static Spheref D_801FBCA0; f32 x; f32 z; @@ -2132,11 +2169,11 @@ s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overla // either radius is 0 return false; } - sphf.center.y = sph->center.y; - sphf.radius = sph->radius; - cylf.pos.y = cyl->pos.y; - cylf.yShift = cyl->yShift; - cylf.height = cyl->height; + D_801FBCA0.center.y = sph->center.y; + D_801FBCA0.radius = sph->radius; + D_801FBC88.pos.y = cyl->pos.y; + D_801FBC88.yShift = cyl->yShift; + D_801FBC88.height = cyl->height; x = (f32)sph->center.x - cyl->pos.x; z = (f32)sph->center.z - cyl->pos.z; combinedRadius = (f32)sph->radius + cyl->radius; @@ -2146,10 +2183,10 @@ s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overla return false; } - cylBottom = (cylf.pos.y + cylf.yShift); - cylTop = cylBottom + cylf.height; - sphBottom = sphf.center.y - sphf.radius; - sphTop = sphf.center.y + sphf.radius; + cylBottom = (D_801FBC88.pos.y + D_801FBC88.yShift); + cylTop = cylBottom + D_801FBC88.height; + sphBottom = D_801FBCA0.center.y - D_801FBCA0.radius; + sphTop = D_801FBCA0.center.y + D_801FBCA0.radius; if ((sphTop >= cylBottom) && (sphBottom <= cylTop)) { // if the cylinder and sphere are intersecting on the xz plane, check if they're intersecting on @@ -2159,9 +2196,9 @@ s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overla } return false; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_SphVsCylOverlapCenterDist.s") -#endif +// #else +// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_SphVsCylOverlapCenterDist.s") +// #endif s32 Math3D_CylOutsideCyl(Cylinder16* ca, Cylinder16* cb, f32* deadSpace) { f32 xzDist; @@ -2169,41 +2206,41 @@ s32 Math3D_CylOutsideCyl(Cylinder16* ca, Cylinder16* cb, f32* deadSpace) { return Math3D_CylOutsideCylDist(ca, cb, deadSpace, &xzDist); } -#ifdef NON_MATCHING +// #ifdef NON_MATCHING // in-function static bss s32 Math3D_CylOutsideCylDist(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32* xzDist) { - static Cylinderf caf; - static Cylinderf cbf; + static Cylinderf D_801FBCB0; + static Cylinderf D_801FBCC8; - Math_Vec3s_ToVec3f(&caf.pos, &ca->pos); - caf.radius = ca->radius; - caf.yShift = ca->yShift; - caf.height = ca->height; + Math_Vec3s_ToVec3f(&D_801FBCB0.pos, &ca->pos); + D_801FBCB0.radius = ca->radius; + D_801FBCB0.yShift = ca->yShift; + D_801FBCB0.height = ca->height; - Math_Vec3s_ToVec3f(&cbf.pos, &cb->pos); - cbf.radius = cb->radius; - cbf.yShift = cb->yShift; - cbf.height = cb->height; + Math_Vec3s_ToVec3f(&D_801FBCC8.pos, &cb->pos); + D_801FBCC8.radius = cb->radius; + D_801FBCC8.yShift = cb->yShift; + D_801FBCC8.height = cb->height; - *xzDist = sqrtf(SQ(caf.pos.x - cbf.pos.x) + SQ(caf.pos.z - cbf.pos.z)); + *xzDist = sqrtf(SQ(D_801FBCB0.pos.x - D_801FBCC8.pos.x) + SQ(D_801FBCB0.pos.z - D_801FBCC8.pos.z)); // The combined radix are within the xz distance - if ((caf.radius + cbf.radius) < *xzDist) { + if ((D_801FBCB0.radius + D_801FBCC8.radius) < *xzDist) { return false; } // top of ca < bottom of cb or top of cb < bottom of ca - if (((caf.pos.y + caf.yShift) + caf.height) < (cbf.pos.y + cbf.yShift) || - (((cbf.pos.y + cbf.yShift) + cbf.height) < (caf.pos.y + caf.yShift))) { + if (((D_801FBCB0.pos.y + D_801FBCB0.yShift) + D_801FBCB0.height) < (D_801FBCC8.pos.y + D_801FBCC8.yShift) || + (((D_801FBCC8.pos.y + D_801FBCC8.yShift) + D_801FBCC8.height) < (D_801FBCB0.pos.y + D_801FBCB0.yShift))) { return false; } - *deadSpace = caf.radius + cbf.radius - *xzDist; + *deadSpace = D_801FBCB0.radius + D_801FBCC8.radius - *xzDist; return true; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_CylOutsideCylDist.s") -#endif +// #else +// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_CylOutsideCylDist.s") +// #endif s32 Math3D_TriVsTriIntersect(TriNorm* ta, TriNorm* tb, Vec3f* intersect) { f32 dist0 = Math3D_Plane(&ta->plane, &tb->vtx[0]); diff --git a/tools/disasm/variables.txt b/tools/disasm/variables.txt index b5ae0f138..753ccad6f 100644 --- a/tools/disasm/variables.txt +++ b/tools/disasm/variables.txt @@ -4119,36 +4119,36 @@ 0x801FBBD2:("D_801FBBD2","UNK_TYPE1","",0x1), 0x801FBBD4:("D_801FBBD4","UNK_TYPE1","",0x1), 0x801FBBE0:("sDmaBuffer","u32","[2]",0x8), - 0x801FBBF0:("Math3D_GetSphVsTriIntersectPoint_sphereCenter","Vec3f","",0xc), - 0x801FBC00:("Math3D_TriVsSphIntersect_triTestLine","Linef","",0x18), - 0x801FBC18:("Math3D_TriVsSphIntersect_sphereCenter","Vec3f","",0xc), - 0x801FBC28:("Math3D_TriVsSphIntersect_sphPlanePos","Vec3f","",0xC), - 0x801FBC38:("topSphere","Sphere16","",0x8), - 0x801FBC40:("bottomSphere","Sphere16","",0x8), - 0x801FBC48:("cylIntersectA","Vec3f","",0xC), - 0x801FBC58:("cylIntersectB","Vec3f","",0xC), - 0x801FBC68:("abDiff","Vec3f","",0xc), - 0x801FBC78:("acDiff","Vec3f","",0xc), - 0x801FBC88:("cylf","Cylinderf","",0x18), - 0x801FBCA0:("sphf","Spheref","",0x10), - 0x801FBCB0:("caf","Cylinderf","",0x18), - 0x801FBCC8:("cbf","Cylinderf","",0x18), - 0x801FBCE0:("triVtx0","Vec3f","",0xC), - 0x801FBCF0:("triVtx1","Vec3f","",0xC), - 0x801FBD00:("triVtx2","Vec3f","",0xC), - 0x801FBD10:("Math3D_LineVsCube_intersectPoint","Vec3f","",0xC), + 0x801FBBF0:("D_801FBBF0","Vec3f","",0xc), + 0x801FBC00:("D_801FBC00","Linef","",0x18), + 0x801FBC18:("D_801FBC18","Vec3f","",0xc), + 0x801FBC28:("D_801FBC28","Vec3f","",0xC), + 0x801FBC38:("D_801FBC38","Sphere16","",0x8), + 0x801FBC40:("D_801FBC40","Sphere16","",0x8), + 0x801FBC48:("D_801FBC48","Vec3f","",0xC), + 0x801FBC58:("D_801FBC58","Vec3f","",0xC), + 0x801FBC68:("D_801FBC68","Vec3f","",0xc), + 0x801FBC78:("D_801FBC78","Vec3f","",0xc), + 0x801FBC88:("D_801FBC88","Cylinderf","",0x18), + 0x801FBCA0:("D_801FBCA0","Spheref","",0x10), + 0x801FBCB0:("D_801FBCB0","Cylinderf","",0x18), + 0x801FBCC8:("D_801FBCC8","Cylinderf","",0x18), + 0x801FBCE0:("D_801FBCE0","Vec3f","",0xC), + 0x801FBCF0:("D_801FBCF0","Vec3f","",0xC), + 0x801FBD00:("D_801FBD00","Vec3f","",0xC), + 0x801FBD10:("D_801FBD10","Vec3f","",0xC), 0x801FBD20:("D_801FBD20","Vec3f","",0xC), 0x801FBD30:("D_801FBD30","Vec3f","",0xC), 0x801FBD40:("D_801FBD40","Vec3f","",0xC), 0x801FBD50:("D_801FBD50","Vec3f","",0xC), - 0x801FBD60:("Math3D_DefPlane_normal","Vec3f","",0xC), - 0x801FBD70:("Math3D_TriChkLineSegParaXIntersect_planePos","Vec3f","",0xC), - 0x801FBD80:("planeIntersectLine","InfiniteLine","",0x18), - 0x801FBD98:("planeIntersectSeg","Linef","",0x18), - 0x801FBDB0:("Math3D_TriChkLineSegParaZIntersect_planePos","Vec3f","",0xC), - 0x801FBDC0:("Math3D_PlaneVsPlaneVsLineClosestPoint_planeIntersect","InfiniteLine","",0x18), - 0x801FBDD8:("sphLinePerpendicularPoint","Vec3f","",0xC), - 0x801FBDE8:("v0v1Center","Vec3f","",0xC), + 0x801FBD60:("D_801FBD60","Vec3f","",0xC), + 0x801FBD70:("D_801FBD70","Vec3f","",0xC), + 0x801FBD80:("D_801FBD80","InfiniteLine","",0x18), + 0x801FBD98:("D_801FBD98","Linef","",0x18), + 0x801FBDB0:("D_801FBDB0","Vec3f","",0xC), + 0x801FBDC0:("D_801FBDC0","InfiniteLine","",0x18), + 0x801FBDD8:("D_801FBDD8","Vec3f","",0xC), + 0x801FBDE8:("D_801FBDE8","Vec3f","",0xC), 0x801FBE00:("sMatrixStack","MtxF*","",0x4), 0x801FBE04:("sCurrentMatrix","MtxF*","",0x4), 0x801FBE10:("D_801FBE10","UNK_TYPE1","",0x1), From 25da52d30bd2e9ee0cdba336befe7a07d0c9eab2 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Fri, 26 May 2023 19:13:23 +1000 Subject: [PATCH 19/29] OK --- src/code/sys_math3d.c | 268 ++++++++++++++++++++++++++++-------------- 1 file changed, 183 insertions(+), 85 deletions(-) diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 93f0475ba..9745e431f 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -35,42 +35,128 @@ // extern Vec3f D_801FBDD8; // extern Vec3f D_801FBDE8; -static Vec3f D_801FBC68; -static Vec3f D_801FBC78; +// Partial structs taken from "prevent_bss_reordering.h" +struct Dummy100 { + int x; +}; +struct Dummy101 { + int x; +}; +struct Dummy102 { + int x; +}; +struct Dummy103 { + int x; +}; +struct Dummy104 { + int x; +}; +struct Dummy105 { + int x; +}; +struct Dummy106 { + int x; +}; +struct Dummy107 { + int x; +}; +struct Dummy108 { + int x; +}; +struct Dummy109 { + int x; +}; +struct Dummy110 { + int x; +}; +struct Dummy111 { + int x; +}; +struct Dummy112 { + int x; +}; +struct Dummy113 { + int x; +}; +struct Dummy114 { + int x; +}; +struct Dummy115 { + int x; +}; +struct Dummy116 { + int x; +}; +struct Dummy117 { + int x; +}; +struct Dummy118 { + int x; +}; +struct Dummy119 { + int x; +}; +struct Dummy120 { + int x; +}; +struct Dummy121 { + int x; +}; +struct Dummy122 { + int x; +}; +struct Dummy123 { + int x; +}; +struct Dummy124 { + int x; +}; +struct Dummy125 { + int x; +}; +struct Dummy126 { + int x; +}; +struct Dummy127 { + int x; +}; +// struct Dummy128 { int x; }; +// struct Dummy129 { int x; }; +// struct Dummy130 { int x; }; +// struct Dummy131 { int x; }; +// struct Dummy132 { int x; }; +// struct Dummy133 { int x; }; +// struct Dummy134 { int x; }; +// struct Dummy135 { int x; }; +// struct Dummy136 { int x; }; +// struct Dummy137 { int x; }; +// struct Dummy138 { int x; }; +// struct Dummy139 { int x; }; +// struct Dummy140 { int x; }; +// struct Dummy141 { int x; }; +// struct Dummy142 { int x; }; +// struct Dummy143 { int x; }; +// struct Dummy144 { int x; }; +// struct Dummy145 { int x; }; +// struct Dummy146 { int x; }; +// struct Dummy147 { int x; }; +// struct Dummy148 { int x; }; +// struct Dummy149 { int x; }; +// struct Dummy150 { int x; }; +// struct Dummy151 { int x; }; +// struct Dummy152 { int x; }; +// struct Dummy153 { int x; }; +// struct Dummy154 { int x; }; +// struct Dummy155 { int x; }; +// struct Dummy156 { int x; }; +// struct Dummy157 { int x; }; +// struct Dummy158 { int x; }; +// struct Dummy159 { int x; }; +// struct Dummy160 { int x; }; +// struct Dummy161 { int x; }; +// struct Dummy162 { int x; }; +typedef int Dummy163; - -// extern Vec3f dummy0; -// extern Vec3f dummy1; -// extern Vec3f dummy2; -// extern Vec3f dummy3; -// extern Vec3f dummy4; -// extern Vec3f dummy5; -// extern Vec3f dummy6; -// extern Vec3f dummy7; -// extern Vec3f dummy8; -// extern Vec3f dummy9; -// extern Vec3f dummy10; -// extern Vec3f dummy11; -// extern Vec3f dummy12; -// extern Vec3f dummy13; -// extern Vec3f dummy14; -// extern Vec3f dummy15; -// extern Vec3f dummy16; -// extern Vec3f dummy17; -// extern Vec3f dummy18; -// extern Vec3f dummy19; -// extern Vec3f dummy20; -// extern Vec3f dummy21; -// extern Vec3f dummy22; -// extern Vec3f dummy23; -// extern Vec3f dummy24; -// extern Vec3f dummy25; -// extern Vec3f dummy26; -// extern Vec3f dummy27; -// extern Vec3f dummy28; -// extern Vec3f dummy29; - -#ifdef NON_MATCHING f32 Math3D_Normalize(Vec3f* vec) { f32 magnitude = Math3D_Vec3fMagnitude(vec); @@ -83,9 +169,6 @@ f32 Math3D_Normalize(Vec3f* vec) { vec->z *= 1.0f / magnitude; return magnitude; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_Normalize.s") -#endif // #ifdef NON_MATCHING // in-function static bss @@ -109,8 +192,7 @@ s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 D_801FBD98.b.z = (D_801FBD80.dir.z * 100.0f) + D_801FBD80.point.z; // closestPoint is a point on planeIntersect, sp34 is a point on linePointA, linePointB - if (!Math3D_LineSegMakePerpLineSeg(&D_801FBD98.a, &D_801FBD98.b, linePointA, linePointB, closestPoint, - &sp34)) { + if (!Math3D_LineSegMakePerpLineSeg(&D_801FBD98.a, &D_801FBD98.b, linePointA, linePointB, closestPoint, &sp34)) { return false; } return true; @@ -592,6 +674,9 @@ f32 Math3D_DistXYZ16toF(Vec3s* a, Vec3f* b) { return Math3D_Vec3fMagnitude(&diff); } +static Vec3f D_801FBC68; +static Vec3f D_801FBC78; + /** * Gets the Z portion of the cross product of vectors `a - (`dx`,`dy`,z) and `b` - (`dx`,`dy`,z) */ @@ -624,6 +709,7 @@ void Math3D_Vec3f_Cross(Vec3f* a, Vec3f* b, Vec3f* ret) { // #ifdef NON_MATCHING // in-function static bss + void Math3D_SurfaceNorm(Vec3f* va, Vec3f* vb, Vec3f* vc, Vec3f* normal) { Math_Vec3f_Diff(vb, va, &D_801FBC68); Math_Vec3f_Diff(vc, va, &D_801FBC78); @@ -795,7 +881,8 @@ s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { D_801FBD00.x = min->x; D_801FBD00.y = max->y; D_801FBD00.z = max->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, -1.0f, 0.0f, 0.0f, min->x, a, b, &D_801FBD10, 0)) { + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, -1.0f, 0.0f, 0.0f, min->x, a, b, &D_801FBD10, + 0)) { return true; } @@ -805,7 +892,8 @@ s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { D_801FBD00.x = min->x; D_801FBD00.y = max->y; D_801FBD00.z = min->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, -1.0f, 0.0f, 0.0f, min->x, a, b, &D_801FBD10, 0)) { + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, -1.0f, 0.0f, 0.0f, min->x, a, b, &D_801FBD10, + 0)) { return true; } @@ -819,7 +907,8 @@ s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { D_801FBD00.x = max->x; D_801FBD00.y = max->y; D_801FBD00.z = max->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 0.0f, 1.0f, -max->z, a, b, &D_801FBD10, 0)) { + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 0.0f, 1.0f, -max->z, a, b, &D_801FBD10, + 0)) { return true; } D_801FBCE0.x = max->x; @@ -829,27 +918,30 @@ s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { //! @bug trVtx1.y should be D_801FBD00.y, prevents a tri on the cube from being checked. D_801FBCF0.y = min->y; D_801FBD00.z = max->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 0.0f, 1.0f, -max->z, a, b, &D_801FBD10, 0)) { + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 0.0f, 1.0f, -max->z, a, b, &D_801FBD10, + 0)) { return true; } // face 3 - D_801FBCE0.x = min->x; - D_801FBCE0.y = max->y; - D_801FBCE0.z = min->z; - D_801FBD00.x = min->x; - D_801FBD00.y = max->y; - D_801FBD00.z = max->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 1.0f, 0.0f, -max->y, a, b, &D_801FBD10, 0)) { - return true; - } - D_801FBCE0.x = max->x; - D_801FBCE0.y = max->y; - D_801FBCE0.z = min->z; D_801FBCF0.x = min->x; D_801FBCF0.y = max->y; D_801FBCF0.z = min->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 1.0f, 0.0f, -max->y, a, b, &D_801FBD10, 0)) { + D_801FBD00.x = min->x; + D_801FBD00.y = max->y; + D_801FBD00.z = max->z; + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 1.0f, 0.0f, -max->y, a, b, &D_801FBD10, + 0)) { + return true; + } + D_801FBCF0.x = max->x; + D_801FBCF0.y = max->y; + D_801FBCF0.z = min->z; + D_801FBD00.x = min->x; + D_801FBD00.y = max->y; + D_801FBD00.z = min->z; + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 1.0f, 0.0f, -max->y, a, b, &D_801FBD10, + 0)) { return true; } @@ -863,38 +955,42 @@ s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { D_801FBD00.x = max->x; D_801FBD00.y = max->y; D_801FBD00.z = min->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 0.0f, -1.0f, min->z, a, b, &D_801FBD10, 0)) { + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 0.0f, -1.0f, min->z, a, b, &D_801FBD10, + 0)) { + return true; + } + D_801FBCF0.x = max->x; + D_801FBCF0.y = max->y; + D_801FBCF0.z = min->z; + D_801FBD00.x = max->x; + D_801FBD00.y = min->y; + D_801FBD00.z = min->z; + + // face 5 + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 0.0f, -1.0f, min->z, a, b, &D_801FBD10, + 0)) { return true; } - D_801FBCE0.x = max->x; - D_801FBCE0.y = max->y; - D_801FBCE0.z = min->z; D_801FBCF0.x = max->x; D_801FBCF0.y = min->y; D_801FBCF0.z = min->z; - - // face 5 - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 0.0f, -1.0f, min->z, a, b, &D_801FBD10, 0)) { + D_801FBD00.x = max->x; + D_801FBD00.y = min->y; + D_801FBD00.z = max->z; + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, -1.0f, 0.0f, min->y, a, b, &D_801FBD10, + 0)) { return true; } - D_801FBCE0.x = max->x; - D_801FBCE0.y = min->y; - D_801FBCE0.z = min->z; D_801FBCF0.x = max->x; D_801FBCF0.y = min->y; D_801FBCF0.z = max->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, -1.0f, 0.0f, min->y, a, b, &D_801FBD10, 0)) { - return true; - } - D_801FBCE0.x = max->x; - D_801FBCE0.y = min->y; - D_801FBCE0.z = max->z; - D_801FBCF0.x = min->x; - D_801FBCF0.y = min->y; - D_801FBCF0.z = max->z; + D_801FBD00.x = min->x; + D_801FBD00.y = min->y; + D_801FBD00.z = max->z; // face 6 - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, -1.0f, 0.0f, min->y, a, b, &D_801FBD10, 0)) { + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, -1.0f, 0.0f, min->y, a, b, &D_801FBD10, + 0)) { return true; } D_801FBCE0.x = max->x; @@ -906,16 +1002,18 @@ s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { D_801FBD00.x = max->x; D_801FBD00.y = max->y; D_801FBD00.z = min->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 1.0f, 0.0f, 0.0f, -max->x, a, b, &D_801FBD10, 0)) { + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 1.0f, 0.0f, 0.0f, -max->x, a, b, &D_801FBD10, + 0)) { return true; } - D_801FBCE0.x = max->x; - D_801FBCE0.y = min->y; - D_801FBCE0.z = max->z; D_801FBCF0.x = max->x; D_801FBCF0.y = min->y; - D_801FBCF0.z = min->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 1.0f, 0.0f, 0.0f, -max->x, a, b, &D_801FBD10, 0)) { + D_801FBCF0.z = max->z; + D_801FBD00.x = max->x; + D_801FBD00.y = min->y; + D_801FBD00.z = min->z; + if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 1.0f, 0.0f, 0.0f, -max->x, a, b, &D_801FBD10, + 0)) { return true; } @@ -1790,8 +1888,8 @@ s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoi Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); return true; } - } else if (Math3D_TriChkPointParaZDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], D_801FBC28.x, - D_801FBC28.y, 0.0f, tri->plane.normal.z)) { + } else if (Math3D_TriChkPointParaZDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], D_801FBC28.x, D_801FBC28.y, + 0.0f, tri->plane.normal.z)) { Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); return true; } From 90e45cce373256882807e7ef10be3f1a36d8e29f Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sun, 11 Jun 2023 01:18:07 +1000 Subject: [PATCH 20/29] small cleanup --- src/code/sys_math3d.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 6252f8308..5c0062957 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -152,7 +152,7 @@ s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 */ s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBPointA, Vec3f* lineBPointB, Vec3f* lineAClosestToB, Vec3f* lineBClosestToA) { - f32 sqMag; + f32 magSq; f32 scaleB; f32 lineAx = lineAPointB->x - lineAPointA->x; f32 lineAy = lineAPointB->y - lineAPointA->y; @@ -167,12 +167,12 @@ s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* f32 tA; f32 tB; - sqMag = SQ(lineBx) + SQ(lineBy) + SQ(lineBz); - if (IS_ZERO(sqMag)) { + magSq = SQ(lineBx) + SQ(lineBy) + SQ(lineBz); + if (IS_ZERO(magSq)) { return false; } - scaleB = 1.0f / sqMag; + scaleB = 1.0f / magSq; compAAlongB = ((lineAx * lineBx) + (lineAy * lineBy) + (lineAz * lineBz)) * scaleB; @@ -184,8 +184,8 @@ s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineAPerpB.y = lineAy - (lineBy * compAAlongB); lineAPerpB.z = lineAz - (lineBz * compAAlongB); - sqMag = SQXYZ(lineAPerpB); - if (IS_ZERO(sqMag)) { + magSq = SQXYZ(lineAPerpB); + if (IS_ZERO(magSq)) { return false; } @@ -193,7 +193,7 @@ s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* lineBAPerpB.y = (lineAPointA->y - lineBPointA->y) - (lineBy * compBAAlongB); lineBAPerpB.z = (lineAPointA->z - lineBPointA->z) - (lineBz * compBAAlongB); - tA = -DOTXYZ(lineAPerpB, lineBAPerpB) / sqMag; + tA = -DOTXYZ(lineAPerpB, lineBAPerpB) / magSq; lineAClosestToB->x = (lineAx * tA) + lineAPointA->x; lineAClosestToB->y = (lineAy * tA) + lineAPointA->y; lineAClosestToB->z = (lineAz * tA) + lineAPointA->z; @@ -211,17 +211,17 @@ s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f* * `point` to `line` closest point is placed in `closestPoint` */ f32 Math3D_LineClosestToPoint(InfiniteLine* line, Vec3f* pos, Vec3f* closestPoint) { - f32 dirVectorSize = Math3D_Vec3fMagnitudeSq(&line->dir); + f32 dirMagnitudeSq = Math3D_Vec3fMagnitudeSq(&line->dir); f32 t; - if (IS_ZERO(dirVectorSize)) { + if (IS_ZERO(dirMagnitudeSq)) { Math_Vec3f_Copy(closestPoint, pos); //! @bug Missing early return } t = (((pos->x - line->point.x) * line->dir.x) + ((pos->y - line->point.y) * line->dir.y) + ((pos->z - line->point.z) * line->dir.z)) / - dirVectorSize; + dirMagnitudeSq; closestPoint->x = (line->dir.x * t) + line->point.x; closestPoint->y = (line->dir.y * t) + line->point.y; closestPoint->z = (line->dir.z * t) + line->point.z; @@ -2432,7 +2432,6 @@ s32 Math3D_CircleLineIntersections(f32 centreX, f32 centerY, f32 radius, f32 poi return ret; } -#ifdef NON_MATCHING void func_8017FD44(Vec3f* arg0, Vec3f* arg1, Vec3f* dst, f32 arg3) { Vec3f sp2C; s16 sp2A; @@ -2450,6 +2449,3 @@ void func_8017FD44(Vec3f* arg0, Vec3f* arg1, Vec3f* dst, f32 arg3) { dst->x = Math_SinS(TRUNCF_BINANG(0x7FFF * arg3) + sp2A) * sp24 + sp2C.x; dst->z = Math_CosS(TRUNCF_BINANG(0x7FFF * arg3) + sp2A) * sp24 + sp2C.z; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/func_8017FD44.s") -#endif From aef3a76e04f1c7484917d5b2417d3fe22e2a3b54 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Tue, 22 Aug 2023 18:10:02 -0700 Subject: [PATCH 21/29] Remove macros.h from sys_math3d --- src/code/sys_math3d.c | 68 ++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 4a65f7dd3..5fc473036 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -1,30 +1,52 @@ -#include "prevent_bss_reordering.h" // Partial structs taken from "prevent_bss_reordering.h" -// clang-format off -struct Dummy200 { int x; }; -struct Dummy201 { int x; }; -struct Dummy202 { int x; }; -struct Dummy203 { int x; }; -struct Dummy204 { int x; }; -struct Dummy205 { int x; }; -struct Dummy206 { int x; }; -struct Dummy207 { int x; }; -struct Dummy208 { int x; }; -struct Dummy209 { int x; }; -struct Dummy210 { int x; }; -struct Dummy211 { int x; }; -struct Dummy212 { int x; }; -struct Dummy213 { int x; }; -struct Dummy214 { int x; }; -struct Dummy215 { int x; }; -struct Dummy216 { int x; }; -struct Dummy217 { int x; }; -// clang-format on - +struct Dummy0 { int x; }; +struct Dummy1 { int x; }; +struct Dummy2 { int x; }; +struct Dummy3 { int x; }; +struct Dummy4 { int x; }; +struct Dummy5 { int x; }; +struct Dummy6 { int x; }; +struct Dummy7 { int x; }; +struct Dummy8 { int x; }; +struct Dummy9 { int x; }; +struct Dummy10 { int x; }; +struct Dummy11 { int x; }; +struct Dummy12 { int x; }; +struct Dummy13 { int x; }; +struct Dummy14 { int x; }; +struct Dummy15 { int x; }; +struct Dummy16 { int x; }; +struct Dummy17 { int x; }; +struct Dummy18 { int x; }; +struct Dummy19 { int x; }; +struct Dummy20 { int x; }; +struct Dummy21 { int x; }; +struct Dummy22 { int x; }; +struct Dummy23 { int x; }; +struct Dummy24 { int x; }; +struct Dummy25 { int x; }; +struct Dummy26 { int x; }; +struct Dummy27 { int x; }; +struct Dummy28 { int x; }; +struct Dummy29 { int x; }; +struct Dummy30 { int x; }; +struct Dummy31 { int x; }; +struct Dummy32 { int x; }; +struct Dummy33 { int x; }; +struct Dummy34 { int x; }; +struct Dummy35 { int x; }; +struct Dummy36 { int x; }; +struct Dummy37 { int x; }; +struct Dummy38 { int x; }; +struct Dummy39 { int x; }; +struct Dummy40 { int x; }; +struct Dummy41 { int x; }; +typedef int Dummy42; #include "z64math.h" #include "libc/stdbool.h" #include "libc/math.h" -#include "macros.h" + +#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) // extern Vec3f D_801FBBF0; // extern Linef D_801FBC00; From 69e7c10fd628dd7b78a3abfda91e9b7777ff1af4 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 20 Oct 2023 07:41:56 -0700 Subject: [PATCH 22/29] Small cleanup --- src/code/sys_math3d.c | 102 ------------------------------------------ 1 file changed, 102 deletions(-) diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 158fd39d4..fd40dc3f6 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -18,37 +18,6 @@ struct Dummy207 { int x; }; #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) -// extern Vec3f D_801FBBF0; -// extern Linef D_801FBC00; -// extern Vec3f D_801FBC18; -// extern Vec3f D_801FBC28; -// extern Sphere16 D_801FBC38; -// extern Sphere16 D_801FBC40; -// extern Vec3f D_801FBC48; -// extern Vec3f D_801FBC58; -// extern Vec3f D_801FBC68; // can be global -// extern Vec3f D_801FBC78; // can be global -// extern Cylinderf D_801FBC88; -// extern Spheref D_801FBCA0; -// extern Cylinderf D_801FBCB0; -// extern Cylinderf D_801FBCC8; -// extern Vec3f D_801FBCE0; -// extern Vec3f D_801FBCF0; -// extern Vec3f D_801FBD00; -// extern Vec3f D_801FBD10; -// extern Vec3f D_801FBD20; -// extern Vec3f D_801FBD30; -// extern Vec3f D_801FBD40; -// extern Vec3f D_801FBD50; -// extern Vec3f D_801FBD60; -// extern Vec3f D_801FBD70; -// extern InfiniteLine D_801FBD80; -// extern Linef D_801FBD98; -// extern Vec3f D_801FBDB0; -// extern InfiniteLine D_801FBDC0; // can be global -// extern Vec3f D_801FBDD8; -// extern Vec3f D_801FBDE8; - f32 Math3D_Normalize(Vec3f* vec) { f32 magnitude = Math3D_Vec3fMagnitude(vec); @@ -62,8 +31,6 @@ f32 Math3D_Normalize(Vec3f* vec) { return magnitude; } -// #ifdef NON_MATCHING -// in-function static bss s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* closestPoint) { @@ -89,9 +56,6 @@ s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 } return true; } -// #else -// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PlaneVsLineSegClosestPoint.s") -// #endif /** * Finds the two points on lines A and B where the lines are closest together. @@ -221,8 +185,6 @@ s32 Math3D_PlaneVsPlaneNewLine(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeA return true; } -// #ifdef NON_MATCHING -// in-function static bss s32 Math3D_PlaneVsPlaneVsLineClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* point, Vec3f* closestPoint) { static InfiniteLine D_801FBDC0; @@ -234,9 +196,6 @@ s32 Math3D_PlaneVsPlaneVsLineClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, Math3D_LineClosestToPoint(&D_801FBDC0, point, closestPoint); return true; } -// #else -// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_PlaneVsPlaneVsLineClosestPoint.s") -// #endif /** * Calculates the point on the line from starting point `v0`, in the direction `dir` scaled by `scale`. Result is placed @@ -599,17 +558,11 @@ void Math3D_Vec3f_Cross(Vec3f* a, Vec3f* b, Vec3f* ret) { ret->z = (a->x * b->y) - (a->y * b->x); } -// #ifdef NON_MATCHING -// in-function static bss - void Math3D_SurfaceNorm(Vec3f* va, Vec3f* vb, Vec3f* vc, Vec3f* normal) { Math_Vec3f_Diff(vb, va, &D_801FBC68); Math_Vec3f_Diff(vc, va, &D_801FBC78); Math3D_Vec3f_Cross(&D_801FBC68, &D_801FBC78, normal); } -// #else -// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_SurfaceNorm.s") -// #endif s32 Math3D_PointRelativeToCubeFaces(Vec3f* point, Vec3f* min, Vec3f* max) { s32 ret = 0; @@ -726,8 +679,6 @@ s32 Math3D_PointRelativeToCubeVertices(Vec3f* point, Vec3f* min, Vec3f* max) { return ret; } -// #ifdef NON_MATCHING -// in-function static bss s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { static Vec3f D_801FBCE0; static Vec3f D_801FBCF0; @@ -911,15 +862,10 @@ s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { return false; } -// #else -// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_LineVsCube.s") -// #endif -// #ifdef NON_MATCHING /** * Checks if a line segment with endpoints `a` and `b` intersect a cube */ -// in-function static bss s32 Math3D_LineVsCubeShort(Vec3s* min, Vec3s* max, Vec3s* a, Vec3s* b) { static Vec3f D_801FBD20; // minF static Vec3f D_801FBD30; // maxF @@ -941,9 +887,6 @@ s32 Math3D_LineVsCubeShort(Vec3s* min, Vec3s* max, Vec3s* a, Vec3s* b) { return Math3D_LineVsCube(&D_801FBD20, &D_801FBD30, &D_801FBD40, &D_801FBD50); } -// #else -// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_LineVsCubeShort.s") -// #endif void Math3D_RotateXZPlane(Vec3f* pointOnPlane, s16 angle, f32* a, f32* c, f32* d) { *a = Math_SinS(angle) * 0x7FFF; @@ -951,8 +894,6 @@ void Math3D_RotateXZPlane(Vec3f* pointOnPlane, s16 angle, f32* a, f32* c, f32* d *d = -((*a * pointOnPlane->x) + (*c * pointOnPlane->z)); } -// #ifdef NON_MATCHING -// in-function static bss void Math3D_DefPlane(Vec3f* va, Vec3f* vb, Vec3f* vc, f32* nx, f32* ny, f32* nz, f32* originDist) { static Vec3f D_801FBD60; @@ -974,9 +915,6 @@ void Math3D_DefPlane(Vec3f* va, Vec3f* vb, Vec3f* vc, f32* nx, f32* ny, f32* nz, *nx = 0.0f; } } -// #else -// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_DefPlane.s") -// #endif f32 Math3D_PlaneF(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* pointOnPlane) { return (nx * pointOnPlane->x) + (ny * pointOnPlane->y) + (nz * pointOnPlane->z) + originDist; @@ -1273,8 +1211,6 @@ s32 Math3D_TriChkPointParaX(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 y, f32 return false; } -// #ifdef NON_MATCHING -// in-function static bss s32 Math3D_TriChkLineSegParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 y, f32 z, f32* xIntersect, f32 x0, f32 x1) { static Vec3f D_801FBD70; @@ -1304,9 +1240,6 @@ s32 Math3D_TriChkLineSegParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, } return false; } -// #else -// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaXIntersect.s") -// #endif s32 Math3D_TriChkLineSegParaXDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 y, f32 z, f32 chkDist) { if (IS_ZERO(plane->normal.x)) { @@ -1399,8 +1332,6 @@ s32 Math3D_TriChkPointParaZ(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 y, f32 return false; } -// #ifdef NON_MATCHING -// in-function static bss s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, f32 y, f32* zIntersect, f32 z0, f32 z1) { static Vec3f D_801FBDB0; @@ -1429,9 +1360,6 @@ s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, } return false; } -// #else -// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriChkLineSegParaZIntersect.s") -// #endif s32 Math3D_TriChkLineSegParaZDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, Plane* plane, f32 x, f32 y, f32 chkDist) { if (IS_ZERO(plane->normal.z)) { @@ -1627,8 +1555,6 @@ s32 func_8017DA24(f32 z0, f32 x0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { return ret; } -// #ifdef NON_MATCHING -// in-function static bss s32 Math3D_LineVsSph(Sphere16* sphere, Linef* line) { static Vec3f D_801FBDD8; @@ -1667,12 +1593,7 @@ s32 Math3D_LineVsSph(Sphere16* sphere, Linef* line) { } return false; } -// #else -// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_LineVsSph.s") -// #endif -// #ifdef NON_MATCHING -// in-function static bss void Math3D_GetSphVsTriIntersectPoint(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoint) { static Vec3f D_801FBDE8; static Vec3f D_801FBBF0; @@ -1697,12 +1618,7 @@ void Math3D_GetSphVsTriIntersectPoint(Sphere16* sphere, TriNorm* tri, Vec3f* int splitRatio = sphere->radius / dist; Math3D_LineSplitRatio(&D_801FBBF0, &D_801FBDE8, splitRatio, intersectPoint); } -// #else -// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_GetSphVsTriIntersectPoint.s") -// #endif -// #ifdef NON_MATCHING -// in-function static bss s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoint) { static Linef D_801FBC00; static Vec3f D_801FBC18; @@ -1787,9 +1703,6 @@ s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoi } return false; } -// #else -// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_TriVsSphIntersect.s") -// #endif s32 Math3D_PointInCyl(Cylinder16* cyl, Vec3f* point) { f32 bottom; @@ -2001,8 +1914,6 @@ dummy:; return count; } -// #ifdef NON_MATCHING -// in-function static bss s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect) { static Sphere16 D_801FBC38; static Sphere16 D_801FBC40; @@ -2095,9 +2006,6 @@ s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect) { } return false; } -// #else -// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_CylTriVsIntersect.s") -// #endif s32 Math3D_CylVsTri(Cylinder16* cyl, TriNorm* tri) { Vec3f intersect; @@ -2141,8 +2049,6 @@ s32 Math3D_SphVsCylOverlapDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize) return Math3D_SphVsCylOverlapCenterDist(sph, cyl, overlapSize, ¢erDist); } -// #ifdef NON_MATCHING -// in-function static bss s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize, f32* centerDist) { static Cylinderf D_801FBC88; static Spheref D_801FBCA0; @@ -2186,9 +2092,6 @@ s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overla } return false; } -// #else -// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_SphVsCylOverlapCenterDist.s") -// #endif s32 Math3D_CylOutsideCyl(Cylinder16* ca, Cylinder16* cb, f32* deadSpace) { f32 xzDist; @@ -2196,8 +2099,6 @@ s32 Math3D_CylOutsideCyl(Cylinder16* ca, Cylinder16* cb, f32* deadSpace) { return Math3D_CylOutsideCylDist(ca, cb, deadSpace, &xzDist); } -// #ifdef NON_MATCHING -// in-function static bss s32 Math3D_CylOutsideCylDist(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32* xzDist) { static Cylinderf D_801FBCB0; static Cylinderf D_801FBCC8; @@ -2228,9 +2129,6 @@ s32 Math3D_CylOutsideCylDist(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32 *deadSpace = D_801FBCB0.radius + D_801FBCC8.radius - *xzDist; return true; } -// #else -// #pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_CylOutsideCylDist.s") -// #endif s32 Math3D_TriVsTriIntersect(TriNorm* ta, TriNorm* tb, Vec3f* intersect) { f32 dist0 = Math3D_Plane(&ta->plane, &tb->vtx[0]); From d209673b1b0c85ee6b2b26e3bb1b98f97efd78c5 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Fri, 20 Oct 2023 08:08:24 -0700 Subject: [PATCH 23/29] Some more small clean up --- src/code/sys_math3d.c | 63 +++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index fd40dc3f6..60c536227 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -287,7 +287,7 @@ s32 func_8017A09C(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 } if (arg3 < (phi_f12 - arg5) || (phi_f14 + arg5) < arg3) { - return 0; + return false; } if (arg0->y < arg1->y) { phi_f12 = arg0->y; @@ -303,9 +303,9 @@ s32 func_8017A09C(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 } if (arg4 < (phi_f12 - arg5) || arg4 > (phi_f14 + arg5)) { - return 0; + return false; } - return 1; + return true; } s32 func_8017A1D0(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 arg5) { @@ -327,7 +327,7 @@ s32 func_8017A1D0(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 } if (arg4 < (phi_f12 - arg5) || (phi_f14 + arg5) < arg4) { - return 0; + return false; } if (arg0->y < arg1->y) { @@ -345,9 +345,9 @@ s32 func_8017A1D0(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 } if (arg3 < (phi_f12 - arg5) || (phi_f14 + arg5) < arg3) { - return 0; + return false; } - return 1; + return true; } s32 func_8017A304(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 arg5) { @@ -369,7 +369,7 @@ s32 func_8017A304(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 } if (arg4 < (phi_f12 - arg5) || (phi_f14 + arg5) < arg4) { - return 0; + return false; } if (arg0->z < arg1->z) { @@ -387,9 +387,9 @@ s32 func_8017A304(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 } if (arg3 < (phi_f12 - arg5) || (phi_f14 + arg5) < arg3) { - return 0; + return false; } - return 1; + return true; } s32 Math3D_SphCubeVsTriCube(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, f32 arg4) { @@ -411,7 +411,7 @@ s32 Math3D_SphCubeVsTriCube(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, } if (arg3->x < (phi_f0 - arg4) || (phi_f2 + arg4) < arg3->x) { - return 0; + return false; } if (arg0->z < arg1->z) { @@ -429,7 +429,7 @@ s32 Math3D_SphCubeVsTriCube(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, } if (arg3->z < (phi_f0 - arg4) || (phi_f2 + arg4) < arg3->z) { - return 0; + return false; } if (arg0->y < arg1->y) { @@ -447,9 +447,9 @@ s32 Math3D_SphCubeVsTriCube(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, } if (arg3->y < (phi_f0 - arg4) || (phi_f2 + arg4) < arg3->y) { - return 0; + return false; } - return 1; + return true; } /** @@ -684,7 +684,6 @@ s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { static Vec3f D_801FBCF0; static Vec3f D_801FBD00; static Vec3f D_801FBD10; - s32 flags[2]; flags[0] = flags[1] = 0; @@ -973,17 +972,17 @@ s32 Math3D_TriChkPointParaYImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f if (fabsf(ny) > 0.5f && chkDistSq > 0.0f) { // Do a check on each face of the triangle, if the point is within `chkDist` units return true. - if ((func_8017DA24(z, x, v0, v1, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { - return 1; + if (func_8017DA24(z, x, v0, v1, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { + return true; } - if ((func_8017DA24(z, x, v1, v2, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { - return 1; + if (func_8017DA24(z, x, v1, v2, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { + return true; } - if ((func_8017DA24(z, x, v2, v0, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { - return 1; + if (func_8017DA24(z, x, v2, v0, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { + return true; } } - return 0; + return false; } s32 Math3D_TriChkPointParaYDeterminate(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f32 detMax, f32 ny) { @@ -1106,13 +1105,13 @@ s32 Math3D_TriChkPointParaYImplNoCheckRange(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 if (fabsf(ny) > 0.5f && chkDistSq > 0.0f) { // Do a check on each face of the triangle, if the point is within `chkDist` units return true. - if ((func_8017DA24(z, x, v0, v1, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { + if (func_8017DA24(z, x, v0, v1, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { return true; } - if ((func_8017DA24(z, x, v1, v2, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { + if (func_8017DA24(z, x, v1, v2, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { return true; } - if ((func_8017DA24(z, x, v2, v0, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { + if (func_8017DA24(z, x, v2, v0, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { return true; } } @@ -1420,9 +1419,9 @@ s32 Math3D_TriLineIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 return false; } - if (((nx == 0.0f) || (Math3D_TriChkPointParaX(v0, v1, v2, nx, intersect->y, intersect->z))) && - ((ny == 0.0f) || (Math3D_TriChkPointParaY(v0, v1, v2, ny, intersect->z, intersect->x))) && - ((nz == 0.0f) || (Math3D_TriChkPointParaZ(v0, v1, v2, nz, intersect->x, intersect->y)))) { + if (((nx == 0.0f) || Math3D_TriChkPointParaX(v0, v1, v2, nx, intersect->y, intersect->z)) && + ((ny == 0.0f) || Math3D_TriChkPointParaY(v0, v1, v2, ny, intersect->z, intersect->x)) && + ((nz == 0.0f) || Math3D_TriChkPointParaZ(v0, v1, v2, nz, intersect->x, intersect->y))) { return true; } @@ -1601,9 +1600,9 @@ void Math3D_GetSphVsTriIntersectPoint(Sphere16* sphere, TriNorm* tri, Vec3f* int f32 dist; f32 splitRatio; - D_801FBDE8.x = ((tri->vtx[0].x + tri->vtx[1].x) * 0.5f); - D_801FBDE8.y = ((tri->vtx[0].y + tri->vtx[1].y) * 0.5f); - D_801FBDE8.z = ((tri->vtx[0].z + tri->vtx[1].z) * 0.5f); + D_801FBDE8.x = (tri->vtx[0].x + tri->vtx[1].x) * 0.5f; + D_801FBDE8.y = (tri->vtx[0].y + tri->vtx[1].y) * 0.5f; + D_801FBDE8.z = (tri->vtx[0].z + tri->vtx[1].z) * 0.5f; D_801FBBF0.x = sphere->center.x; D_801FBBF0.y = sphere->center.y; D_801FBBF0.z = sphere->center.z; @@ -2000,8 +1999,8 @@ s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect) { D_801FBC40.center.y = cylBottom; D_801FBC38.radius = D_801FBC40.radius = cyl->radius; - if ((Math3D_TriVsSphIntersect(&D_801FBC38, tri, intersect)) || - (Math3D_TriVsSphIntersect(&D_801FBC40, tri, intersect))) { + if (Math3D_TriVsSphIntersect(&D_801FBC38, tri, intersect) || + Math3D_TriVsSphIntersect(&D_801FBC40, tri, intersect)) { return true; } return false; From b4626812f625b4a7e91ee1092a073932005a4194 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sun, 22 Oct 2023 03:30:02 +1100 Subject: [PATCH 24/29] cleanup and docs --- include/z64collision_check.h | 2 +- include/z64math.h | 26 +- src/code/sys_math3d.c | 994 ++++++++++-------- src/code/z_actor.c | 14 +- src/code/z_bgcheck.c | 2 +- src/code/z_collision_check.c | 65 +- .../ovl_Bg_Dblue_Movebg/z_bg_dblue_movebg.c | 4 +- src/overlays/actors/ovl_En_Horse/z_en_horse.c | 2 +- .../actors/ovl_En_Mt_tag/z_en_mt_tag.c | 2 +- src/overlays/actors/ovl_En_Rg/z_en_rg.c | 4 +- tools/disasm/functions.txt | 24 +- tools/disasm/variables.txt | 60 +- tools/namefixer.py | 10 +- tools/sizes/code_functions.csv | 24 +- 14 files changed, 698 insertions(+), 535 deletions(-) diff --git a/include/z64collision_check.h b/include/z64collision_check.h index f960f5f28..26c1a3f5b 100644 --- a/include/z64collision_check.h +++ b/include/z64collision_check.h @@ -625,7 +625,7 @@ void CollisionCheck_SetHitEffects(struct PlayState* play, CollisionCheckContext* void CollisionCheck_AC(struct PlayState* play, CollisionCheckContext* colCtxt, Collider* colAT); void CollisionCheck_AT(struct PlayState* play, CollisionCheckContext* colCtxt); s32 CollisionCheck_GetMassType(u8 mass); -void CollisionCheck_SetOCvsOC(struct PlayState* play, Collider* left, ColliderInfo* leftInfo, Vec3f* leftPos, Collider* right, ColliderInfo* rightInfo, Vec3f* rightPos, f32 overlap); +void CollisionCheck_SetOCvsOC(struct PlayState* play, Collider* left, ColliderInfo* leftInfo, Vec3f* leftPos, Collider* right, ColliderInfo* rightInfo, Vec3f* rightPos, f32 overlapSize); void CollisionCheck_OC_JntSphVsJntSph(struct PlayState* play, CollisionCheckContext* colCtxt, Collider* l, Collider* r); void CollisionCheck_OC_JntSphVsCyl(struct PlayState* play, CollisionCheckContext* colCtxt, Collider* l, Collider* r); void CollisionCheck_OC_JntSphVsSphere(struct PlayState* play, CollisionCheckContext* colCtxt, Collider* l, Collider* r); diff --git a/include/z64math.h b/include/z64math.h index 657aaf346..c0f20bc6d 100644 --- a/include/z64math.h +++ b/include/z64math.h @@ -272,10 +272,10 @@ f32 Math3D_Cos(Vec3f* a, Vec3f* b); s32 Math3D_CosOut(Vec3f* a, Vec3f* b, f32* dst); void Math3D_Vec3fReflect(Vec3f* vec, Vec3f* normal, Vec3f* reflVec); s32 Math3D_PointInSquare2D(f32 upperLeftX, f32 lowerRightX, f32 upperLeftY, f32 lowerRightY, f32 x, f32 y); -s32 func_8017A09C(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 arg5); -s32 func_8017A1D0(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 arg5); -s32 func_8017A304(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 arg5); -s32 Math3D_SphCubeVsTriCube(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, f32 arg4); +s32 Math3D_CirSquareVsTriSquareXY(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 centerX, f32 centerY, f32 radius); +s32 Math3D_CirSquareVsTriSquareYZ(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 centerY, f32 centerZ, f32 radius); +s32 Math3D_CirSquareVsTriSquareZX(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 centerZ, f32 centerX, f32 radius); +s32 Math3D_SphCubeVsTriCube(Vec3f* v0, Vec3f* v1, Vec3f* v2, Vec3f* center, f32 radius); f32 Math3D_Dist1DSq(f32 a, f32 b); f32 Math3D_Dist1D(f32 a, f32 b); f32 Math3D_Dist2DSq(f32 x0, f32 y0, f32 x1, f32 y1); @@ -328,11 +328,11 @@ s32 Math3D_LineSegVsPlane(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePoi s32 Math3D_TriLineIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersect, s32 fromFront) ; void Math3D_TriNorm(TriNorm* tri, Vec3f* va, Vec3f* vb, Vec3f* vc); s32 Math3D_PointInSph(Sphere16* sphere, Vec3f* point); -s32 Math3D_PointDistToLine2D(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* perpXOut, f32* perpYOut, f32* lineLenSq); // returns boolean -s32 func_8017D7C0(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* lineLenSq); -s32 func_8017D814(f32 x0, f32 y0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); -s32 func_8017D91C(f32 y0, f32 z0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); -s32 func_8017DA24(f32 z0, f32 x0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); +s32 Math3D_PointDistSqToLine2DImpl(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* perpXOut, f32* perpYOut, f32* lineLenSq); // returns boolean +s32 Math3D_PointDistSqToLine2D(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* lineLenSq); +s32 Math3D_PointDistSqToLineXY(f32 x0, f32 y0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); +s32 Math3D_PointDistSqToLineYZ(f32 y0, f32 z0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); +s32 Math3D_PointDistSqToLineZX(f32 z0, f32 x0, Vec3f* p1, Vec3f* p2, f32* lineLenSq); s32 Math3D_LineVsSph(Sphere16* sphere, Linef* line); void Math3D_GetSphVsTriIntersectPoint(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoint); s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoint); @@ -342,11 +342,11 @@ s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect); s32 Math3D_CylVsTri(Cylinder16* cyl, TriNorm* tri); s32 Math3D_SphVsSph(Sphere16* sphereA, Sphere16* sphereB); s32 Math3D_SphVsSphOverlap(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize); -s32 Math3D_SphVsSphOverlapCenter(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize, f32* centerDist); -s32 Math3D_SphVsCylOverlapDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize); +s32 Math3D_SphVsSphOverlapCenterDist(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize, f32* centerDist); +s32 Math3D_SphVsCylOverlap(Sphere16* sph, Cylinder16* cyl, f32* overlapSize); s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize, f32* centerDist); -s32 Math3D_CylOutsideCyl(Cylinder16* ca, Cylinder16* cb, f32* deadSpace); -s32 Math3D_CylOutsideCylDist(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32* xzDist); +s32 Math3D_CylVsCylOverlap(Cylinder16* ca, Cylinder16* cb, f32* overlapSize); +s32 Math3D_CylVsCylOverlapCenterDist(Cylinder16* ca, Cylinder16* cb, f32* overlapSize, f32* centerDist); s32 Math3D_TriVsTriIntersect(TriNorm* ta, TriNorm* tb, Vec3f* intersect); s32 Math3D_XZInSphere(Sphere16* sphere, f32 x, f32 z); s32 Math3D_XYInSphere(Sphere16* sphere, f32 x, f32 y); diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 60c536227..076ed9e38 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -31,27 +31,33 @@ f32 Math3D_Normalize(Vec3f* vec) { return magnitude; } +/** + * Creates an infinite line along the intersection of the plane defined from `planeAA`x + `planeAB`y + `planeAB`z + + * `planeADist` = 0 and `planeBA`x + `planeBB`y + `planeBC`z + `planeBDist` = 0, and finds the closest point on that + * intersection to the line segment `linePointA and linePointB`, outputs the intersection to `closestPoint` + */ s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* closestPoint) { - static InfiniteLine D_801FBD80; - static Linef D_801FBD98; + static InfiniteLine sPlaneIntersectLine; + static Linef sPlaneIntersectSeg; Vec3f sp34; // unused if (!Math3D_PlaneVsPlaneNewLine(planeAA, planeAB, planeAC, planeADist, planeBA, planeBB, planeBC, planeBDist, - &D_801FBD80)) { + &sPlaneIntersectLine)) { // The planes are parallel return false; } // create a line segment on the plane. - Math_Vec3f_Copy(&D_801FBD98.a, &D_801FBD80.point); - D_801FBD98.b.x = (D_801FBD80.dir.x * 100.0f) + D_801FBD80.point.x; - D_801FBD98.b.y = (D_801FBD80.dir.y * 100.0f) + D_801FBD80.point.y; - D_801FBD98.b.z = (D_801FBD80.dir.z * 100.0f) + D_801FBD80.point.z; + Math_Vec3f_Copy(&sPlaneIntersectSeg.a, &sPlaneIntersectLine.point); + sPlaneIntersectSeg.b.x = (sPlaneIntersectLine.dir.x * 100.0f) + sPlaneIntersectLine.point.x; + sPlaneIntersectSeg.b.y = (sPlaneIntersectLine.dir.y * 100.0f) + sPlaneIntersectLine.point.y; + sPlaneIntersectSeg.b.z = (sPlaneIntersectLine.dir.z * 100.0f) + sPlaneIntersectLine.point.z; // closestPoint is a point on planeIntersect, sp34 is a point on linePointA, linePointB - if (!Math3D_LineSegMakePerpLineSeg(&D_801FBD98.a, &D_801FBD98.b, linePointA, linePointB, closestPoint, &sp34)) { + if (!Math3D_LineSegMakePerpLineSeg(&sPlaneIntersectSeg.a, &sPlaneIntersectSeg.b, linePointA, linePointB, + closestPoint, &sp34)) { return false; } return true; @@ -146,6 +152,11 @@ void Math3D_FindPointOnPlaneIntersect(f32 planeAAxis1Norm, f32 planeAAxis2Norm, *axis2Point = ((planeBAxis1Norm * planeADist) - (planeAAxis1Norm * planeBDist)) / axis3Direction; } +/** + * Creates a line between the intersections of two planes defined from `planeAA`x + `planeAB`y + `planeAC`z + + * `planeADist` = 0 and `planeBA`x + `planeBB`y + `planeBC`z + `planeBDist` = 0, and outputs the line to `intersect`. + * Returns false if the planes are parallel. + */ s32 Math3D_PlaneVsPlaneNewLine(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, InfiniteLine* intersect) { s32 pad; @@ -185,15 +196,22 @@ s32 Math3D_PlaneVsPlaneNewLine(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeA return true; } +/** + * Gets the closest point on the line formed from the intersection of of the planes defined from + * `planeAA`x + `planeAB`y + `planeAC`z + `planeADist` = 0 and + * `planeBA`x + `planeBB`y + `planeBC`z + `planeBDist` = 0 + * the point on the intersection line closest to `point` is placed in `closestPoint` + * returns false if the planes are parallel. + */ s32 Math3D_PlaneVsPlaneVsLineClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* point, Vec3f* closestPoint) { - static InfiniteLine D_801FBDC0; + static InfiniteLine sPlaneIntersect; if (!Math3D_PlaneVsPlaneNewLine(planeAA, planeAB, planeAC, planeADist, planeBA, planeBB, planeBC, planeBDist, - &D_801FBDC0)) { + &sPlaneIntersect)) { return false; } - Math3D_LineClosestToPoint(&D_801FBDC0, point, closestPoint); + Math3D_LineClosestToPoint(&sPlaneIntersect, point, closestPoint); return true; } @@ -207,6 +225,10 @@ void Math3D_PointOnDirectedLine(Vec3f* v0, Vec3f* dir, f32 scale, Vec3f* ret) { ret->z = (dir->z * scale) + v0->z; } +/** + * Splits the line segment from end points `v0` and `v1`, and splits that segment + * by `ratio` of `v0`:`v1`, places the resulting point on the line in `ret` + */ void Math3D_LineSplitRatio(Vec3f* v0, Vec3f* v1, f32 ratio, Vec3f* ret) { Vec3f diff; @@ -239,6 +261,10 @@ s32 Math3D_CosOut(Vec3f* a, Vec3f* b, f32* dst) { return false; } +/** + * Reflects vector `vec` across the normal vector `normal`, reflection vector is placed in + * `reflVec` + */ void Math3D_Vec3fReflect(Vec3f* vec, Vec3f* normal, Vec3f* reflVec) { f32 normScaleY; Vec3f negVec; @@ -261,6 +287,10 @@ void Math3D_Vec3fReflect(Vec3f* vec, Vec3f* normal, Vec3f* reflVec) { reflVec->z = ((normScaleZ + vec->z) + (normScaleZ + vec->z)) + negVec.z; } +/** + * Checks if the point (`x`,`y`) is contained within the square formed from (`upperLeftX`,`upperLeftY`) to + * (`lowerRightX`,`lowerRightY`) + */ s32 Math3D_PointInSquare2D(f32 upperLeftX, f32 lowerRightX, f32 upperLeftY, f32 lowerRightY, f32 x, f32 y) { if ((x >= upperLeftX) && (x <= lowerRightX) && (y >= upperLeftY) && (y <= lowerRightY)) { return true; @@ -268,185 +298,202 @@ s32 Math3D_PointInSquare2D(f32 upperLeftX, f32 lowerRightX, f32 upperLeftY, f32 return false; } -s32 func_8017A09C(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 arg5) { - f32 phi_f12; - f32 phi_f14; +/** + * Checks if the square in the XY planed formed around the circle with center (`centerX`,`centerY`) + * with radius `radius` touches any portion of the square formed around the triangle formed from `v0`, `v1`, and `v2` + */ +s32 Math3D_CirSquareVsTriSquareXY(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 centerX, f32 centerY, f32 radius) { + f32 min; + f32 max; - if (arg0->x < arg1->x) { - phi_f12 = arg0->x; - phi_f14 = arg1->x; + if (v0->x < v1->x) { + min = v0->x; + max = v1->x; } else { - phi_f12 = arg1->x; - phi_f14 = arg0->x; + min = v1->x; + max = v0->x; } - if (arg2->x < phi_f12) { - phi_f12 = arg2->x; - } else if (phi_f14 < arg2->x) { - phi_f14 = arg2->x; + if (min > v2->x) { + min = v2->x; + } else if (max < v2->x) { + max = v2->x; } - if (arg3 < (phi_f12 - arg5) || (phi_f14 + arg5) < arg3) { + if ((centerX < (min - radius)) || ((max + radius) < centerX)) { return false; } - if (arg0->y < arg1->y) { - phi_f12 = arg0->y; - phi_f14 = arg1->y; + if (v0->y < v1->y) { + min = v0->y; + max = v1->y; } else { - phi_f12 = arg1->y; - phi_f14 = arg0->y; + min = v1->y; + max = v0->y; } - if (arg2->y < phi_f12) { - phi_f12 = arg2->y; - } else if (phi_f14 < arg2->y) { - phi_f14 = arg2->y; + if (min > v2->y) { + min = v2->y; + } else if (max < v2->y) { + max = v2->y; } - if (arg4 < (phi_f12 - arg5) || arg4 > (phi_f14 + arg5)) { + if ((centerY < (min - radius)) || (centerY > (max + radius))) { return false; } return true; } -s32 func_8017A1D0(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 arg5) { - f32 phi_f12; - f32 phi_f14; +/** + * Checks if the square in the YZ planed formed around the circle with center (`centerY`,`centerZ`) + * with radius `radius` touches any portion of the square formed around the triangle formed from `v0`, `v1`, and `v2` + */ +s32 Math3D_CirSquareVsTriSquareYZ(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 centerY, f32 centerZ, f32 radius) { + f32 min; + f32 max; - if (arg0->z < arg1->z) { - phi_f12 = arg0->z; - phi_f14 = arg1->z; + if (v0->z < v1->z) { + min = v0->z; + max = v1->z; } else { - phi_f12 = arg1->z; - phi_f14 = arg0->z; + min = v1->z; + max = v0->z; } - if (arg2->z < phi_f12) { - phi_f12 = arg2->z; - } else if (phi_f14 < arg2->z) { - phi_f14 = arg2->z; + if (min > v2->z) { + min = v2->z; + } else if (max < v2->z) { + max = v2->z; } - if (arg4 < (phi_f12 - arg5) || (phi_f14 + arg5) < arg4) { + if ((centerZ < (min - radius)) || ((max + radius) < centerZ)) { return false; } - if (arg0->y < arg1->y) { - phi_f12 = arg0->y; - phi_f14 = arg1->y; + if (v0->y < v1->y) { + min = v0->y; + max = v1->y; } else { - phi_f12 = arg1->y; - phi_f14 = arg0->y; + min = v1->y; + max = v0->y; } - if (arg2->y < phi_f12) { - phi_f12 = arg2->y; - } else if (phi_f14 < arg2->y) { - phi_f14 = arg2->y; + if (min > v2->y) { + min = v2->y; + } else if (max < v2->y) { + max = v2->y; } - if (arg3 < (phi_f12 - arg5) || (phi_f14 + arg5) < arg3) { + if ((centerY < (min - radius)) || ((max + radius) < centerY)) { return false; } return true; } -s32 func_8017A304(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, f32 arg3, f32 arg4, f32 arg5) { - f32 phi_f12; - f32 phi_f14; +/** + * Checks if the square in the ZX planed formed around the circle with center (`centerZ`,`centerX`) + * with radius `radius` touches any portion of the square formed around the triangle formed from `v0`, `v1`, and `v2` + */ +s32 Math3D_CirSquareVsTriSquareZX(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 centerZ, f32 centerX, f32 radius) { + f32 min; + f32 max; - if (arg0->x < arg1->x) { - phi_f12 = arg0->x; - phi_f14 = arg1->x; + if (v0->x < v1->x) { + min = v0->x; + max = v1->x; } else { - phi_f12 = arg1->x; - phi_f14 = arg0->x; + min = v1->x; + max = v0->x; } - if (arg2->x < phi_f12) { - phi_f12 = arg2->x; - } else if (phi_f14 < arg2->x) { - phi_f14 = arg2->x; + if (min > v2->x) { + min = v2->x; + } else if (max < v2->x) { + max = v2->x; } - if (arg4 < (phi_f12 - arg5) || (phi_f14 + arg5) < arg4) { + if ((centerX < (min - radius)) || ((max + radius) < centerX)) { return false; } - if (arg0->z < arg1->z) { - phi_f12 = arg0->z; - phi_f14 = arg1->z; + if (v0->z < v1->z) { + min = v0->z; + max = v1->z; } else { - phi_f12 = arg1->z; - phi_f14 = arg0->z; + min = v1->z; + max = v0->z; } - if (arg2->z < phi_f12) { - phi_f12 = arg2->z; - } else if (phi_f14 < arg2->z) { - phi_f14 = arg2->z; + if (min > v2->z) { + min = v2->z; + } else if (max < v2->z) { + max = v2->z; } - if (arg3 < (phi_f12 - arg5) || (phi_f14 + arg5) < arg3) { + if ((centerZ < (min - radius)) || ((max + radius) < centerZ)) { return false; } return true; } -s32 Math3D_SphCubeVsTriCube(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, f32 arg4) { - f32 phi_f0; - f32 phi_f2; +/** + * Checks if the cube formed around the triangle formed from `v0`, `v1`, and `v2` + * has any portion touching the cube formed around the sphere with center `center` + * and radius of `radius` + */ +s32 Math3D_SphCubeVsTriCube(Vec3f* v0, Vec3f* v1, Vec3f* v2, Vec3f* center, f32 radius) { + f32 min; + f32 max; - if (arg0->x < arg1->x) { - phi_f0 = arg0->x; - phi_f2 = arg1->x; + if (v0->x < v1->x) { + min = v0->x; + max = v1->x; } else { - phi_f0 = arg1->x; - phi_f2 = arg0->x; + min = v1->x; + max = v0->x; } - if (arg2->x < phi_f0) { - phi_f0 = arg2->x; - } else if (phi_f2 < arg2->x) { - phi_f2 = arg2->x; + if (min > v2->x) { + min = v2->x; + } else if (max < v2->x) { + max = v2->x; } - if (arg3->x < (phi_f0 - arg4) || (phi_f2 + arg4) < arg3->x) { + if ((center->x < (min - radius)) || ((max + radius) < center->x)) { return false; } - if (arg0->z < arg1->z) { - phi_f0 = arg0->z; - phi_f2 = arg1->z; + if (v0->z < v1->z) { + min = v0->z; + max = v1->z; } else { - phi_f0 = arg1->z; - phi_f2 = arg0->z; + min = v1->z; + max = v0->z; } - if (arg2->z < phi_f0) { - phi_f0 = arg2->z; - } else if (phi_f2 < arg2->z) { - phi_f2 = arg2->z; + if (min > v2->z) { + min = v2->z; + } else if (max < v2->z) { + max = v2->z; } - if (arg3->z < (phi_f0 - arg4) || (phi_f2 + arg4) < arg3->z) { + if ((center->z < (min - radius)) || ((max + radius) < center->z)) { return false; } - if (arg0->y < arg1->y) { - phi_f0 = arg0->y; - phi_f2 = arg1->y; + if (v0->y < v1->y) { + min = v0->y; + max = v1->y; } else { - phi_f0 = arg1->y; - phi_f2 = arg0->y; + min = v1->y; + max = v0->y; } - if (arg2->y < phi_f0) { - phi_f0 = arg2->y; - } else if (phi_f2 < arg2->y) { - phi_f2 = arg2->y; + if (min > v2->y) { + min = v2->y; + } else if (max < v2->y) { + max = v2->y; } - if (arg3->y < (phi_f0 - arg4) || (phi_f2 + arg4) < arg3->y) { + if ((center->y < (min - radius)) || ((max + radius) < center->y)) { return false; } return true; @@ -481,14 +528,14 @@ f32 Math3D_Dist2D(f32 x0, f32 y0, f32 x1, f32 y1) { } /** - * Returns the magntiude (length) squared of `vec` + * Returns the magnitude (length) squared of `vec` */ f32 Math3D_Vec3fMagnitudeSq(Vec3f* vec) { return SQ(vec->x) + SQ(vec->y) + SQ(vec->z); } /** - * Returns the magnitude(length) of `vec` + * Returns the magnitude (length) of `vec` */ f32 Math3D_Vec3fMagnitude(Vec3f* vec) { return sqrtf(Math3D_Vec3fMagnitudeSq(vec)); @@ -525,8 +572,8 @@ f32 Math3D_DistXYZ16toF(Vec3s* a, Vec3f* b) { return Math3D_Vec3fMagnitude(&diff); } -static Vec3f D_801FBC68; -static Vec3f D_801FBC78; +static Vec3f sABDiff; +static Vec3f sACDiff; /** * Gets the Z portion of the cross product of vectors `a - (`dx`,`dy`,z) and `b` - (`dx`,`dy`,z) @@ -558,12 +605,19 @@ void Math3D_Vec3f_Cross(Vec3f* a, Vec3f* b, Vec3f* ret) { ret->z = (a->x * b->y) - (a->y * b->x); } +/* + * Calculates the normal vector to a surface with sides `vb` - `va` and `vc` - `va` + * outputs the normal to `normal` + */ void Math3D_SurfaceNorm(Vec3f* va, Vec3f* vb, Vec3f* vc, Vec3f* normal) { - Math_Vec3f_Diff(vb, va, &D_801FBC68); - Math_Vec3f_Diff(vc, va, &D_801FBC78); - Math3D_Vec3f_Cross(&D_801FBC68, &D_801FBC78, normal); + Math_Vec3f_Diff(vb, va, &sABDiff); + Math_Vec3f_Diff(vc, va, &sACDiff); + Math3D_Vec3f_Cross(&sABDiff, &sACDiff, normal); } +/** + * Creates flags relative to the faces of a cube. + */ s32 Math3D_PointRelativeToCubeFaces(Vec3f* point, Vec3f* min, Vec3f* max) { s32 ret = 0; @@ -588,6 +642,9 @@ s32 Math3D_PointRelativeToCubeFaces(Vec3f* point, Vec3f* min, Vec3f* max) { return ret; } +/** + * Creates flags of `point` relative to the edges of a cube + */ s32 Math3D_PointRelativeToCubeEdges(Vec3f* point, Vec3f* min, Vec3f* max) { s32 ret = 0; @@ -641,6 +698,9 @@ s32 Math3D_PointRelativeToCubeEdges(Vec3f* point, Vec3f* min, Vec3f* max) { return ret; } +/** + * Creates flags for `point` relative to the vertices of a cube + */ s32 Math3D_PointRelativeToCubeVertices(Vec3f* point, Vec3f* min, Vec3f* max) { s32 ret = 0; @@ -679,11 +739,14 @@ s32 Math3D_PointRelativeToCubeVertices(Vec3f* point, Vec3f* min, Vec3f* max) { return ret; } +/** + * Checks if a line segment with endpoints `a` and `b` intersect a cube + */ s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { - static Vec3f D_801FBCE0; - static Vec3f D_801FBCF0; - static Vec3f D_801FBD00; - static Vec3f D_801FBD10; + static Vec3f sTriVtx0; + static Vec3f sTriVtx1; + static Vec3f sTriVtx2; + static Vec3f sIntersectPoint; s32 flags[2]; flags[0] = flags[1] = 0; @@ -714,147 +777,147 @@ s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { } // face 1 - D_801FBCE0.x = min->x; - D_801FBCE0.y = min->y; - D_801FBCE0.z = min->z; - D_801FBCF0.x = min->x; - D_801FBCF0.y = min->y; - D_801FBCF0.z = max->z; - D_801FBD00.x = min->x; - D_801FBD00.y = max->y; - D_801FBD00.z = max->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, -1.0f, 0.0f, 0.0f, min->x, a, b, &D_801FBD10, + sTriVtx0.x = min->x; + sTriVtx0.y = min->y; + sTriVtx0.z = min->z; + sTriVtx1.x = min->x; + sTriVtx1.y = min->y; + sTriVtx1.z = max->z; + sTriVtx2.x = min->x; + sTriVtx2.y = max->y; + sTriVtx2.z = max->z; + if (Math3D_TriLineIntersect(&sTriVtx0, &sTriVtx1, &sTriVtx2, -1.0f, 0.0f, 0.0f, min->x, a, b, &sIntersectPoint, 0)) { return true; } - D_801FBCF0.x = min->x; - D_801FBCF0.y = max->y; - D_801FBCF0.z = max->z; - D_801FBD00.x = min->x; - D_801FBD00.y = max->y; - D_801FBD00.z = min->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, -1.0f, 0.0f, 0.0f, min->x, a, b, &D_801FBD10, + sTriVtx1.x = min->x; + sTriVtx1.y = max->y; + sTriVtx1.z = max->z; + sTriVtx2.x = min->x; + sTriVtx2.y = max->y; + sTriVtx2.z = min->z; + if (Math3D_TriLineIntersect(&sTriVtx0, &sTriVtx1, &sTriVtx2, -1.0f, 0.0f, 0.0f, min->x, a, b, &sIntersectPoint, 0)) { return true; } // face 2 - D_801FBCE0.x = min->x; - D_801FBCE0.y = max->y; - D_801FBCE0.z = max->z; - D_801FBCF0.x = min->x; - D_801FBCF0.y = min->y; - D_801FBCF0.z = max->z; - D_801FBD00.x = max->x; - D_801FBD00.y = max->y; - D_801FBD00.z = max->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 0.0f, 1.0f, -max->z, a, b, &D_801FBD10, + sTriVtx0.x = min->x; + sTriVtx0.y = max->y; + sTriVtx0.z = max->z; + sTriVtx1.x = min->x; + sTriVtx1.y = min->y; + sTriVtx1.z = max->z; + sTriVtx2.x = max->x; + sTriVtx2.y = max->y; + sTriVtx2.z = max->z; + if (Math3D_TriLineIntersect(&sTriVtx0, &sTriVtx1, &sTriVtx2, 0.0f, 0.0f, 1.0f, -max->z, a, b, &sIntersectPoint, 0)) { return true; } - D_801FBCE0.x = max->x; - D_801FBCE0.y = max->y; - D_801FBCE0.z = max->z; - D_801FBD00.x = max->x; - //! @bug trVtx1.y should be D_801FBD00.y, prevents a tri on the cube from being checked. - D_801FBCF0.y = min->y; - D_801FBD00.z = max->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 0.0f, 1.0f, -max->z, a, b, &D_801FBD10, + sTriVtx0.x = max->x; + sTriVtx0.y = max->y; + sTriVtx0.z = max->z; + sTriVtx2.x = max->x; + //! @bug trVtx1.y should be sTriVtx2.y, prevents a tri on the cube from being checked. + sTriVtx1.y = min->y; + sTriVtx2.z = max->z; + if (Math3D_TriLineIntersect(&sTriVtx0, &sTriVtx1, &sTriVtx2, 0.0f, 0.0f, 1.0f, -max->z, a, b, &sIntersectPoint, 0)) { return true; } // face 3 - D_801FBCF0.x = min->x; - D_801FBCF0.y = max->y; - D_801FBCF0.z = min->z; - D_801FBD00.x = min->x; - D_801FBD00.y = max->y; - D_801FBD00.z = max->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 1.0f, 0.0f, -max->y, a, b, &D_801FBD10, + sTriVtx1.x = min->x; + sTriVtx1.y = max->y; + sTriVtx1.z = min->z; + sTriVtx2.x = min->x; + sTriVtx2.y = max->y; + sTriVtx2.z = max->z; + if (Math3D_TriLineIntersect(&sTriVtx0, &sTriVtx1, &sTriVtx2, 0.0f, 1.0f, 0.0f, -max->y, a, b, &sIntersectPoint, 0)) { return true; } - D_801FBCF0.x = max->x; - D_801FBCF0.y = max->y; - D_801FBCF0.z = min->z; - D_801FBD00.x = min->x; - D_801FBD00.y = max->y; - D_801FBD00.z = min->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 1.0f, 0.0f, -max->y, a, b, &D_801FBD10, + sTriVtx1.x = max->x; + sTriVtx1.y = max->y; + sTriVtx1.z = min->z; + sTriVtx2.x = min->x; + sTriVtx2.y = max->y; + sTriVtx2.z = min->z; + if (Math3D_TriLineIntersect(&sTriVtx0, &sTriVtx1, &sTriVtx2, 0.0f, 1.0f, 0.0f, -max->y, a, b, &sIntersectPoint, 0)) { return true; } // face 4 - D_801FBCE0.x = min->x; - D_801FBCE0.y = min->y; - D_801FBCE0.z = min->z; - D_801FBCF0.x = min->x; - D_801FBCF0.y = max->y; - D_801FBCF0.z = min->z; - D_801FBD00.x = max->x; - D_801FBD00.y = max->y; - D_801FBD00.z = min->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 0.0f, -1.0f, min->z, a, b, &D_801FBD10, + sTriVtx0.x = min->x; + sTriVtx0.y = min->y; + sTriVtx0.z = min->z; + sTriVtx1.x = min->x; + sTriVtx1.y = max->y; + sTriVtx1.z = min->z; + sTriVtx2.x = max->x; + sTriVtx2.y = max->y; + sTriVtx2.z = min->z; + if (Math3D_TriLineIntersect(&sTriVtx0, &sTriVtx1, &sTriVtx2, 0.0f, 0.0f, -1.0f, min->z, a, b, &sIntersectPoint, 0)) { return true; } - D_801FBCF0.x = max->x; - D_801FBCF0.y = max->y; - D_801FBCF0.z = min->z; - D_801FBD00.x = max->x; - D_801FBD00.y = min->y; - D_801FBD00.z = min->z; + sTriVtx1.x = max->x; + sTriVtx1.y = max->y; + sTriVtx1.z = min->z; + sTriVtx2.x = max->x; + sTriVtx2.y = min->y; + sTriVtx2.z = min->z; // face 5 - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, 0.0f, -1.0f, min->z, a, b, &D_801FBD10, + if (Math3D_TriLineIntersect(&sTriVtx0, &sTriVtx1, &sTriVtx2, 0.0f, 0.0f, -1.0f, min->z, a, b, &sIntersectPoint, 0)) { return true; } - D_801FBCF0.x = max->x; - D_801FBCF0.y = min->y; - D_801FBCF0.z = min->z; - D_801FBD00.x = max->x; - D_801FBD00.y = min->y; - D_801FBD00.z = max->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, -1.0f, 0.0f, min->y, a, b, &D_801FBD10, + sTriVtx1.x = max->x; + sTriVtx1.y = min->y; + sTriVtx1.z = min->z; + sTriVtx2.x = max->x; + sTriVtx2.y = min->y; + sTriVtx2.z = max->z; + if (Math3D_TriLineIntersect(&sTriVtx0, &sTriVtx1, &sTriVtx2, 0.0f, -1.0f, 0.0f, min->y, a, b, &sIntersectPoint, 0)) { return true; } - D_801FBCF0.x = max->x; - D_801FBCF0.y = min->y; - D_801FBCF0.z = max->z; - D_801FBD00.x = min->x; - D_801FBD00.y = min->y; - D_801FBD00.z = max->z; + sTriVtx1.x = max->x; + sTriVtx1.y = min->y; + sTriVtx1.z = max->z; + sTriVtx2.x = min->x; + sTriVtx2.y = min->y; + sTriVtx2.z = max->z; // face 6 - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 0.0f, -1.0f, 0.0f, min->y, a, b, &D_801FBD10, + if (Math3D_TriLineIntersect(&sTriVtx0, &sTriVtx1, &sTriVtx2, 0.0f, -1.0f, 0.0f, min->y, a, b, &sIntersectPoint, 0)) { return true; } - D_801FBCE0.x = max->x; - D_801FBCE0.y = max->y; - D_801FBCE0.z = max->z; - D_801FBCF0.x = max->x; - D_801FBCF0.y = min->y; - D_801FBCF0.z = min->z; - D_801FBD00.x = max->x; - D_801FBD00.y = max->y; - D_801FBD00.z = min->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 1.0f, 0.0f, 0.0f, -max->x, a, b, &D_801FBD10, + sTriVtx0.x = max->x; + sTriVtx0.y = max->y; + sTriVtx0.z = max->z; + sTriVtx1.x = max->x; + sTriVtx1.y = min->y; + sTriVtx1.z = min->z; + sTriVtx2.x = max->x; + sTriVtx2.y = max->y; + sTriVtx2.z = min->z; + if (Math3D_TriLineIntersect(&sTriVtx0, &sTriVtx1, &sTriVtx2, 1.0f, 0.0f, 0.0f, -max->x, a, b, &sIntersectPoint, 0)) { return true; } - D_801FBCF0.x = max->x; - D_801FBCF0.y = min->y; - D_801FBCF0.z = max->z; - D_801FBD00.x = max->x; - D_801FBD00.y = min->y; - D_801FBD00.z = min->z; - if (Math3D_TriLineIntersect(&D_801FBCE0, &D_801FBCF0, &D_801FBD00, 1.0f, 0.0f, 0.0f, -max->x, a, b, &D_801FBD10, + sTriVtx1.x = max->x; + sTriVtx1.y = min->y; + sTriVtx1.z = max->z; + sTriVtx2.x = max->x; + sTriVtx2.y = min->y; + sTriVtx2.z = min->z; + if (Math3D_TriLineIntersect(&sTriVtx0, &sTriVtx1, &sTriVtx2, 1.0f, 0.0f, 0.0f, -max->x, a, b, &sIntersectPoint, 0)) { return true; } @@ -866,46 +929,54 @@ s32 Math3D_LineVsCube(Vec3f* min, Vec3f* max, Vec3f* a, Vec3f* b) { * Checks if a line segment with endpoints `a` and `b` intersect a cube */ s32 Math3D_LineVsCubeShort(Vec3s* min, Vec3s* max, Vec3s* a, Vec3s* b) { - static Vec3f D_801FBD20; // minF - static Vec3f D_801FBD30; // maxF - static Vec3f D_801FBD40; // aF - static Vec3f D_801FBD50; // bF + static Vec3f sMinF; + static Vec3f sMaxF; + static Vec3f sAF; + static Vec3f sBF; - D_801FBD20.x = min->x; - D_801FBD20.y = min->y; - D_801FBD20.z = min->z; - D_801FBD30.x = max->x; - D_801FBD30.y = max->y; - D_801FBD30.z = max->z; - D_801FBD40.x = a->x; - D_801FBD40.y = a->y; - D_801FBD40.z = a->z; - D_801FBD50.x = b->x; - D_801FBD50.y = b->y; - D_801FBD50.z = b->z; + sMinF.x = min->x; + sMinF.y = min->y; + sMinF.z = min->z; + sMaxF.x = max->x; + sMaxF.y = max->y; + sMaxF.z = max->z; + sAF.x = a->x; + sAF.y = a->y; + sAF.z = a->z; + sBF.x = b->x; + sBF.y = b->y; + sBF.z = b->z; - return Math3D_LineVsCube(&D_801FBD20, &D_801FBD30, &D_801FBD40, &D_801FBD50); + return Math3D_LineVsCube(&sMinF, &sMaxF, &sAF, &sBF); } +/** + * Rotates the xz plane around the y axis `angle` degrees. + * outputs the plane equation `a``pointOnPlane->x` + 0y + `c``pointOnPlane->z`+`d` = 0 + */ void Math3D_RotateXZPlane(Vec3f* pointOnPlane, s16 angle, f32* a, f32* c, f32* d) { *a = Math_SinS(angle) * 0x7FFF; *c = Math_CosS(angle) * 0x7FFF; *d = -((*a * pointOnPlane->x) + (*c * pointOnPlane->z)); } +/* + * Defines a plane from vertices `va`, `vb`, and `vc`. Normal components are output to + * `nx`, `ny`, and `nz`. Distance from the origin is output to `originDist` + * Satisfies the plane equation NxVx + NyVy + NzVz + D = 0 + */ void Math3D_DefPlane(Vec3f* va, Vec3f* vb, Vec3f* vc, f32* nx, f32* ny, f32* nz, f32* originDist) { - static Vec3f D_801FBD60; - + static Vec3f sNormal; f32 normMagnitude; f32 normMagInv; - Math3D_SurfaceNorm(va, vb, vc, &D_801FBD60); - normMagnitude = sqrtf(SQ(D_801FBD60.x) + SQ(D_801FBD60.y) + SQ(D_801FBD60.z)); + Math3D_SurfaceNorm(va, vb, vc, &sNormal); + normMagnitude = sqrtf(SQ(sNormal.x) + SQ(sNormal.y) + SQ(sNormal.z)); if (!IS_ZERO(normMagnitude)) { normMagInv = 1.0f / normMagnitude; - *nx = D_801FBD60.x * normMagInv; - *ny = D_801FBD60.y * normMagInv; - *nz = D_801FBD60.z * normMagInv; + *nx = sNormal.x * normMagInv; + *ny = sNormal.y * normMagInv; + *nz = sNormal.z * normMagInv; *originDist = -((*nx * va->x) + (*ny * va->y) + (*nz * va->z)); } else { *originDist = 0.0f; @@ -915,19 +986,33 @@ void Math3D_DefPlane(Vec3f* va, Vec3f* vb, Vec3f* vc, f32* nx, f32* ny, f32* nz, } } +/* + * Returns the answer to the plane equation with elements specified by arguments. + */ f32 Math3D_PlaneF(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* pointOnPlane) { return (nx * pointOnPlane->x) + (ny * pointOnPlane->y) + (nz * pointOnPlane->z) + originDist; } +/* + * Returns the answer to the plane equation + */ f32 Math3D_Plane(Plane* plane, Vec3f* pointOnPlane) { return (plane->normal.x * pointOnPlane->x) + (plane->normal.y * pointOnPlane->y) + (plane->normal.z * pointOnPlane->z) + plane->originDist; } +/* + * Calculates the absolute distance from a point `p` to the plane defined as + * `nx`, `ny`, `nz`, and `originDist` + */ f32 Math3D_UDistPlaneToPos(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* p) { return fabsf(Math3D_DistPlaneToPos(nx, ny, nz, originDist, p)); } +/* + * Calculates the signed distance from a point `p` to a plane defined as + * `nx`, `ny`, `nz`, and `originDist` + */ f32 Math3D_DistPlaneToPos(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* p) { f32 normMagnitude = sqrtf(SQ(nx) + SQ(ny) + SQ(nz)); @@ -937,6 +1022,9 @@ f32 Math3D_DistPlaneToPos(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* p) { return Math3D_PlaneF(nx, ny, nz, originDist, p) / normMagnitude; } +/** + * Checks if the point defined by (`z`,`x`) is within distance of the triangle defined from `v0`,`v1`, and `v2` + */ s32 Math3D_TriChkPointParaYImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f32 detMax, f32 chkDist, f32 ny) { f32 detv0v1; f32 detv1v2; @@ -945,14 +1033,14 @@ s32 Math3D_TriChkPointParaYImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f f32 chkDistSq; // first check if the point is within range of the triangle. - if (!func_8017A304(v0, v1, v2, z, x, chkDist)) { + if (!Math3D_CirSquareVsTriSquareZX(v0, v1, v2, z, x, chkDist)) { return false; } // check if the point is within `chkDist` units of any vertex of the triangle. chkDistSq = SQ(chkDist); - if (SQ(v0->z - z) + SQ(v0->x - x) < chkDistSq || SQ(v1->z - z) + SQ(v1->x - x) < chkDistSq || - SQ(v2->z - z) + SQ(v2->x - x) < chkDistSq) { + if (((SQ(v0->z - z) + SQ(v0->x - x)) < chkDistSq) || ((SQ(v1->z - z) + SQ(v1->x - x)) < chkDistSq) || + ((SQ(v2->z - z) + SQ(v2->x - x)) < chkDistSq)) { return true; } @@ -970,15 +1058,15 @@ s32 Math3D_TriChkPointParaYImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x, f return true; } - if (fabsf(ny) > 0.5f && chkDistSq > 0.0f) { + if ((fabsf(ny) > 0.5f) && (chkDistSq > 0.0f)) { // Do a check on each face of the triangle, if the point is within `chkDist` units return true. - if (func_8017DA24(z, x, v0, v1, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { + if (Math3D_PointDistSqToLineZX(z, x, v0, v1, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { return true; } - if (func_8017DA24(z, x, v1, v2, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { + if (Math3D_PointDistSqToLineZX(z, x, v1, v2, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { return true; } - if (func_8017DA24(z, x, v2, v0, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { + if (Math3D_PointDistSqToLineZX(z, x, v2, v0, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { return true; } } @@ -993,6 +1081,9 @@ s32 Math3D_TriChkPointParaYSlopedY(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 z, f32 x return Math3D_TriChkPointParaYImpl(v0, v1, v2, z, x, 300.0f, 1.0f, 0.6f); } +/** + * Performs the triangle and point check parallel to the Y axis, outputs the y coordinate of the point to `yIntersect` + */ s32 Math3D_TriChkPointParaYIntersectDist(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 z, f32 x, f32* yIntersect, f32 chkDist) { if (IS_ZERO(ny)) { @@ -1085,8 +1176,8 @@ s32 Math3D_TriChkPointParaYImplNoCheckRange(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 // check if the point is within `chkDist` units of any vertex of the triangle. chkDistSq = SQ(chkDist); - if (SQ(v0->z - z) + SQ(v0->x - x) < chkDistSq || SQ(v1->z - z) + SQ(v1->x - x) < chkDistSq || - SQ(v2->z - z) + SQ(v2->x - x) < chkDistSq) { + if (((SQ(v0->z - z) + SQ(v0->x - x)) < chkDistSq) || ((SQ(v1->z - z) + SQ(v1->x - x)) < chkDistSq) || + ((SQ(v2->z - z) + SQ(v2->x - x)) < chkDistSq)) { return true; } @@ -1103,15 +1194,15 @@ s32 Math3D_TriChkPointParaYImplNoCheckRange(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 return true; } - if (fabsf(ny) > 0.5f && chkDistSq > 0.0f) { + if ((fabsf(ny) > 0.5f) && (chkDistSq > 0.0f)) { // Do a check on each face of the triangle, if the point is within `chkDist` units return true. - if (func_8017DA24(z, x, v0, v1, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { + if (Math3D_PointDistSqToLineZX(z, x, v0, v1, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { return true; } - if (func_8017DA24(z, x, v1, v2, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { + if (Math3D_PointDistSqToLineZX(z, x, v1, v2, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { return true; } - if (func_8017DA24(z, x, v2, v0, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { + if (Math3D_PointDistSqToLineZX(z, x, v2, v0, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { return true; } } @@ -1141,14 +1232,14 @@ s32 Math3D_TriChkPointParaXImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f f32 chkDistSq; // first check if the point is within range of the triangle. - if (!func_8017A1D0(v0, v1, v2, y, z, chkDist)) { + if (!Math3D_CirSquareVsTriSquareYZ(v0, v1, v2, y, z, chkDist)) { return false; } // check if the point is within `chkDist` units of any vertex of the triangle. chkDistSq = SQ(chkDist); - if (SQ(v0->y - y) + SQ(v0->z - z) < chkDistSq || SQ(v1->y - y) + SQ(v1->z - z) < chkDistSq || - SQ(v2->y - y) + SQ(v2->z - z) < chkDistSq) { + if (((SQ(v0->y - y) + SQ(v0->z - z)) < chkDistSq) || ((SQ(v1->y - y) + SQ(v1->z - z)) < chkDistSq) || + ((SQ(v2->y - y) + SQ(v2->z - z)) < chkDistSq)) { return true; } @@ -1167,13 +1258,13 @@ s32 Math3D_TriChkPointParaXImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 y, f32 z, f if ((fabsf(ny) > 0.5f) && (chkDistSq > 0.0f)) { // Do a check on each face of the triangle, if the point is within `chkDist` units return true. - if ((func_8017D91C(y, z, v0, v1, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { + if ((Math3D_PointDistSqToLineYZ(y, z, v0, v1, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { return true; } - if ((func_8017D91C(y, z, v1, v2, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { + if ((Math3D_PointDistSqToLineYZ(y, z, v1, v2, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { return true; } - if ((func_8017D91C(y, z, v2, v0, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { + if ((Math3D_PointDistSqToLineYZ(y, z, v2, v0, &distToEdgeSq) != 0) && (distToEdgeSq < chkDistSq)) { return true; } } @@ -1212,8 +1303,7 @@ s32 Math3D_TriChkPointParaX(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 y, f32 s32 Math3D_TriChkLineSegParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 y, f32 z, f32* xIntersect, f32 x0, f32 x1) { - static Vec3f D_801FBD70; - + static Vec3f sPlanePos; f32 pointADist; f32 pointBDist; @@ -1221,13 +1311,13 @@ s32 Math3D_TriChkLineSegParaXIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, return false; } - D_801FBD70.x = x0; - D_801FBD70.y = y; - D_801FBD70.z = z; - pointADist = Math3D_PlaneF(nx, ny, nz, originDist, &D_801FBD70); + sPlanePos.x = x0; + sPlanePos.y = y; + sPlanePos.z = z; + pointADist = Math3D_PlaneF(nx, ny, nz, originDist, &sPlanePos); - D_801FBD70.x = x1; - pointBDist = Math3D_PlaneF(nx, ny, nz, originDist, &D_801FBD70); + sPlanePos.x = x1; + pointBDist = Math3D_PlaneF(nx, ny, nz, originDist, &sPlanePos); if (((pointADist > 0.0f) && (pointBDist > 0.0f)) || ((pointADist < 0.0f) && (pointBDist < 0.0f))) { return false; @@ -1259,7 +1349,7 @@ s32 Math3D_TriChkPointParaZImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 x, f32 y, f f32 distToEdgeSq; f32 chkDistSq; - if (!func_8017A09C(v0, v1, v2, x, y, chkDist)) { + if (!Math3D_CirSquareVsTriSquareXY(v0, v1, v2, x, y, chkDist)) { return false; } @@ -1285,15 +1375,15 @@ s32 Math3D_TriChkPointParaZImpl(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 x, f32 y, f if (fabsf(nz) > 0.5f && chkDistSq > 0.0f) { - if (func_8017D814(x, y, v0, v1, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { + if (Math3D_PointDistSqToLineXY(x, y, v0, v1, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { return true; } - if (func_8017D814(x, y, v1, v2, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { + if (Math3D_PointDistSqToLineXY(x, y, v1, v2, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { return true; } - if (func_8017D814(x, y, v2, v0, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { + if (Math3D_PointDistSqToLineXY(x, y, v2, v0, &distToEdgeSq) && (distToEdgeSq < chkDistSq)) { return true; } } @@ -1333,21 +1423,22 @@ s32 Math3D_TriChkPointParaZ(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 y, f32 s32 Math3D_TriChkLineSegParaZIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, f32 x, f32 y, f32* zIntersect, f32 z0, f32 z1) { - static Vec3f D_801FBDB0; - + static Vec3f sPlanePos; f32 pointADist; f32 pointBDist; if (IS_ZERO(nz)) { return false; } - D_801FBDB0.x = x; - D_801FBDB0.y = y; - D_801FBDB0.z = z0; - pointADist = Math3D_PlaneF(nx, ny, nz, originDist, &D_801FBDB0); - D_801FBDB0.z = z1; - pointBDist = Math3D_PlaneF(nx, ny, nz, originDist, &D_801FBDB0); + sPlanePos.x = x; + sPlanePos.y = y; + sPlanePos.z = z0; + pointADist = Math3D_PlaneF(nx, ny, nz, originDist, &sPlanePos); + + sPlanePos.z = z1; + pointBDist = Math3D_PlaneF(nx, ny, nz, originDist, &sPlanePos); + if (((pointADist > 0.0f) && (pointBDist > 0.0f)) || ((pointADist < 0.0f) && (pointBDist < 0.0f))) { // points on the line segment are on the same side of the plane return false; @@ -1394,6 +1485,11 @@ s32 Math3D_LineSegFindPlaneIntersect(f32 pointADist, f32 pointBDist, Vec3f* poin return true; } +/** + * Determines if the line segment from `linePointA` to `linePointB` crosses the plane + * from `nx` + `ny` + `nz` + `originDist` = 0. If fromFront is set, then detection will only + * be true if point A crosses from the front of the plane + */ s32 Math3D_LineSegVsPlane(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersect, s32 fromFront) { f32 pointADist = Math3D_PlaneF(nx, ny, nz, originDist, linePointA); @@ -1412,6 +1508,12 @@ s32 Math3D_LineSegVsPlane(f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePoi return Math3D_LineSegFindPlaneIntersect(pointADist, pointBDist, linePointA, linePointB, intersect); } +/* + * Determines if the line formed by `linePointA` and `linePointB` intersect with Triangle formed from + * vertices `v0`, `v1`, and `v2` with normal vector `nx`, `ny`, and `nz` with plane distance from origin + * `originDist` Outputs the intersection point at to `intersect` + * Returns 1 if the line intersects with the triangle, 0 otherwise + */ s32 Math3D_TriLineIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 nz, f32 originDist, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersect, s32 fromFront) { @@ -1429,6 +1531,10 @@ s32 Math3D_TriLineIntersect(Vec3f* v0, Vec3f* v1, Vec3f* v2, f32 nx, f32 ny, f32 return false; } +/* + * Creates a TriNorm output to `tri`, and calculates the normal vector and plane from vertices + * `va`, `vb`, and `vc` + */ void Math3D_TriNorm(TriNorm* tri, Vec3f* va, Vec3f* vb, Vec3f* vc) { tri->vtx[0] = *va; tri->vtx[1] = *vb; @@ -1438,6 +1544,9 @@ void Math3D_TriNorm(TriNorm* tri, Vec3f* va, Vec3f* vb, Vec3f* vc) { &tri->plane.originDist); } +/* + * Determines if point `point` lies within `sphere` + */ s32 Math3D_PointInSph(Sphere16* sphere, Vec3f* point) { if (Math3D_DistXYZ16toF(&sphere->center, point) < sphere->radius) { return true; @@ -1446,8 +1555,13 @@ s32 Math3D_PointInSph(Sphere16* sphere, Vec3f* point) { return false; } -s32 Math3D_PointDistToLine2D(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* perpXOut, f32* perpYOut, - f32* lineLenSq) { +/** + * Determines the distance from point (`x0`,`y0`) to the line formed from (`x1`,`y1`) and (`x2`,`y2`) + * Distance squared is output to `lineLenSq`, returns true if the point perpendicular from (`x0`,`y0`) + * is contained within the segment between (`x1`,`y1`) and (`x2`,`y2`) + */ +s32 Math3D_PointDistSqToLine2DImpl(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* perpXOut, f32* perpYOut, + f32* lineLenSq) { f32 perpendicularRatio; f32 xDiff = x2 - x1; f32 yDiff = y2 - y1; @@ -1460,7 +1574,7 @@ s32 Math3D_PointDistToLine2D(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32 } perpendicularRatio = ((x0 - x1) * xDiff + (y0 - y1) * yDiff) / distSq; - if (perpendicularRatio >= 0.0f && perpendicularRatio <= 1.0f) { + if ((perpendicularRatio >= 0.0f) && (perpendicularRatio <= 1.0f)) { ret = true; } @@ -1471,15 +1585,19 @@ s32 Math3D_PointDistToLine2D(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32 return ret; } -s32 func_8017D7C0(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* lineLenSq) { +/** + * Determines the distance from point (`x0`,`y0`) to the line formed from (`x1`,`y1`) and (`x2`,`y2`) + * Distance squared is output to `lineLenSq`, returns true if the point perpendicular from (`x0`,`y0`) + * is contained within the segment between (`x1`,`y1`) and (`x2`,`y2`) + */ +s32 Math3D_PointDistSqToLine2D(f32 x0, f32 y0, f32 x1, f32 y1, f32 x2, f32 y2, f32* lineLenSq) { f32 perpX; f32 perpY; - return Math3D_PointDistToLine2D(x0, y0, x1, y1, x2, y2, &perpX, &perpY, lineLenSq); + return Math3D_PointDistSqToLine2DImpl(x0, y0, x1, y1, x2, y2, &perpX, &perpY, lineLenSq); } -// Math3D_PointDistToLine2D_ -s32 func_8017D814(f32 x0, f32 y0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { +s32 Math3D_PointDistSqToLineXY(f32 x0, f32 y0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { f32 perpendicularRatio; f32 xDiff = p2->x - p1->x; f32 yDiff = p2->y - p1->y; @@ -1494,7 +1612,7 @@ s32 func_8017D814(f32 x0, f32 y0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { } perpendicularRatio = ((x0 - p1->x) * xDiff + (y0 - p1->y) * yDiff) / distSq; - if (perpendicularRatio >= 0.0f && perpendicularRatio <= 1.0f) { + if ((perpendicularRatio >= 0.0f) && (perpendicularRatio <= 1.0f)) { ret = true; } perpX = (xDiff * perpendicularRatio) + p1->x; @@ -1504,7 +1622,7 @@ s32 func_8017D814(f32 x0, f32 y0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { return ret; } -s32 func_8017D91C(f32 y0, f32 z0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { +s32 Math3D_PointDistSqToLineYZ(f32 y0, f32 z0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { f32 perpendicularRatio; f32 yDiff = p2->y - p1->y; f32 zDiff = p2->z - p1->z; @@ -1519,7 +1637,7 @@ s32 func_8017D91C(f32 y0, f32 z0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { } perpendicularRatio = ((y0 - p1->y) * yDiff + (z0 - p1->z) * zDiff) / distSq; - if (perpendicularRatio >= 0.0f && perpendicularRatio <= 1.0f) { + if ((perpendicularRatio >= 0.0f) && (perpendicularRatio <= 1.0f)) { ret = true; } perpY = (yDiff * perpendicularRatio) + p1->y; @@ -1529,7 +1647,7 @@ s32 func_8017D91C(f32 y0, f32 z0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { return ret; } -s32 func_8017DA24(f32 z0, f32 x0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { +s32 Math3D_PointDistSqToLineZX(f32 z0, f32 x0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { f32 perpendicularRatio; f32 zDiff = p2->z - p1->z; f32 xDiff = p2->x - p1->x; @@ -1544,7 +1662,7 @@ s32 func_8017DA24(f32 z0, f32 x0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { } perpendicularRatio = ((z0 - p1->z) * zDiff + (x0 - p1->x) * xDiff) / distSq; - if (perpendicularRatio >= 0.0f && perpendicularRatio <= 1.0f) { + if ((perpendicularRatio >= 0.0f) && (perpendicularRatio <= 1.0f)) { ret = true; } perpZ = (zDiff * perpendicularRatio) + p1->z; @@ -1554,9 +1672,11 @@ s32 func_8017DA24(f32 z0, f32 x0, Vec3f* p1, Vec3f* p2, f32* lineLenSq) { return ret; } +/** + * Determines if the line `line` is touching the sphere `sphere` at any point in the line. + */ s32 Math3D_LineVsSph(Sphere16* sphere, Linef* line) { - static Vec3f D_801FBDD8; - + static Vec3f sSphLinePerpendicularPoint; Vec3f lineDiff; f32 temp_f0_2; f32 lineLenSq; @@ -1581,65 +1701,69 @@ s32 Math3D_LineVsSph(Sphere16* sphere, Linef* line) { return false; } - D_801FBDD8.x = (lineDiff.x * temp_f0_2) + line->a.x; - D_801FBDD8.y = (lineDiff.y * temp_f0_2) + line->a.y; - D_801FBDD8.z = (lineDiff.z * temp_f0_2) + line->a.z; + sSphLinePerpendicularPoint.x = (lineDiff.x * temp_f0_2) + line->a.x; + sSphLinePerpendicularPoint.y = (lineDiff.y * temp_f0_2) + line->a.y; + sSphLinePerpendicularPoint.z = (lineDiff.z * temp_f0_2) + line->a.z; - if (SQ(D_801FBDD8.x - sphere->center.x) + SQ(D_801FBDD8.y - sphere->center.y) + - SQ(D_801FBDD8.z - sphere->center.z) <= - SQ((f32)sphere->radius)) { + if ((SQ(sSphLinePerpendicularPoint.x - sphere->center.x) + SQ(sSphLinePerpendicularPoint.y - sphere->center.y) + + SQ(sSphLinePerpendicularPoint.z - sphere->center.z)) <= SQ((f32)sphere->radius)) { return true; } return false; } +/** + * Gets the surface point of `sphere` intersecting with `tri` generated from the line formed from the + * sphere's surface to the midpoint of the line formed from the first two vertices of the tri + */ void Math3D_GetSphVsTriIntersectPoint(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoint) { - static Vec3f D_801FBDE8; - static Vec3f D_801FBBF0; - + static Vec3f sV0V1Center; + static Vec3f sSphereCenter; f32 dist; f32 splitRatio; - D_801FBDE8.x = (tri->vtx[0].x + tri->vtx[1].x) * 0.5f; - D_801FBDE8.y = (tri->vtx[0].y + tri->vtx[1].y) * 0.5f; - D_801FBDE8.z = (tri->vtx[0].z + tri->vtx[1].z) * 0.5f; - D_801FBBF0.x = sphere->center.x; - D_801FBBF0.y = sphere->center.y; - D_801FBBF0.z = sphere->center.z; - dist = Math3D_Vec3f_DistXYZ(&D_801FBDE8, &D_801FBBF0); + sV0V1Center.x = (tri->vtx[0].x + tri->vtx[1].x) * 0.5f; + sV0V1Center.y = (tri->vtx[0].y + tri->vtx[1].y) * 0.5f; + sV0V1Center.z = (tri->vtx[0].z + tri->vtx[1].z) * 0.5f; + sSphereCenter.x = sphere->center.x; + sSphereCenter.y = sphere->center.y; + sSphereCenter.z = sphere->center.z; + dist = Math3D_Vec3f_DistXYZ(&sV0V1Center, &sSphereCenter); // Distance from the sphere's center to the center of the line formed from v0->v1 if (IS_ZERO(dist)) { - intersectPoint->x = D_801FBBF0.x; - intersectPoint->y = D_801FBBF0.y; - intersectPoint->z = D_801FBBF0.z; + intersectPoint->x = sSphereCenter.x; + intersectPoint->y = sSphereCenter.y; + intersectPoint->z = sSphereCenter.z; return; } splitRatio = sphere->radius / dist; - Math3D_LineSplitRatio(&D_801FBBF0, &D_801FBDE8, splitRatio, intersectPoint); + Math3D_LineSplitRatio(&sSphereCenter, &sV0V1Center, splitRatio, intersectPoint); } +/** + * Determines if `sphere` and `tri` and touching, and outputs the intersection point to `intersectPoint` + */ s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoint) { - static Linef D_801FBC00; - static Vec3f D_801FBC18; - static Vec3f D_801FBC28; - + static Linef sTriTestLine; + static Vec3f sSphereCenter; + static Vec3f sSphPlanePos; f32 radius; f32 nx; f32 ny; f32 nz; f32 planeDist; - D_801FBC18.x = sphere->center.x; - D_801FBC18.y = sphere->center.y; - D_801FBC18.z = sphere->center.z; + sSphereCenter.x = sphere->center.x; + sSphereCenter.y = sphere->center.y; + sSphereCenter.z = sphere->center.z; radius = sphere->radius; - if (!Math3D_SphCubeVsTriCube(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], &D_801FBC18, radius)) { + if (!Math3D_SphCubeVsTriCube(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], &sSphereCenter, radius)) { return false; } planeDist = Math3D_UDistPlaneToPos(tri->plane.normal.x, tri->plane.normal.y, tri->plane.normal.z, - tri->plane.originDist, &D_801FBC18); + tri->plane.originDist, &sSphereCenter); if (radius < planeDist) { // the point that lies within the plane of the triangle which is perpendicular to the sphere's center is more // than the radius of the sphere, the plane never crosses the sphere. @@ -1647,23 +1771,23 @@ s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoi } // tests if any of the edges of the triangle are intersecting the sphere - D_801FBC00.a = tri->vtx[0]; - D_801FBC00.b = tri->vtx[1]; - if (Math3D_LineVsSph(sphere, &D_801FBC00)) { + sTriTestLine.a = tri->vtx[0]; + sTriTestLine.b = tri->vtx[1]; + if (Math3D_LineVsSph(sphere, &sTriTestLine)) { Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); return true; } - D_801FBC00.a = tri->vtx[1]; - D_801FBC00.b = tri->vtx[2]; - if (Math3D_LineVsSph(sphere, &D_801FBC00)) { + sTriTestLine.a = tri->vtx[1]; + sTriTestLine.b = tri->vtx[2]; + if (Math3D_LineVsSph(sphere, &sTriTestLine)) { Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); return true; } - D_801FBC00.a = tri->vtx[2]; - D_801FBC00.b = tri->vtx[0]; - if (Math3D_LineVsSph(sphere, &D_801FBC00)) { + sTriTestLine.a = tri->vtx[2]; + sTriTestLine.b = tri->vtx[0]; + if (Math3D_LineVsSph(sphere, &sTriTestLine)) { Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); return true; } @@ -1673,36 +1797,40 @@ s32 Math3D_TriVsSphIntersect(Sphere16* sphere, TriNorm* tri, Vec3f* intersectPoi nz = tri->plane.normal.z * planeDist; if (Math3D_PlaneF(tri->plane.normal.x, tri->plane.normal.y, tri->plane.normal.z, tri->plane.originDist, - &D_801FBC18) > 0.0f) { - D_801FBC28.x = D_801FBC18.x - nx; - D_801FBC28.y = D_801FBC18.y - ny; - D_801FBC28.z = D_801FBC18.z - nz; + &sSphereCenter) > 0.0f) { + sSphPlanePos.x = sSphereCenter.x - nx; + sSphPlanePos.y = sSphereCenter.y - ny; + sSphPlanePos.z = sSphereCenter.z - nz; } else { - D_801FBC28.x = D_801FBC18.x + nx; - D_801FBC28.y = D_801FBC18.y + ny; - D_801FBC28.z = D_801FBC18.z + nz; + sSphPlanePos.x = sSphereCenter.x + nx; + sSphPlanePos.y = sSphereCenter.y + ny; + sSphPlanePos.z = sSphereCenter.z + nz; } if (fabsf(tri->plane.normal.y) > 0.5f) { - if (Math3D_TriChkPointParaYDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], D_801FBC28.z, D_801FBC28.x, + if (Math3D_TriChkPointParaYDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], sSphPlanePos.z, sSphPlanePos.x, 0.0f, tri->plane.normal.y)) { Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); return true; } } else if (fabsf(tri->plane.normal.x) > 0.5f) { - if (Math3D_TriChkPointParaXDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], D_801FBC28.y, D_801FBC28.z, + if (Math3D_TriChkPointParaXDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], sSphPlanePos.y, sSphPlanePos.z, 0.0f, tri->plane.normal.x)) { Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); return true; } - } else if (Math3D_TriChkPointParaZDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], D_801FBC28.x, D_801FBC28.y, - 0.0f, tri->plane.normal.z)) { + } else if (Math3D_TriChkPointParaZDeterminate(&tri->vtx[0], &tri->vtx[1], &tri->vtx[2], sSphPlanePos.x, + sSphPlanePos.y, 0.0f, tri->plane.normal.z)) { Math3D_GetSphVsTriIntersectPoint(sphere, tri, intersectPoint); return true; } return false; } +/* + * Checks if point `point` is within cylinder `cyl` + * Returns 1 if the point is inside the cylinder, 0 otherwise. + */ s32 Math3D_PointInCyl(Cylinder16* cyl, Vec3f* point) { f32 bottom; f32 top; @@ -1772,11 +1900,11 @@ dummy:; if (!IS_ZERO(ptAToPtB.y)) { // fraction of length along AB to reach y = 0 fracBase = -cylToPtA.y / ptAToPtB.y; - if ((0.0f <= fracBase) && (fracBase <= 1.0f)) { + if ((fracBase >= 0.0f) && (fracBase <= 1.0f)) { f32 baseIntX = (ptAToPtB.x * fracBase) + cylToPtA.x; f32 baseIntZ = (ptAToPtB.z * fracBase) + cylToPtA.z; - if (SQ(baseIntX) + SQ(baseIntZ) < cylRadiusSq) { + if ((SQ(baseIntX) + SQ(baseIntZ)) < cylRadiusSq) { // adds base intersection point to intPts and sets its flag intPts[0].x = cyl->pos.x + baseIntX; intPts[0].y = (f32)cyl->pos.y + cyl->yShift; @@ -1786,11 +1914,11 @@ dummy:; } // fraction of length along AB to reach y = cyl->height fracA = (cyl->height - cylToPtA.y) / ptAToPtB.y; - if ((0.0f <= fracA) && (fracA <= 1.0f)) { + if ((fracA >= 0.0f) && (fracA <= 1.0f)) { f32 topIntX = ptAToPtB.x * fracA + cylToPtA.x; f32 topIntZ = ptAToPtB.z * fracA + cylToPtA.z; - if (SQ(topIntX) + SQ(topIntZ) < cylRadiusSq) { + if ((SQ(topIntX) + SQ(topIntZ)) < cylRadiusSq) { // adds top intersection point to intPts and sets its flag intPts[1].x = cyl->pos.x + topIntX; intPts[1].y = (f32)cyl->pos.y + cyl->yShift + cyl->height; @@ -1808,11 +1936,11 @@ dummy:; radSqDiff = SQXZ(cylToPtA) - cylRadiusSq; if (!IS_ZERO(2.0f * SQXZ(ptAToPtB))) { dot2AB = 2.0f * DOTXZ(ptAToPtB, cylToPtA); - if (SQ(dot2AB) < 4.0f * SQXZ(ptAToPtB) * radSqDiff) { + if (SQ(dot2AB) < (4.0f * SQXZ(ptAToPtB) * radSqDiff)) { // Line's closest xz-approach is outside cylinder. No intersections. return 0; } - if (SQ(dot2AB) - (4.0f * SQXZ(ptAToPtB) * radSqDiff) > zero) { + if ((SQ(dot2AB) - (4.0f * SQXZ(ptAToPtB) * radSqDiff)) > zero) { sideIntA = sideIntB = 1; } else { // Line is tangent in xz-plane. At most 1 side intersection. @@ -1839,12 +1967,12 @@ dummy:; // checks for intersection points outside the bounds of the segment if (!sideIntB) { - if (fracA < 0.0f || 1.0f < fracA) { + if ((fracA < 0.0f) || (fracA > 1.0f)) { return 0; } } else { - intBeyondA = fracA < 0.0f || 1.0f < fracA; - intBeyondB = fracB < 0.0f || 1.0f < fracB; + intBeyondA = (fracA < 0.0f) || (fracA > 1.0f); + intBeyondB = (fracB < 0.0f) || (fracB > 1.0f); if (intBeyondA && intBeyondB) { return 0; } @@ -1858,14 +1986,14 @@ dummy:; // checks for intersection points outside the bounds of the cylinder if ((sideIntA != 0) && - ((fracA * ptAToPtB.y + cylToPtA.y) < 0.0f || cyl->height < (fracA * ptAToPtB.y + cylToPtA.y))) { + (((fracA * ptAToPtB.y + cylToPtA.y) < 0.0f) || (cyl->height < (fracA * ptAToPtB.y + cylToPtA.y)))) { sideIntA = 0; } if ((sideIntB != 0) && - ((fracB * ptAToPtB.y + cylToPtA.y) < 0.0f || cyl->height < (fracB * ptAToPtB.y + cylToPtA.y))) { + (((fracB * ptAToPtB.y + cylToPtA.y) < 0.0f) || (cyl->height < (fracB * ptAToPtB.y + cylToPtA.y)))) { sideIntB = 0; } - if (sideIntA == 0 && sideIntB == 0) { + if ((sideIntA == 0) && (sideIntB == 0)) { return 0; } @@ -1913,12 +2041,15 @@ dummy:; return count; } +/* + * Determines if `cyl` and `tri` are touching. The point of intersection + * is placed in `intersect` Returns 1 if they are touching, 0 otherwise. + */ s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect) { - static Sphere16 D_801FBC38; - static Sphere16 D_801FBC40; - static Vec3f D_801FBC48; - static Vec3f D_801FBC58; - + static Sphere16 sTopSphere; + static Sphere16 sBottomSphere; + static Vec3f sCylIntersectA; + static Vec3f sCylIntersectB; f32 yIntersect; f32 cylTop; f32 cylBottom; @@ -1932,29 +2063,29 @@ s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect) { if (((tri->vtx[0].y < cylBottom) && (tri->vtx[1].y < cylBottom) && (tri->vtx[2].y < cylBottom)) || ((cylTop < tri->vtx[0].y) && (cylTop < tri->vtx[1].y) && (cylTop < tri->vtx[2].y))) { - // If all of the verticies are below or all of the verticies are above the cylinder. + // If all of the vertices are below or all of the vertices are above the cylinder. return false; } minDistSq = 1.e38f; - if (Math3D_CylVsLineSeg(cyl, &tri->vtx[0], &tri->vtx[1], &D_801FBC48, &D_801FBC58)) { - distFromPointAToIntersectASq = Math3D_Vec3fDistSq(&D_801FBC48, &tri->vtx[0]); + if (Math3D_CylVsLineSeg(cyl, &tri->vtx[0], &tri->vtx[1], &sCylIntersectA, &sCylIntersectB)) { + distFromPointAToIntersectASq = Math3D_Vec3fDistSq(&sCylIntersectA, &tri->vtx[0]); minDistSq = distFromPointAToIntersectASq; - *intersect = D_801FBC48; + *intersect = sCylIntersectA; } - if (Math3D_CylVsLineSeg(cyl, &tri->vtx[2], &tri->vtx[1], &D_801FBC48, &D_801FBC58)) { - distFromPointAToIntersectASq = Math3D_Vec3fDistSq(&D_801FBC48, &tri->vtx[2]); + if (Math3D_CylVsLineSeg(cyl, &tri->vtx[2], &tri->vtx[1], &sCylIntersectA, &sCylIntersectB)) { + distFromPointAToIntersectASq = Math3D_Vec3fDistSq(&sCylIntersectA, &tri->vtx[2]); if (distFromPointAToIntersectASq < minDistSq) { - *intersect = D_801FBC48; + *intersect = sCylIntersectA; minDistSq = distFromPointAToIntersectASq; } } - if (Math3D_CylVsLineSeg(cyl, &tri->vtx[0], &tri->vtx[2], &D_801FBC48, &D_801FBC58)) { - distFromPointAToIntersectASq = Math3D_Vec3fDistSq(&D_801FBC48, &tri->vtx[0]); + if (Math3D_CylVsLineSeg(cyl, &tri->vtx[0], &tri->vtx[2], &sCylIntersectA, &sCylIntersectB)) { + distFromPointAToIntersectASq = Math3D_Vec3fDistSq(&sCylIntersectA, &tri->vtx[0]); if (distFromPointAToIntersectASq < minDistSq) { - *intersect = D_801FBC48; + *intersect = sCylIntersectA; minDistSq = distFromPointAToIntersectASq; } } @@ -1993,38 +2124,51 @@ s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect) { return true; } - D_801FBC38.center.x = D_801FBC40.center.x = cyl->pos.x; - D_801FBC38.center.z = D_801FBC40.center.z = cyl->pos.z; - D_801FBC38.center.y = cylTop; - D_801FBC40.center.y = cylBottom; - D_801FBC38.radius = D_801FBC40.radius = cyl->radius; + sTopSphere.center.x = sBottomSphere.center.x = cyl->pos.x; + sTopSphere.center.z = sBottomSphere.center.z = cyl->pos.z; + sTopSphere.center.y = cylTop; + sBottomSphere.center.y = cylBottom; + sTopSphere.radius = sBottomSphere.radius = cyl->radius; - if (Math3D_TriVsSphIntersect(&D_801FBC38, tri, intersect) || - Math3D_TriVsSphIntersect(&D_801FBC40, tri, intersect)) { + if (Math3D_TriVsSphIntersect(&sTopSphere, tri, intersect) || + Math3D_TriVsSphIntersect(&sBottomSphere, tri, intersect)) { return true; } return false; } +/* + * Determines if `cyl` and `tri` are touching. + */ s32 Math3D_CylVsTri(Cylinder16* cyl, TriNorm* tri) { Vec3f intersect; return Math3D_CylTriVsIntersect(cyl, tri, &intersect); } +/* + * Determines if two spheres are touching. + */ s32 Math3D_SphVsSph(Sphere16* sphereA, Sphere16* sphereB) { f32 overlapSize; return Math3D_SphVsSphOverlap(sphereA, sphereB, &overlapSize); } +/* + * Determines if two spheres are touching. The amount that they're overlapping is placed in `overlapSize` + */ s32 Math3D_SphVsSphOverlap(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize) { f32 centerDist; - return Math3D_SphVsSphOverlapCenter(sphereA, sphereB, overlapSize, ¢erDist); + return Math3D_SphVsSphOverlapCenterDist(sphereA, sphereB, overlapSize, ¢erDist); } -s32 Math3D_SphVsSphOverlapCenter(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize, f32* centerDist) { +/* + * Determines if two spheres are touching The distance from the centers is placed in `centerDist`, + * and the amount that they're overlapping is placed in `overlapSize` + */ +s32 Math3D_SphVsSphOverlapCenterDist(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize, f32* centerDist) { Vec3f diff; diff.x = (f32)sphereA->center.x - (f32)sphereB->center.x; @@ -2042,16 +2186,22 @@ s32 Math3D_SphVsSphOverlapCenter(Sphere16* sphereA, Sphere16* sphereB, f32* over return false; } -s32 Math3D_SphVsCylOverlapDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize) { +/** + * Checks if `sph` and `cyl` are touching, output the amount of xz overlap to `overlapSize` + */ +s32 Math3D_SphVsCylOverlap(Sphere16* sph, Cylinder16* cyl, f32* overlapSize) { f32 centerDist; return Math3D_SphVsCylOverlapCenterDist(sph, cyl, overlapSize, ¢erDist); } +/** + * Checks if `sph` and `cyl` are touching, output the xz distance of the centers to `centerDist`, and the amount of + * xz overlap to `overlapSize` + */ s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize, f32* centerDist) { - static Cylinderf D_801FBC88; - static Spheref D_801FBCA0; - + static Cylinderf sCylf; + static Spheref sSphf; f32 x; f32 z; f32 combinedRadius; @@ -2064,11 +2214,11 @@ s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overla // either radius is 0 return false; } - D_801FBCA0.center.y = sph->center.y; - D_801FBCA0.radius = sph->radius; - D_801FBC88.pos.y = cyl->pos.y; - D_801FBC88.yShift = cyl->yShift; - D_801FBC88.height = cyl->height; + sSphf.center.y = sph->center.y; + sSphf.radius = sph->radius; + sCylf.pos.y = cyl->pos.y; + sCylf.yShift = cyl->yShift; + sCylf.height = cyl->height; x = (f32)sph->center.x - cyl->pos.x; z = (f32)sph->center.z - cyl->pos.z; combinedRadius = (f32)sph->radius + cyl->radius; @@ -2078,10 +2228,10 @@ s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overla return false; } - cylBottom = (D_801FBC88.pos.y + D_801FBC88.yShift); - cylTop = cylBottom + D_801FBC88.height; - sphBottom = D_801FBCA0.center.y - D_801FBCA0.radius; - sphTop = D_801FBCA0.center.y + D_801FBCA0.radius; + cylBottom = (sCylf.pos.y + sCylf.yShift); + cylTop = cylBottom + sCylf.height; + sphBottom = sSphf.center.y - sSphf.radius; + sphTop = sSphf.center.y + sSphf.radius; if ((sphTop >= cylBottom) && (sphBottom <= cylTop)) { // if the cylinder and sphere are intersecting on the xz plane, check if they're intersecting on @@ -2092,43 +2242,55 @@ s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overla return false; } -s32 Math3D_CylOutsideCyl(Cylinder16* ca, Cylinder16* cb, f32* deadSpace) { - f32 xzDist; +/** + * Checks if `ca` and `cb` are touching, output the amount of xz overlap to `overlapSize` + */ +s32 Math3D_CylVsCylOverlap(Cylinder16* ca, Cylinder16* cb, f32* overlapSize) { + f32 centerDist; - return Math3D_CylOutsideCylDist(ca, cb, deadSpace, &xzDist); + return Math3D_CylVsCylOverlapCenterDist(ca, cb, overlapSize, ¢erDist); } -s32 Math3D_CylOutsideCylDist(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32* xzDist) { - static Cylinderf D_801FBCB0; - static Cylinderf D_801FBCC8; +/** + * Checks if `ca` and `cb` are touching, output the xz distance of the centers to `centerDist`, and the amount of + * xz overlap to `overlapSize` + */ +s32 Math3D_CylVsCylOverlapCenterDist(Cylinder16* ca, Cylinder16* cb, f32* overlapSize, f32* centerDist) { + static Cylinderf sCaf; + static Cylinderf sCbf; - Math_Vec3s_ToVec3f(&D_801FBCB0.pos, &ca->pos); - D_801FBCB0.radius = ca->radius; - D_801FBCB0.yShift = ca->yShift; - D_801FBCB0.height = ca->height; + Math_Vec3s_ToVec3f(&sCaf.pos, &ca->pos); + sCaf.radius = ca->radius; + sCaf.yShift = ca->yShift; + sCaf.height = ca->height; - Math_Vec3s_ToVec3f(&D_801FBCC8.pos, &cb->pos); - D_801FBCC8.radius = cb->radius; - D_801FBCC8.yShift = cb->yShift; - D_801FBCC8.height = cb->height; + Math_Vec3s_ToVec3f(&sCbf.pos, &cb->pos); + sCbf.radius = cb->radius; + sCbf.yShift = cb->yShift; + sCbf.height = cb->height; - *xzDist = sqrtf(SQ(D_801FBCB0.pos.x - D_801FBCC8.pos.x) + SQ(D_801FBCB0.pos.z - D_801FBCC8.pos.z)); + *centerDist = sqrtf(SQ(sCaf.pos.x - sCbf.pos.x) + SQ(sCaf.pos.z - sCbf.pos.z)); - // The combined radix are within the xz distance - if ((D_801FBCB0.radius + D_801FBCC8.radius) < *xzDist) { + // The combined radii are within the xz distance + if ((sCaf.radius + sCbf.radius) < *centerDist) { return false; } // top of ca < bottom of cb or top of cb < bottom of ca - if (((D_801FBCB0.pos.y + D_801FBCB0.yShift) + D_801FBCB0.height) < (D_801FBCC8.pos.y + D_801FBCC8.yShift) || - (((D_801FBCC8.pos.y + D_801FBCC8.yShift) + D_801FBCC8.height) < (D_801FBCB0.pos.y + D_801FBCB0.yShift))) { + if ((((sCaf.pos.y + sCaf.yShift) + sCaf.height) < (sCbf.pos.y + sCbf.yShift)) || + (((sCbf.pos.y + sCbf.yShift) + sCbf.height) < (sCaf.pos.y + sCaf.yShift))) { return false; } - *deadSpace = D_801FBCB0.radius + D_801FBCC8.radius - *xzDist; + *overlapSize = sCaf.radius + sCbf.radius - *centerDist; return true; } +/* + * Determines if triangle `ta` intersects with triangle `tb` the point of + * intersection is output to `intersect. + * Returns true is the triangles intersect, 0 otherwise + */ s32 Math3D_TriVsTriIntersect(TriNorm* ta, TriNorm* tb, Vec3f* intersect) { f32 dist0 = Math3D_Plane(&ta->plane, &tb->vtx[0]); f32 dist1 = Math3D_Plane(&ta->plane, &tb->vtx[1]); diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 717548605..01a778227 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -4133,8 +4133,8 @@ void Actor_GetClosestPosOnPath(Vec3s* points, s32 numPoints, Vec3f* srcPos, Vec3 if ((closestPointIndex != 0) || isPathLoop) { // Use the adjacent line useAdjacentLines[0] = - Math3D_PointDistToLine2D(srcPos->x, srcPos->z, closestPointPrev.x, closestPointPrev.z, closestPoint.x, - closestPoint.z, &closestPos[0].x, &closestPos[0].z, &distSq); + Math3D_PointDistSqToLine2DImpl(srcPos->x, srcPos->z, closestPointPrev.x, closestPointPrev.z, closestPoint.x, + closestPoint.z, &closestPos[0].x, &closestPos[0].z, &distSq); } // Analyze point on path immediately next to the closest point @@ -4150,8 +4150,8 @@ void Actor_GetClosestPosOnPath(Vec3s* points, s32 numPoints, Vec3f* srcPos, Vec3 } if ((closestPointIndex + 1 != numPoints) || isPathLoop) { useAdjacentLines[1] = - Math3D_PointDistToLine2D(srcPos->x, srcPos->z, closestPoint.x, closestPoint.z, closestPointNext.x, - closestPointNext.z, &closestPos[1].x, &closestPos[1].z, &distSq); + Math3D_PointDistSqToLine2DImpl(srcPos->x, srcPos->z, closestPoint.x, closestPoint.z, closestPointNext.x, + closestPointNext.z, &closestPos[1].x, &closestPos[1].z, &distSq); } /** @@ -4188,9 +4188,9 @@ void Actor_GetClosestPosOnPath(Vec3s* points, s32 numPoints, Vec3f* srcPos, Vec3 // srcPos is somewhere withing the bend of the path if (!isRightSideOfAdjacentLines[0] && !isRightSideOfAdjacentLines[1]) { // srcPos is not inside a loop - if (!Math3D_PointDistToLine2D(srcPos->x, srcPos->z, closestPos[0].x, closestPos[0].z, closestPos[1].x, - closestPos[1].z, &dstPos->x, &dstPos->z, &distSq)) { - // The dstPos calculated in Math3D_PointDistToLine2D was not valid. + if (!Math3D_PointDistSqToLine2DImpl(srcPos->x, srcPos->z, closestPos[0].x, closestPos[0].z, closestPos[1].x, + closestPos[1].z, &dstPos->x, &dstPos->z, &distSq)) { + // The dstPos calculated in Math3D_PointDistSqToLine2DImpl was not valid. // Take the midpoint of the two closest ponits instead dstPos->x = (closestPos[1].x + closestPos[0].x) * 0.5f; dstPos->z = (closestPos[1].z + closestPos[0].z) * 0.5f; diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c index 631a89bbb..ef2b7ea6a 100644 --- a/src/code/z_bgcheck.c +++ b/src/code/z_bgcheck.c @@ -351,7 +351,7 @@ s32 CollisionPoly_CheckYIntersect(CollisionPoly* poly, Vec3s* vtxList, f32 x, f3 D_801EDA18[2].y = sVerts->y; D_801EDA18[2].z = sVerts->z; - if (!func_8017A304(&D_801EDA18[0], &D_801EDA18[1], &D_801EDA18[2], z, x, checkDist)) { + if (!Math3D_CirSquareVsTriSquareZX(&D_801EDA18[0], &D_801EDA18[1], &D_801EDA18[2], z, x, checkDist)) { return 0; } nx = COLPOLY_GET_NORMAL(poly->normal.x); diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c index 880a9ab64..e8a3a9017 100644 --- a/src/code/z_collision_check.c +++ b/src/code/z_collision_check.c @@ -1741,8 +1741,8 @@ void CollisionCheck_AC_JntSphVsJntSph(PlayState* play, CollisionCheckContext* co continue; } - if (Math3D_SphVsSphOverlapCenter(&atElem->dim.worldSphere, &acElem->dim.worldSphere, &overlapSize, - ¢erDist) != 0) { + if (Math3D_SphVsSphOverlapCenterDist(&atElem->dim.worldSphere, &acElem->dim.worldSphere, &overlapSize, + ¢erDist) != 0) { f32 acToHit; Vec3f hitPos; Vec3f atPos; @@ -1916,8 +1916,8 @@ void CollisionCheck_AC_JntSphVsSphere(PlayState* play, CollisionCheckContext* co if (CollisionCheck_NoSharedFlags(&sphElem->info, &ac->info)) { continue; } - if (Math3D_SphVsSphOverlapCenter(&sphElem->dim.worldSphere, &ac->dim.worldSphere, &overlapSize, - ¢erDist) != 0) { + if (Math3D_SphVsSphOverlapCenterDist(&sphElem->dim.worldSphere, &ac->dim.worldSphere, &overlapSize, + ¢erDist) != 0) { f32 acToHit; Vec3f hitPos; Vec3f atPos; @@ -2011,7 +2011,7 @@ void CollisionCheck_AC_CylVsCyl(PlayState* play, CollisionCheckContext* colCtxt, return; } - if (Math3D_CylOutsideCylDist(&at->dim, &ac->dim, &overlapSize, ¢erDist) != 0) { + if (Math3D_CylVsCylOverlapCenterDist(&at->dim, &ac->dim, &overlapSize, ¢erDist) != 0) { Vec3f hitPos; Vec3f atPos; Vec3f acPos; @@ -2565,8 +2565,8 @@ void CollisionCheck_AC_SphereVsJntSph(PlayState* play, CollisionCheckContext* co continue; } - if (Math3D_SphVsSphOverlapCenter(&at->dim.worldSphere, &acElem->dim.worldSphere, &overlapSize, - ¢erDist) != 0) { + if (Math3D_SphVsSphOverlapCenterDist(&at->dim.worldSphere, &acElem->dim.worldSphere, &overlapSize, + ¢erDist) != 0) { f32 acToHit; Vec3f hitPos; Vec3f atPos; @@ -2716,7 +2716,7 @@ void CollisionCheck_AC_SphereVsSphere(PlayState* play, CollisionCheckContext* co return; } - if (Math3D_SphVsSphOverlapCenter(&at->dim.worldSphere, &ac->dim.worldSphere, &overlapSize, ¢erDist) != 0) { + if (Math3D_SphVsSphOverlapCenterDist(&at->dim.worldSphere, &ac->dim.worldSphere, &overlapSize, ¢erDist) != 0) { f32 acToHit; Vec3f hitPos; Vec3f atPos; @@ -2933,7 +2933,7 @@ s32 CollisionCheck_GetMassType(u8 mass) { * also performs an elastic collision where both colliders are moved apart in proportion to their masses. */ void CollisionCheck_SetOCvsOC(PlayState* play, Collider* left, ColliderInfo* leftInfo, Vec3f* leftPos, Collider* right, - ColliderInfo* rightInfo, Vec3f* rightPos, f32 overlap) { + ColliderInfo* rightInfo, Vec3f* rightPos, f32 overlapSize) { f32 pad; f32 leftDispRatio; f32 rightDispRatio; @@ -3013,15 +3013,15 @@ void CollisionCheck_SetOCvsOC(PlayState* play, Collider* left, ColliderInfo* lef } if (!IS_ZERO(xzDist)) { - xDelta *= overlap / xzDist; - zDelta *= overlap / xzDist; + xDelta *= overlapSize / xzDist; + zDelta *= overlapSize / xzDist; leftActor->colChkInfo.displacement.x += -xDelta * leftDispRatio; leftActor->colChkInfo.displacement.z += -zDelta * leftDispRatio; rightActor->colChkInfo.displacement.x += xDelta * rightDispRatio; rightActor->colChkInfo.displacement.z += zDelta * rightDispRatio; - } else if (overlap != 0.0f) { - leftActor->colChkInfo.displacement.x += -overlap * leftDispRatio; - rightActor->colChkInfo.displacement.x += overlap * rightDispRatio; + } else if (overlapSize != 0.0f) { + leftActor->colChkInfo.displacement.x += -overlapSize * leftDispRatio; + rightActor->colChkInfo.displacement.x += overlapSize * rightDispRatio; } else { leftActor->colChkInfo.displacement.x += -leftDispRatio; rightActor->colChkInfo.displacement.x += rightDispRatio; @@ -3036,7 +3036,7 @@ void CollisionCheck_OC_JntSphVsJntSph(PlayState* play, CollisionCheckContext* co ColliderJntSph* right = (ColliderJntSph*)r; ColliderJntSphElement* leftElem; ColliderJntSphElement* rightElem; - f32 overlap; + f32 overlapSize; if ((left->count > 0) && (left->elements != NULL) && (right->count > 0) && (right->elements != NULL) && (left->base.ocFlags1 & OCELEM_ON) && (right->base.ocFlags1 & OCELEM_ON)) { @@ -3049,14 +3049,15 @@ void CollisionCheck_OC_JntSphVsJntSph(PlayState* play, CollisionCheckContext* co if (!(rightElem->info.ocElemFlags & OCELEM_ON)) { continue; } - if (Math3D_SphVsSphOverlap(&leftElem->dim.worldSphere, &rightElem->dim.worldSphere, &overlap) != 0) { + if (Math3D_SphVsSphOverlap(&leftElem->dim.worldSphere, &rightElem->dim.worldSphere, &overlapSize) != + 0) { Vec3f leftPos; Vec3f rightPos; Math_Vec3s_ToVec3f(&leftPos, &leftElem->dim.worldSphere.center); Math_Vec3s_ToVec3f(&rightPos, &rightElem->dim.worldSphere.center); CollisionCheck_SetOCvsOC(play, &left->base, &leftElem->info, &leftPos, &right->base, - &rightElem->info, &rightPos, overlap); + &rightElem->info, &rightPos, overlapSize); } } } @@ -3070,7 +3071,7 @@ void CollisionCheck_OC_JntSphVsCyl(PlayState* play, CollisionCheckContext* colCt ColliderJntSph* left = (ColliderJntSph*)l; ColliderCylinder* right = (ColliderCylinder*)r; ColliderJntSphElement* leftElem; - f32 overlap; + f32 overlapSize; if ((left->count > 0) && (left->elements != NULL) && (left->base.ocFlags1 & OCELEM_ON) && (right->base.ocFlags1 & OCELEM_ON) && (right->info.ocElemFlags & OCELEM_ON)) { @@ -3079,14 +3080,14 @@ void CollisionCheck_OC_JntSphVsCyl(PlayState* play, CollisionCheckContext* colCt if (!(leftElem->info.ocElemFlags & OCELEM_ON)) { continue; } - if (Math3D_SphVsCylOverlapDist(&leftElem->dim.worldSphere, &right->dim, &overlap) != 0) { + if (Math3D_SphVsCylOverlap(&leftElem->dim.worldSphere, &right->dim, &overlapSize) != 0) { Vec3f leftPos; Vec3f rightPos; Math_Vec3s_ToVec3f(&leftPos, &leftElem->dim.worldSphere.center); Math_Vec3s_ToVec3f(&rightPos, &right->dim.pos); CollisionCheck_SetOCvsOC(play, &left->base, &leftElem->info, &leftPos, &right->base, &right->info, - &rightPos, overlap); + &rightPos, overlapSize); } } } @@ -3099,7 +3100,7 @@ void CollisionCheck_OC_JntSphVsSphere(PlayState* play, CollisionCheckContext* co ColliderJntSph* left = (ColliderJntSph*)l; ColliderSphere* right = (ColliderSphere*)r; ColliderJntSphElement* leftElem; - f32 overlap; + f32 overlapSize; if ((left->count > 0) && (left->elements != NULL) && (left->base.ocFlags1 & OCELEM_ON) && (right->base.ocFlags1 & OCELEM_ON) && (right->info.ocElemFlags & OCELEM_ON)) { @@ -3108,14 +3109,14 @@ void CollisionCheck_OC_JntSphVsSphere(PlayState* play, CollisionCheckContext* co if (!(leftElem->info.ocElemFlags & OCELEM_ON)) { continue; } - if (Math3D_SphVsSphOverlap(&leftElem->dim.worldSphere, &right->dim.worldSphere, &overlap) != 0) { + if (Math3D_SphVsSphOverlap(&leftElem->dim.worldSphere, &right->dim.worldSphere, &overlapSize) != 0) { Vec3f leftPos; Vec3f rightPos; Math_Vec3s_ToVec3f(&leftPos, &leftElem->dim.worldSphere.center); Math_Vec3s_ToVec3f(&rightPos, &right->dim.worldSphere.center); CollisionCheck_SetOCvsOC(play, &left->base, &leftElem->info, &leftPos, &right->base, &right->info, - &rightPos, overlap); + &rightPos, overlapSize); } } } @@ -3134,18 +3135,18 @@ void CollisionCheck_OC_CylVsJntSph(PlayState* play, CollisionCheckContext* colCt void CollisionCheck_OC_CylVsCyl(PlayState* play, CollisionCheckContext* colCtxt, Collider* l, Collider* r) { ColliderCylinder* left = (ColliderCylinder*)l; ColliderCylinder* right = (ColliderCylinder*)r; - f32 overlap; + f32 overlapSize; if ((left->base.ocFlags1 & OCELEM_ON) && (right->base.ocFlags1 & OCELEM_ON) && (left->info.ocElemFlags & OCELEM_ON) && (right->info.ocElemFlags & OCELEM_ON)) { - if (Math3D_CylOutsideCyl(&left->dim, &right->dim, &overlap) != 0) { + if (Math3D_CylVsCylOverlap(&left->dim, &right->dim, &overlapSize) != 0) { Vec3f leftPos; Vec3f rightPos; Math_Vec3s_ToVec3f(&leftPos, &left->dim.pos); Math_Vec3s_ToVec3f(&rightPos, &right->dim.pos); CollisionCheck_SetOCvsOC(play, &left->base, &left->info, &leftPos, &right->base, &right->info, &rightPos, - overlap); + overlapSize); } } } @@ -3156,18 +3157,18 @@ void CollisionCheck_OC_CylVsCyl(PlayState* play, CollisionCheckContext* colCtxt, void CollisionCheck_OC_CylVsSphere(PlayState* play, CollisionCheckContext* colCtxt, Collider* l, Collider* r) { ColliderCylinder* left = (ColliderCylinder*)l; ColliderSphere* right = (ColliderSphere*)r; - f32 overlap; + f32 overlapSize; if ((left->base.ocFlags1 & OCELEM_ON) && (left->info.ocElemFlags & OCELEM_ON) && (right->base.ocFlags1 & OCELEM_ON) && (right->info.ocElemFlags & OCELEM_ON)) { - if (Math3D_SphVsCylOverlapDist(&right->dim.worldSphere, &left->dim, &overlap) != 0) { + if (Math3D_SphVsCylOverlap(&right->dim.worldSphere, &left->dim, &overlapSize) != 0) { Vec3f leftPos; Vec3f rightPos; Math_Vec3s_ToVec3f(&leftPos, &left->dim.pos); Math_Vec3s_ToVec3f(&rightPos, &right->dim.worldSphere.center); CollisionCheck_SetOCvsOC(play, &left->base, &left->info, &leftPos, &right->base, &right->info, &rightPos, - overlap); + overlapSize); } } } @@ -3192,18 +3193,18 @@ void CollisionCheck_OC_SphereVsCyl(PlayState* play, CollisionCheckContext* colCt void CollisionCheck_OC_SphereVsSphere(PlayState* play, CollisionCheckContext* colCtxt, Collider* l, Collider* r) { ColliderSphere* left = (ColliderSphere*)l; ColliderSphere* right = (ColliderSphere*)r; - f32 overlap; + f32 overlapSize; if ((left->base.ocFlags1 & OCELEM_ON) && (left->info.ocElemFlags & OCELEM_ON) && (right->base.ocFlags1 & OCELEM_ON) && (right->info.ocElemFlags & OCELEM_ON)) { - if (Math3D_SphVsSphOverlap(&left->dim.worldSphere, &right->dim.worldSphere, &overlap) != 0) { + if (Math3D_SphVsSphOverlap(&left->dim.worldSphere, &right->dim.worldSphere, &overlapSize) != 0) { Vec3f leftPos; Vec3f rightPos; Math_Vec3s_ToVec3f(&leftPos, &left->dim.worldSphere.center); Math_Vec3s_ToVec3f(&rightPos, &right->dim.worldSphere.center); CollisionCheck_SetOCvsOC(play, &left->base, &left->info, &leftPos, &right->base, &right->info, &rightPos, - overlap); + overlapSize); } } } diff --git a/src/overlays/actors/ovl_Bg_Dblue_Movebg/z_bg_dblue_movebg.c b/src/overlays/actors/ovl_Bg_Dblue_Movebg/z_bg_dblue_movebg.c index be3623f2d..9b25a8e70 100644 --- a/src/overlays/actors/ovl_Bg_Dblue_Movebg/z_bg_dblue_movebg.c +++ b/src/overlays/actors/ovl_Bg_Dblue_Movebg/z_bg_dblue_movebg.c @@ -686,8 +686,8 @@ void func_80A2AED0(BgDblueMovebg* this, PlayState* play) { Vec3f sp54; f32 sp50; - if (Math3D_PointDistToLine2D(play->view.eye.x, play->view.eye.z, this->unk_190.x, this->unk_190.z, - this->unk_19C.x, this->unk_19C.z, &sp54.x, &sp54.z, &sp50)) { + if (Math3D_PointDistSqToLine2DImpl(play->view.eye.x, play->view.eye.z, this->unk_190.x, this->unk_190.z, + this->unk_19C.x, this->unk_19C.z, &sp54.x, &sp54.z, &sp50)) { sp54.y = this->dyna.actor.world.pos.y; } else { if (Math_Vec3f_DistXYZ(&play->view.eye, &this->unk_190) <= diff --git a/src/overlays/actors/ovl_En_Horse/z_en_horse.c b/src/overlays/actors/ovl_En_Horse/z_en_horse.c index 7c368a6c6..d1abeb3e4 100644 --- a/src/overlays/actors/ovl_En_Horse/z_en_horse.c +++ b/src/overlays/actors/ovl_En_Horse/z_en_horse.c @@ -360,7 +360,7 @@ void func_8087B7C0(EnHorse* this, PlayState* play, Path* path) { Math_Vec3s_ToVec3f(&sp80, &spA0[this->curRaceWaypoint - 1]); } - func_8017D7C0(this->actor.world.pos.x, this->actor.world.pos.z, sp80.x, sp80.z, sp8C.x, sp8C.z, &sp70); + Math3D_PointDistSqToLine2D(this->actor.world.pos.x, this->actor.world.pos.z, sp80.x, sp80.z, sp8C.x, sp8C.z, &sp70); if ((this->actor.bgCheckFlags & BGCHECKFLAG_WALL) || (this->unk_1EC & 4)) { EnHorse_RotateToPoint(this, play, &sp8C, 0xC80); diff --git a/src/overlays/actors/ovl_En_Mt_tag/z_en_mt_tag.c b/src/overlays/actors/ovl_En_Mt_tag/z_en_mt_tag.c index fdb0ad051..a04c76f49 100644 --- a/src/overlays/actors/ovl_En_Mt_tag/z_en_mt_tag.c +++ b/src/overlays/actors/ovl_En_Mt_tag/z_en_mt_tag.c @@ -154,7 +154,7 @@ s32 EnMttag_GetCurrentCheckpoint(Actor* actor, PlayState* play, s32* upcomingChe // Iterates through all possible checkpoints that are associated with this sceneExitIndex. do { - if ((Math3D_PointDistToLine2D( + if ((Math3D_PointDistSqToLine2DImpl( actor->world.pos.x, actor->world.pos.z, (&sCheckpointPositions[checkpointIterator])[-1].x, (&sCheckpointPositions[checkpointIterator])[-1].z, (&sCheckpointPositions[checkpointIterator])[1].x, (&sCheckpointPositions[checkpointIterator])[1].z, &perpendicularPointX, &perpendicularPointZ, diff --git a/src/overlays/actors/ovl_En_Rg/z_en_rg.c b/src/overlays/actors/ovl_En_Rg/z_en_rg.c index bdb3acd27..c957f071d 100644 --- a/src/overlays/actors/ovl_En_Rg/z_en_rg.c +++ b/src/overlays/actors/ovl_En_Rg/z_en_rg.c @@ -382,8 +382,8 @@ s32 func_80BF43FC(EnRg* this) { do { SubS_CopyPointFromPathCheckBounds(this->path, phi_s0 - 1, &sp9C); SubS_CopyPointFromPathCheckBounds(this->path, phi_s0 + 1, &sp90); - if (Math3D_PointDistToLine2D(this->actor.world.pos.x, this->actor.world.pos.z, sp9C.x, sp9C.z, sp90.x, sp90.z, - &sp8C, &sp88, &sp84) && + if (Math3D_PointDistSqToLine2DImpl(this->actor.world.pos.x, this->actor.world.pos.z, sp9C.x, sp9C.z, sp90.x, + sp90.z, &sp8C, &sp88, &sp84) && (!phi_s6 || ((phi_s4 + 1) == phi_s0) || (sp84 < phi_f20))) { phi_s6 = 1; phi_f20 = sp84; diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index 6d26128cd..318ca4942 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -3268,9 +3268,9 @@ 0x80179EAC:("Math3D_CosOut",), 0x80179F64:("Math3D_Vec3fReflect",), 0x8017A038:("Math3D_PointInSquare2D",), - 0x8017A09C:("func_8017A09C",), - 0x8017A1D0:("func_8017A1D0",), - 0x8017A304:("func_8017A304",), + 0x8017A09C:("Math3D_CirSquareVsTriSquareXY",), + 0x8017A1D0:("Math3D_CirSquareVsTriSquareYZ",), + 0x8017A304:("Math3D_CirSquareVsTriSquareZX",), 0x8017A438:("Math3D_SphCubeVsTriCube",), 0x8017A5F8:("Math3D_Dist1DSq",), 0x8017A610:("Math3D_Dist1D",), @@ -3324,11 +3324,11 @@ 0x8017D404:("Math3D_TriLineIntersect",), 0x8017D568:("Math3D_TriNorm",), 0x8017D618:("Math3D_PointInSph",), - 0x8017D668:("Math3D_PointDistToLine2D",), - 0x8017D7C0:("func_8017D7C0",), - 0x8017D814:("func_8017D814",), - 0x8017D91C:("func_8017D91C",), - 0x8017DA24:("func_8017DA24",), + 0x8017D668:("Math3D_PointDistSqToLine2DImpl",), + 0x8017D7C0:("Math3D_PointDistSqToLine2D",), + 0x8017D814:("Math3D_PointDistSqToLineXY",), + 0x8017D91C:("Math3D_PointDistSqToLineYZ",), + 0x8017DA24:("Math3D_PointDistSqToLineZX",), 0x8017DB2C:("Math3D_LineVsSph",), 0x8017DD34:("Math3D_GetSphVsTriIntersectPoint",), 0x8017DE74:("Math3D_TriVsSphIntersect",), @@ -3338,11 +3338,11 @@ 0x8017F1A0:("Math3D_CylVsTri",), 0x8017F1C0:("Math3D_SphVsSph",), 0x8017F1E0:("Math3D_SphVsSphOverlap",), - 0x8017F200:("Math3D_SphVsSphOverlapCenter",), - 0x8017F2CC:("Math3D_SphVsCylOverlapDist",), + 0x8017F200:("Math3D_SphVsSphOverlapCenterDist",), + 0x8017F2CC:("Math3D_SphVsCylOverlap",), 0x8017F2EC:("Math3D_SphVsCylOverlapCenterDist",), - 0x8017F45C:("Math3D_CylOutsideCyl",), - 0x8017F47C:("Math3D_CylOutsideCylDist",), + 0x8017F45C:("Math3D_CylVsCylOverlap",), + 0x8017F47C:("Math3D_CylVsCylOverlapCenterDist",), 0x8017F64C:("Math3D_TriVsTriIntersect",), 0x8017F9C0:("Math3D_XZInSphere",), 0x8017FA34:("Math3D_XYInSphere",), diff --git a/tools/disasm/variables.txt b/tools/disasm/variables.txt index 5d6bc3a38..9da2a3ff8 100644 --- a/tools/disasm/variables.txt +++ b/tools/disasm/variables.txt @@ -4060,36 +4060,36 @@ 0x801FBBD2:("gCfbUpperAdjust","UNK_TYPE1","",0x1), 0x801FBBD4:("gSysCfbHiResEnabled","UNK_TYPE1","",0x1), 0x801FBBE0:("sDmaBuffer","u32","[2]",0x8), - 0x801FBBF0:("D_801FBBF0","Vec3f","",0xc), - 0x801FBC00:("D_801FBC00","Linef","",0x18), - 0x801FBC18:("D_801FBC18","Vec3f","",0xc), - 0x801FBC28:("D_801FBC28","Vec3f","",0xC), - 0x801FBC38:("D_801FBC38","Sphere16","",0x8), - 0x801FBC40:("D_801FBC40","Sphere16","",0x8), - 0x801FBC48:("D_801FBC48","Vec3f","",0xC), - 0x801FBC58:("D_801FBC58","Vec3f","",0xC), - 0x801FBC68:("D_801FBC68","Vec3f","",0xc), - 0x801FBC78:("D_801FBC78","Vec3f","",0xc), - 0x801FBC88:("D_801FBC88","Cylinderf","",0x18), - 0x801FBCA0:("D_801FBCA0","Spheref","",0x10), - 0x801FBCB0:("D_801FBCB0","Cylinderf","",0x18), - 0x801FBCC8:("D_801FBCC8","Cylinderf","",0x18), - 0x801FBCE0:("D_801FBCE0","Vec3f","",0xC), - 0x801FBCF0:("D_801FBCF0","Vec3f","",0xC), - 0x801FBD00:("D_801FBD00","Vec3f","",0xC), - 0x801FBD10:("D_801FBD10","Vec3f","",0xC), - 0x801FBD20:("D_801FBD20","Vec3f","",0xC), - 0x801FBD30:("D_801FBD30","Vec3f","",0xC), - 0x801FBD40:("D_801FBD40","Vec3f","",0xC), - 0x801FBD50:("D_801FBD50","Vec3f","",0xC), - 0x801FBD60:("D_801FBD60","Vec3f","",0xC), - 0x801FBD70:("D_801FBD70","Vec3f","",0xC), - 0x801FBD80:("D_801FBD80","InfiniteLine","",0x18), - 0x801FBD98:("D_801FBD98","Linef","",0x18), - 0x801FBDB0:("D_801FBDB0","Vec3f","",0xC), - 0x801FBDC0:("D_801FBDC0","InfiniteLine","",0x18), - 0x801FBDD8:("D_801FBDD8","Vec3f","",0xC), - 0x801FBDE8:("D_801FBDE8","Vec3f","",0xC), + 0x801FBBF0:("sSphereCenter","Vec3f","",0xc), + 0x801FBC00:("sTriTestLine","Linef","",0x18), + 0x801FBC18:("sSphereCenter","Vec3f","",0xc), + 0x801FBC28:("sSphPlanePos","Vec3f","",0xC), + 0x801FBC38:("sTopSphere","Sphere16","",0x8), + 0x801FBC40:("sBottomSphere","Sphere16","",0x8), + 0x801FBC48:("sCylIntersectA","Vec3f","",0xC), + 0x801FBC58:("sCylIntersectB","Vec3f","",0xC), + 0x801FBC68:("sABDiff","Vec3f","",0xc), + 0x801FBC78:("sACDiff","Vec3f","",0xc), + 0x801FBC88:("sCylf","Cylinderf","",0x18), + 0x801FBCA0:("sSphf","Spheref","",0x10), + 0x801FBCB0:("sCaf","Cylinderf","",0x18), + 0x801FBCC8:("sCbf","Cylinderf","",0x18), + 0x801FBCE0:("sTriVtx0","Vec3f","",0xC), + 0x801FBCF0:("sTriVtx1","Vec3f","",0xC), + 0x801FBD00:("sTriVtx2","Vec3f","",0xC), + 0x801FBD10:("sIntersectPoint","Vec3f","",0xC), + 0x801FBD20:("sMinF","Vec3f","",0xC), + 0x801FBD30:("sMaxF","Vec3f","",0xC), + 0x801FBD40:("sAF","Vec3f","",0xC), + 0x801FBD50:("sBF","Vec3f","",0xC), + 0x801FBD60:("sNormal","Vec3f","",0xC), + 0x801FBD70:("sPlanePos","Vec3f","",0xC), + 0x801FBD80:("sPlaneIntersectLine","InfiniteLine","",0x18), + 0x801FBD98:("sPlaneIntersectSeg","Linef","",0x18), + 0x801FBDB0:("sPlanePos","Vec3f","",0xC), + 0x801FBDC0:("sPlaneIntersect","InfiniteLine","",0x18), + 0x801FBDD8:("sSphLinePerpendicularPoint","Vec3f","",0xC), + 0x801FBDE8:("sV0V1Center","Vec3f","",0xC), 0x801FBE00:("sMatrixStack","MtxF*","",0x4), 0x801FBE04:("sCurrentMatrix","MtxF*","",0x4), 0x801FBE10:("sFlashromMesgQueue","UNK_TYPE1","",0x1), diff --git a/tools/namefixer.py b/tools/namefixer.py index 355f58244..6ea350f7f 100755 --- a/tools/namefixer.py +++ b/tools/namefixer.py @@ -548,7 +548,7 @@ wordReplace = { "func_800CA22C": "WaterBox_GetSurface2", "func_800CA6D8": "WaterBox_GetLightSettingIndex", - "func_8017D668": "Math3D_PointDistToLine2D", + "func_8017D668": "Math3D_PointDistSqToLine2DImpl", "func_80179678": "Math3D_PlaneVsLineSegClosestPoint", "Math3D_DistanceSquared": "Math3D_Vec3fDistSq", "Math3D_NormalVector": "Math3D_SurfaceNorm", @@ -590,14 +590,14 @@ wordReplace = { "func_80179B94": "Math3D_PlaneVsPlaneNewLine", "func_8017B9D8": "Math3D_Plane", "func_8017D404": "Math3D_TriLineIntersect", - "Math3D_ColCylinderCylinderAmountAndDistance": "Math3D_CylOutsideCylDist", - "Math3D_ColCylinderCylinderAmount": "Math3D_CylOutsideCyl", + "Math3D_ColCylinderCylinderAmountAndDistance": "Math3D_CylVsCylOverlapCenterDist", + "Math3D_ColCylinderCylinderAmount": "Math3D_CylVsCylOverlap", "Math3D_ColSphereCylinderDistanceAndAmount": "Math3D_SphVsCylOverlapCenterDist", "Math3D_ColCylinderTri": "Math3D_CylTriVsIntersect", "func_8017F1A0": "Math3D_CylVsTri", "Math3D_ColSphereSphereIntersect": "Math3D_SphVsSphOverlap", - "Math3D_ColSphereSphereIntersectAndDistance": "Math3D_SphVsSphOverlapCenter", - "Math3D_ColSphereCylinderDistance": "Math3D_SphVsCylOverlapDist", + "Math3D_ColSphereSphereIntersectAndDistance": "Math3D_SphVsSphOverlapCenterDist", + "Math3D_ColSphereCylinderDistance": "Math3D_SphVsCylOverlap", "func_8017E350": "Math3D_CylVsLineSeg", "Math3D_ColSphereTri": "Math3D_TriVsSphIntersect", "Math3D_ScaleAndAdd": "Math3D_PointOnDirectedLine", diff --git a/tools/sizes/code_functions.csv b/tools/sizes/code_functions.csv index 554dc9608..a42eacd66 100644 --- a/tools/sizes/code_functions.csv +++ b/tools/sizes/code_functions.csv @@ -2782,9 +2782,9 @@ asm/non_matchings/code/sys_math3d/Math3D_Cos.s,Math3D_Cos,0x80179E88,0x9 asm/non_matchings/code/sys_math3d/Math3D_CosOut.s,Math3D_CosOut,0x80179EAC,0x2E asm/non_matchings/code/sys_math3d/Math3D_Vec3fReflect.s,Math3D_Vec3fReflect,0x80179F64,0x35 asm/non_matchings/code/sys_math3d/Math3D_PointInSquare2D.s,Math3D_PointInSquare2D,0x8017A038,0x19 -asm/non_matchings/code/sys_math3d/func_8017A09C.s,func_8017A09C,0x8017A09C,0x4D -asm/non_matchings/code/sys_math3d/func_8017A1D0.s,func_8017A1D0,0x8017A1D0,0x4D -asm/non_matchings/code/sys_math3d/func_8017A304.s,func_8017A304,0x8017A304,0x4D +asm/non_matchings/code/sys_math3d/Math3D_CirSquareVsTriSquareXY.s,Math3D_CirSquareVsTriSquareXY,0x8017A09C,0x4D +asm/non_matchings/code/sys_math3d/Math3D_CirSquareVsTriSquareYZ.s,Math3D_CirSquareVsTriSquareYZ,0x8017A1D0,0x4D +asm/non_matchings/code/sys_math3d/Math3D_CirSquareVsTriSquareZX.s,Math3D_CirSquareVsTriSquareZX,0x8017A304,0x4D asm/non_matchings/code/sys_math3d/Math3D_SphCubeVsTriCube.s,Math3D_SphCubeVsTriCube,0x8017A438,0x70 asm/non_matchings/code/sys_math3d/Math3D_Dist1DSq.s,Math3D_Dist1DSq,0x8017A5F8,0x6 asm/non_matchings/code/sys_math3d/Math3D_Dist1D.s,Math3D_Dist1D,0x8017A610,0x9 @@ -2838,11 +2838,11 @@ asm/non_matchings/code/sys_math3d/Math3D_LineSegVsPlane.s,Math3D_LineSegVsPlane, asm/non_matchings/code/sys_math3d/Math3D_TriLineIntersect.s,Math3D_TriLineIntersect,0x8017D404,0x59 asm/non_matchings/code/sys_math3d/Math3D_TriNorm.s,Math3D_TriNorm,0x8017D568,0x2C asm/non_matchings/code/sys_math3d/Math3D_PointInSph.s,Math3D_PointInSph,0x8017D618,0x14 -asm/non_matchings/code/sys_math3d/Math3D_PointDistToLine2D.s,Math3D_PointDistToLine2D,0x8017D668,0x56 -asm/non_matchings/code/sys_math3d/func_8017D7C0.s,func_8017D7C0,0x8017D7C0,0x15 -asm/non_matchings/code/sys_math3d/func_8017D814.s,func_8017D814,0x8017D814,0x42 -asm/non_matchings/code/sys_math3d/func_8017D91C.s,func_8017D91C,0x8017D91C,0x42 -asm/non_matchings/code/sys_math3d/func_8017DA24.s,func_8017DA24,0x8017DA24,0x42 +asm/non_matchings/code/sys_math3d/Math3D_PointDistSqToLine2DImpl.s,Math3D_PointDistSqToLine2DImpl,0x8017D668,0x56 +asm/non_matchings/code/sys_math3d/Math3D_PointDistSqToLine2D.s,Math3D_PointDistSqToLine2D,0x8017D7C0,0x15 +asm/non_matchings/code/sys_math3d/Math3D_PointDistSqToLineXY.s,Math3D_PointDistSqToLineXY,0x8017D814,0x42 +asm/non_matchings/code/sys_math3d/Math3D_PointDistSqToLineYZ.s,Math3D_PointDistSqToLineYZ,0x8017D91C,0x42 +asm/non_matchings/code/sys_math3d/Math3D_PointDistSqToLineZX.s,Math3D_PointDistSqToLineZX,0x8017DA24,0x42 asm/non_matchings/code/sys_math3d/Math3D_LineVsSph.s,Math3D_LineVsSph,0x8017DB2C,0x82 asm/non_matchings/code/sys_math3d/Math3D_GetSphVsTriIntersectPoint.s,Math3D_GetSphVsTriIntersectPoint,0x8017DD34,0x50 asm/non_matchings/code/sys_math3d/Math3D_TriVsSphIntersect.s,Math3D_TriVsSphIntersect,0x8017DE74,0x108 @@ -2852,11 +2852,11 @@ asm/non_matchings/code/sys_math3d/Math3D_CylTriVsIntersect.s,Math3D_CylTriVsInte asm/non_matchings/code/sys_math3d/Math3D_CylVsTri.s,Math3D_CylVsTri,0x8017F1A0,0x8 asm/non_matchings/code/sys_math3d/Math3D_ColSphereSphere.s,Math3D_ColSphereSphere,0x8017F1C0,0x8 asm/non_matchings/code/sys_math3d/Math3D_SphVsSphOverlap.s,Math3D_SphVsSphOverlap,0x8017F1E0,0x8 -asm/non_matchings/code/sys_math3d/Math3D_SphVsSphOverlapCenter.s,Math3D_SphVsSphOverlapCenter,0x8017F200,0x33 -asm/non_matchings/code/sys_math3d/Math3D_SphVsCylOverlapDist.s,Math3D_SphVsCylOverlapDist,0x8017F2CC,0x8 +asm/non_matchings/code/sys_math3d/Math3D_SphVsSphOverlapCenterDist.s,Math3D_SphVsSphOverlapCenterDist,0x8017F200,0x33 +asm/non_matchings/code/sys_math3d/Math3D_SphVsCylOverlap.s,Math3D_SphVsCylOverlap,0x8017F2CC,0x8 asm/non_matchings/code/sys_math3d/Math3D_SphVsCylOverlapCenterDist.s,Math3D_SphVsCylOverlapCenterDist,0x8017F2EC,0x5C -asm/non_matchings/code/sys_math3d/Math3D_CylOutsideCyl.s,Math3D_CylOutsideCyl,0x8017F45C,0x8 -asm/non_matchings/code/sys_math3d/Math3D_CylOutsideCylDist.s,Math3D_CylOutsideCylDist,0x8017F47C,0x74 +asm/non_matchings/code/sys_math3d/Math3D_CylVsCylOverlap.s,Math3D_CylVsCylOverlap,0x8017F45C,0x8 +asm/non_matchings/code/sys_math3d/Math3D_CylVsCylOverlapCenterDist.s,Math3D_CylVsCylOverlapCenterDist,0x8017F47C,0x74 asm/non_matchings/code/sys_math3d/Math3D_TriVsTriIntersect.s,Math3D_TriVsTriIntersect,0x8017F64C,0xDD asm/non_matchings/code/sys_math3d/Math3D_XZInSphere.s,Math3D_XZInSphere,0x8017F9C0,0x1D asm/non_matchings/code/sys_math3d/Math3D_XYInSphere.s,Math3D_XYInSphere,0x8017FA34,0x1D From 9c2c3f1bb834b4793b58368fc4c6c0aec2df858b Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sun, 22 Oct 2023 03:35:44 +1100 Subject: [PATCH 25/29] cleanup --- include/macros.h | 3 --- include/variables.h | 2 +- src/libultra/gu/cosf.c | 3 ++- src/libultra/gu/sinf.c | 3 ++- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/macros.h b/include/macros.h index bc7439394..9513893bb 100644 --- a/include/macros.h +++ b/include/macros.h @@ -87,9 +87,6 @@ #define VTX_T(x, y, z, s, t, cr, cg, cb, a) \ { { x, y, z }, 0, { s, t }, { cr, cg, cb, a }, } -#define SQ(x) ((x) * (x)) -#define ABS(x) ((x) >= 0 ? (x) : -(x)) -#define ABS_ALT(x) ((x) < 0 ? -(x) : (x)) #define DECR(x) ((x) == 0 ? 0 : --(x)) #define CLAMP(x, min, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x)) diff --git a/include/variables.h b/include/variables.h index 236fe92de..946fc2c06 100644 --- a/include/variables.h +++ b/include/variables.h @@ -1459,7 +1459,7 @@ extern f32 D_801E0134; extern f32 D_801E0138; extern f32 D_801E013C; extern f32 D_801E0140; -extern f32 Math3D_CosOut_min_length; +extern f32 Math3D_AngleBetweenVectors_min_length; extern f32 D_801E0148; extern f32 D_801E014C; extern f32 Math3D_UnitNormalVector_min_length; diff --git a/src/libultra/gu/cosf.c b/src/libultra/gu/cosf.c index 65330e9a6..a738e8b7a 100644 --- a/src/libultra/gu/cosf.c +++ b/src/libultra/gu/cosf.c @@ -1,5 +1,6 @@ #include "libc/math.h" -#include "macros.h" +#include "ultra64.h" +#include "z64math.h" #pragma weak cosf = __cosf diff --git a/src/libultra/gu/sinf.c b/src/libultra/gu/sinf.c index 963bc2022..c18971706 100644 --- a/src/libultra/gu/sinf.c +++ b/src/libultra/gu/sinf.c @@ -1,5 +1,6 @@ #include "libc/math.h" -#include "macros.h" +#include "ultra64.h" +#include "z64math.h" #pragma weak sinf = __sinf From 08035011c80362ac58aa9bd68ba67327b7a5dd26 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sun, 22 Oct 2023 17:27:35 +1100 Subject: [PATCH 26/29] PR Review --- include/z64collision_check.h | 168 +++++++++++++++++------------------ src/code/sys_math3d.c | 2 +- 2 files changed, 85 insertions(+), 85 deletions(-) diff --git a/include/z64collision_check.h b/include/z64collision_check.h index 26c1a3f5b..07f4939b8 100644 --- a/include/z64collision_check.h +++ b/include/z64collision_check.h @@ -10,100 +10,100 @@ struct PlayState; typedef struct { /* 0x00 */ struct Actor* actor; // Attached actor - /* 0x04 */ struct Actor* at; // Actor attached to what it collided with as an AT collider. - /* 0x08 */ struct Actor* ac; // Actor attached to what it collided with as an AC collider. - /* 0x0C */ struct Actor* oc; // Actor attached to what it collided with as an OC collider. - /* 0x10 */ u8 atFlags; // Information flags for AT collisions. - /* 0x11 */ u8 acFlags; // Information flags for AC collisions. - /* 0x12 */ u8 ocFlags1; // Information flags for OC collisions. - /* 0x13 */ u8 ocFlags2; // Flags related to which colliders it can OC collide with. - /* 0x14 */ u8 colType; // Determines hitmarks and sound effects during AC collisions. - /* 0x15 */ u8 shape; // JntSph, Cylinder, Tris, or Quad + /* 0x04 */ struct Actor* at; // Actor attached to what it collided with as an AT collider. + /* 0x08 */ struct Actor* ac; // Actor attached to what it collided with as an AC collider. + /* 0x0C */ struct Actor* oc; // Actor attached to what it collided with as an OC collider. + /* 0x10 */ u8 atFlags; // Information flags for AT collisions. + /* 0x11 */ u8 acFlags; // Information flags for AC collisions. + /* 0x12 */ u8 ocFlags1; // Information flags for OC collisions. + /* 0x13 */ u8 ocFlags2; // Flags related to which colliders it can OC collide with. + /* 0x14 */ u8 colType; // Determines hitmarks and sound effects during AC collisions. + /* 0x15 */ u8 shape; // JntSph, Cylinder, Tris, or Quad } Collider; // size = 0x18 typedef struct { - /* 0x0 */ u8 colType; // Determines hitmarks and sound effects during AC collisions. - /* 0x1 */ u8 atFlags; // Information flags for AT collisions. - /* 0x2 */ u8 acFlags; // Information flags for OC collisions. + /* 0x0 */ u8 colType; // Determines hitmarks and sound effects during AC collisions. + /* 0x1 */ u8 atFlags; // Information flags for AT collisions. + /* 0x2 */ u8 acFlags; // Information flags for OC collisions. /* 0x3 */ u8 ocFlags1; // Information flags for OC collisions. /* 0x4 */ u8 ocFlags2; // Flags related to which colliders it can OC collide with. - /* 0x5 */ u8 shape; // JntSph, Cylinder, Tris, or Quad + /* 0x5 */ u8 shape; // JntSph, Cylinder, Tris, or Quad } ColliderInit; // size = 0x6 typedef struct { - /* 0x0 */ u8 colType; // Determines hitmarks and sound effects during AC collisions. - /* 0x1 */ u8 atFlags; // Information flags for AT collisions. - /* 0x2 */ u8 acFlags; // Information flags for AC collisions. + /* 0x0 */ u8 colType; // Determines hitmarks and sound effects during AC collisions. + /* 0x1 */ u8 atFlags; // Information flags for AT collisions. + /* 0x2 */ u8 acFlags; // Information flags for AC collisions. /* 0x3 */ u8 ocFlags1; // Information flags for OC collisions. - /* 0x4 */ u8 shape; // JntSph, Cylinder, Tris, or Quad + /* 0x4 */ u8 shape; // JntSph, Cylinder, Tris, or Quad } ColliderInitType1; // size = 0x5 typedef struct { /* 0x0 */ struct Actor* actor; // Attached actor - /* 0x4 */ u8 atFlags; // Information flags for AT collisions. - /* 0x5 */ u8 acFlags; // Information flags for AC collisions. - /* 0x6 */ u8 ocFlags1; // Information flags for OC collisions. - /* 0x7 */ u8 shape; // JntSph, Cylinder, Tris, or Quad + /* 0x4 */ u8 atFlags; // Information flags for AT collisions. + /* 0x5 */ u8 acFlags; // Information flags for AC collisions. + /* 0x6 */ u8 ocFlags1; // Information flags for OC collisions. + /* 0x7 */ u8 shape; // JntSph, Cylinder, Tris, or Quad } ColliderInitToActor; // size = 0x8 typedef struct { - /* 0x0 */ u32 dmgFlags; // Toucher damage type flags. - /* 0x4 */ u8 effect; // Damage Effect (Knockback, Fire, etc.) - /* 0x5 */ u8 damage; // Damage or Stun Timer + /* 0x0 */ u32 dmgFlags; // Toucher damage type flags. + /* 0x4 */ u8 effect; // Damage Effect (Knockback, Fire, etc.) + /* 0x5 */ u8 damage; // Damage or Stun Timer } ColliderTouch; // size = 0x8 typedef struct { - /* 0x0 */ u32 dmgFlags; // Toucher damage type flags. - /* 0x4 */ u8 effect; // Damage Effect (Knockback, Fire, etc.) - /* 0x5 */ u8 damage; // Damage or Stun Timer + /* 0x0 */ u32 dmgFlags; // Toucher damage type flags. + /* 0x4 */ u8 effect; // Damage Effect (Knockback, Fire, etc.) + /* 0x5 */ u8 damage; // Damage or Stun Timer } ColliderTouchInit; // size = 0x8 typedef struct { - /* 0x0 */ u32 dmgFlags; // Bumper damage type flags. - /* 0x4 */ u8 effect; // Damage Effect (Knockback, Fire, etc.) - /* 0x5 */ u8 defense; // Damage Resistance - /* 0x6 */ Vec3s hitPos; // Point of contact + /* 0x0 */ u32 dmgFlags; // Bumper damage type flags. + /* 0x4 */ u8 effect; // Damage Effect (Knockback, Fire, etc.) + /* 0x5 */ u8 defense; // Damage Resistance + /* 0x6 */ Vec3s hitPos; // Point of contact } ColliderBump; // size = 0xC typedef struct { - /* 0x0 */ u32 dmgFlags; // Bumper exclusion mask - /* 0x4 */ u8 effect; // Damage Effect (Knockback, Fire, etc.) - /* 0x5 */ u8 defense; // Damage Resistance + /* 0x0 */ u32 dmgFlags; // Bumper exclusion mask + /* 0x4 */ u8 effect; // Damage Effect (Knockback, Fire, etc.) + /* 0x5 */ u8 defense; // Damage Resistance } ColliderBumpInit; // size = 0x8 typedef struct ColliderInfo { - /* 0x00 */ ColliderTouch toucher; // Damage properties when acting as an AT collider - /* 0x08 */ ColliderBump bumper; // Damage properties when acting as an AC collider - /* 0x14 */ u8 elemType; // Affects sfx reaction when attacked by Link and hookability. Full purpose unknown. - /* 0x15 */ u8 toucherFlags; // Information flags for AT collisions - /* 0x16 */ u8 bumperFlags; // Information flags for AC collisions - /* 0x17 */ u8 ocElemFlags; // Information flags for OC collisions - /* 0x18 */ Collider* atHit; // object touching this element's AT collider - /* 0x1C */ Collider* acHit; // object touching this element's AC collider - /* 0x20 */ struct ColliderInfo* atHitInfo; // element that hit the AT collider - /* 0x24 */ struct ColliderInfo* acHitInfo; // element that hit the AC collider + /* 0x00 */ ColliderTouch toucher; // Damage properties when acting as an AT collider + /* 0x08 */ ColliderBump bumper; // Damage properties when acting as an AC collider + /* 0x14 */ u8 elemType; // Affects sfx reaction when attacked by Link and hookability. Full purpose unknown. + /* 0x15 */ u8 toucherFlags; // Information flags for AT collisions + /* 0x16 */ u8 bumperFlags; // Information flags for AC collisions + /* 0x17 */ u8 ocElemFlags; // Information flags for OC collisions + /* 0x18 */ Collider* atHit; // object touching this element's AT collider + /* 0x1C */ Collider* acHit; // object touching this element's AC collider + /* 0x20 */ struct ColliderInfo* atHitInfo; // element that hit the AT collider + /* 0x24 */ struct ColliderInfo* acHitInfo; // element that hit the AC collider } ColliderInfo; // size = 0x28 typedef struct { - /* 0x00 */ u8 elemType; // Affects sfx reaction when attacked by Link and hookability. Full purpose unknown. - /* 0x04 */ ColliderTouchInit toucher; // Damage properties when acting as an AT collider - /* 0x0C */ ColliderBumpInit bumper; // Damage properties when acting as an AC collider - /* 0x14 */ u8 toucherFlags; // Information flags for AT collisions - /* 0x15 */ u8 bumperFlags; // Information flags for AC collisions - /* 0x16 */ u8 ocElemFlags; // Information flags for OC collisions + /* 0x00 */ u8 elemType; // Affects sfx reaction when attacked by Link and hookability. Full purpose unknown. + /* 0x04 */ ColliderTouchInit toucher; // Damage properties when acting as an AT collider + /* 0x0C */ ColliderBumpInit bumper; // Damage properties when acting as an AC collider + /* 0x14 */ u8 toucherFlags; // Information flags for AT collisions + /* 0x15 */ u8 bumperFlags; // Information flags for AC collisions + /* 0x16 */ u8 ocElemFlags; // Information flags for OC collisions } ColliderInfoInit; // size = 0x18 typedef struct { - /* 0x00 */ Sphere16 modelSphere; // model space sphere - /* 0x08 */ Sphere16 worldSphere; // world space sphere - /* 0x10 */ f32 scale; // worldsphere = modelsphere * scale * 0.01 - /* 0x14 */ u8 limb; // attached limb + /* 0x00 */ Sphere16 modelSphere; // model space sphere + /* 0x08 */ Sphere16 worldSphere; // world space sphere + /* 0x10 */ f32 scale; // worldsphere = modelsphere * scale * 0.01 + /* 0x14 */ u8 limb; // attached limb } ColliderJntSphElementDim; // size = 0x18 typedef struct { - /* 0x0 */ u8 limb; // attached limb - /* 0x2 */ Sphere16 modelSphere; // model space sphere - /* 0xA */ s16 scale; // world space sphere = model * scale * 0.01 + /* 0x0 */ u8 limb; // attached limb + /* 0x2 */ Sphere16 modelSphere; // model space sphere + /* 0xA */ s16 scale; // world space sphere = model * scale * 0.01 } ColliderJntSphElementDimInit; // size = 0xC typedef struct { @@ -141,27 +141,27 @@ typedef struct { } ColliderJntSphInitToActor; // size = 0x10 typedef struct { - /* 0x00 */ Collider base; + /* 0x00 */ Collider base; /* 0x18 */ ColliderInfo info; - /* 0x40 */ Cylinder16 dim; + /* 0x40 */ Cylinder16 dim; } ColliderCylinder; // size = 0x4C typedef struct { - /* 0x00 */ ColliderInit base; + /* 0x00 */ ColliderInit base; /* 0x08 */ ColliderInfoInit info; - /* 0x20 */ Cylinder16 dim; + /* 0x20 */ Cylinder16 dim; } ColliderCylinderInit; // size = 0x2C typedef struct { /* 0x00 */ ColliderInitType1 base; - /* 0x08 */ ColliderInfoInit info; - /* 0x20 */ Cylinder16 dim; + /* 0x08 */ ColliderInfoInit info; + /* 0x20 */ Cylinder16 dim; } ColliderCylinderInitType1; // size = 0x2C typedef struct { /* 0x00 */ ColliderInitToActor base; - /* 0x08 */ ColliderInfoInit info; - /* 0x20 */ Cylinder16 dim; + /* 0x08 */ ColliderInfoInit info; + /* 0x20 */ Cylinder16 dim; } ColliderCylinderInitToActor; // size = 0x2C typedef struct { @@ -170,7 +170,7 @@ typedef struct { typedef struct { /* 0x00 */ ColliderInfo info; - /* 0x28 */ TriNorm dim; + /* 0x28 */ TriNorm dim; } ColliderTrisElement; // size = 0x5C typedef struct { @@ -198,9 +198,9 @@ typedef struct { typedef struct { /* 0x00 */ Vec3f quad[4]; - /* 0x30 */ Vec3s dcMid; // midpoint of vectors d, c - /* 0x36 */ Vec3s baMid; // midpoint of vectors b, a - /* 0x3C */ f32 acDist; // distance to nearest AC collision this frame. + /* 0x30 */ Vec3s dcMid; // midpoint of vectors d, c + /* 0x36 */ Vec3s baMid; // midpoint of vectors b, a + /* 0x3C */ f32 acDist; // distance to nearest AC collision this frame. } ColliderQuadDim; // size = 0x40 typedef struct { @@ -208,50 +208,50 @@ typedef struct { } ColliderQuadDimInit; // size = 0x30 typedef struct { - /* 0x00 */ Collider base; - /* 0x18 */ ColliderInfo info; + /* 0x00 */ Collider base; + /* 0x18 */ ColliderInfo info; /* 0x40 */ ColliderQuadDim dim; } ColliderQuad; // size = 0x80 typedef struct { - /* 0x00 */ ColliderInit base; - /* 0x08 */ ColliderInfoInit info; + /* 0x00 */ ColliderInit base; + /* 0x08 */ ColliderInfoInit info; /* 0x20 */ ColliderQuadDimInit dim; } ColliderQuadInit; // size = 0x50 typedef struct { - /* 0x00 */ ColliderInitType1 base; - /* 0x08 */ ColliderInfoInit info; + /* 0x00 */ ColliderInitType1 base; + /* 0x08 */ ColliderInfoInit info; /* 0x20 */ ColliderQuadDimInit dim; } ColliderQuadInitType1; // size = 0x50 typedef struct { - /* 0x00 */ Collider base; + /* 0x00 */ Collider base; /* 0x18 */ ColliderInfo info; /* 0x40 */ ColliderJntSphElementDim dim; } ColliderSphere; // size = 0x58 typedef struct { - /* 0x00 */ ColliderInit base; + /* 0x00 */ ColliderInit base; /* 0x08 */ ColliderInfoInit info; /* 0x20 */ ColliderJntSphElementDimInit dim; } ColliderSphereInit; // size = 0x2C typedef struct { /* 0x00 */ Linef line; - /* 0x18 */ u16 ocFlags; + /* 0x18 */ u16 ocFlags; } OcLine; // size = 0x1C typedef struct { - /* 0x000 */ s16 colATCount; - /* 0x002 */ u16 sacFlags; // Controls whether new collidors can be added or removed, or only swapped + /* 0x000 */ s16 colATCount; + /* 0x002 */ u16 sacFlags; // Controls whether new collidors can be added or removed, or only swapped /* 0x004 */ Collider* colAT[50]; - /* 0x0CC */ s32 colACCount; + /* 0x0CC */ s32 colACCount; /* 0x0D0 */ Collider* colAC[60]; - /* 0x1C0 */ s32 colOCCount; + /* 0x1C0 */ s32 colOCCount; /* 0x1C4 */ Collider* colOC[50]; - /* 0x28C */ s32 colLineCount; - /* 0x290 */ OcLine* colLine[3]; + /* 0x28C */ s32 colLineCount; + /* 0x290 */ OcLine* colLine[3]; } CollisionCheckContext; // size = 0x29C typedef struct { diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c index 076ed9e38..3710c1e1e 100644 --- a/src/code/sys_math3d.c +++ b/src/code/sys_math3d.c @@ -247,7 +247,7 @@ f32 Math3D_Cos(Vec3f* a, Vec3f* b) { } /** - * Calculates the cosine between vectors `a` and `b` and places the result in `ret` + * Calculates the cosine between vectors `a` and `b` and places the result in `dst` * returns true if the cosine cannot be calculated because the product of the magnitudes is zero */ s32 Math3D_CosOut(Vec3f* a, Vec3f* b, f32* dst) { From 986e34c03664274d29c0fc9af07636e78ad2d997 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Wed, 25 Oct 2023 12:50:39 +1100 Subject: [PATCH 27/29] cleanup --- src/code/z_eff_tire_mark.c | 4 ++-- src/overlays/actors/ovl_En_Mt_tag/z_en_mt_tag.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/code/z_eff_tire_mark.c b/src/code/z_eff_tire_mark.c index 5e8781a84..6747fbc98 100644 --- a/src/code/z_eff_tire_mark.c +++ b/src/code/z_eff_tire_mark.c @@ -57,8 +57,8 @@ void func_800AE930(CollisionContext* colCtx, EffectTireMark* this, Vec3f* pos, f sp48.y = spB8.y; sp48.z = spB8.z; - if ((Math3D_LineSegMakePerpLineSeg(&sp84, &sp90, &sp54, &sp60, &sp6C, &sp30) != 0) && - (Math3D_LineSegMakePerpLineSeg(&sp84, &sp90, &sp3C, &sp48, &sp78, &sp30) != 0)) { + if (Math3D_LineSegMakePerpLineSeg(&sp84, &sp90, &sp54, &sp60, &sp6C, &sp30) && + Math3D_LineSegMakePerpLineSeg(&sp84, &sp90, &sp3C, &sp48, &sp78, &sp30)) { if (!(spAC->flags & 2)) { spAC->flags |= 1; } diff --git a/src/overlays/actors/ovl_En_Mt_tag/z_en_mt_tag.c b/src/overlays/actors/ovl_En_Mt_tag/z_en_mt_tag.c index a04c76f49..28d9f818e 100644 --- a/src/overlays/actors/ovl_En_Mt_tag/z_en_mt_tag.c +++ b/src/overlays/actors/ovl_En_Mt_tag/z_en_mt_tag.c @@ -154,11 +154,11 @@ s32 EnMttag_GetCurrentCheckpoint(Actor* actor, PlayState* play, s32* upcomingChe // Iterates through all possible checkpoints that are associated with this sceneExitIndex. do { - if ((Math3D_PointDistSqToLine2DImpl( + if (Math3D_PointDistSqToLine2DImpl( actor->world.pos.x, actor->world.pos.z, (&sCheckpointPositions[checkpointIterator])[-1].x, (&sCheckpointPositions[checkpointIterator])[-1].z, (&sCheckpointPositions[checkpointIterator])[1].x, (&sCheckpointPositions[checkpointIterator])[1].z, &perpendicularPointX, &perpendicularPointZ, - &lineLenSq)) && + &lineLenSq) && (!hasSetCurrentCheckpointOnce || ((curentCheckpoint + 1) == checkpointIterator) || (lineLenSq < minLineLengthSq))) { minLineLengthSq = lineLenSq; From 0350836d94c83f681bbe1803f7b9427324fbf307 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sat, 28 Oct 2023 08:11:01 +1100 Subject: [PATCH 28/29] fix merge --- src/code/z_message.c | 1 + src/libultra/gu/lookat.c | 2 +- src/libultra/gu/lookathil.c | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/code/z_message.c b/src/code/z_message.c index 4bc104fec..dff2aac01 100644 --- a/src/code/z_message.c +++ b/src/code/z_message.c @@ -1,3 +1,4 @@ +#include "prevent_bss_reordering.h" #include "global.h" #include "z64horse.h" #include "z64shrink_window.h" diff --git a/src/libultra/gu/lookat.c b/src/libultra/gu/lookat.c index 692bb089a..09aa16310 100644 --- a/src/libultra/gu/lookat.c +++ b/src/libultra/gu/lookat.c @@ -1,5 +1,5 @@ #include "ultra64.h" -#include "macros.h" +#include "z64math.h" void guLookAtF(f32 mf[4][4], f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp) { f32 length; diff --git a/src/libultra/gu/lookathil.c b/src/libultra/gu/lookathil.c index ef8b443db..366e6d9f2 100644 --- a/src/libultra/gu/lookathil.c +++ b/src/libultra/gu/lookathil.c @@ -1,5 +1,5 @@ #include "ultra64.h" -#include "macros.h" +#include "z64math.h" void guLookAtHiliteF(f32 mf[4][4], LookAt* l, Hilite* h, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp, f32 xl1, f32 yl1, f32 zl1, /* light 1 direction */ From aba8eed3f086fc03ba5ba95afc38ab78f8dbd48d Mon Sep 17 00:00:00 2001 From: angie Date: Tue, 31 Oct 2023 09:54:15 -0300 Subject: [PATCH 29/29] fix merge --- src/code/z_kankyo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c index 0326dcd24..67329548a 100644 --- a/src/code/z_kankyo.c +++ b/src/code/z_kankyo.c @@ -1874,7 +1874,7 @@ void Environment_DrawLensFlare(PlayState* play, EnvironmentContext* envCtx, View OPEN_DISPS(gfxCtx); - dist = Math3D_Distance(&pos, &view->eye) / 12.0f; + dist = Math3D_Vec3f_DistXYZ(&pos, &view->eye) / 12.0f; // compute a unit vector in the look direction tempX = view->at.x - view->eye.x;