diff --git a/.vscode/settings.json b/.vscode/settings.json index c5d8e7b9..88c89020 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -91,7 +91,8 @@ "ast_allies.h": "c", "ast_font.h": "c", "fox_std_lib_assets.h": "c", - "fox_versus_assets.h": "c" + "fox_versus_assets.h": "c", + "guint.h": "c" }, "C_Cpp_Runner.msvcBatchPath": "" } \ No newline at end of file diff --git a/include/macros.h b/include/macros.h index be6b20cc..e1e1e906 100644 --- a/include/macros.h +++ b/include/macros.h @@ -24,8 +24,9 @@ #define SIGN_OF(x) (((x) > 0) ? 1 : ((x) == 0) ? 0 : -1) #define SQ(x) ((x) * (x)) #define CUBE(x) ((x) * (x) * (x)) -#define VEC3F_SQ(vec) (SQ((vec).x) + SQ((vec).y) + SQ((vec).z)) -#define DOT_XYZ(a, b) ((a).x * (b).x + (a).y * (b).y + (a).z * (b).z) + +#define DOT_XYZ(v1Ptr, v2Ptr) ((v1Ptr)->x * (v2Ptr)->x + (v1Ptr)->y * (v2Ptr)->y + (v1Ptr)->z * (v2Ptr)->z) +#define VEC3F_MAG(vecPtr) sqrtf(DOT_XYZ(vecPtr, vecPtr)) #define ABS(x) ((x) >= 0 ? (x) : -(x)) #define ABSF(x) ((x) >= 0.0f ? (x) : -(x)) #define ROUND(float) ((s32)((float)+0.5f)) diff --git a/include/prevent_context_reordering.h b/include/prevent_context_reordering.h index 1bf9bd1f..48109fed 100644 --- a/include/prevent_context_reordering.h +++ b/include/prevent_context_reordering.h @@ -1,9 +1,9 @@ #ifndef PREVENT_CONTEXT_REORDERING_H #define PREVENT_CONTEXT_REORDERING_H -// extern int Dummyhalf; -struct Dummy0 {int x;}; -struct Dummy1 {int x;}; +extern int Dummyhalf; +// struct Dummy0 {int x;}; +// struct Dummy1 {int x;}; struct Dummy2 {int x;}; struct Dummy3 {int x;}; struct Dummy4 {int x;}; diff --git a/include/sf64object.h b/include/sf64object.h index 18d90f32..aa5ff095 100644 --- a/include/sf64object.h +++ b/include/sf64object.h @@ -20,7 +20,7 @@ typedef struct { } Hitbox; // size = 0x18 typedef struct { - /* 0x00 */ s16 vtx[3]; + /* 0x00 */ Triangle tri; /* 0x06 */ s16 unk_06; /* 0x08 */ Vec3s normal; /* 0x10 */ s32 dist; @@ -288,6 +288,57 @@ typedef struct { /* 0x18C */ Vec3f vwork[30]; } Actor; // size = 0x2F4 +#define EVENT_CMD(opcode, arg1, arg2) (((opcode) & 0x7F << 9) & (arg1 & 0x1FF)), arg2 + +typedef enum { + /* 0 */ EVOP_0, + /* 1 */ EVOP_1, + /* 2 */ EVOP_2, + /* 3 */ EVOP_3, + /* 4 */ EVOP_4, + /* 8 */ EVOP_8 = 8, + /* 9 */ EVOP_9, + /* 10 */ EVOP_10, + /* 11 */ EVOP_11, + /* 12 */ EVOP_12, + /* 16 */ EVOP_16 = 16, + /* 17 */ EVOP_17, + /* 18 */ EVOP_18, + /* 19 */ EVOP_19, + /* 20 */ EVOP_20, + /* 21 */ EVOP_21, + /* 24 */ EVOP_24 = 24, + /* 25 */ EVOP_25, + /* 40 */ EVOP_40 = 40, + /* 41 */ EVOP_41, + /* 42 */ EVOP_42, + /* 43 */ EVOP_43, + /* 44 */ EVOP_44, + /* 45 */ EVOP_45, + /* 46 */ EVOP_46, + /* 47 */ EVOP_47, + /* 48 */ EVOP_48, + /* 56 */ EVOP_56 = 56, + /* 57 */ EVOP_57, + /* 58 */ EVOP_58, + /* 59 */ EVOP_59, + /* 96 */ EVOP_96 = 96, + /* 104 */ EVOP_104 = 104, + /* 105 */ EVOP_105, + /* 112 */ EVOP_112 = 112, + /* 113 */ EVOP_113, + /* 116 */ EVOP_116 = 116, + /* 118 */ EVOP_118 = 118, + /* 119 */ EVOP_119, + /* 120 */ EVOP_120, + /* 121 */ EVOP_121, + /* 122 */ EVOP_122, + /* 124 */ EVOP_124 = 124, + /* 125 */ EVOP_125, + /* 126 */ EVOP_126, + /* 127 */ EVOP_127, +} EventOpcode; + typedef enum ObjectId { /* -1 */ OBJ_INVALID=-1, /* 0 */ OBJ_80_0, diff --git a/src/main/fox_97F80.c b/src/main/fox_97F80.c index 6f734dce..fd30737c 100644 --- a/src/main/fox_97F80.c +++ b/src/main/fox_97F80.c @@ -26,6 +26,7 @@ f32 __pos_z; #define TRINORM_Y(A, B, C) ((B##_z - A##_z) * (C##_x - B##_x) - (B##_x - A##_x) * (C##_z - B##_z)) #define TRINORM_Z(A, B, C) ((B##_x - A##_x) * (C##_y - B##_y) - (B##_y - A##_y) * (C##_x - B##_x)) +// Calculate the directed plane that contains the ordered triangle tri, given as an array of Vec3s void func_80097380(Plane* plane, Vec3s** tri) { Vec3s a; Vec3s b; @@ -62,6 +63,8 @@ void func_80097380(Plane* plane, Vec3s** tri) { -a.x * b.y * c.z - b.x * c.y * a.z - c.x * a.y * b.z + a.x * c.y * b.z + b.x * a.y * c.z + c.x * b.y * a.z; } +// Calculate the directed plane that contains the ordered triangle tri, given as an array of Vec3s. Duplicate of +// previous void func_80097558(Plane* plane, Vec3s** tri) { Vec3s a; Vec3s b; @@ -98,6 +101,7 @@ void func_80097558(Plane* plane, Vec3s** tri) { -a.x * b.y * c.z - b.x * c.y * a.z - c.x * a.y * b.z + a.x * c.y * b.z + b.x * a.y * c.z + c.x * b.y * a.z; } +// Calculate the normal vector of an ordered triangle, given as a Vec3f array void func_80097730(Vec3f* norm, Vec3f* tri) { __vtx0_x = tri->x; __vtx0_y = tri->y; @@ -124,6 +128,7 @@ void func_80097730(Vec3f* norm, Vec3f* tri) { norm->z = (__dx1 * __dy2) - (__dy1 * __dx2); } +// Calculate the normal vector of an ordered triangle, given as integer coordinates void func_800978C4(Vec3f* norm, s32 ax, s32 ay, s32 az, s32 bx, s32 by, s32 bz, s32 cx, s32 cy, s32 cz) { __dx1 = bx - ax; __dx2 = cx - bx; @@ -137,6 +142,7 @@ void func_800978C4(Vec3f* norm, s32 ax, s32 ay, s32 az, s32 bx, s32 by, s32 bz, norm->z = (__dx1 * __dy2) - (__dy1 * __dx2); } +// Calculate the normal vector of an ordered triangle, given as vertices void func_800979E8(Vtx_tn* tri) { s32 i; Vec3f temp; @@ -165,7 +171,7 @@ void func_800979E8(Vtx_tn* tri) { temp.x = (__dy1 * __dz2) - (__dz1 * __dy2); temp.y = (__dz1 * __dx2) - (__dx1 * __dz2); temp.z = (__dx1 * __dy2) - (__dy1 * __dx2); - temp_fv0 = sqrtf(VEC3F_SQ(temp)); + temp_fv0 = VEC3F_MAG(&temp); if (temp_fv0 != 0.0f) { temp.x = temp.x * 127.0f / temp_fv0; temp.y = temp.y * 127.0f / temp_fv0; @@ -179,6 +185,7 @@ void func_800979E8(Vtx_tn* tri) { } } +// calculate the normal vectors of the two ordered triangles in a quad void func_80097C88(Vec3f* norms, Vtx_tn* quad) { f32 temp_fv0; @@ -202,7 +209,7 @@ void func_80097C88(Vec3f* norms, Vtx_tn* quad) { norms->x = (__dy1 * __dz2) - (__dz1 * __dy2); norms->y = (__dz1 * __dx2) - (__dx1 * __dz2); norms->z = (__dx1 * __dy2) - (__dy1 * __dx2); - temp_fv0 = sqrtf(SQ(norms->x) + SQ(norms->y) + SQ(norms->z)); + temp_fv0 = VEC3F_MAG(norms); if (temp_fv0 != 0.0f) { norms->x = (norms->x / temp_fv0) * 127.0f; norms->y = (norms->y / temp_fv0) * 127.0f; @@ -226,7 +233,7 @@ void func_80097C88(Vec3f* norms, Vtx_tn* quad) { norms->x = (__dy1 * __dz2) - (__dz1 * __dy2); norms->y = (__dz1 * __dx2) - (__dx1 * __dz2); norms->z = (__dx1 * __dy2) - (__dy1 * __dx2); - temp_fv0 = sqrtf(SQ(norms->x) + SQ(norms->y) + SQ(norms->z)); + temp_fv0 = VEC3F_MAG(norms); if (temp_fv0 != 0.0f) { norms->x = (norms->x / temp_fv0) * 127.0f; norms->y = (norms->y / temp_fv0) * 127.0f; @@ -234,7 +241,9 @@ void func_80097C88(Vec3f* norms, Vtx_tn* quad) { } } -s32 func_8009808C(Vec3f* pos, Vtx_tn* quad, Vec3f* norm) { +// check if the projection of pos onto either ordered triangle of quad lies within that triangle +// If it does and lies on the positive side, return which triangle it's within and that triangle's normal +s32 func_8009808C(Vec3f* pos, Vtx_tn* quad, Vec3f* normOut) { f32 temp_fv0; s32 var_v1 = 0; f32 test1; @@ -260,10 +269,10 @@ s32 func_8009808C(Vec3f* pos, Vtx_tn* quad, Vec3f* norm) { if (test1 >= 0.0f) { test1 = TRINORM_Y(__vtx2, __vtx0, __pos); if (test1 >= 0.0f) { - norm->x = TRINORM_X(__vtx0, __vtx1, __vtx2); - norm->y = TRINORM_Y(__vtx0, __vtx1, __vtx2); - norm->z = TRINORM_Z(__vtx0, __vtx1, __vtx2); - if ((norm->x != 0.0f) || (norm->y != 0.0f) || (norm->z != 0.0f)) { + normOut->x = TRINORM_X(__vtx0, __vtx1, __vtx2); + normOut->y = TRINORM_Y(__vtx0, __vtx1, __vtx2); + normOut->z = TRINORM_Z(__vtx0, __vtx1, __vtx2); + if ((normOut->x != 0.0f) || (normOut->y != 0.0f) || (normOut->z != 0.0f)) { var_v1 = 1; } } @@ -276,10 +285,10 @@ s32 func_8009808C(Vec3f* pos, Vtx_tn* quad, Vec3f* norm) { if (test1 >= 0.0f) { test1 = TRINORM_Y(__vtx3, __vtx0, __pos); if (test1 >= 0.0f) { - norm->x = TRINORM_X(__vtx0, __vtx2, __vtx3); - norm->y = TRINORM_Y(__vtx0, __vtx2, __vtx3); - norm->z = TRINORM_Z(__vtx0, __vtx2, __vtx3); - if ((norm->x != 0.0f) || (norm->y != 0.0f) || (norm->z != 0.0f)) { + normOut->x = TRINORM_X(__vtx0, __vtx2, __vtx3); + normOut->y = TRINORM_Y(__vtx0, __vtx2, __vtx3); + normOut->z = TRINORM_Z(__vtx0, __vtx2, __vtx3); + if ((normOut->x != 0.0f) || (normOut->y != 0.0f) || (normOut->z != 0.0f)) { var_v1 = 2; } } @@ -288,17 +297,18 @@ s32 func_8009808C(Vec3f* pos, Vtx_tn* quad, Vec3f* norm) { } if (var_v1 != 0) { - temp_fv0 = sqrtf(SQ(norm->x) + SQ(norm->y) + SQ(norm->z)); + temp_fv0 = VEC3F_MAG(normOut); if (temp_fv0 == 0) { return 0; } - norm->x = (norm->x / temp_fv0) * 127.0f; - norm->y = (norm->y / temp_fv0) * 127.0f; - norm->z = (norm->z / temp_fv0) * 127.0f; + normOut->x = (normOut->x / temp_fv0) * 127.0f; + normOut->y = (normOut->y / temp_fv0) * 127.0f; + normOut->z = (normOut->z / temp_fv0) * 127.0f; } return var_v1; } +// check if vec lies within tri when projected to the xz-plane bool func_800985CC(Vec3f* vec, Vtx_tn* tri) { f32 sp24; f32 sp20; @@ -337,28 +347,29 @@ void func_80098860(Plane* plane, Vec3f* point, Vec3f* normal) { plane->dist = -normal->x * point->x - normal->y * point->y - normal->z * point->z; } -// y dist to plane +// y dist to closest point on plane s32 func_800988B4(Vec3f* vec, Plane* plane) { return (-plane->normal.x * vec->x - plane->normal.z * vec->z - plane->dist) / plane->normal.y; } -// z dist to plane +// z dist to closest point on plane s32 func_800988F8(Vec3f* vec, Plane* plane) { return (-plane->normal.x * vec->x - plane->normal.y * vec->y - plane->dist) / plane->normal.z; } -// x dist to plane +// x dist to closest point on plane s32 func_8009893C(Vec3f* vec, Plane* plane) { return (-plane->normal.y * vec->y - plane->normal.z * vec->z - plane->dist) / plane->normal.x; } #define INTSIGN_OF(x) ((((x) >= 1.0f) || ((x) <= -1.0f)) ? (f32) SIGN_OF(x) : 0.0f) -s32 func_80098980(Vec3f* out, Vec3s** tri, Vec3f* vec) { - s32 signa2y; - s32 signa2z; +// checks if the projection of pos onto the plane of tri lies within tri and it is on the same side as the normal. +bool func_80098980(Vec3f* pos, Vec3s** tri, Vec3f* normal) { + s32 normSignY; + s32 normSignZ; s32 signCross; - s32 signa2x; + s32 normSignX; f32 cross; s32 var_v1; Vec3s* pad; @@ -371,9 +382,9 @@ s32 func_80098980(Vec3f* out, Vec3s** tri, Vec3f* vec) { f32 t2x; f32 t2y; f32 t2z; - f32 a0x; - f32 a0y; - f32 a0z; + f32 xPos; + f32 yPos; + f32 zPos; f32 d01x; f32 d12x; f32 d20x; @@ -384,7 +395,7 @@ s32 func_80098980(Vec3f* out, Vec3s** tri, Vec3f* vec) { f32 d12z; f32 d20z; - var_v1 = 0; + var_v1 = false; pad = *tri++; if (1) { // some sort of macro? @@ -404,9 +415,9 @@ s32 func_80098980(Vec3f* out, Vec3s** tri, Vec3f* vec) { t2y = pad->y; t2z = pad->z; - a0x = out->x; - a0y = out->y; - a0z = out->z; + xPos = pos->x; + yPos = pos->y; + zPos = pos->z; d01x = t1x - t0x; d12x = t2x - t1x; @@ -418,39 +429,39 @@ s32 func_80098980(Vec3f* out, Vec3s** tri, Vec3f* vec) { d12z = t2z - t1z; d20z = t0z - t2z; - signa2x = SIGN_OF(vec->x); - signa2y = SIGN_OF(vec->y); - signa2z = SIGN_OF(vec->z); + normSignX = SIGN_OF(normal->x); + normSignY = SIGN_OF(normal->y); + normSignZ = SIGN_OF(normal->z); } - cross = ((a0z - t1z) * d01y) - (d01z * (a0y - t1y)); + cross = ((zPos - t1z) * d01y) - (d01z * (yPos - t1y)); signCross = INTSIGN_OF(cross); - if ((signa2x == 0) || (signCross == signa2x) || (signCross == 0)) { - cross = ((a0z - t2z) * d12y) - (d12z * (a0y - t2y)); + if ((normSignX == 0) || (signCross == normSignX) || (signCross == 0)) { + cross = ((zPos - t2z) * d12y) - (d12z * (yPos - t2y)); signCross = INTSIGN_OF(cross); - if ((signa2x == 0) || (signCross == signa2x) || (signCross == 0)) { - cross = ((a0z - t0z) * d20y) - (d20z * (a0y - t0y)); + if ((normSignX == 0) || (signCross == normSignX) || (signCross == 0)) { + cross = ((zPos - t0z) * d20y) - (d20z * (yPos - t0y)); signCross = INTSIGN_OF(cross); - if ((signa2x == 0) || (signCross == signa2x) || (signCross == 0)) { - cross = ((a0x - t1x) * d01z) - (d01x * (a0z - t1z)); + if ((normSignX == 0) || (signCross == normSignX) || (signCross == 0)) { + cross = ((xPos - t1x) * d01z) - (d01x * (zPos - t1z)); signCross = INTSIGN_OF(cross); - if ((signa2y == 0) || (signCross == signa2y) || (signCross == 0)) { - cross = ((a0x - t2x) * d12z) - (d12x * (a0z - t2z)); + if ((normSignY == 0) || (signCross == normSignY) || (signCross == 0)) { + cross = ((xPos - t2x) * d12z) - (d12x * (zPos - t2z)); signCross = INTSIGN_OF(cross); - if ((signa2y == 0) || (signCross == signa2y) || (signCross == 0)) { - cross = ((a0x - t0x) * d20z) - (d20x * (a0z - t0z)); + if ((normSignY == 0) || (signCross == normSignY) || (signCross == 0)) { + cross = ((xPos - t0x) * d20z) - (d20x * (zPos - t0z)); signCross = INTSIGN_OF(cross); - if ((signa2y == 0) || (signCross == signa2y) || (signCross == 0)) { - cross = ((a0y - t1y) * d01x) - (d01y * (a0x - t1x)); + if ((normSignY == 0) || (signCross == normSignY) || (signCross == 0)) { + cross = ((yPos - t1y) * d01x) - (d01y * (xPos - t1x)); signCross = INTSIGN_OF(cross); - if ((signa2z == 0) || (signCross == signa2z) || (signCross == 0)) { - cross = ((a0y - t2y) * d12x) - (d12y * (a0x - t2x)); + if ((normSignZ == 0) || (signCross == normSignZ) || (signCross == 0)) { + cross = ((yPos - t2y) * d12x) - (d12y * (xPos - t2x)); signCross = INTSIGN_OF(cross); - if ((signa2z == 0) || (signCross == signa2z) || (signCross == 0)) { - cross = ((a0y - t0y) * d20x) - (d20y * (a0x - t0x)); + if ((normSignZ == 0) || (signCross == normSignZ) || (signCross == 0)) { + cross = ((yPos - t0y) * d20x) - (d20y * (xPos - t0x)); signCross = INTSIGN_OF(cross); - if ((signa2z == 0) || (signCross == 0) || (signCross == signa2z)) { - var_v1 = 1; + if ((normSignZ == 0) || (signCross == 0) || (signCross == normSignZ)) { + var_v1 = true; } } } @@ -464,137 +475,157 @@ s32 func_80098980(Vec3f* out, Vec3s** tri, Vec3f* vec) { return var_v1; } -bool func_80099254(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, CollisionHeader* arg3, Vec3f* arg4, f32* arg5) { - Vec3s* sp12C[3]; - Vec3f temp_V3f1; +bool func_80099254(Vec3f* objPos, Vec3f* colliderPos, Vec3f* objVel, CollisionHeader* colHeader, Vec3f* hitPosOut, + f32* hitAnglesOut) { + Vec3s* polyVtxPos[3]; + Vec3f objRel; s32 pad11C; s32 pad118; - Plane sp108; - f32 temp_fs0; - s32 sp100 = false; - s32 temp_v0; - CollisionPoly* var_s0; - Vec3s* temp_s2; - s32 spF0; - f32 spEC; + Plane polyPlane; + f32 tempf; + s32 didHit = false; + s32 swapBuff; + CollisionPoly* colPoly; + Vec3s* mesh; + s32 polyCount; + f32 speed; s32 i; - Vec3f spDC; - f32* padD8; - s32 spD4; - s32 spD0; - s32 spCC; - s32 spC8; - s32 spC4; - s32 spC0; - s32 spBC; - s32 spB8; - s32 spB4; - s32 spB0; - s32 spAC; - s32 spA8; + Vec3f hitPosRel; + s32 padD8; + s32 polyMinX; + s32 polyMaxX; + s32 polyMinY; + s32 polyMaxY; + s32 polyMinZ; + s32 polyMaxZ; + s32 objMinX; + s32 objMaxX; + s32 objMinY; + s32 objMaxY; + s32 objMinZ; + s32 objMaxZ; Vec3f min; Vec3f max; - arg4->x = arg4->y = arg4->z = arg5[0] = arg5[1] = 0.0f; - temp_V3f1.x = arg0->x - arg1->x; - temp_V3f1.y = arg0->y - arg1->y; - temp_V3f1.z = arg0->z - arg1->z; - min.x = arg3->min.x; - min.y = arg3->min.y; - min.z = arg3->min.z; - max.x = arg3->max.x; - max.y = arg3->max.y; - max.z = arg3->max.z; + hitPosOut->x = hitPosOut->y = hitPosOut->z = hitAnglesOut[0] = hitAnglesOut[1] = 0.0f; + objRel.x = objPos->x - colliderPos->x; + objRel.y = objPos->y - colliderPos->y; + objRel.z = objPos->z - colliderPos->z; + min.x = colHeader->min.x; + min.y = colHeader->min.y; + min.z = colHeader->min.z; + max.x = colHeader->max.x; + max.y = colHeader->max.y; + max.z = colHeader->max.z; - if ((temp_V3f1.x < min.x) || (temp_V3f1.y < min.y) || (temp_V3f1.z < min.z) || (max.x < temp_V3f1.x) || - (max.y < temp_V3f1.y) || ((max.z < temp_V3f1.z))) { + // check if object is outside the collision's bounding box + if ((objRel.x < min.x) || (objRel.y < min.y) || (objRel.z < min.z) || (max.x < objRel.x) || (max.y < objRel.y) || + ((max.z < objRel.z))) { return false; } - if ((arg2->x == 0.0f) && (arg2->y == 0.0f) && (arg2->z == 0.0f)) { - arg2->y = -5.0f; - } - spBC = temp_V3f1.x; - spB4 = temp_V3f1.y; - spAC = temp_V3f1.z; - spB8 = temp_V3f1.x - arg2->x; - spB0 = temp_V3f1.y - arg2->y; - spA8 = temp_V3f1.z - arg2->z; - - if (spB8 < spBC) { - temp_v0 = spB8; - spB8 = spBC; - spBC = temp_v0; - } - if (spB0 < spB4) { - temp_v0 = spB0; - spB0 = spB4; - spB4 = temp_v0; + if ((objVel->x == 0.0f) && (objVel->y == 0.0f) && (objVel->z == 0.0f)) { + objVel->y = -5.0f; } - if (spA8 < spAC) { - temp_v0 = spA8; - spA8 = spAC; - spAC = temp_v0; + // find the bounding box of the object's movement from the last frame to this one. + objMinX = objRel.x; + objMinY = objRel.y; + objMinZ = objRel.z; + objMaxX = objRel.x - objVel->x; + objMaxY = objRel.y - objVel->y; + objMaxZ = objRel.z - objVel->z; + + if (objMaxX < objMinX) { + swapBuff = objMaxX; + objMaxX = objMinX; + objMinX = swapBuff; + } + if (objMaxY < objMinY) { + swapBuff = objMaxY; + objMaxY = objMinY; + objMinY = swapBuff; } - var_s0 = SEGMENTED_TO_VIRTUAL(arg3->polys); - temp_s2 = SEGMENTED_TO_VIRTUAL(arg3->mesh); - spF0 = arg3->polyCount; - spEC = sqrtf(SQ(arg2->x) + SQ(arg2->y) + SQ(arg2->z)); + if (objMaxZ < objMinZ) { + swapBuff = objMaxZ; + objMaxZ = objMinZ; + objMinZ = swapBuff; + } - for (i = 0; i < spF0; i++, var_s0++) { - sp12C[0] = &temp_s2[var_s0->vtx[0]]; - sp12C[1] = &temp_s2[var_s0->vtx[1]]; - sp12C[2] = &temp_s2[var_s0->vtx[2]]; - Math_MinMax(&spD4, &spD0, sp12C[0]->x, sp12C[1]->x, sp12C[2]->x); - Math_MinMax(&spCC, &spC8, sp12C[0]->y, sp12C[1]->y, sp12C[2]->y); - Math_MinMax(&spC4, &spC0, sp12C[0]->z, sp12C[1]->z, sp12C[2]->z); - if ((spBC < spD0) && (spD4 < spB8) && (spB4 < spC8) && (spCC < spB0) && (spAC < spC0) && (spC4 < spA8)) { - sp108.normal.x = var_s0->normal.x; - sp108.normal.y = var_s0->normal.y; - sp108.normal.z = var_s0->normal.z; - sp108.dist = var_s0->dist; - if ((DOT_XYZ(sp108.normal, temp_V3f1) + sp108.dist) <= 0.0f) { - temp_fs0 = sp108.normal.x * arg2->x + sp108.normal.y * arg2->y + sp108.normal.z * arg2->z; - if (Math_FAcosF(temp_fs0 / (sqrtf(VEC3F_SQ(sp108.normal)) * spEC)) > M_PI / 2) { - temp_fs0 = (DOT_XYZ(sp108.normal, temp_V3f1) + sp108.dist) / temp_fs0; - spDC.x = temp_V3f1.x - (arg2->x * temp_fs0); - spDC.y = temp_V3f1.y - (arg2->y * temp_fs0); - spDC.z = temp_V3f1.z - (arg2->z * temp_fs0); - if (func_80098980(&spDC, sp12C, &sp108.normal) == 1) { - arg4->x = arg1->x + spDC.x; - arg4->y = arg1->y + spDC.y; - arg4->z = arg1->z + spDC.z; - if (sp108.normal.x != 0.0) { - sp108.normal.x = -sp108.dist / sp108.normal.x; + colPoly = SEGMENTED_TO_VIRTUAL(colHeader->polys); + mesh = SEGMENTED_TO_VIRTUAL(colHeader->mesh); + polyCount = colHeader->polyCount; + speed = VEC3F_MAG(objVel); + + for (i = 0; i < polyCount; i++, colPoly++) { + polyVtxPos[0] = &mesh[colPoly->tri.vtx[0]]; + polyVtxPos[1] = &mesh[colPoly->tri.vtx[1]]; + polyVtxPos[2] = &mesh[colPoly->tri.vtx[2]]; + Math_MinMax(&polyMinX, &polyMaxX, polyVtxPos[0]->x, polyVtxPos[1]->x, polyVtxPos[2]->x); + Math_MinMax(&polyMinY, &polyMaxY, polyVtxPos[0]->y, polyVtxPos[1]->y, polyVtxPos[2]->y); + Math_MinMax(&polyMinZ, &polyMaxZ, polyVtxPos[0]->z, polyVtxPos[1]->z, polyVtxPos[2]->z); + + // check if bounding boxes of the object's movement and the collision polygon overlap + if ((objMinX < polyMaxX) && (objMaxX > polyMinX) && (objMinY < polyMaxY) && (objMaxY > polyMinY) && + (objMinZ < polyMaxZ) && (objMaxZ > polyMinZ)) { + polyPlane.normal.x = colPoly->normal.x; + polyPlane.normal.y = colPoly->normal.y; + polyPlane.normal.z = colPoly->normal.z; + polyPlane.dist = colPoly->dist; + + // check if object is on the "back" side of the polygon + if ((DOT_XYZ(&polyPlane.normal, &objRel) + polyPlane.dist) <= 0.0f) { + + // calculate the normal component of velocity + tempf = DOT_XYZ(&polyPlane.normal, objVel); + + // check if the angle between the normal and velocity is > 90. That is, the object was moving toward the + // front of the polygon + if (Math_FAcosF(tempf / (VEC3F_MAG(&polyPlane.normal) * speed)) > DEG_TO_RAD(90.0f)) { + // Calculate the time since the plane was crossed. Reusing the temp is required to match + tempf = (DOT_XYZ(&polyPlane.normal, &objRel) + polyPlane.dist) / tempf; + + // find the point where the object crossed the plane of the polygon + hitPosRel.x = objRel.x - (objVel->x * tempf); + hitPosRel.y = objRel.y - (objVel->y * tempf); + hitPosRel.z = objRel.z - (objVel->z * tempf); + + // check if that point is within the polygon + if (func_80098980(&hitPosRel, polyVtxPos, &polyPlane.normal) == true) { + hitPosOut->x = colliderPos->x + hitPosRel.x; + hitPosOut->y = colliderPos->y + hitPosRel.y; + hitPosOut->z = colliderPos->z + hitPosRel.z; + if (polyPlane.normal.x != 0.0) { + polyPlane.normal.x = -polyPlane.dist / polyPlane.normal.x; } - if (sp108.normal.y != 0.0f) { - sp108.normal.y = -sp108.dist / sp108.normal.y; + if (polyPlane.normal.y != 0.0f) { + polyPlane.normal.y = -polyPlane.dist / polyPlane.normal.y; } - if (sp108.normal.z != 0.0f) { - sp108.normal.z = -sp108.dist / sp108.normal.z; + if (polyPlane.normal.z != 0.0f) { + polyPlane.normal.z = -polyPlane.dist / polyPlane.normal.z; } - arg5[0] = Math_Atan2F_XY(sp108.normal.y, sp108.normal.z); - if (sp108.normal.z != 0.0f) { - arg5[1] = - -Math_Atan2F_XY(__sinf(Math_Atan2F_XY(sp108.normal.y, sp108.normal.z)) * sp108.normal.z, - sp108.normal.x); - } else if (arg5[0] >= M_PI) { - arg5[1] = Math_Atan2F_XY(sp108.normal.y, sp108.normal.x); + hitAnglesOut[0] = Math_Atan2F_XY(polyPlane.normal.y, polyPlane.normal.z); + if (polyPlane.normal.z != 0.0f) { + hitAnglesOut[1] = -Math_Atan2F_XY( + __sinf(Math_Atan2F_XY(polyPlane.normal.y, polyPlane.normal.z)) * polyPlane.normal.z, + polyPlane.normal.x); + } else if (hitAnglesOut[0] >= M_PI) { + hitAnglesOut[1] = Math_Atan2F_XY(polyPlane.normal.y, polyPlane.normal.x); } else { - arg5[1] = -Math_Atan2F_XY(sp108.normal.y, sp108.normal.x); + hitAnglesOut[1] = -Math_Atan2F_XY(polyPlane.normal.y, polyPlane.normal.x); } - sp100 = true; + didHit = true; break; } } } } } - return sp100; + return didHit; } -bool func_800998FC(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2, s32 arg3, Vec3f* arg4, f32* arg5) { - return func_80099254(arg0, arg1, arg2, SEGMENTED_TO_VIRTUAL(&D_800D2B38[arg3]), arg4, arg5); +bool func_800998FC(Vec3f* objPos, Vec3f* colliderPos, Vec3f* objVel, s32 colId, Vec3f* hitPosOut, f32* hitAnglesOut) { + return func_80099254(objPos, colliderPos, objVel, SEGMENTED_TO_VIRTUAL(&D_800D2B38[colId]), hitPosOut, + hitAnglesOut); } diff --git a/src/main/fox_A4290.c b/src/main/fox_A4290.c index 6818206a..fb94fb9e 100644 --- a/src/main/fox_A4290.c +++ b/src/main/fox_A4290.c @@ -2,15 +2,15 @@ #include "fox_A4290_colheaders.c" -bool func_800A36FC(Vec3f* arg0, Vec3f* arg1, CollisionHeader2* arg2, Vec3f* arg3); -bool func_800A3A74(Vec3f*, Vec3f** arg1, Vec3f*); +bool func_800A36FC(Vec3f* objPos, Vec3f* colliderPos, CollisionHeader2* colHeader, Vec3f* hitDataOut); +bool func_800A3A74(Vec3f* point, Vec3f** tri, Vec3f* normOut); -bool func_800A3690(Vec3f* arg0, Vec3f* arg1, s32 arg2, Vec3f* arg3) { - return func_800A36FC(arg0, arg1, SEGMENTED_TO_VIRTUAL(&D_800D2CA0[arg2]), arg3); +bool func_800A3690(Vec3f* objPos, Vec3f* colliderPos, s32 colId, Vec3f* hitDataOut) { + return func_800A36FC(objPos, colliderPos, SEGMENTED_TO_VIRTUAL(&D_800D2CA0[colId]), hitDataOut); } -bool func_800A36FC(Vec3f* arg0, Vec3f* arg1, CollisionHeader2* arg2, Vec3f* arg3) { - Vec3f pos; +bool func_800A36FC(Vec3f* objPos, Vec3f* colliderPos, CollisionHeader2* colHeader, Vec3f* hitDataOut) { + Vec3f objRelPos; Plane triPlane; bool above; s32 i; @@ -23,22 +23,22 @@ bool func_800A36FC(Vec3f* arg0, Vec3f* arg1, CollisionHeader2* arg2, Vec3f* arg3 Triangle* polys; Vec3f* mesh; - pos.x = arg0->x - arg1->x; - pos.y = arg0->y - arg1->y; - pos.z = arg0->z - arg1->z; - if ((pos.x < arg2->min.x) || (pos.y < arg2->min.y) || (pos.z < arg2->min.z) || (arg2->max.x < pos.x) || - (arg2->max.y < pos.y) || (arg2->max.z < pos.z)) { + objRelPos.x = objPos->x - colliderPos->x; + objRelPos.y = objPos->y - colliderPos->y; + objRelPos.z = objPos->z - colliderPos->z; + if ((objRelPos.x < colHeader->min.x) || (objRelPos.y < colHeader->min.y) || (objRelPos.z < colHeader->min.z) || + (colHeader->max.x < objRelPos.x) || (colHeader->max.y < objRelPos.y) || (colHeader->max.z < objRelPos.z)) { return false; } above = false; - count = arg2->polyCount; - polys = SEGMENTED_TO_VIRTUAL(arg2->polys); - mesh = SEGMENTED_TO_VIRTUAL(arg2->mesh); + count = colHeader->polyCount; + polys = SEGMENTED_TO_VIRTUAL(colHeader->polys); + mesh = SEGMENTED_TO_VIRTUAL(colHeader->mesh); for (i = 0; i < count; i++, polys++) { for (j = 0; j < 3; j++) { tri[j] = &mesh[polys->vtx[j]]; } - above = func_800A3A74(&pos, tri, &norm); + above = func_800A3A74(&objRelPos, tri, &norm); if (above) { break; } @@ -48,7 +48,7 @@ bool func_800A36FC(Vec3f* arg0, Vec3f* arg1, CollisionHeader2* arg2, Vec3f* arg3 vtx.y = tri[0]->y; vtx.z = tri[0]->z; func_80098860(&triPlane, &vtx, &norm); - arg3->y = func_800988B4(&pos, &triPlane); + hitDataOut->y = func_800988B4(&objRelPos, &triPlane); if (triPlane.normal.x != 0.0f) { norm.x = -triPlane.dist / triPlane.normal.x; } else { @@ -64,23 +64,23 @@ bool func_800A36FC(Vec3f* arg0, Vec3f* arg1, CollisionHeader2* arg2, Vec3f* arg3 } else { norm.z = 0.0f; } - arg3->x = Math_Atan2F_XY(norm.y, norm.z); + hitDataOut->x = Math_Atan2F_XY(norm.y, norm.z); if (norm.z != 0.0f) { - arg3->z = -Math_Atan2F_XY(__sinf(Math_Atan2F_XY(norm.y, norm.z)) * norm.z, norm.x); - } else if (arg3->x >= M_PI) { - arg3->z = Math_Atan2F_XY(norm.y, norm.x); + hitDataOut->z = -Math_Atan2F_XY(__sinf(Math_Atan2F_XY(norm.y, norm.z)) * norm.z, norm.x); + } else if (hitDataOut->x >= M_PI) { + hitDataOut->z = Math_Atan2F_XY(norm.y, norm.x); } else { - arg3->z = -Math_Atan2F_XY(norm.y, norm.x); + hitDataOut->z = -Math_Atan2F_XY(norm.y, norm.x); } - if ((arg0->y <= arg3->y) || (gCurrentLevel == LEVEL_MACBETH)) { + if ((objPos->y - hitDataOut->y <= 0.0f) || (gCurrentLevel == LEVEL_MACBETH)) { sp38 = true; } } return sp38; } -// Checks if point is above the triangle tri. If so, returns the triangle normal in arg2. -s32 func_800A3A74(Vec3f* point, Vec3f** tri, Vec3f* norm) { +// Checks if point is above the triangle tri. If so, puts the triangle normal in normOut +bool func_800A3A74(Vec3f* point, Vec3f** tri, Vec3f* normOut) { s32 pad; f32 temp1; bool ret = false; @@ -111,15 +111,15 @@ s32 func_800A3A74(Vec3f* point, Vec3f** tri, Vec3f* norm) { if (((vtx3.x - vtx2.x) * (ptz - vtx3.z)) <= ((vtx3.z - vtx2.z) * (ptx - vtx3.x))) { if (((vtx1.x - vtx3.x) * (ptz - vtx1.z)) <= ((vtx1.z - vtx3.z) * (ptx - vtx1.x))) { ret = true; - norm->x = ((vtx2.y - vtx1.y) * (vtx3.z - vtx2.z)) - ((vtx2.z - vtx1.z) * (vtx3.y - vtx2.y)); - norm->y = ((vtx2.z - vtx1.z) * (vtx3.x - vtx2.x)) - ((vtx2.x - vtx1.x) * (vtx3.z - vtx2.z)); - norm->z = ((vtx2.x - vtx1.x) * (vtx3.y - vtx2.y)) - ((vtx2.y - vtx1.y) * (vtx3.x - vtx2.x)); - if ((norm->x != 0.0f) || (norm->y != 0.0f) || (norm->z != 0.0f)) { - temp_fv0 = sqrtf(SQ(norm->x) + SQ(norm->y) + SQ(norm->z)); + normOut->x = ((vtx2.y - vtx1.y) * (vtx3.z - vtx2.z)) - ((vtx2.z - vtx1.z) * (vtx3.y - vtx2.y)); + normOut->y = ((vtx2.z - vtx1.z) * (vtx3.x - vtx2.x)) - ((vtx2.x - vtx1.x) * (vtx3.z - vtx2.z)); + normOut->z = ((vtx2.x - vtx1.x) * (vtx3.y - vtx2.y)) - ((vtx2.y - vtx1.y) * (vtx3.x - vtx2.x)); + if ((normOut->x != 0.0f) || (normOut->y != 0.0f) || (normOut->z != 0.0f)) { + temp_fv0 = VEC3F_MAG(normOut); if (temp_fv0 != 0) { - norm->x = (norm->x / temp_fv0) * 127.0f; - norm->y = (norm->y / temp_fv0) * 127.0f; - norm->z = (norm->z / temp_fv0) * 127.0f; + normOut->x = (normOut->x / temp_fv0) * 127.0f; + normOut->y = (normOut->y / temp_fv0) * 127.0f; + normOut->z = (normOut->z / temp_fv0) * 127.0f; } } } diff --git a/src/main/fox_beam.c b/src/main/fox_beam.c index f2489109..04884e0c 100644 --- a/src/main/fox_beam.c +++ b/src/main/fox_beam.c @@ -717,9 +717,7 @@ void func_80038140(PlayerShot* shot) { s32 i; s32 temp_v0; s32 spA4; - f32 temp_fa0; - f32 temp_fv0; - f32 temp_fv1; + Vec3f test; f32 sp94; Vec3f sp88; Vec3f sp7C; @@ -767,10 +765,10 @@ void func_80038140(PlayerShot* shot) { return; } } else if (actor->unk_0B4 == 63) { - temp_fv1 = fabsf(actor->obj.pos.x - shot->obj.pos.x); - temp_fa0 = fabsf(actor->obj.pos.y - shot->obj.pos.y); - temp_fv0 = fabsf(actor->obj.pos.z - shot->obj.pos.z); - if (sqrtf(SQ(temp_fv1) + SQ(temp_fa0) + SQ(temp_fv0)) < 1000.0f) { + test.x = fabsf(actor->obj.pos.x - shot->obj.pos.x); + test.y = fabsf(actor->obj.pos.y - shot->obj.pos.y); + test.z = fabsf(actor->obj.pos.z - shot->obj.pos.z); + if (VEC3F_MAG(&test) < 1000.0f) { func_80037CF4(shot, actor, 0); } } else { @@ -816,27 +814,28 @@ void func_80038140(PlayerShot* shot) { } if (gLevelMode == LEVELMODE_ALL_RANGE) { for (i = 0, player = gPlayer; i < gCamCount; i++, player++) { - temp_fv1 = 50.0f; + test.x = 50.0f; if (gVersusMode && (shot->playerNum < 4) && !((gLaserStrength[shot->playerNum] == LASERS_SINGLE) && (shot->obj.id != PLAYERSHOT_8))) { - temp_fv1 = 100.0f; + test.x = 100.0f; } if (player->unk_280 >= 100) { - temp_fv1 = 150.0f; + test.x = 150.0f; } if (player->form == FORM_LANDMASTER) { - temp_fv1 *= 2.0f; - temp_fa0 = temp_fv1 + 50.0f; + test.x *= 2.0f; + test.y = test.x + 50.0f; } else if (player->form == FORM_ON_FOOT) { - temp_fa0 = temp_fv1 + 50.0f; + test.y = test.x + 50.0f; } else { - temp_fa0 = temp_fv1; + test.y = test.x; } + test.z = test.x; if ((i != shot->playerNum) && ((player->state_1C8 == PLAYERSTATE_1C8_3) || (player->state_1C8 == PLAYERSTATE_1C8_4)) && - (fabsf(player->unk_138 - shot->obj.pos.z) < temp_fv1) && - (fabsf(player->pos.x - shot->obj.pos.x) < temp_fv1) && - (fabsf(player->pos.y - shot->obj.pos.y) < temp_fa0)) { + (fabsf(player->unk_138 - shot->obj.pos.z) < test.z) && + (fabsf(player->pos.x - shot->obj.pos.x) < test.x) && + (fabsf(player->pos.y - shot->obj.pos.y) < test.y)) { if (player->unk_280 >= 100) { shot->obj.rot.y = player->unk_0E8 + player->unk_114 + 180.0f + 90.0f; shot->obj.rot.x = RAND_FLOAT(360.0f); @@ -944,10 +943,10 @@ void func_80038140(PlayerShot* shot) { (boss->obj.id == OBJ_BOSS_313)) { func_8003774C(shot, boss->obj.id, &boss->obj); } else if (boss->obj.id == OBJ_BOSS_310) { - temp_fv1 = fabsf(boss->obj.pos.x - shot->obj.pos.x) * .8333333f; - temp_fa0 = fabsf(boss->obj.pos.y - shot->obj.pos.y) * 2; - temp_fv0 = fabsf(boss->obj.pos.z - shot->obj.pos.z) * 0.8333333f; - if (sqrtf(SQ(temp_fv1) + SQ(temp_fa0) + SQ(temp_fv0)) < 1500.0f) { + test.x = fabsf(boss->obj.pos.x - shot->obj.pos.x) * .8333333f; + test.y = fabsf(boss->obj.pos.y - shot->obj.pos.y) * 2; + test.z = fabsf(boss->obj.pos.z - shot->obj.pos.z) * 0.8333333f; + if (VEC3F_MAG(&test) < 1500.0f) { if (shot->obj.id == PLAYERSHOT_4) { Object_Kill(&shot->obj, shot->sfxSource); } else { @@ -958,10 +957,10 @@ void func_80038140(PlayerShot* shot) { } } else { if (boss->obj.id == OBJ_BOSS_316) { - temp_fv1 = fabsf(boss->obj.pos.x - shot->obj.pos.x); - temp_fa0 = fabsf(boss->obj.pos.y - 300.0f - shot->obj.pos.y) * 7.42f; - temp_fv0 = fabsf(boss->obj.pos.z - shot->obj.pos.z); - if (sqrtf(SQ(temp_fv1) + SQ(temp_fa0) + SQ(temp_fv0)) < 2700.0f) { + test.x = fabsf(boss->obj.pos.x - shot->obj.pos.x); + test.y = fabsf(boss->obj.pos.y - 300.0f - shot->obj.pos.y) * 7.42f; + test.z = fabsf(boss->obj.pos.z - shot->obj.pos.z); + if (VEC3F_MAG(&test) < 2700.0f) { if (shot->obj.id == PLAYERSHOT_4) { Object_Kill(&shot->obj, shot->sfxSource); } else { @@ -1743,9 +1742,7 @@ void func_8003C008(PlayerShot* shot) { s32 j; f32* hitboxData; Boss* boss; - f32 temp_ft4; - f32 temp_ft5; - f32 var_fa1; + Vec3f test; f32 var_fs2; Vec3f sp8C; Vec3f sp80; @@ -1784,13 +1781,13 @@ void func_8003C008(PlayerShot* shot) { sp8C.y = shot->obj.pos.y - boss->obj.pos.y; sp8C.z = shot->obj.pos.z - boss->obj.pos.z; Matrix_MultVec3fNoTranslate(gCalcMatrix, &sp8C, &sp80); - temp_ft4 = (hitboxData[4] + boss->obj.pos.x) - (boss->obj.pos.x + sp80.x); - temp_ft5 = (hitboxData[2] + boss->obj.pos.y) - (boss->obj.pos.y + sp80.y); - var_fa1 = (hitboxData[0] + boss->obj.pos.z) - (boss->obj.pos.z + sp80.z); - if ((gLevelMode == LEVELMODE_ON_RAILS) && (var_fa1 < 0.0f)) { - var_fa1 *= 0.6f; + test.x = (hitboxData[4] + boss->obj.pos.x) - (boss->obj.pos.x + sp80.x); + test.y = (hitboxData[2] + boss->obj.pos.y) - (boss->obj.pos.y + sp80.y); + test.z = (hitboxData[0] + boss->obj.pos.z) - (boss->obj.pos.z + sp80.z); + if ((gLevelMode == LEVELMODE_ON_RAILS) && (test.z < 0.0f)) { + test.z *= 0.6f; } - if (sqrtf(SQ(temp_ft4) + SQ(temp_ft5) + SQ(var_fa1)) < var_fs2) { + if (VEC3F_MAG(&test) < var_fs2) { boss->dmgPart = j; boss->dmgType = DMG_BOMB; boss->damage = 20; @@ -1977,9 +1974,7 @@ void func_8003C4D0(PlayerShot* shot, s32 damage) { } void func_8003CC08(PlayerShot* shot) { - f32 temp_fa0; - f32 temp_fa1; - f32 temp_fv1; + Vec3f test; f32 var_ft5; switch (shot->unk_5C) { @@ -2022,10 +2017,10 @@ void func_8003CC08(PlayerShot* shot) { if ((shot->unk_64 > 0) && (shot->unk_64 < 30)) { if (!gVersusMode && ((gPlayer[0].state_1C8 == PLAYERSTATE_1C8_3) || (gPlayer[0].state_1C8 == PLAYERSTATE_1C8_5))) { - temp_fv1 = gPlayer[0].pos.x - shot->obj.pos.x; - temp_fa0 = gPlayer[0].pos.y - shot->obj.pos.y; - temp_fa1 = gPlayer[0].unk_138 - shot->obj.pos.z; - var_ft5 = sqrtf(SQ(temp_fv1) + SQ(temp_fa0) + SQ(temp_fa1)) * 0.01f; + test.x = gPlayer[0].pos.x - shot->obj.pos.x; + test.y = gPlayer[0].pos.y - shot->obj.pos.y; + test.z = gPlayer[0].unk_138 - shot->obj.pos.z; + var_ft5 = VEC3F_MAG(&test) * 0.01f; if (var_ft5 > 60.0f) { var_ft5 = 60.0f; } diff --git a/src/main/fox_display.c b/src/main/fox_display.c index ed391ebd..e6686032 100644 --- a/src/main/fox_display.c +++ b/src/main/fox_display.c @@ -1365,7 +1365,7 @@ void func_80057248(void) { RCP_SetupDL_40(); for (i = 0; i < ARRAY_COUNT(D_80177E98); i++) { if (D_80177E98[i].z < 0.0f) { - var_fs0 = sqrtf(VEC3F_SQ(D_80177E98[i])) * 0.0015f; + var_fs0 = (VEC3F_MAG(&D_80177E98[i])) * 0.0015f; if (var_fs0 > 100.0f) { var_fs0 = 100.0f; } else if (var_fs0 < 1.0f) { @@ -1401,7 +1401,7 @@ void func_80057504(void) { for (i = 0; i < gCamCount; i++) { if (D_80161578[i].z < 0.0f) { - var_fs0 = sqrtf(VEC3F_SQ(D_80161578[i])); + var_fs0 = (VEC3F_MAG(&D_80161578[i])); if (var_fs0 < 20000.0f) { var_fs0 *= 0.0015f; if (var_fs0 > 100.0f) { diff --git a/src/main/fox_edisplay.c b/src/main/fox_edisplay.c index 9f3e58ac..418af819 100644 --- a/src/main/fox_edisplay.c +++ b/src/main/fox_edisplay.c @@ -1460,7 +1460,7 @@ void func_8005F670(Vec3f* arg0) { sp9C.x = arg0->x - D_80178370; sp9C.y = arg0->y - D_80178374; sp9C.z = arg0->z - D_80178378; - temp_fv0 = sqrtf(VEC3F_SQ(sp9C)); + temp_fv0 = (VEC3F_MAG(&sp9C)); if (gPlayer[0].state_1C8 == PLAYERSTATE_1C8_2) { var_fs0 = 700.0f / temp_fv0; } else { diff --git a/src/main/fox_effect.c b/src/main/fox_effect.c index 7cbff95b..842ed9e2 100644 --- a/src/main/fox_effect.c +++ b/src/main/fox_effect.c @@ -104,7 +104,7 @@ void BonusText_Draw(BonusText* bonus) { if ((fabsf(sp54.x) < 20000.0f) && (fabsf(sp54.y) < 20000.0f)) { if ((sp54.z < 0.0f) && (sp54.z > -20000.0f)) { - sp50 = sqrtf(VEC3F_SQ(sp54)) * 0.0015f * 0.2f; + sp50 = (VEC3F_MAG(&sp54)) * 0.0015f * 0.2f; Matrix_RotateY(gGfxMatrix, -gPlayer[gPlayerNum].unk_058, 1); Matrix_RotateX(gGfxMatrix, gPlayer[gPlayerNum].unk_05C, 1); Matrix_Scale(gGfxMatrix, sp50, sp50, 1.0f, 1); diff --git a/src/main/fox_enmy.c b/src/main/fox_enmy.c index 418d0f92..c94e9c27 100644 --- a/src/main/fox_enmy.c +++ b/src/main/fox_enmy.c @@ -844,7 +844,7 @@ s32 func_8006351C(s32 index, Vec3f* pos, Vec3f* arg2, s32 arg3) { temp.x = fabsf(boss->obj.pos.x - pos->x) * (5.0f / 6.0f); temp.y = fabsf(boss->obj.pos.y - pos->y) * 2; temp.z = fabsf(boss->obj.pos.z - pos->z) * (5.0f / 6.0f); - if (sqrtf(VEC3F_SQ(temp)) < 1500.0f) { + if ((VEC3F_MAG(&temp)) < 1500.0f) { boss->dmgType = DMG_BEAM; return 2; } @@ -853,7 +853,7 @@ s32 func_8006351C(s32 index, Vec3f* pos, Vec3f* arg2, s32 arg3) { temp.x = fabsf(boss->obj.pos.x - pos->x); temp.y = fabsf(boss->obj.pos.y - 300.0f - pos->y) * 7.42f; temp.z = fabsf(boss->obj.pos.z - pos->z); - if (sqrtf(VEC3F_SQ(temp)) < 2700.0f) { + if ((VEC3F_MAG(&temp)) < 2700.0f) { return 2; } } diff --git a/src/main/fox_enmy2.c b/src/main/fox_enmy2.c index 3cc7b3ee..b3345e51 100644 --- a/src/main/fox_enmy2.c +++ b/src/main/fox_enmy2.c @@ -1026,14 +1026,14 @@ void func_8006D36C(Actor* actor) { temp_s1 = SEGMENTED_TO_VIRTUAL(var_v1[actor->unk_0E4]); switch (temp_s1[actor->unk_0E6] & 0xFE00) { - case 0xFE00: + case EVOP_127 << 9: actor->state = 200; if (actor->info.unk_10 > 10000.0f) { actor->info.unk_10 = 100.0f; } break; - case 0xD000: + case EVOP_104 << 9: Audio_KillSfxBySource(actor->sfxSource); actor->unk_0B4 = temp_s1[actor->unk_0E6 + 1]; @@ -1163,7 +1163,7 @@ void func_8006D36C(Actor* actor) { func_8006D36C(actor); break; - case 0xD200: + case EVOP_105 << 9: actor->iwork[12] = temp_s1[actor->unk_0E6 + 1]; if (actor->iwork[12] < 4) { @@ -1174,14 +1174,14 @@ void func_8006D36C(Actor* actor) { func_8006D36C(actor); break; - case 0xE200: + case EVOP_113 << 9: actor->iwork[15] = temp_s1[actor->unk_0E6 + 1]; actor->iwork[16] = temp_s1[actor->unk_0E6] & 0x1FF; actor->unk_0E6 += 2; func_8006D36C(actor); break; - case 0x0600: + case EVOP_3 << 9: D_80177E78 = actor->index; D_80177F10.x = actor->obj.pos.x; D_80177F10.y = actor->obj.pos.y; @@ -1193,7 +1193,7 @@ void func_8006D36C(Actor* actor) { func_8006D36C(actor); break; - case 0xE000: + case EVOP_112 << 9: if (temp_s1[actor->unk_0E6 + 1] == 0xE) { actor->state = 0xA; actor->fwork[11] = 0.0f; @@ -1222,19 +1222,19 @@ void func_8006D36C(Actor* actor) { func_8006D36C(actor); break; - case 0xE800: + case EVOP_116 << 9: actor->unk_044 = temp_s1[actor->unk_0E6 + 1]; actor->unk_0E6 += 2; func_8006D36C(actor); break; - case 0xEC00: + case EVOP_118 << 9: Audio_SetBaseSfxReverb(temp_s1[actor->unk_0E6 + 1]); actor->unk_0E6 += 2; func_8006D36C(actor); break; - case 0xF000: + case EVOP_120 << 9: temp_v0_4 = Message_PtrFromId(temp_s1[actor->unk_0E6 + 1]); if ((temp_v0_4 != NULL) && (gPlayer[0].state_1C8 == PLAYERSTATE_1C8_3)) { Radio_PlayMessage(temp_v0_4, temp_s1[actor->unk_0E6] & 0x1FF); @@ -1243,7 +1243,7 @@ void func_8006D36C(Actor* actor) { func_8006D36C(actor); break; - case 0xEE00: + case EVOP_119 << 9: if ((D_80161A88 == 2) && (temp_s1[actor->unk_0E6 + 1] != 2)) { Audio_KillSfxBySourceAndId(gPlayer[0].sfxSource, 0x1100000B); } @@ -1253,39 +1253,39 @@ void func_8006D36C(Actor* actor) { actor->obj.status = OBJ_FREE; break; - case 0x7000: + case EVOP_56 << 9: D_800CFF90 = temp_s1[actor->unk_0E6] & 0x1FF; D_80161690 = temp_s1[actor->unk_0E6 + 1]; actor->unk_0E6 += 2; func_8006D36C(actor); break; - case 0x7200: + case EVOP_57 << 9: gTeamShields[temp_s1[actor->unk_0E6 + 1]] = 0xFF; actor->unk_0E6 += 2; func_8006D36C(actor); break; - case 0x7400: + case EVOP_58 << 9: func_8001D2FC(actor->sfxSource, temp_s1[actor->unk_0E6 + 1]); actor->unk_0E6 += 2; func_8006D36C(actor); break; - case 0x7600: + case EVOP_59 << 9: func_8001D3A0(actor->sfxSource, temp_s1[actor->unk_0E6 + 1]); actor->unk_0E6 += 2; func_8006D36C(actor); break; - case 0xF400: + case EVOP_122 << 9: SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_BGM, 50); SEQCMD_STOP_SEQUENCE(SEQ_PLAYER_FANFARE, 50); actor->unk_0E6 += 2; func_8006D36C(actor); break; - case 0xF200: + case EVOP_121 << 9: if (actor->iwork[12] == temp_s1[actor->unk_0E6 + 1]) { actor->unk_0D0 = 1; actor->damage = temp_s1[actor->unk_0E6] & 0x1FF; @@ -1297,7 +1297,7 @@ void func_8006D36C(Actor* actor) { func_8006D36C(actor); break; - case 0xF800: + case EVOP_124 << 9: actor->iwork[7] = 1; for (i = 0; i < ARRAY_COUNT(gUnkEntities30); i++) { if (gUnkEntities30[i].mode == 0) { @@ -1318,41 +1318,41 @@ void func_8006D36C(Actor* actor) { func_8006D36C(actor); break; - case 0xFA00: + case EVOP_125 << 9: actor->iwork[7] = 0; actor->unk_0E6 += 2; func_8006D36C(actor); break; - case 0x5000: + case EVOP_40 << 9: actor->state = 6; actor->timer_0BC = temp_s1[actor->unk_0E6 + 1]; actor->fwork[24] = temp_s1[actor->unk_0E6] & 0x1FF; actor->unk_0E6 += 2; break; - case 0x5200: + case EVOP_41 << 9: actor->state = 7; actor->timer_0BC = temp_s1[actor->unk_0E6 + 1]; actor->fwork[24] = temp_s1[actor->unk_0E6] & 0x1FF; actor->unk_0E6 += 2; break; - case 0x5400: + case EVOP_42 << 9: actor->state = 8; actor->timer_0BC = temp_s1[actor->unk_0E6 + 1]; actor->fwork[24] = temp_s1[actor->unk_0E6] & 0x1FF; actor->unk_0E6 += 2; break; - case 0x5600: + case EVOP_43 << 9: actor->state = 9; actor->timer_0BC = temp_s1[actor->unk_0E6 + 1]; actor->fwork[24] = temp_s1[actor->unk_0E6] & 0x1FF; actor->unk_0E6 += 2; break; - case 0x5A00: + case EVOP_45 << 9: actor->state = 1; actor->iwork[1] = D_800CFF80[temp_s1[actor->unk_0E6] & 0x1FF]; actor->fwork[17] = temp_s1[actor->unk_0E6 + 1]; @@ -1360,35 +1360,35 @@ void func_8006D36C(Actor* actor) { actor->unk_0E6 += 2; break; - case 0x5800: + case EVOP_44 << 9: actor->state = 0xD; actor->timer_0BC = temp_s1[actor->unk_0E6 + 1]; actor->fwork[24] = temp_s1[actor->unk_0E6] & 0x1FF; actor->unk_0E6 += 2; break; - case 0x5C00: + case EVOP_46 << 9: actor->state = 0xE; actor->timer_0BC = temp_s1[actor->unk_0E6 + 1]; actor->fwork[24] = temp_s1[actor->unk_0E6] & 0x1FF; actor->unk_0E6 += 2; break; - case 0x5E00: + case EVOP_47 << 9: actor->state = 0xF; actor->timer_0BC = temp_s1[actor->unk_0E6 + 1]; actor->fwork[24] = temp_s1[actor->unk_0E6] & 0x1FF; actor->unk_0E6 += 2; break; - case 0xC000: + case EVOP_96 << 9: actor->iwork[2] = temp_s1[actor->unk_0E6 + 1]; actor->iwork[3] = temp_s1[actor->unk_0E6] & 0x1FF; actor->unk_0E6 += 2; func_8006D36C(actor); break; - case 0xFC00: + case EVOP_126 << 9: if (temp_s1[actor->unk_0E6 + 1] < actor->iwork[0]) { actor->unk_0E6 += 2; actor->iwork[0] = 0; @@ -1403,13 +1403,13 @@ void func_8006D36C(Actor* actor) { func_8006D36C(actor); break; - case 0x6000: + case EVOP_48 << 9: actor->state = 1; actor->timer_0BC = temp_s1[actor->unk_0E6 + 1]; actor->unk_0E6 += 2; break; - case 0x0000: + case EVOP_0 << 9: actor->fwork[0] = temp_s1[actor->unk_0E6] & 0x7F; actor->fwork[1] = actor->fwork[0]; actor->iwork[5] = temp_s1[actor->unk_0E6] & 0x180; @@ -1418,13 +1418,13 @@ void func_8006D36C(Actor* actor) { actor->unk_0E6 += 2; break; - case 0x0400: + case EVOP_2 << 9: actor->fwork[22] = temp_s1[actor->unk_0E6 + 1] & 0xFF; actor->unk_0E6 += 2; func_8006D36C(actor); break; - case 0x0200: + case EVOP_1 << 9: actor->fwork[1] = temp_s1[actor->unk_0E6] & 0x7F; actor->iwork[5] = temp_s1[actor->unk_0E6] & 0x180; actor->timer_0BC = temp_s1[actor->unk_0E6 + 1]; @@ -1432,48 +1432,48 @@ void func_8006D36C(Actor* actor) { actor->unk_0E6 += 2; break; - case 0x0800: + case EVOP_4 << 9: actor->timer_0C0 = temp_s1[actor->unk_0E6 + 1]; actor->iwork[13] = 1; actor->unk_0E6 += 2; func_8006D36C(actor); break; - case 0x1000: + case EVOP_8 << 9: actor->iwork[13] = 0; actor->unk_0E6 += 2; func_8006D36C(actor); break; - case 0x1200: + case EVOP_9 << 9: actor->state = 2; actor->fwork[2] = temp_s1[actor->unk_0E6] & 0x1FF; actor->fwork[3] = temp_s1[actor->unk_0E6 + 1] * 0.1f; actor->unk_0E6 += 2; break; - case 0x1400: + case EVOP_10 << 9: actor->state = 3; actor->fwork[2] = temp_s1[actor->unk_0E6] & 0x1FF; actor->fwork[3] = temp_s1[actor->unk_0E6 + 1] * 0.1f; actor->unk_0E6 += 2; break; - case 0x1600: + case EVOP_11 << 9: actor->state = 4; actor->fwork[2] = temp_s1[actor->unk_0E6] & 0x1FF; actor->fwork[3] = temp_s1[actor->unk_0E6 + 1] * 0.1f; actor->unk_0E6 += 2; break; - case 0x1800: + case EVOP_12 << 9: actor->state = 5; actor->fwork[2] = temp_s1[actor->unk_0E6] & 0x1FF; actor->fwork[3] = temp_s1[actor->unk_0E6 + 1] * 0.1f; actor->unk_0E6 += 2; break; - case 0x2000: + case EVOP_16 << 9: actor->fwork[4] = temp_s1[actor->unk_0E6] & 0x1FF; actor->fwork[5] = temp_s1[actor->unk_0E6 + 1] * 0.1f; actor->fwork[6] = 1.0f; @@ -1481,7 +1481,7 @@ void func_8006D36C(Actor* actor) { func_8006D36C(actor); break; - case 0x2200: + case EVOP_17 << 9: actor->fwork[4] = temp_s1[actor->unk_0E6] & 0x1FF; actor->fwork[5] = temp_s1[actor->unk_0E6 + 1] * 0.1f; actor->fwork[6] = -1.0f; @@ -1489,7 +1489,7 @@ void func_8006D36C(Actor* actor) { func_8006D36C(actor); break; - case 0x2400: + case EVOP_18 << 9: actor->fwork[7] = temp_s1[actor->unk_0E6] & 0x1FF; actor->fwork[8] = temp_s1[actor->unk_0E6 + 1] * 0.1f; actor->fwork[9] = 1.0f; @@ -1497,7 +1497,7 @@ void func_8006D36C(Actor* actor) { func_8006D36C(actor); break; - case 0x2600: + case EVOP_19 << 9: actor->fwork[7] = temp_s1[actor->unk_0E6] & 0x1FF; actor->fwork[8] = temp_s1[actor->unk_0E6 + 1] * 0.1f; actor->fwork[9] = -1.0f; @@ -1505,7 +1505,7 @@ void func_8006D36C(Actor* actor) { func_8006D36C(actor); break; - case 0x2800: + case EVOP_20 << 9: actor->fwork[10] = temp_s1[actor->unk_0E6] & 0x1FF; actor->fwork[11] = temp_s1[actor->unk_0E6 + 1] * 0.1f; actor->fwork[12] = 1.0f; @@ -1513,7 +1513,7 @@ void func_8006D36C(Actor* actor) { func_8006D36C(actor); break; - case 0x2A00: + case EVOP_21 << 9: actor->fwork[10] = temp_s1[actor->unk_0E6] & 0x1FF; actor->fwork[11] = temp_s1[actor->unk_0E6 + 1] * 0.1f; actor->fwork[12] = -1.0f; @@ -1521,13 +1521,13 @@ void func_8006D36C(Actor* actor) { func_8006D36C(actor); break; - case 0x3000: + case EVOP_24 << 9: actor->iwork[6] = 1; actor->unk_0E6 += 2; func_8006D36C(actor); break; - case 0x3200: + case EVOP_25 << 9: actor->iwork[6] = 0; actor->unk_0E6 += 2; func_8006D36C(actor); diff --git a/src/main/fox_play.c b/src/main/fox_play.c index 5f1f032d..8543e810 100644 --- a/src/main/fox_play.c +++ b/src/main/fox_play.c @@ -1813,7 +1813,7 @@ void func_800A8BA4(Player* player) { spfD4.x = fabsf(boss->obj.pos.x - player->pos.x) * .8333333f; spfD4.y = fabsf(boss->obj.pos.y - player->pos.y) * 2; spfD4.z = fabsf(boss->obj.pos.z - player->unk_138) * 0.8333333f; - if (sqrtf(VEC3F_SQ(spfD4)) < 1500.0f) { + if ((VEC3F_MAG(&spfD4)) < 1500.0f) { Player_ApplyDamage(player, 0, boss->info.damage); player->unk_110 = 0.0f; player->timer_498 = 5; @@ -1834,7 +1834,7 @@ void func_800A8BA4(Player* player) { spfD4.x = fabsf(boss->obj.pos.x - player->pos.x); spfD4.y = fabsf(boss->obj.pos.y - 300.0f - player->pos.y) * 7.42f; spfD4.z = fabsf(boss->obj.pos.z - player->unk_138); - if (sqrtf(VEC3F_SQ(spfD4)) < 2700.0f) { + if ((VEC3F_MAG(&spfD4)) < 2700.0f) { Player_ApplyDamage(player, 3, boss->info.damage); } } @@ -1887,7 +1887,7 @@ void func_800A8BA4(Player* player) { spfD4.x = fabsf(actor->obj.pos.x - player->pos.x); spfD4.y = fabsf(actor->obj.pos.y - player->pos.y); spfD4.z = fabsf(actor->obj.pos.z - player->unk_138); - if (sqrtf(VEC3F_SQ(spfD4)) < 900.0f) { + if ((VEC3F_MAG(&spfD4)) < 900.0f) { Player_ApplyDamage(player, 0, actor->info.damage); actor->unk_0D0 = 3; } diff --git a/src/main/fox_std_lib.c b/src/main/fox_std_lib.c index cabacedc..51aec737 100644 --- a/src/main/fox_std_lib.c +++ b/src/main/fox_std_lib.c @@ -532,7 +532,7 @@ s32 Math_PursueVec3f(Vec3f* pos, Vec3f* target, Vec3f* rot, f32 stepSize, f32 sc diff.y = target->y - pos->y; diff.z = target->z - pos->z; - return sqrtf(VEC3F_SQ(diff)) < dist; + return (VEC3F_MAG(&diff)) < dist; } void TextureRect_4bCI(Gfx** gfxPtr, void* texture, void* palette, u32 width, u32 height, f32 xPos, f32 yPos, f32 xScale, diff --git a/src/overlays/ovl_i1/fox_ve1.c b/src/overlays/ovl_i1/fox_ve1.c index 433bd459..3f80c9b4 100644 --- a/src/overlays/ovl_i1/fox_ve1.c +++ b/src/overlays/ovl_i1/fox_ve1.c @@ -420,7 +420,7 @@ void func_i1_80192518(Actor* actor) { case 2: if (actor->timer_0BC == 0) { - src.x = temp_fv1_2 = Math_SmoothStepToF(actor->fwork, actor->fwork[1], 0.7f, 80.0f, 0.01f); + src.x = temp_fv1_2 = Math_SmoothStepToF(&actor->fwork[0], actor->fwork[1], 0.7f, 80.0f, 0.01f); src.y = 0.0f; src.z = 0.0f; @@ -728,7 +728,7 @@ void func_i1_80192EB0(Actor* actor) { case 2: if (actor->timer_0BC == 0) { - sp50.y = sp40 = Math_SmoothStepToF(actor->fwork, actor->fwork[1], 0.7f, 80.0f, 0.01f); + sp50.y = sp40 = Math_SmoothStepToF(&actor->fwork[0], actor->fwork[1], 0.7f, 80.0f, 0.01f); sp50.x = 0.0f; sp50.z = 0.0f; @@ -1989,19 +1989,19 @@ void func_i1_80194398(Boss* boss) { switch (boss->swork[7]) { case 0: if (boss->fwork[11] < 0.9f) { - Math_SmoothStepToF(boss->fwork, 0.2f, 0.5f, 0.05f, 0.01f); + Math_SmoothStepToF(&boss->fwork[0], 0.2f, 0.5f, 0.05f, 0.01f); Math_SmoothStepToVec3fArray(sp118, boss->vwork, 1, 27, boss->fwork[0], 360.0f, 0.01f); } else { - Math_SmoothStepToF(boss->fwork, 1.0f, 0.5f, 0.05f, 0.01f); + Math_SmoothStepToF(&boss->fwork[0], 1.0f, 0.5f, 0.05f, 0.01f); Math_SmoothStepToVec3fArray(sp118, boss->vwork, 1, 27, boss->fwork[0], 360.0f, 0.01f); } break; case 1: - Math_SmoothStepToF(boss->fwork, 1.0f, 0.1f, 0.05f, 0.01f); + Math_SmoothStepToF(&boss->fwork[0], 1.0f, 0.1f, 0.05f, 0.01f); Math_SmoothStepToVec3fArray(sp118, boss->vwork, 1, 27, boss->fwork[0], 360.0f, 0.01f); break; case 2: - Math_SmoothStepToF(boss->fwork, 0.7f, 0.07f, 0.05f, 0.01f); + Math_SmoothStepToF(&boss->fwork[0], 0.7f, 0.07f, 0.05f, 0.01f); Math_SmoothStepToVec3fArray(sp118, boss->vwork, 1, 27, boss->fwork[0], 45.0f, 0.01f); break; } @@ -2421,7 +2421,7 @@ void func_i1_8019864C(PlayerShot* playerShot) { diff.z = hitboxData[0] - sp78.z; diff.z *= 0.6f; - D_i1_8019B7F0[j] = (sqrtf(VEC3F_SQ(diff)) < temp_fs1) ? 1 : 0; + D_i1_8019B7F0[j] = ((VEC3F_MAG(&diff)) < temp_fs1) ? 1 : 0; } } } diff --git a/src/overlays/ovl_i2/fox_sx.c b/src/overlays/ovl_i2/fox_sx.c index 12f4cfe2..e9c07bdf 100644 --- a/src/overlays/ovl_i2/fox_sx.c +++ b/src/overlays/ovl_i2/fox_sx.c @@ -600,7 +600,7 @@ void func_i2_80190078(Boss* boss) { frameData = Animation_GetFrameData(&D_6016E28, boss->unk_04C, sp80); Math_SmoothStepToVec3fArray(sp80, boss->vwork, 1, frameData, boss->fwork[0], 100.0f, 0.0f); - Math_SmoothStepToF(boss->fwork, 1.0f, 1.0f, 0.05f, 0); + Math_SmoothStepToF(&boss->fwork[0], 1.0f, 1.0f, 0.05f, 0); boss->unk_04C++; if (boss->unk_04C >= Animation_GetFrameCount(&D_6016E28)) { @@ -636,7 +636,7 @@ void func_i2_80190078(Boss* boss) { frameData = Animation_GetFrameData(&D_60123BC, boss->unk_04C, sp80); Math_SmoothStepToVec3fArray(sp80, boss->vwork, 1, frameData, boss->fwork[0], 100.0f, 0.0f); - Math_SmoothStepToF(boss->fwork, 1.0f, 1.0f, 0.05f, 0); + Math_SmoothStepToF(&boss->fwork[0], 1.0f, 1.0f, 0.05f, 0); boss->unk_04C++; if (boss->unk_04C >= Animation_GetFrameCount(&D_60123BC)) { @@ -672,7 +672,7 @@ void func_i2_80190078(Boss* boss) { frameData = Animation_GetFrameData(&D_6013798, boss->unk_04C, sp80); Math_SmoothStepToVec3fArray(sp80, boss->vwork, 1, frameData, boss->fwork[0], 100.0f, 0.0f); - Math_SmoothStepToF(boss->fwork, 1.0f, 1.0f, 0.05f, 0); + Math_SmoothStepToF(&boss->fwork[0], 1.0f, 1.0f, 0.05f, 0); boss->unk_04C++; if (boss->unk_04C >= Animation_GetFrameCount(&D_6013798)) { @@ -706,7 +706,7 @@ void func_i2_80190078(Boss* boss) { frameData = Animation_GetFrameData(&D_6016E28, 0, sp80); Math_SmoothStepToVec3fArray(sp80, boss->vwork, 1, frameData, boss->fwork[0], 100.0f, 0.0f); - Math_SmoothStepToF(boss->fwork, 1.0f, 1.0f, 0.05f, 0); + Math_SmoothStepToF(&boss->fwork[0], 1.0f, 1.0f, 0.05f, 0); Math_SmoothStepToF(&boss->fwork[27], 30.0f, 0.05f, 1.0f, 0); Math_SmoothStepToF(&boss->fwork[28], -30.0f, 0.05f, 1.0f, 0); @@ -833,7 +833,7 @@ void func_i2_80190078(Boss* boss) { frameData = Animation_GetFrameData(&D_601C690, boss->unk_04C, sp80); Math_SmoothStepToVec3fArray(sp80, boss->vwork, 1, frameData, boss->fwork[0], 100.0f, 0.0f); - Math_SmoothStepToF(boss->fwork, 1.0f, 1.0f, 0.05f, 0); + Math_SmoothStepToF(&boss->fwork[0], 1.0f, 1.0f, 0.05f, 0); boss->unk_04C++; if (boss->unk_04C >= Animation_GetFrameCount(&D_601C690)) { @@ -851,7 +851,7 @@ void func_i2_80190078(Boss* boss) { frameData = Animation_GetFrameData(&D_600A2D4, 0, sp80); Math_SmoothStepToVec3fArray(sp80, boss->vwork, 1, frameData, boss->fwork[0], 2.5f, 0.0f); - Math_SmoothStepToF(boss->fwork, 0.1f, 1.0f, 0.005f, 0); + Math_SmoothStepToF(&boss->fwork[0], 0.1f, 1.0f, 0.005f, 0); if (boss->timer_050 == 0) { boss->state = 8; @@ -879,7 +879,7 @@ void func_i2_80190078(Boss* boss) { frameData = Animation_GetFrameData(&D_600F890, boss->unk_04C, sp80); Math_SmoothStepToVec3fArray(sp80, boss->vwork, 1, frameData, boss->fwork[0], 100.0f, 0.0f); - Math_SmoothStepToF(boss->fwork, 1.0f, 1.0f, 0.02f, 0); + Math_SmoothStepToF(&boss->fwork[0], 1.0f, 1.0f, 0.02f, 0); boss->unk_04C++; if (boss->unk_04C >= Animation_GetFrameCount(&D_600F890)) { @@ -899,7 +899,7 @@ void func_i2_80190078(Boss* boss) { frameData = Animation_GetFrameData(&D_60123BC, boss->unk_04C, sp80); Math_SmoothStepToVec3fArray(sp80, boss->vwork, 1, frameData, boss->fwork[0], 50.0f, 0.0f); - Math_SmoothStepToF(boss->fwork, 1.0f, 1.0f, 0.01f, 0); + Math_SmoothStepToF(&boss->fwork[0], 1.0f, 1.0f, 0.01f, 0); if (boss->timer_050 == 0) { boss->unk_04C++; @@ -931,7 +931,7 @@ void func_i2_80190078(Boss* boss) { frameData = Animation_GetFrameData(&D_601AA28, boss->unk_04C, sp80); Math_SmoothStepToVec3fArray(sp80, boss->vwork, 1, frameData, boss->fwork[0], 50.0f, 0.0f); - Math_SmoothStepToF(boss->fwork, 1.0f, 1.0f, 0.01f, 0); + Math_SmoothStepToF(&boss->fwork[0], 1.0f, 1.0f, 0.01f, 0); boss->unk_04C++; if (boss->unk_04C >= Animation_GetFrameCount(&D_601AA28)) { @@ -960,7 +960,7 @@ void func_i2_80190078(Boss* boss) { frameData = Animation_GetFrameData(&D_60158C4, boss->unk_04C, sp80); Math_SmoothStepToVec3fArray(sp80, boss->vwork, 1, frameData, boss->fwork[0], 100.0f, 0.0f); - Math_SmoothStepToF(boss->fwork, 1.0f, 1.0f, 0.05f, 0); + Math_SmoothStepToF(&boss->fwork[0], 1.0f, 1.0f, 0.05f, 0); boss->unk_04C++; if (!(boss->unk_04C & 15)) { @@ -1023,7 +1023,7 @@ void func_i2_80190078(Boss* boss) { frameData = Animation_GetFrameData(&D_6009FF8, 0, sp80); Math_SmoothStepToVec3fArray(sp80, boss->vwork, 1, frameData, boss->fwork[0], 5.0f, 0.0f); - Math_SmoothStepToF(boss->fwork, 0.1f, 1.0f, 0.001f, 0); + Math_SmoothStepToF(&boss->fwork[0], 0.1f, 1.0f, 0.001f, 0); Math_SmoothStepToF(&boss->unk_078.y, 10.0f, 1.0f, 0.1f, 0); Math_SmoothStepToF(&boss->obj.rot.y, 2880.0f, 0.1f, boss->unk_078.y, 0.1f); @@ -1051,7 +1051,7 @@ void func_i2_80190078(Boss* boss) { frameData = Animation_GetFrameData(&D_601C690, boss->unk_04C, sp80); Math_SmoothStepToVec3fArray(sp80, boss->vwork, 1, frameData, boss->fwork[0], 100.0f, 0.0f); - Math_SmoothStepToF(boss->fwork, 1.0f, 1.0f, 0.05f, 0); + Math_SmoothStepToF(&boss->fwork[0], 1.0f, 1.0f, 0.05f, 0); boss->unk_04C++; if (boss->unk_04C >= Animation_GetFrameCount(&D_601C690)) { diff --git a/src/overlays/ovl_i3/fox_aq.c b/src/overlays/ovl_i3/fox_aq.c index b17a1532..2a39c7e3 100644 --- a/src/overlays/ovl_i3/fox_aq.c +++ b/src/overlays/ovl_i3/fox_aq.c @@ -2155,7 +2155,7 @@ void func_i3_801AFA5C(Actor* actor) { break; case 5: if (actor->obj.pos.y > (gGroundLevel + 70.0f)) { - Math_SmoothStepToF(actor->fwork, 1.0f, 0.1f, 0.2f, 0.0001f); + Math_SmoothStepToF(&actor->fwork[0], 1.0f, 0.1f, 0.2f, 0.0001f); Math_SmoothStepToF(&actor->fwork[1], 1.0f, 0.1f, 0.2f, 0.0001f); Math_SmoothStepToF(&actor->fwork[2], 1.0f, 0.1f, 0.2f, 0.0001f); Math_SmoothStepToF(&actor->vel.y, -10.0f, 0.1f, 1.0f, 0.001f); @@ -2191,7 +2191,7 @@ void func_i3_801AFA5C(Actor* actor) { if (actor->timer_0BE == 0) { actor->timer_0BE = 10; } - Math_SmoothStepToF(actor->fwork, 0.0f, 0.05f, 0.1f, 0.001f); + Math_SmoothStepToF(&actor->fwork[0], 0.0f, 0.05f, 0.1f, 0.001f); Math_SmoothStepToF(&actor->fwork[1], 0.0f, 0.05f, 0.1f, 0.001f); Math_SmoothStepToF(&actor->fwork[2], 0.0f, 0.05f, 0.1f, 0.001f); Math_SmoothStepToF(&actor->obj.pos.y, -300.0f, 0.1f, 1.0f, 0.001f); diff --git a/src/overlays/ovl_i3/fox_so.c b/src/overlays/ovl_i3/fox_so.c index 0ccd65e7..c501dd5e 100644 --- a/src/overlays/ovl_i3/fox_so.c +++ b/src/overlays/ovl_i3/fox_so.c @@ -2363,7 +2363,7 @@ void func_i3_801A5B3C(Boss* bossSO) { bossSO->fwork[SO_FWK_31] - 20.0f, 1.0f); } } - Math_SmoothStepToF(bossSO->fwork, 1.0f, 0.01f, 0.01f, 0.0f); + Math_SmoothStepToF(&bossSO->fwork[0], 1.0f, 0.01f, 0.01f, 0.0f); if ((bossSO->health > 0) || (bossSO->swork[SO_SWK_0] == 0)) { D_i3_801BF980[bossSO->swork[SO_SWK_0]](bossSO); } diff --git a/src/overlays/ovl_i4/fox_bo.c b/src/overlays/ovl_i4/fox_bo.c index 65de412f..ad39ce35 100644 --- a/src/overlays/ovl_i4/fox_bo.c +++ b/src/overlays/ovl_i4/fox_bo.c @@ -2003,7 +2003,7 @@ void func_i4_80191AFC(Boss* boss) { void func_i4_80191BAC(Boss* boss) { D_i4_801A0530 = 0; - Math_SmoothStepToF(boss->fwork, D_i4_801A03DC * 9.0f + 10.0f, 1.0f, 10.0f, 0.0f); + Math_SmoothStepToF(&boss->fwork[0], D_i4_801A03DC * 9.0f + 10.0f, 1.0f, 10.0f, 0.0f); Texture_Scroll(&D_600CF88, 16, 16, 0); Texture_Scroll(&D_600CF88, 16, 16, 0); diff --git a/src/overlays/ovl_i4/fox_ka.c b/src/overlays/ovl_i4/fox_ka.c index e06d9e6f..28cfb281 100644 --- a/src/overlays/ovl_i4/fox_ka.c +++ b/src/overlays/ovl_i4/fox_ka.c @@ -1171,7 +1171,7 @@ void func_i4_801946C4(Boss* boss) { } } if (boss->swork[10] != 0) { - Math_SmoothStepToF(boss->fwork, boss->fwork[5], 0.03f, 0.5f, 0); + Math_SmoothStepToF(&boss->fwork[0], boss->fwork[5], 0.03f, 0.5f, 0); } if (boss->swork[11] != 0) { Math_SmoothStepToF(&boss->fwork[1], boss->fwork[6], 0.03f, 0.5f, 0); diff --git a/src/overlays/ovl_i4/fox_sz.c b/src/overlays/ovl_i4/fox_sz.c index abf71e8d..5f2e22e9 100644 --- a/src/overlays/ovl_i4/fox_sz.c +++ b/src/overlays/ovl_i4/fox_sz.c @@ -1189,7 +1189,7 @@ void func_i4_8019C85C(Player* player) { Math_SmoothStepToAngle(&boss0->unk_078.x, 20.0f, 0.03f, boss0->fwork[1], 0.0f); Math_SmoothStepToAngle(&boss0->unk_078.y, 180.0f, 0.03f, boss0->fwork[2], 0.0f); Math_SmoothStepToAngle(&boss0->unk_078.z, 30.0f, 0.03f, boss0->fwork[3], 0.0f); - Math_SmoothStepToF(boss0->fwork, 20.0f, 0.05f, 0.3f, 0.0f); + Math_SmoothStepToF(&boss0->fwork[0], 20.0f, 0.05f, 0.3f, 0.0f); Math_SmoothStepToF(&boss0->fwork[1], 0.07f, 1.0f, 0.07f, 0.0f); Math_SmoothStepToF(&boss0->fwork[2], 0.5f, 1.0f, 0.05f, 0.0f); Math_SmoothStepToF(&boss0->fwork[3], 0.7f, 1.0f, 0.7f, 0.0f); @@ -1588,7 +1588,7 @@ void func_i4_8019DD20(Actor* actor) { case 11: Math_SmoothStepToF(&actor->unk_0F4.x, 215.0f, 0.1f, 7.0f, 0.0f); - Math_SmoothStepToF(actor->fwork, 10.0f, 0.1f, 1.5f, 0.0f); + Math_SmoothStepToF(&actor->fwork[0], 10.0f, 0.1f, 1.5f, 0.0f); Math_SmoothStepToAngle(&actor->unk_0F4.y, 140.0f, 0.1f, 1.0f, 0.0f); if (actor->unk_0F4.x > 180.0f) { actor->state = 12; @@ -1599,7 +1599,7 @@ void func_i4_8019DD20(Actor* actor) { Math_SmoothStepToAngle(&actor->unk_0F4.x, 218.0f, 0.1f, 7.0f, 0.0f); Math_SmoothStepToAngle(&actor->unk_0F4.y, 147.0f, 0.1f, 1.0f, 0.0f); Math_SmoothStepToF(&actor->unk_0F4.z, 170.0f, 0.03f, 3.0f, 0.0f); - Math_SmoothStepToF(actor->fwork, 20.0f, 0.1f, 1.0f, 0.0f); + Math_SmoothStepToF(&actor->fwork[0], 20.0f, 0.1f, 1.0f, 0.0f); break; } @@ -1628,7 +1628,7 @@ void func_i4_8019DD20(Actor* actor) { if (gCsFrameCount > 430) { actor->fwork[29] = 3.0f; Math_SmoothStepToF(&actor->unk_0F4.z, 500.0f, 0.1f, 20.0f, 0.0f); - Math_SmoothStepToF(actor->fwork, 40.0f, 0.1f, 3.0f, 0.0f); + Math_SmoothStepToF(&actor->fwork[0], 40.0f, 0.1f, 3.0f, 0.0f); if ((gCsFrameCount < 460) && !(gCsFrameCount & 3)) { Matrix_RotateY(gCalcMatrix, actor->obj.rot.y * M_DTOR, 0); diff --git a/src/overlays/ovl_i5/fox_ground.c b/src/overlays/ovl_i5/fox_ground.c index 3a02258c..617e2f62 100644 --- a/src/overlays/ovl_i5/fox_ground.c +++ b/src/overlays/ovl_i5/fox_ground.c @@ -459,15 +459,9 @@ void func_i5_801B5FE0(s32 arg0, s32 arg1, s32 arg2) { f32 spDC; f32 spD8; f32 spD4; - f32 temp_ft4; - f32 temp_ft5; - f32 temp_fs0; - f32 temp_fs1; - f32 temp_fs2; - f32 temp_fs3; - f32 temp_fv1; - f32 temp_fa0; - f32 temp_fa1; + Vec3f v1; + Vec3f v2; + Vec3f v3; f32 var_fv0; s32 j1; s32 j3; @@ -494,22 +488,22 @@ void func_i5_801B5FE0(s32 arg0, s32 arg1, s32 arg2) { spD8 = D_i5_801BA9C4[i2 + 1] * D_i5_801C24B8[(D_i5_801BA994[i2 + 1] + var_s1) % 28]; spD4 = D_i5_801BA9C4[i2 + 2] * D_i5_801C24B8[(D_i5_801BA994[i2 + 2] + var_s1) % 28]; - temp_ft4 = spF0 - spF4; - temp_ft5 = spEC - spF0; - temp_fs0 = spE4 - spE8; - temp_fs1 = spE0 - spE4; - temp_fs2 = spD8 - spDC; - temp_fs3 = spD4 - spD8; + v1.x = spF0 - spF4; + v2.x = spEC - spF0; + v1.y = spE4 - spE8; + v2.y = spE0 - spE4; + v1.z = spD8 - spDC; + v2.z = spD4 - spD8; - temp_fv1 = (temp_fs0 * temp_fs3) - (temp_fs2 * temp_fs1); - temp_fa0 = (temp_fs2 * temp_ft5) - (temp_ft4 * temp_fs3); - temp_fa1 = (temp_ft4 * temp_fs1) - (temp_fs0 * temp_ft5); + v3.x = (v1.y * v2.z) - (v1.z * v2.y); + v3.y = (v1.z * v2.x) - (v1.x * v2.z); + v3.z = (v1.x * v2.y) - (v1.y * v2.x); - var_fv0 = sqrtf(SQ(temp_fv1) + SQ(temp_fa0) + SQ(temp_fa1)); + var_fv0 = VEC3F_MAG(&v3); - D_i5_801C65B8[i0][i1][i2].a[0] = (temp_fv1 * 127.0f) / var_fv0; - D_i5_801C65B8[i0][i1][i2].a[1] = (temp_fa0 * 127.0f) / var_fv0; - D_i5_801C65B8[i0][i1][i2].a[2] = (temp_fa1 * 127.0f) / var_fv0; + D_i5_801C65B8[i0][i1][i2].a[0] = (v3.x * 127.0f) / var_fv0; + D_i5_801C65B8[i0][i1][i2].a[1] = (v3.y * 127.0f) / var_fv0; + D_i5_801C65B8[i0][i1][i2].a[2] = (v3.z * 127.0f) / var_fv0; } } diff --git a/src/overlays/ovl_i5/fox_ma.c b/src/overlays/ovl_i5/fox_ma.c index 68e7b57d..b507e6ba 100644 --- a/src/overlays/ovl_i5/fox_ma.c +++ b/src/overlays/ovl_i5/fox_ma.c @@ -2887,7 +2887,7 @@ void func_i5_801A3E98(Actor* actor) { AUDIO_PLAY_SFX(0x29121007, actor->sfxSource, 4); actor->unk_0D0 = 0; } - Math_SmoothStepToF(actor->fwork, 30.0f, 0.4f, 10.0f, 0.0f); + Math_SmoothStepToF(&actor->fwork[0], 30.0f, 0.4f, 10.0f, 0.0f); Math_SmoothStepToF(&actor->fwork[4], 30.0f, 0.4f, 10.0f, 0.0f); if (actor->fwork[0] < 31.0f) { if (actor->state >= 3) { @@ -3145,7 +3145,7 @@ void func_i5_801A4B24(Actor* actor) { actor->unk_0D0 = 0; AUDIO_PLAY_SFX(0x29121007, actor->sfxSource, 4); } - Math_SmoothStepToF(actor->fwork, 30, 0.4f, actor->fwork[1], 0.0f); + Math_SmoothStepToF(&actor->fwork[0], 30, 0.4f, actor->fwork[1], 0.0f); Math_SmoothStepToF(&actor->fwork[4], 30, 0.4f, actor->fwork[1], 0.0f); if (actor->fwork[0] < 31.0f) { actor->fwork[0] = 255.0f; @@ -3514,9 +3514,7 @@ void func_i5_801A68F8(Actor* actor, s16 arg1, f32 arg2, f32 arg3, f32 arg4, f32 void func_i5_801A6984(Actor* actor) { s16 var_s3; - f32 temp_fa0; - f32 temp_fs0; - f32 temp_fa1; + Vec3f test; f32 temp_fs3; s32 var_s4; f32 temp_fs2_2; @@ -3536,12 +3534,12 @@ void func_i5_801A6984(Actor* actor) { var_s3 = 0; if (!((gPlayer[0].unk_138 - actor->obj.pos.z) > 7000.0f)) { - temp_fa0 = actor->obj.pos.x - D_i5_801BE368[4]; - temp_fs0 = actor->obj.pos.y - D_i5_801BE368[5]; - temp_fa1 = actor->obj.pos.z - D_i5_801BE368[6]; - temp_fs3 = sqrtf(SQ(temp_fa0) + SQ(temp_fs0) + SQ(temp_fa1)); - Math_Atan2F(temp_fa0, temp_fa1); - Math_Atan2F(temp_fs0, sqrtf(SQ(temp_fa0) + SQ(temp_fa1))); + test.x = actor->obj.pos.x - D_i5_801BE368[4]; + test.y = actor->obj.pos.y - D_i5_801BE368[5]; + test.z = actor->obj.pos.z - D_i5_801BE368[6]; + temp_fs3 = VEC3F_MAG(&test); + Math_Atan2F(test.x, test.z); + Math_Atan2F(test.y, sqrtf(SQ(test.x) + SQ(test.z))); var_s4 = (s32) (temp_fs3 / 40.0f); if (var_s4 == 0) { var_s4 = 1; @@ -4502,7 +4500,7 @@ void func_i5_801A7E7C(Actor* actor) { Matrix_RotateY(gCalcMatrix, -actor->vwork[5].y * M_DTOR, 1); Matrix_MultVec3f(gCalcMatrix, &sp348, &sp354); D_i5_801BE368[14] = Math_RadToDeg(Math_Atan2F(sp354.x, sp354.z)); - temp = sqrtf((sp354.x * sp354.x) + (sp354.z * sp354.z)); + temp = sqrtf(SQ(sp354.x) + SQ(sp354.z)); D_i5_801BE368[13] = Math_RadToDeg(-Math_Atan2F(sp354.y, temp)); Matrix_RotateY(gCalcMatrix, actor->vwork[5].y * M_DTOR, 0); Matrix_RotateX(gCalcMatrix, actor->vwork[5].x * M_DTOR, 1); @@ -5167,9 +5165,7 @@ void func_i5_801AD144(PlayerShot* playerShot) { s32 j; Actor* actor; f32 temp_fs2; - f32 temp_ft4; - f32 temp_ft5; - f32 var_fa0; + Vec3f test; f32* var_s1; Vec3f sp8C; Vec3f sp80; @@ -5206,13 +5202,13 @@ void func_i5_801AD144(PlayerShot* playerShot) { sp8C.y = playerShot->obj.pos.y - actor->obj.pos.y; sp8C.z = playerShot->obj.pos.z - actor->obj.pos.z; Matrix_MultVec3fNoTranslate(gCalcMatrix, &sp8C, &sp80); - temp_ft4 = (var_s1[4] + actor->obj.pos.x) - (actor->obj.pos.x + sp80.x); - temp_ft5 = (var_s1[2] + actor->obj.pos.y) - (actor->obj.pos.y + sp80.y); - var_fa0 = (var_s1[0] + actor->obj.pos.z) - (actor->obj.pos.z + sp80.z); - if ((gLevelMode == LEVELMODE_ON_RAILS) && (var_fa0 < 0.0f)) { - var_fa0 *= 0.6f; + test.x = (var_s1[4] + actor->obj.pos.x) - (actor->obj.pos.x + sp80.x); + test.y = (var_s1[2] + actor->obj.pos.y) - (actor->obj.pos.y + sp80.y); + test.z = (var_s1[0] + actor->obj.pos.z) - (actor->obj.pos.z + sp80.z); + if ((gLevelMode == LEVELMODE_ON_RAILS) && (test.z < 0.0f)) { + test.z *= 0.6f; } - if (sqrtf(SQ(temp_ft4) + SQ(temp_ft5) + SQ(var_fa0)) < temp_fs2) { + if (VEC3F_MAG(&test) < temp_fs2) { actor->unk_0D2 = j; actor->unk_0D0 = -1; if ((gPlayer[0].unk_138 - actor->obj.pos.z) < 5000.0f) { diff --git a/src/overlays/ovl_i5/fox_ti.c b/src/overlays/ovl_i5/fox_ti.c index ee93dc99..1ac64046 100644 --- a/src/overlays/ovl_i5/fox_ti.c +++ b/src/overlays/ovl_i5/fox_ti.c @@ -3444,7 +3444,7 @@ void func_i5_80192118(Boss* boss) { Animation_GetFrameData(&D_8000D80, D_i5_801BBEF0[22] >> 1, D_i5_801BC978); Animation_GetFrameData(&D_8000D80, D_i5_801BBEF0[23] >> 1, D_i5_801BC9D8); Animation_GetFrameData(&D_8000708, D_i5_801BBEF0[24] >> 1, D_i5_801BCA38); - Math_SmoothStepToF(boss->fwork, 0.5f, 0.05f, 0.05f, 0.01f); + Math_SmoothStepToF(&boss->fwork[0], 0.5f, 0.05f, 0.05f, 0.01f); Math_SmoothStepToVec3fArray(D_i5_801BC978, D_i5_801BCDC8, 1, 8, boss->fwork[0], 360.0f, 0.01f); Math_SmoothStepToVec3fArray(D_i5_801BC9D8, D_i5_801BCE28, 1, 8, boss->fwork[0], 360.0f, 0.01f); Math_SmoothStepToVec3fArray(D_i5_801BCA38, D_i5_801BCE88, 1, 13, boss->fwork[0], 360.0f, 0.01f); @@ -4273,7 +4273,7 @@ void func_i5_80193DF0(Boss* boss) { } } Animation_GetFrameData(&D_900FC4C, boss->unk_04C >> 1, D_i5_801BC978); - Math_SmoothStepToF(boss->fwork, 0.5f, 1.0f, 0.02f, 0.0f); + Math_SmoothStepToF(&boss->fwork[0], 0.5f, 1.0f, 0.02f, 0.0f); Math_SmoothStepToVec3fArray(D_i5_801BC978, D_i5_801BCDC8, 1, 0x5C, boss->fwork[0], 360.0f, 0.01f); boss->unk_04C++; if (boss->unk_04C >= (Animation_GetFrameCount(&D_900FC4C) * 2)) { @@ -4335,7 +4335,7 @@ void func_i5_80193DF0(Boss* boss) { D_i5_801BBEF4[8] = 48; D_i5_801BBEF4[9] = 48; } - Math_SmoothStepToF(boss->fwork, 0.5f, 1.0f, 0.02f, 0.0f); + Math_SmoothStepToF(&boss->fwork[0], 0.5f, 1.0f, 0.02f, 0.0f); Math_SmoothStepToVec3fArray(D_i5_801BC978, D_i5_801BCDC8, 1, 0x5C, boss->fwork[0], 360.0f, 0.01f); boss->unk_04C++; if (boss->unk_04C >= (Animation_GetFrameCount(&D_70084CC) * 2)) { @@ -4390,7 +4390,7 @@ void func_i5_80193DF0(Boss* boss) { D_80178480 = 0x14; } } - Math_SmoothStepToF(boss->fwork, 0.5f, 1.0f, 0.02f, 0.0f); + Math_SmoothStepToF(&boss->fwork[0], 0.5f, 1.0f, 0.02f, 0.0f); Math_SmoothStepToVec3fArray(D_i5_801BC978, D_i5_801BCDC8, 1, 0x5C, boss->fwork[0], 360.0f, 0.01f); boss->unk_04C++; if (boss->unk_04C >= (Animation_GetFrameCount(&D_7003EE8) * 2)) { @@ -4398,7 +4398,7 @@ void func_i5_80193DF0(Boss* boss) { } break; case 9: - Math_SmoothStepToF(boss->fwork, 0.5f, 1.0f, 0.02f, 0.0f); + Math_SmoothStepToF(&boss->fwork[0], 0.5f, 1.0f, 0.02f, 0.0f); Math_SmoothStepToVec3fArray(D_i5_801BC978, D_i5_801BCDC8, 1, 0x5C, boss->fwork[0], 360.0f, 0.01f); boss->unk_04C++; if (boss->unk_04C >= (Animation_GetFrameCount(&D_8008FE8) * 2)) { @@ -4406,7 +4406,7 @@ void func_i5_80193DF0(Boss* boss) { } break; case 10: - Math_SmoothStepToF(boss->fwork, 0.5f, 1.0f, 0.02f, 0.0f); + Math_SmoothStepToF(&boss->fwork[0], 0.5f, 1.0f, 0.02f, 0.0f); Math_SmoothStepToVec3fArray(D_i5_801BC978, D_i5_801BCDC8, 1, 0x5C, boss->fwork[0], 360.0f, 0.01f); boss->unk_04C++; if (boss->unk_04C >= (Animation_GetFrameCount(&D_700E244) * 2)) { @@ -4549,7 +4549,7 @@ void func_i5_80193DF0(Boss* boss) { Audio_KillSfxBySourceAndId(boss->sfxSource, 0x39435830); } } - Math_SmoothStepToF(boss->fwork, 0.5f, 1.0f, 0.02f, 0.0f); + Math_SmoothStepToF(&boss->fwork[0], 0.5f, 1.0f, 0.02f, 0.0f); Math_SmoothStepToVec3fArray(D_i5_801BC978, D_i5_801BCDC8, 1, 0x5C, boss->fwork[0], 360.0f, 0.01f); boss->unk_04C++; if (boss->unk_04C >= (Animation_GetFrameCount(&D_9004288) * 2)) { @@ -4565,7 +4565,7 @@ void func_i5_80193DF0(Boss* boss) { boss->fwork[1] = ((f32) (boss->unk_04C - 0x26) * 360.0f) / 102.0f; } Math_SmoothStepToAngle(&boss->fwork[0x31], boss->fwork[1], 0.5f, 180.0f, 0.0f); - Math_SmoothStepToF(boss->fwork, 0.5f, 1.0f, 0.02f, 0.0f); + Math_SmoothStepToF(&boss->fwork[0], 0.5f, 1.0f, 0.02f, 0.0f); Math_SmoothStepToVec3fArray(D_i5_801BC978, D_i5_801BCDC8, 1, 0x5C, boss->fwork[0], 360.0f, 0.01f); boss->unk_04C++; if (boss->unk_04C >= (Animation_GetFrameCount(&D_A009990) * 2)) { @@ -4581,7 +4581,7 @@ void func_i5_80193DF0(Boss* boss) { } Math_SmoothStepToAngle(&boss->fwork[0x31], boss->fwork[1], 0.5f, 180.0f, 0.0f); } - Math_SmoothStepToF(boss->fwork, 0.5f, 1.0f, 0.02f, 0.01f); + Math_SmoothStepToF(&boss->fwork[0], 0.5f, 1.0f, 0.02f, 0.01f); Math_SmoothStepToVec3fArray(D_i5_801BC978, D_i5_801BCDC8, 1, 0x5C, boss->fwork[0], 360.0f, 0.01f); if (boss->swork[38] & 1) { boss->unk_04C++; diff --git a/src/overlays/ovl_i6/fox_andross.c b/src/overlays/ovl_i6/fox_andross.c index b57ad15f..e539e248 100644 --- a/src/overlays/ovl_i6/fox_andross.c +++ b/src/overlays/ovl_i6/fox_andross.c @@ -283,7 +283,7 @@ void func_i6_801880E4(Actor* actor) { } } - Math_SmoothStepToF(actor->fwork, actor->fwork[1], 0.2f, 3.0f, 0.00001f); + Math_SmoothStepToF(&actor->fwork[0], actor->fwork[1], 0.2f, 3.0f, 0.00001f); yaw = Math_RadToDeg(Math_Atan2F(xDisplacement, zDisplacement)); Math_SmoothStepToAngle(&actor->unk_0F4.x, Math_RadToDeg(Math_Atan2F(yDisplacement, sqrtf(SQ(xDisplacement) + SQ(zDisplacement)))), @@ -1117,7 +1117,7 @@ void func_i6_80189B70(Boss* boss) { } else if (boss->timer_054 == 0) { Math_SmoothStepToAngle(&boss->obj.rot.y, Math_RadToDeg(-gPlayer[0].unk_058), 0.3f, 1.5f, 0.0f); } - Math_SmoothStepToF(boss->fwork, boss->fwork[1], 0.2f, 1.0f, 0.00001f); + Math_SmoothStepToF(&boss->fwork[0], boss->fwork[1], 0.2f, 1.0f, 0.00001f); Matrix_RotateY(gCalcMatrix, boss->unk_078.y * M_DTOR, 0U); Matrix_RotateX(gCalcMatrix, -boss->unk_078.x * M_DTOR, 1U); vec.x = 0.0f; diff --git a/src/overlays/ovl_i6/fox_sy.c b/src/overlays/ovl_i6/fox_sy.c index 6b0d615a..76c896c2 100644 --- a/src/overlays/ovl_i6/fox_sy.c +++ b/src/overlays/ovl_i6/fox_sy.c @@ -1435,7 +1435,7 @@ void func_i6_8019C888(Boss* boss) { sp58.z = boss->fwork[20] - boss->obj.pos.z; Matrix_MultVec3fNoTranslate(gCalcMatrix, &sp58, &sp4C); sp1E4 = Math_RadToDeg(Math_Atan2F(sp4C.x, sp4C.z)); - sp1E8 = Math_RadToDeg(-Math_Atan2F(sp4C.y, sqrtf((sp4C.x * sp4C.x) + (sp4C.z * sp4C.z)))); + sp1E8 = Math_RadToDeg(-Math_Atan2F(sp4C.y, sqrtf(SQ(sp4C.x) + SQ(sp4C.z)))); if ((sp1E8 > 30.0f) && (sp1E8 <= 180.0f)) { sp1E8 = 30.0f; @@ -1459,7 +1459,7 @@ void func_i6_8019C888(Boss* boss) { sp58.z = boss->fwork[20] - boss->obj.pos.z; Matrix_MultVec3fNoTranslate(gCalcMatrix, &sp58, &sp4C); sp1E0 = Math_RadToDeg(Math_Atan2F(sp4C.x, sp4C.z)); - sp1DC = Math_RadToDeg(-Math_Atan2F(sp4C.y, sqrtf((sp4C.x * sp4C.x) + (sp4C.z * sp4C.z)))); + sp1DC = Math_RadToDeg(-Math_Atan2F(sp4C.y, sqrtf(SQ(sp4C.x) + SQ(sp4C.z)))); if ((sp1DC > 30.0f) && (sp1DC <= 180.0f)) { sp1DC = 30.0f; @@ -1481,7 +1481,7 @@ void func_i6_8019C888(Boss* boss) { sp58.z = boss->fwork[20] - boss->obj.pos.z; Matrix_MultVec3fNoTranslate(gCalcMatrix, &sp58, &sp4C); sp1D8 = Math_RadToDeg(Math_Atan2F(sp4C.x, sp4C.z)); - sp1D4 = Math_RadToDeg(-Math_Atan2F(sp4C.y, sqrtf((sp4C.x * sp4C.x) + (sp4C.z * sp4C.z)))); + sp1D4 = Math_RadToDeg(-Math_Atan2F(sp4C.y, sqrtf(SQ(sp4C.x) + SQ(sp4C.z)))); if ((sp1D4 > 80.0f) && (sp1D4 <= 180.0f)) { sp1D4 = 80.0f; @@ -1505,7 +1505,7 @@ void func_i6_8019C888(Boss* boss) { sp58.z = (boss->fwork[20] - boss->obj.pos.z) - (COS_DEG(boss->obj.rot.y) * 60.0f); Matrix_MultVec3fNoTranslate(gCalcMatrix, &sp58, &sp4C); sp1E4 = Math_RadToDeg(Math_Atan2F(sp4C.x, sp4C.z)); - sp1E8 = Math_RadToDeg(-Math_Atan2F(sp4C.y, sqrtf((sp4C.x * sp4C.x) + (sp4C.z * sp4C.z)))); + sp1E8 = Math_RadToDeg(-Math_Atan2F(sp4C.y, sqrtf(SQ(sp4C.x) + SQ(sp4C.z)))); if ((sp1E8 > 80.0f) && (sp1E8 <= 180.0f)) { sp1E8 = 80.0f; @@ -3432,7 +3432,7 @@ void func_i6_801A3BD4(Actor* actor) { sp5C.z = gPlayer[0].pos.z - actor->obj.pos.z; Matrix_MultVec3fNoTranslate(gCalcMatrix, &sp5C, &sp50); sp1D4 = Math_RadToDeg(Math_Atan2F(sp50.x, sp50.z)); - sp1D8 = Math_RadToDeg(-Math_Atan2F(sp50.y, sqrtf((sp50.x * sp50.x) + (sp50.z * sp50.z)))); + sp1D8 = Math_RadToDeg(-Math_Atan2F(sp50.y, sqrtf(SQ(sp50.x) + SQ(sp50.z)))); if ((sp1D8 > 90.0f) && (sp1D8 < 180.0f)) { sp1D8 = 90.0f; } diff --git a/src/overlays/ovl_i6/fox_ve2.c b/src/overlays/ovl_i6/fox_ve2.c index e3be1cb3..b587ceab 100644 --- a/src/overlays/ovl_i6/fox_ve2.c +++ b/src/overlays/ovl_i6/fox_ve2.c @@ -1,7 +1,7 @@ #include "global.h" void func_i6_80196210(Boss* boss) { - Math_SmoothStepToF(boss->fwork, boss->fwork[1], 0.5f, 5.0f, 0.0f); + Math_SmoothStepToF(&boss->fwork[0], boss->fwork[1], 0.5f, 5.0f, 0.0f); } s32 func_i6_8019624C(s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3f* rot, void* data) { diff --git a/src/overlays/ovl_menu/fox_map.c b/src/overlays/ovl_menu/fox_map.c index 77acfb1d..3ed8df0c 100644 --- a/src/overlays/ovl_menu/fox_map.c +++ b/src/overlays/ovl_menu/fox_map.c @@ -6119,27 +6119,28 @@ void func_menu_801ABF1C(void) { } void func_menu_801AC200(s32 index) { - f32 x; - f32 y; - f32 z; + // f32 z; + // f32 x; + // f32 y; + Vec3f v; f32 r; f32 r2; Vec3f vec; - x = gUnkEntities30[index].unk_10.x - gUnkEntities30[index].unk_04.x; - y = gUnkEntities30[index].unk_10.y - gUnkEntities30[index].unk_04.y; - z = gUnkEntities30[index].unk_10.z - gUnkEntities30[index].unk_04.z; + v.x = gUnkEntities30[index].unk_10.x - gUnkEntities30[index].unk_04.x; + v.y = gUnkEntities30[index].unk_10.y - gUnkEntities30[index].unk_04.y; + v.z = gUnkEntities30[index].unk_10.z - gUnkEntities30[index].unk_04.z; - r = sqrtf(SQ(x) + SQ(y) + SQ(z)); + r = VEC3F_MAG(&v); if (r == 0.0f) { r = 1.0f; } if (sPaths[index].unk_14 == 2) { - vec.x = (x / r) * (r / (sPaths[index].length - 1)); - vec.y = (y / r) * (r / (sPaths[index].length - 1)); - vec.z = (z / r) * (r / (sPaths[index].length - 1)); + vec.x = (v.x / r) * (r / (sPaths[index].length - 1)); + vec.y = (v.y / r) * (r / (sPaths[index].length - 1)); + vec.z = (v.z / r) * (r / (sPaths[index].length - 1)); D_menu_801CEEB0.x = gUnkEntities30[index].unk_04.x + (vec.x * D_menu_801CEEA0); D_menu_801CEEB0.y = gUnkEntities30[index].unk_04.y + (vec.y * D_menu_801CEEA0); @@ -6180,18 +6181,18 @@ void func_menu_801AC200(s32 index) { return; } } else { - vec.x = (x / r) * gUnkEntities30[index].unk_24; - vec.y = (y / r) * gUnkEntities30[index].unk_24; - vec.z = (z / r) * gUnkEntities30[index].unk_24; + vec.x = (v.x / r) * gUnkEntities30[index].unk_24; + vec.y = (v.y / r) * gUnkEntities30[index].unk_24; + vec.z = (v.z / r) * gUnkEntities30[index].unk_24; D_menu_801CEEB0.x = gUnkEntities30[index].unk_04.x + vec.x; D_menu_801CEEB0.y = gUnkEntities30[index].unk_04.y + vec.y; D_menu_801CEEB0.z = gUnkEntities30[index].unk_04.z + vec.z; - x = D_menu_801CEEB0.x - gUnkEntities30[index].unk_04.x; - y = D_menu_801CEEB0.y - gUnkEntities30[index].unk_04.y; - z = D_menu_801CEEB0.z - gUnkEntities30[index].unk_04.z; - r2 = sqrtf(SQ(x) + SQ(y) + SQ(z)); + v.x = D_menu_801CEEB0.x - gUnkEntities30[index].unk_04.x; + v.y = D_menu_801CEEB0.y - gUnkEntities30[index].unk_04.y; + v.z = D_menu_801CEEB0.z - gUnkEntities30[index].unk_04.z; + r2 = VEC3F_MAG(&v); if (((r / 9.0f) * 8.0f) < r2) { D_menu_801CEEAC -= 16; @@ -6461,9 +6462,7 @@ void func_menu_801ACD90(s32 index, Vec3f* src, Vec3f* dest) { f32 x2; f32 y2; f32 z2; - f32 x; - f32 y; - f32 z; + Vec3f v0; f32 r; f32 temp1; f32 temp2; @@ -6531,19 +6530,19 @@ void func_menu_801ACD90(s32 index, Vec3f* src, Vec3f* dest) { temp2 = 30.0f; } - x = sPlanets[sPaths[index].end].pos.x - sPlanets[sPaths[index].start].pos.x; - y = sPlanets[sPaths[index].end].pos.y - sPlanets[sPaths[index].start].pos.y; - z = sPlanets[sPaths[index].end].pos.z - sPlanets[sPaths[index].start].pos.z; + v0.x = sPlanets[sPaths[index].end].pos.x - sPlanets[sPaths[index].start].pos.x; + v0.y = sPlanets[sPaths[index].end].pos.y - sPlanets[sPaths[index].start].pos.y; + v0.z = sPlanets[sPaths[index].end].pos.z - sPlanets[sPaths[index].start].pos.z; - r = sqrtf(SQ(x) + SQ(y) + SQ(z)); + r = VEC3F_MAG(&v0); - x1 = sPlanets[sPaths[index].start].pos.x + (temp1 * sPlanets[sPaths[index].start].scale * (x / r)); - y1 = sPlanets[sPaths[index].start].pos.y + (temp1 * sPlanets[sPaths[index].start].scale * (y / r)); - z1 = sPlanets[sPaths[index].start].pos.z + (temp1 * sPlanets[sPaths[index].start].scale * (z / r)); + x1 = sPlanets[sPaths[index].start].pos.x + (temp1 * sPlanets[sPaths[index].start].scale * (v0.x / r)); + y1 = sPlanets[sPaths[index].start].pos.y + (temp1 * sPlanets[sPaths[index].start].scale * (v0.y / r)); + z1 = sPlanets[sPaths[index].start].pos.z + (temp1 * sPlanets[sPaths[index].start].scale * (v0.z / r)); - x2 = sPlanets[sPaths[index].end].pos.x + (temp2 * sPlanets[sPaths[index].end].scale * (-x / r)); - y2 = sPlanets[sPaths[index].end].pos.y + (temp2 * sPlanets[sPaths[index].end].scale * (-y / r)); - z2 = sPlanets[sPaths[index].end].pos.z + (temp2 * sPlanets[sPaths[index].end].scale * (-z / r)); + x2 = sPlanets[sPaths[index].end].pos.x + (temp2 * sPlanets[sPaths[index].end].scale * (-v0.x / r)); + y2 = sPlanets[sPaths[index].end].pos.y + (temp2 * sPlanets[sPaths[index].end].scale * (-v0.y / r)); + z2 = sPlanets[sPaths[index].end].pos.z + (temp2 * sPlanets[sPaths[index].end].scale * (-v0.z / r)); src->x = x1; src->y = y1; diff --git a/tools/Torch b/tools/Torch index e4608e57..84b6686f 160000 --- a/tools/Torch +++ b/tools/Torch @@ -1 +1 @@ -Subproject commit e4608e57763f86b8326422c8011db43d8b8d9b95 +Subproject commit 84b6686f5b051ce729cc03d92dc71c94d0f19537