summaryrefslogtreecommitdiff
path: root/src/code
diff options
context:
space:
mode:
authorpetrie911 <69443847+petrie911@users.noreply.github.com>2020-12-27 10:13:38 -0600
committerGitHub <noreply@github.com>2020-12-27 11:13:38 -0500
commit3727cc38b8c6567d843845041ba0113fb195d931 (patch)
tree82355bcd72b93a7ff80e6de929a1496fa0b620ca /src/code
parentb95643b3978cce2d1557606d111d925e9d3aade9 (diff)
matched Math3D_CylVsLineSeg and fixed a Math_ error (#564)
* matched cylvsline * slight name adjustment * format * and asm * comment cleanup * fixed misspelling and added mathfixer tool * formatting Co-authored-by: petrie911 <pmontag@DESKTOP-LG8A167.localdomain>
Diffstat (limited to 'src/code')
-rw-r--r--src/code/sys_math3d.c336
-rw-r--r--src/code/z_collision_check.c139
-rw-r--r--src/code/z_en_item00.c6
-rw-r--r--src/code/z_lib.c2
4 files changed, 219 insertions, 264 deletions
diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c
index 04a7fa864..6ca814f36 100644
--- a/src/code/sys_math3d.c
+++ b/src/code/sys_math3d.c
@@ -62,6 +62,11 @@ s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f*
Vec3f lineABPointADiff;
f32 t;
f32 t2;
+ f32 tempf1;
+ f32 tempf2;
+ f32 tempf3;
+ f32 tempf4;
+ f32 tempf5;
lineADiff.x = lineAPointB->x - lineAPointA->x;
lineADiff.y = lineAPointB->y - lineAPointA->y;
@@ -70,21 +75,18 @@ s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f*
lineBDiff.y = lineBPointB->y - lineBPointA->y;
lineBDiff.z = lineBPointB->z - lineBPointA->z;
- if (IS_ZERO(SQ(lineBDiff.x) + SQ(lineBDiff.y) + SQ(lineBDiff.z))) {
+ if (IS_ZERO(SQXYZ(lineBDiff))) {
return false;
}
-
- sp5C = ((lineADiff.x * lineBDiff.x) + (lineADiff.y * lineBDiff.y) + (lineADiff.z * lineBDiff.z)) *
- (1.0f / (SQ(lineBDiff.x) + SQ(lineBDiff.y) + SQ(lineBDiff.z)));
+ tempf1 = 1.0f / SQXYZ(lineBDiff);
+ sp5C = DOTXYZ(lineADiff, lineBDiff) * tempf1;
lineABPointADiff.x = lineAPointA->x - lineBPointA->x;
lineABPointADiff.y = lineAPointA->y - lineBPointA->y;
lineABPointADiff.z = lineAPointA->z - lineBPointA->z;
// most reordering is here.
- temp_f18 =
- ((lineABPointADiff.x * lineBDiff.x) + (lineABPointADiff.y * lineBDiff.y) + (lineABPointADiff.z * lineBDiff.z)) *
- (1.0f / (SQ(lineBDiff.x) + SQ(lineBDiff.y) + SQ(lineBDiff.z)));
+ temp_f18 = DOTXYZ(lineABPointADiff, lineBDiff) * tempf1;
sp4C = lineADiff.x - (lineBDiff.x * sp5C);
sp50 = lineADiff.y - (lineBDiff.y * sp5C);
@@ -92,7 +94,6 @@ s32 Math3D_LineSegMakePerpLineSeg(Vec3f* lineAPointA, Vec3f* lineAPointB, Vec3f*
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))) +
@@ -1624,72 +1625,28 @@ s32 Math3D_PointInCyl(Cylinder16* cyl, Vec3f* point) {
}
}
-#ifdef NON_MATCHING
s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, Vec3f* intersectA, Vec3f* intersectB) {
- Vec3f pointACylBottomDiff;
- Vec3f pointBCylBottomDiff;
- Vec3f spD4;
- f32 spD0;
- f32 spCC;
- f32 spB8;
- s32 sp9C;
- Vec3f sp6C[4];
- s32 sp68;
- f32 sp4C;
- f32 sp2C;
- f32 sp28;
- f32* temp_a0;
- f32* temp_a1;
- f32* temp_s0;
- f32 temp_f0;
- f32 temp_f0_2;
- f32 temp_f0_3;
- f32 temp_f0_4;
- f32 temp_f0_5;
- f32 temp_f0_6;
- f32 temp_f10;
- f32 temp_f12;
- f32 temp_f12_2;
+ Vec3f cylToPtA;
+ Vec3f cylToPtB;
+ Vec3f ptAToPtB;
+ f32 fracA;
+ f32 fracB;
+ f32 fracBase;
+ f32 zero = 0.0f;
+ f32 pad;
f32 cylRadiusSq;
- f32 temp_f14_2;
- f32 temp_f14_3;
- f32 temp_f16;
- f32 temp_f16_2;
- f32 temp_f18;
- f32 temp_f2;
- f32 temp_f2_2;
- f32 temp_f2_3;
- f32 temp_f2_4;
- f32 temp_f2_5;
- f32 temp_f2_6;
- f32 temp_f2_7;
- s32 temp_a0_2;
- s32 temp_t0;
- s32 temp_v0;
- s32 temp_v1;
- void* temp_t2;
- s32 phi_a1;
- s32 phi_a1_2;
- f32 phi_f2;
- s32 phi_v0;
- s32 phi_v0_2;
- s32 phi_v1;
- s32 phi_v1_2;
- s32 phi_a2;
- s32 phi_a1_3;
- s32 phi_a2_2;
- s32 phi_a1_4;
- s32 phi_v0_3;
- s32 phi_t0;
- s32 phi_v1_3;
- s32 phi_v1_4;
- s32 phi_a2_3;
- s32 phi_a2_4;
- s32 phi_t0_2;
- s32 phi_v1_5;
- s32 phi_t0_3;
-
- sp9C = 0;
+ 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;
@@ -1697,151 +1654,158 @@ s32 Math3D_CylVsLineSeg(Cylinder16* cyl, Vec3f* linePointA, Vec3f* linePointB, V
return 2;
}
- pointACylBottomDiff.x = linePointA->x - cyl->pos.x;
- pointACylBottomDiff.y = linePointA->y - cyl->pos.y - cyl->yShift;
- pointACylBottomDiff.z = linePointA->z - cyl->pos.z;
- pointBCylBottomDiff.x = linePointB->x - cyl->pos.x;
- pointBCylBottomDiff.y = linePointB->y - cyl->pos.y - cyl->yShift;
- pointBCylBottomDiff.z = linePointB->z - cyl->pos.z;
- Math_Vec3f_Diff(&pointBCylBottomDiff, &pointACylBottomDiff, &spD4);
+ 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);
- if (!IS_ZERO(spD4.y)) {
- if (1) {}
- if ((-pointACylBottomDiff.y / spD4.y) >= 0.0f) {
- if ((-pointACylBottomDiff.y / spD4.y) <= 1.0f) {
- if ((SQ((spD4.x * (-pointACylBottomDiff.y / spD4.y)) + pointACylBottomDiff.x) +
- SQ((spD4.z * (-pointACylBottomDiff.y / spD4.y)) + pointACylBottomDiff.z)) < cylRadiusSq) {
- sp6C[0].x =
- (f32)cyl->pos.x + ((spD4.x * (-pointACylBottomDiff.y / spD4.y)) + pointACylBottomDiff.x);
- sp6C[0].y = (f32)cyl->pos.y + (f32)cyl->yShift;
- sp6C[0].z =
- (f32)cyl->pos.z + ((spD4.z * (-pointACylBottomDiff.y / spD4.y)) + pointACylBottomDiff.z);
- sp9C |= 1;
- }
+
+ /**
+ * 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;
}
}
-
- phi_f2 = ((cyl->height - pointACylBottomDiff.y) / spD4.y);
- if (phi_f2 >= 0.0f) {
- if (phi_f2 <= 1.0f) {
- if ((SQ(pointACylBottomDiff.x + (spD4.x * phi_f2)) + SQ(pointACylBottomDiff.z + (spD4.z * phi_f2))) <
- cylRadiusSq) {
- sp6C[1].x = (f32)cyl->pos.x + pointACylBottomDiff.x + (spD4.x * phi_f2);
- sp6C[1].y = (f32)cyl->pos.y + cyl->height + cyl->yShift;
- sp6C[1].z = (f32)cyl->pos.z + pointACylBottomDiff.z + (spD4.x * phi_f2);
- sp9C |= 2;
- }
+ // 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;
}
}
}
-
- spB8 = SQ(pointACylBottomDiff.x) + SQ(pointACylBottomDiff.z) - cylRadiusSq; // 498c
- temp_f12_2 = SQ(spD4.z) + SQ(spD4.x);
- temp_f18 = temp_f12_2 * 2.0f;
- if (!IS_ZERO(temp_f18)) {
- temp_f2_3 = (spD4.x * pointACylBottomDiff.x) + (spD4.z * pointACylBottomDiff.z);
- temp_f14_2 = temp_f2_3 + temp_f2_3;
- temp_f0_3 = temp_f14_2 * temp_f14_2;
- temp_f16_2 = (4.0f * temp_f12_2) * spB8;
- if (temp_f0_3 < temp_f16_2) {
- return false;
+ /**
+ * 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;
}
-
- phi_a1 = (temp_f0_3 - temp_f16_2) > 0.0f;
- phi_f2 = (sqrtf((temp_f0_3 - temp_f16_2)) - temp_f14_2) / temp_f18;
-
- if (phi_a1) {
- spCC = (-temp_f14_2 - sqrtf((temp_f0_3 - temp_f16_2))) / temp_f18;
+ 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;
}
- } else if (!IS_ZERO(((spD4.x * pointACylBottomDiff.x) + (spD4.z * pointACylBottomDiff.z)) +
- ((spD4.x * pointACylBottomDiff.x) + (spD4.z * pointACylBottomDiff.z)))) {
- phi_f2 = -spB8 / ((spD4.x * pointACylBottomDiff.x) + (spD4.z * pointACylBottomDiff.z)) +
- ((spD4.x * pointACylBottomDiff.x) + (spD4.z * pointACylBottomDiff.z));
- phi_a2 = 1;
- phi_a1 = 0;
+ distCent2 = sqrtf(SQ(dot2AB) - (4.0f * SQXZ(ptAToPtB) * radSqDiff));
+ if (sideIntA == 1) {
+ // fraction of length along AB for side intersection closer to A
+ fracA = (distCent2 - dot2AB) / (2.0f * SQXZ(ptAToPtB));
+ }
+ if (sideIntB == 1) {
+ // 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;
}
-
- if (!phi_a1) {
- if (phi_f2 < 0.0f || phi_f2 > 1.0f) {
- return false;
+ // checks for intersection points outside the bounds of the segment
+ if (!sideIntB) {
+ if (fracA < 0.0f || 1.0f < fracA) {
+ return 0;
}
} else {
- phi_a2 = phi_f2 < 0.0f || phi_f2 > 1.0f;
-
- phi_a1 = spCC < 0.0f || spCC > 1.0f;
-
- if (phi_a1 && phi_a2) {
+ intBeyondA = fracA < 0.0f || 1.0f < fracA;
+ intBeyondB = fracB < 0.0f || 1.0f < fracB;
+ if (intBeyondA && intBeyondB) {
return 0;
}
-
- if (phi_a2) {
- phi_a2 = 0;
+ if (intBeyondA) {
+ sideIntA = 0;
}
-
- if (phi_a1) {
- phi_a1 = 0;
+ if (intBeyondB) {
+ sideIntB = 0;
}
}
-
- if ((phi_a2 == 1) && (((phi_f2 * spD4.y) + pointACylBottomDiff.y) < 0.0f ||
- cyl->height < ((phi_f2 * spD4.y) + pointACylBottomDiff.y))) {
- phi_a2 = 0;
+ // checks for intersection points outside the bounds of the cylinder
+ if ((sideIntA == 1) &&
+ ((fracA * ptAToPtB.y + cylToPtA.y) < 0.0f || cyl->height < (fracA * ptAToPtB.y + cylToPtA.y))) {
+ sideIntA = 0;
}
-
- if ((phi_a1 == 1) &&
- (((spCC * spD4.y) + pointACylBottomDiff.y) < 0.0f || cyl->height < ((spCC * spD4.y) + pointACylBottomDiff.y))) {
- phi_a1 = 0;
+ if ((sideIntB == 1) &&
+ ((fracB * ptAToPtB.y + cylToPtA.y) < 0.0f || cyl->height < (fracB * ptAToPtB.y + cylToPtA.y))) {
+ sideIntB = 0;
}
- if (phi_a2 == 0 && phi_a1 == 0) {
+ if (sideIntA == 0 && sideIntB == 0) {
return 0;
}
-
- if (phi_a2 == 1 && phi_a1 == 1) {
- sp6C[2].x = ((phi_f2 * spD4.x) + pointACylBottomDiff.x) + (f32)cyl->pos.x;
- sp6C[2].y = (((phi_f2 * spD4.y) + pointACylBottomDiff.y) + (f32)cyl->pos.y) + (f32)cyl->yShift;
- sp6C[2].z = ((phi_f2 * spD4.z) + pointACylBottomDiff.z) + (f32)cyl->pos.z;
- sp6C[2].x = ((spCC * spD4.x) + pointACylBottomDiff.x) + (f32)cyl->pos.x;
- sp6C[2].y = (((spCC * spD4.y) + pointACylBottomDiff.y) + (f32)cyl->pos.y) + (f32)cyl->yShift;
- sp6C[2].z = ((spCC * spD4.z) + pointACylBottomDiff.z) + (f32)cyl->pos.z;
- sp9C = (sp9C | 4) | 8;
- } else if (phi_a2 == 1) {
- sp6C[2].x = ((phi_f2 * spD4.x) + pointACylBottomDiff.x) + (f32)cyl->pos.x;
- sp6C[2].y = (((phi_f2 * spD4.y) + pointACylBottomDiff.y) + (f32)cyl->pos.y) + (f32)cyl->yShift;
- sp6C[2].z = ((phi_f2 * spD4.z) + pointACylBottomDiff.z) + (f32)cyl->pos.z;
- sp9C |= 4;
- } else if (phi_a1 == 1) {
- sp6C[2].x = ((spCC * spD4.x) + pointACylBottomDiff.x) + (f32)cyl->pos.x;
- sp6C[2].y = (((spCC * spD4.y) + pointACylBottomDiff.y) + (f32)cyl->pos.y) + (f32)cyl->yShift;
- sp6C[2].z = ((spCC * spD4.z) + pointACylBottomDiff.z) + (f32)cyl->pos.z;
- sp9C |= 4;
- }
-
- for (phi_v0_3 = 0, phi_v1_3 = 0; phi_v0_3 < 4; phi_v0_3++) {
- if (sp9C & (1 << phi_v0_3)) {
- if (phi_v1_3 == 0) {
- *intersectA = sp6C[phi_v0_3];
- } else if (phi_v1_3 == 1) {
- if (Math3D_Vec3fDistSq(intersectA, linePointA) < Math3D_Vec3fDistSq(intersectA, &sp6C[phi_v0_3])) {
- *intersectB = sp6C[phi_v0_3];
+ // Adds intersection points to intPts and sets side A and side B flags
+ if (sideIntA == 1 && sideIntB == 1) {
+ 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 == 1) {
+ 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 == 1) {
+ 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 = sp6C[phi_v0_3];
+ *intersectA = intPts[i];
}
break;
}
+ count++;
}
- phi_v1_3++;
}
-
- return phi_v1_3;
+ return count;
}
-#else
-#pragma GLOBAL_ASM("asm/non_matchings/code/sys_math3d/Math3D_CylVsLineSeg.s")
-#endif
-
/*
* Determines if `cyl` and `tri` are touching. The point of intersection
* is placed in `intersect` Returns 1 if they are touching, 0 otherwise.
diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c
index 42772dfdd..0bb44587d 100644
--- a/src/code/z_collision_check.c
+++ b/src/code/z_collision_check.c
@@ -3160,9 +3160,6 @@ void func_80062E14(GlobalContext* globalCtx, Vec3f* v, Vec3f* arg2) {
Audio_PlaySoundGeneral(NA_SE_IT_REFLECTION_WOOD, arg2, 4, &D_801333E0, &D_801333E0, &D_801333E8);
}
-#define SQXZ(vec) (SQ(vec.x) + SQ(vec.z))
-#define DOTXZ(vec1, vec2) ((vec1.x) * (vec2.x) + (vec1.z) * (vec2.z))
-
/*
* Determines if the line segment connecting itemPos and itemProjPos intersects the side of a cylinder with the given
* radius, height, and offset at actorPos. Returns 3 if either endpoint is inside the cylinder, otherwise returns the
@@ -3174,18 +3171,18 @@ s32 func_80062ECC(f32 radius, f32 height, f32 offset, Vec3f* actorPos, Vec3f* it
Vec3f actorToItem;
Vec3f actorToItemProj;
Vec3f itemStep;
- f32 sp50;
- f32 sp4C;
- u32 phi_v0;
- u32 phi_v1;
- u32 phi_a1;
- u32 phi_a2;
- f32 sp38;
- f32 temp_f14;
- f32 temp_f2;
+ f32 frac1;
+ f32 frac2;
+ u32 intersect2;
+ u32 intersect1;
+ u32 test1;
+ u32 test2;
+ f32 radSqDiff;
+ f32 actorDotItemXZ;
f32 zero = 0.0f;
- f32 temp_f0;
- f32 pad;
+ f32 closeDist;
+ s32 pad1;
+ s32 pad2;
actorToItem.x = itemPos->x - actorPos->x;
actorToItem.y = itemPos->y - actorPos->y - offset;
@@ -3199,54 +3196,51 @@ s32 func_80062ECC(f32 radius, f32 height, f32 offset, Vec3f* actorPos, Vec3f* it
itemStep.y = actorToItemProj.y - actorToItem.y;
itemStep.z = actorToItemProj.z - actorToItem.z;
- if ((actorToItem.y > 0.0f) && (actorToItem.y < height) && (sqrtf(SQ(actorToItem.x) + SQ(actorToItem.z)) < radius)) {
+ if ((actorToItem.y > 0.0f) && (actorToItem.y < height) && (sqrtf(SQXZ(actorToItem)) < radius)) {
return 3;
}
- if ((actorToItemProj.y > 0.0f) && (actorToItemProj.y < height) &&
- (sqrtf(SQ(actorToItemProj.x) + SQ(actorToItemProj.z)) < radius)) {
+ if ((actorToItemProj.y > 0.0f) && (actorToItemProj.y < height) && (sqrtf(SQXZ(actorToItemProj)) < radius)) {
return 3;
}
- sp38 = SQXZ(actorToItem) - SQ(radius);
- temp_f2 = SQXZ(itemStep);
- if (!IS_ZERO(temp_f2)) {
- temp_f14 = DOTXZ(2.0f * itemStep, actorToItem);
- if (SQ(temp_f14) < (4.0f * temp_f2) * sp38) {
+ radSqDiff = SQXZ(actorToItem) - SQ(radius);
+ if (!IS_ZERO(SQXZ(itemStep))) {
+ actorDotItemXZ = DOTXZ(2.0f * itemStep, actorToItem);
+ if (SQ(actorDotItemXZ) < (4.0f * SQXZ(itemStep) * radSqDiff)) {
return 0;
}
- if (SQ(temp_f14) - ((4.0f * temp_f2) * sp38) > zero) {
- phi_v1 = phi_v0 = 1;
+ if (SQ(actorDotItemXZ) - (4.0f * SQXZ(itemStep) * radSqDiff) > zero) {
+ intersect1 = intersect2 = 1;
} else {
- phi_v1 = 1;
- phi_v0 = 0;
+ intersect1 = 1;
+ intersect2 = 0;
}
- temp_f0 = sqrtf(SQ(temp_f14) - (4.0f * temp_f2) * sp38);
- if (phi_v1 == 1) {
- sp50 = (temp_f0 - temp_f14) / (2.0f * temp_f2);
+ closeDist = sqrtf(SQ(actorDotItemXZ) - (4.0f * SQXZ(itemStep) * radSqDiff));
+ if (intersect1 == 1) {
+ frac1 = (closeDist - actorDotItemXZ) / (2.0f * SQXZ(itemStep));
}
- if (phi_v0 == 1) {
- sp4C = (-temp_f14 - temp_f0) / (2.0f * temp_f2);
+ if (intersect2 == 1) {
+ frac2 = (-actorDotItemXZ - closeDist) / (2.0f * SQXZ(itemStep));
}
-
} else if (!IS_ZERO(DOTXZ(2.0f * itemStep, actorToItem))) {
- phi_v1 = 1;
- phi_v0 = 0;
- sp50 = -sp38 / DOTXZ(2.0f * itemStep, actorToItem);
+ intersect1 = 1;
+ intersect2 = 0;
+ frac1 = -radSqDiff / DOTXZ(2.0f * itemStep, actorToItem);
} else {
- if (sp38 <= 0.0f) {
- phi_a1 = (0.0f < actorToItem.y) && (actorToItem.y < height);
- phi_a2 = (0.0f < actorToItemProj.y) && (actorToItemProj.y < height);
+ if (radSqDiff <= 0.0f) {
+ test1 = (0.0f < actorToItem.y) && (actorToItem.y < height);
+ test2 = (0.0f < actorToItemProj.y) && (actorToItemProj.y < height);
- if (phi_a1 && phi_a2) {
+ if (test1 && test2) {
*out1 = actorToItem;
*out2 = actorToItemProj;
return 2;
}
- if (phi_a1) {
+ if (test1) {
*out1 = actorToItem;
return 1;
}
- if (phi_a2) {
+ if (test2) {
*out1 = actorToItemProj;
return 1;
}
@@ -3254,58 +3248,57 @@ s32 func_80062ECC(f32 radius, f32 height, f32 offset, Vec3f* actorPos, Vec3f* it
return 0;
}
- if (phi_v0 == 0) {
- if (sp50 < 0.0f || 1.0f < sp50) {
+ if (intersect2 == 0) {
+ if (frac1 < 0.0f || 1.0f < frac1) {
return 0;
}
} else {
- phi_a1 = (sp50 < 0.0f || 1.0f < sp50);
- phi_a2 = (sp4C < 0.0f || 1.0f < sp4C);
+ test1 = (frac1 < 0.0f || 1.0f < frac1);
+ test2 = (frac2 < 0.0f || 1.0f < frac2);
- if (phi_a1 && phi_a2) {
+ if (test1 && test2) {
return 0;
}
- if (phi_a1) {
- phi_v1 = 0;
+ if (test1) {
+ intersect1 = 0;
}
- if (phi_a2) {
- phi_v0 = 0;
+ if (test2) {
+ intersect2 = 0;
}
}
- if ((phi_v1 == 1) && ((sp50 * itemStep.y + actorToItem.y < 0.0f) || (height < sp50 * itemStep.y + actorToItem.y))) {
- phi_v1 = 0;
+ if ((intersect1 == 1) &&
+ ((frac1 * itemStep.y + actorToItem.y < 0.0f) || (height < frac1 * itemStep.y + actorToItem.y))) {
+ intersect1 = 0;
}
- if ((phi_v0 == 1) && ((sp4C * itemStep.y + actorToItem.y < 0.0f) || (height < sp4C * itemStep.y + actorToItem.y))) {
- phi_v0 = 0;
+ if ((intersect2 == 1) &&
+ ((frac2 * itemStep.y + actorToItem.y < 0.0f) || (height < frac2 * itemStep.y + actorToItem.y))) {
+ intersect2 = 0;
}
- if (phi_v1 == 0 && phi_v0 == 0) {
+ if (intersect1 == 0 && intersect2 == 0) {
return 0;
- } else if ((phi_v1 == 1) && (phi_v0 == 1)) {
- out1->x = sp50 * itemStep.x + actorToItem.x + actorPos->x;
- out1->y = sp50 * itemStep.y + actorToItem.y + actorPos->y;
- out1->z = sp50 * itemStep.z + actorToItem.z + actorPos->z;
- out2->x = sp4C * itemStep.x + actorToItem.x + actorPos->x;
- out2->y = sp4C * itemStep.y + actorToItem.y + actorPos->y;
- out2->z = sp4C * itemStep.z + actorToItem.z + actorPos->z;
+ } else if ((intersect1 == 1) && (intersect2 == 1)) {
+ out1->x = frac1 * itemStep.x + actorToItem.x + actorPos->x;
+ out1->y = frac1 * itemStep.y + actorToItem.y + actorPos->y;
+ out1->z = frac1 * itemStep.z + actorToItem.z + actorPos->z;
+ out2->x = frac2 * itemStep.x + actorToItem.x + actorPos->x;
+ out2->y = frac2 * itemStep.y + actorToItem.y + actorPos->y;
+ out2->z = frac2 * itemStep.z + actorToItem.z + actorPos->z;
return 2;
- } else if (phi_v1 == 1) {
- out1->x = sp50 * itemStep.x + actorToItem.x + actorPos->x;
- out1->y = sp50 * itemStep.y + actorToItem.y + actorPos->y;
- out1->z = sp50 * itemStep.z + actorToItem.z + actorPos->z;
+ } else if (intersect1 == 1) {
+ out1->x = frac1 * itemStep.x + actorToItem.x + actorPos->x;
+ out1->y = frac1 * itemStep.y + actorToItem.y + actorPos->y;
+ out1->z = frac1 * itemStep.z + actorToItem.z + actorPos->z;
return 1;
- } else if (phi_v0 == 1) {
- out1->x = sp4C * itemStep.x + actorToItem.x + actorPos->x;
- out1->y = sp4C * itemStep.y + actorToItem.y + actorPos->y;
- out1->z = sp4C * itemStep.z + actorToItem.z + actorPos->z;
+ } else if (intersect2 == 1) {
+ out1->x = frac2 * itemStep.x + actorToItem.x + actorPos->x;
+ out1->y = frac2 * itemStep.y + actorToItem.y + actorPos->y;
+ out1->z = frac2 * itemStep.z + actorToItem.z + actorPos->z;
return 1;
}
return 1;
}
-#undef SQXZ
-#undef DOTXZ
-
s32 func_800635D0(s32 arg0) {
s32 result;
diff --git a/src/code/z_en_item00.c b/src/code/z_en_item00.c
index 0a79d0dc4..d014a176c 100644
--- a/src/code/z_en_item00.c
+++ b/src/code/z_en_item00.c
@@ -286,13 +286,11 @@ void func_8001DFC8(EnItem00* this, GlobalContext* globalCtx) {
} else {
if ((this->actor.params >= ITEM00_SHIELD_DEKU) && (this->actor.params != ITEM00_BOMBS_SPECIAL)) {
if (this->unk_15A == -1) {
- if (!Math_SmoothStepToS(&this->actor.shape.rot.x, this->actor.posRot.rot.x - 0x4000, 2, 3000,
- 1500)) {
+ if (!Math_SmoothStepToS(&this->actor.shape.rot.x, this->actor.posRot.rot.x - 0x4000, 2, 3000, 1500)) {
this->unk_15A = -2;
}
} else {
- if (!Math_SmoothStepToS(&this->actor.shape.rot.x, -this->actor.posRot.rot.x - 0x4000, 2, 3000,
- 1500)) {
+ if (!Math_SmoothStepToS(&this->actor.shape.rot.x, -this->actor.posRot.rot.x - 0x4000, 2, 3000, 1500)) {
this->unk_15A = -1;
}
}
diff --git a/src/code/z_lib.c b/src/code/z_lib.c
index 177217f3c..54f90bb3b 100644
--- a/src/code/z_lib.c
+++ b/src/code/z_lib.c
@@ -175,7 +175,7 @@ s32 Math_StepUntilF(f32* pValue, f32 limit, f32 step) {
* Changes pValue toward target by incrStep if pValue is smaller and by decrStep if it is greater, setting it equal when
* target is reached. Returns true when target is reached, false otherwise.
*/
-s32 Math_AymStepToF(f32* pValue, f32 target, f32 incrStep, f32 decrStep) {
+s32 Math_AsymStepToF(f32* pValue, f32 target, f32 incrStep, f32 decrStep) {
f32 step = (target >= *pValue) ? incrStep : decrStep;
if (step != 0.0f) {