1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-07-03 22:44:30 +00:00

Math3D and olib updates (#315)

* wip

* Olib updates

* wip

* wip

* rename most Math3D functions, few matches, documentation

* wip

* document most of math3d

* pr updates

* pr updates

* add missing comment block finalizer
This commit is contained in:
krimtonz 2020-08-17 14:42:08 -05:00 committed by GitHub
parent 2826421c98
commit f11a74d41d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
110 changed files with 1959 additions and 1787 deletions

2410
src/code/sys_math3d.c Executable file → Normal file

File diff suppressed because it is too large Load diff

View file

@ -1797,7 +1797,7 @@ s16 func_8004391C(s16 arg0, s16 arg1, f32 arg2, s16 arg3) {
return ret;
}
//*t = func_800439AC(sp4C.theta, *t, 0.4f, 0x7D0);
s16 func_800439AC(s16 arg0, s16 arg1, f32 arg2, s16 arg3) {
s16 temp1 = arg0 - arg1;
s16 temp2;
@ -1850,7 +1850,7 @@ Vec3f* func_80043BC4(Vec3f* arg0, Vec3s* arg1) {
Vec3f* func_80043C28(Vec3f* arg0, Vec3f* arg1, VecSph* arg2) {
Vec3f sp24, sp18;
OLib_VecSphRot90ToVec3f(&sp18, arg2);
OLib_VecSphGeoToVec3f(&sp18, arg2);
sp24.x = arg1->x + sp18.x;
sp24.y = arg1->y + sp18.y;
@ -1880,7 +1880,7 @@ s32 func_80043D18(Camera* camera, Vec3f* arg1, struct_80043D18* arg2) {
VecSph sp3C;
colCtx = &camera->globalCtx->colCtx;
OLib_Vec3fDiffToVecSphRot90(&sp3C, arg1, &arg2->unk_00);
OLib_Vec3fDiffToVecSphGeo(&sp3C, arg1, &arg2->unk_00);
sp3C.r += 8.0f;
func_80043C28(&sp5C, arg1, &sp3C);
@ -2152,9 +2152,9 @@ f32 func_80045714(Vec3f* arg0, s16 arg1, s16 arg2, f32 arg3) {
VecSph sp1C;
f32 sp18;
OLib_Vec3fToVecSphRot90(&sp1C, arg0);
sp18 = Math_Coss(sp1C.phi);
sp18 = fabsf(Math_Coss(arg1 - sp1C.theta) * sp18);
OLib_Vec3fToVecSphGeo(&sp1C, arg0);
sp18 = Math_Coss(sp1C.pitch);
sp18 = fabsf(Math_Coss(arg1 - sp1C.yaw) * sp18);
return Math_Coss(arg1 - arg2) * (sp18 * arg3);
}
#else
@ -2162,7 +2162,7 @@ f32 func_80045714(Vec3f* a, s16 b, s16 c, f32 arg3);
#pragma GLOBAL_ASM("asm/non_matchings/code/z_camera/func_80045714.s")
#endif
f32 func_8007C0A8(f32, f32);
f32 OLib_ClampMaxDist(f32, f32);
s32 func_800457A8(Camera* camera, VecSph* arg1, f32 arg2, s16 arg3) {
f32 unused;
@ -2180,7 +2180,7 @@ s32 func_800457A8(Camera* camera, VecSph* arg1, f32 arg2, s16 arg3) {
sp2C = &camera->playerPosRot;
if (arg3 != 0) {
sp50.y -= func_8007C0A8(func_80045714(&camera->unk_108, sp2C->rot.y, arg1->theta, OREG(9)), temp_ret);
sp50.y -= OLib_ClampMaxDist(func_80045714(&camera->unk_108, sp2C->rot.y, arg1->yaw, OREG(9)), temp_ret);
}
func_80043A3C(&sp50, &camera->unk_E4, camera->unk_CC.y, camera->unk_CC.x, 0.1f);
@ -2209,7 +2209,7 @@ s32 func_800458D4(Camera* camera, VecSph* arg1, f32 arg2, f32* arg3, s16 arg4) {
temp_s1 = &camera->playerPosRot;
if (arg4 != 0) {
sp60.y -= func_80045714(&camera->unk_108, temp_s1->rot.y, arg1->theta, OREG(9));
sp60.y -= func_80045714(&camera->unk_108, temp_s1->rot.y, arg1->yaw, OREG(9));
}
sp48 = temp_s1->pos.y - *arg3;
@ -2253,9 +2253,9 @@ s32 func_80045B08(Camera* camera, VecSph* arg1, f32 arg2, s16 arg3) {
temp_s1 = &camera->playerPosRot;
if (temp_ret < 0.0f) {
phi_f2 = Math_Coss(temp_s1->rot.y - arg1->theta);
phi_f2 = Math_Coss(temp_s1->rot.y - arg1->yaw);
} else {
phi_f2 = -Math_Coss(temp_s1->rot.y - arg1->theta);
phi_f2 = -Math_Coss(temp_s1->rot.y - arg1->yaw);
}
sp48.y -= temp_ret * phi_f2 * OREG(9);
@ -2306,7 +2306,7 @@ s32 func_800466F8(Camera* camera, VecSph* arg1, f32 arg2, f32* arg3, s16 arg4) {
sp60.y = sp48 + arg2;
if (arg4 != 0) {
sp60.y -= func_80045714(&camera->unk_108, camera->playerPosRot.rot.y, arg1->theta, OREG(9));
sp60.y -= func_80045714(&camera->unk_108, camera->playerPosRot.rot.y, arg1->yaw, OREG(9));
}
func_80043A3C(&sp60, &camera->unk_E4, camera->unk_CC.y, camera->unk_CC.x, 0.1f);
@ -2509,8 +2509,8 @@ s32 Camera_Normal3(Camera* camera) {
sp44 = &camera->at;
sp40 = &camera->eyeNext;
playerPostRot = &camera->playerPosRot;
OLib_Vec3fDiffToVecSphRot90(&sp7C, sp44, sp48);
OLib_Vec3fDiffToVecSphRot90(&sp74, sp44, sp40);
OLib_Vec3fDiffToVecSphGeo(&sp7C, sp44, sp48);
OLib_Vec3fDiffToVecSphGeo(&sp74, sp44, sp40);
D_8011D3E8 = 1;
D_8011D3A0.w = normal3->unk_1E;
unk20 = &normal3->unk_20;
@ -2531,7 +2531,7 @@ s32 Camera_Normal3(Camera* camera) {
unk20->unk_20 = camera->unk_104;
unk20->unk_10 = normal3->unk_0C;
unk20->unk_2A = 0xA;
unk20->unk_26 = (1.0f / OREG(23)) * (s16)(playerPostRot->rot.y - 0x7FFF - sp7C.theta);
unk20->unk_26 = (1.0f / OREG(23)) * (s16)(playerPostRot->rot.y - 0x7FFF - sp7C.yaw);
unk20->unk_28 = OREG(23);
camera->unk_15E = 1;
unk20->unk_1A = 0;
@ -2561,26 +2561,26 @@ s32 Camera_Normal3(Camera* camera) {
camera->unk_CC.y = func_8004389C(OREG(3) * 0.01f, camera->unk_CC.y, sp94, 0.1f);
camera->unk_CC.z = func_8004389C(OREG(4) * 0.01f, camera->unk_CC.z, sp94, 0.1f);
temp_f0 = (1.0f / normal3->unk_10) * 0.5f;
unk20->unk_24 = func_8004391C(func_80044ADC(camera, sp7C.theta - 0x7FFF, 1), unk20->unk_24,
unk20->unk_24 = func_8004391C(func_80044ADC(camera, sp7C.yaw - 0x7FFF, 1), unk20->unk_24,
temp_f0 + (temp_f0 * (1.0f - camera->unk_E0)), 0xF);
func_800466F8(camera, &sp74, normal3->unk_00, &unk20->unk_20, 1);
sp90 = (normal3->unk_08 + normal3->unk_04) * 0.5f;
OLib_Vec3fDiffToVecSphRot90(&sp84, sp44, sp40);
OLib_Vec3fDiffToVecSphGeo(&sp84, sp44, sp40);
sp84.r = func_800469C0(camera, sp84.r, normal3->unk_04, normal3->unk_08, unk20->unk_2A);
camera->dist = sp84.r;
if (0.001f < camera->unk_D8) {
sp84.r += (sp90 - sp84.r) * 0.002f;
}
sp84.phi = func_8004391C(normal3->unk_1C - unk20->unk_24, sp74.phi, 1.0f / camera->unk_C0.y, 0xA);
if (OREG(5) < sp84.phi) {
sp84.phi = OREG(5);
sp84.pitch = func_8004391C(normal3->unk_1C - unk20->unk_24, sp74.pitch, 1.0f / camera->unk_C0.y, 0xA);
if (OREG(5) < sp84.pitch) {
sp84.pitch = OREG(5);
}
if (sp84.phi < OREG(34)) {
sp84.phi = OREG(34);
if (sp84.pitch < OREG(34)) {
sp84.pitch = OREG(34);
}
// Probably some type of abs/clamp.
temp_a0 = playerPostRot->rot.y - (sp74.theta - 0x7FFF);
temp_a0 = playerPostRot->rot.y - (sp74.yaw - 0x7FFF);
phi_v1_2 = -temp_a0;
if (temp_a0 >= 0) {
phi_v1_2 = temp_a0;
@ -2595,14 +2595,14 @@ s32 Camera_Normal3(Camera* camera) {
}
temp_f16_2 = (phi_a0 * ((camera->unk_E0 * (1.0f - 0.5f)) + 0.5f)) / camera->unk_C0.z;
if ((150.0f * (1.0f - camera->unk_E0)) < fabsf(temp_f16_2)) {
sp84.theta = sp74.theta + temp_f16_2;
// sp8A = sp74.theta + temp_f16_2;
sp84.yaw = sp74.yaw + temp_f16_2;
// sp8A = sp74.yaw + temp_f16_2;
} else {
sp84.theta = sp74.theta;
sp84.yaw = sp74.yaw;
// sp8A = sp7A;
}
if (unk20->unk_28 > 0) {
sp84.theta += unk20->unk_26;
sp84.yaw += unk20->unk_26;
// sp8A = sp8A + unk20->unk_26;
unk20->unk_28--;
@ -2837,8 +2837,8 @@ void func_80054478(PosRot* arg0, Vec3f* arg1, Vec3f* arg2) {
Vec3f sp1C;
Camera_Vec3fCopy(arg1, &sp1C);
OLib_Vec3fToVecSphRot90(&sp28, &sp1C);
sp28.theta += arg0->rot.y;
OLib_Vec3fToVecSphGeo(&sp28, &sp1C);
sp28.yaw += arg0->rot.y;
func_80043C28(arg2, &arg0->pos, &sp28);
}
@ -3222,8 +3222,8 @@ void func_80058148(Camera* camera, Player* player) {
sp4C.r = 180.0f;
camera->dist = 180.0f;
camera->unk_134.y = sp54.rot.y;
sp4C.phi = 0x71C;
sp4C.theta = camera->unk_134.y - 0x7FFF;
sp4C.pitch = 0x71C;
sp4C.yaw = camera->unk_134.y - 0x7FFF;
camera->unk_134.x = 0x71C;
camera->unk_134.z = 0;
camera->unk_13A = camera->unk_134;

View file

@ -507,7 +507,7 @@ s32 Collider_SetTrisItemDim(GlobalContext* globalCtx, TriNorm* dest, ColliderTri
*d++ = *s++;
}
func_800CC8B4(&src->vtx[0], &src->vtx[1], &src->vtx[2], &nx, &ny, &nz, &nd);
Math3D_DefPlane(&src->vtx[0], &src->vtx[1], &src->vtx[2], &nx, &ny, &nz, &nd);
dest->plane.normal.x = nx;
dest->plane.normal.y = ny;
@ -818,7 +818,7 @@ s32 func_8005D218(GlobalContext* globalCtx, ColliderQuad* quad, Vec3f* arg2) {
return 1;
}
Math_Vec3s_ToVec3f(&sp20, &quad->dim.dcMid);
temp = func_800CB650(&sp20, arg2);
temp = Math3D_Vec3fDistSq(&sp20, arg2);
if (temp < quad->dim.unk_3C) {
quad->dim.unk_3C = temp;
if (quad->body.atHit != NULL) {
@ -928,12 +928,12 @@ void func_8005D4DC(GlobalContext* globalCtx, Collider* collider) {
case COLSHAPE_JNTSPH:
jntSph = (ColliderJntSph*)collider;
for (i = 0; i < jntSph->count; i++) {
func_800D05D0(globalCtx, &jntSph->list[i].dim.worldSphere);
Math3D_DrawSphere(globalCtx, &jntSph->list[i].dim.worldSphere);
}
break;
case COLSHAPE_CYLINDER:
cylinder = (ColliderCylinder*)collider;
func_800D05DC(globalCtx, &cylinder->dim);
Math3D_DrawCylinder(globalCtx, &cylinder->dim);
break;
case COLSHAPE_TRIS:
tris = (ColliderTris*)collider;
@ -1547,8 +1547,7 @@ void CollisionCheck_AC_JntSphVsJntSph(GlobalContext* globalCtx, CollisionCheckCo
if (func_8005DF74(&lItem->body, &rItem->body) == 1) {
continue;
}
if (Math3D_SpheresTouchingSurfaceCenter(&lItem->dim.worldSphere, &rItem->dim.worldSphere, &sp8C, &sp88) ==
1) {
if (Math3D_SphVsSphOverlapCenter(&lItem->dim.worldSphere, &rItem->dim.worldSphere, &sp8C, &sp88) == 1) {
sp6C.x = lItem->dim.worldSphere.center.x;
sp6C.y = lItem->dim.worldSphere.center.y;
sp6C.z = lItem->dim.worldSphere.center.z;
@ -1597,7 +1596,7 @@ void CollisionCheck_AC_JntSphVsCyl(GlobalContext* globalCtx, CollisionCheckConte
if (func_8005DF74(&lItem->body, &right->body) == 1) {
continue;
}
if (func_800CFDA4(&lItem->dim.worldSphere, &right->dim, &sp80, &sp7C) != 0) {
if (Math3D_SphVsCylOverlapCenterDist(&lItem->dim.worldSphere, &right->dim, &sp80, &sp7C) != 0) {
sp64.x = lItem->dim.worldSphere.center.x;
sp64.y = lItem->dim.worldSphere.center.y;
sp64.z = lItem->dim.worldSphere.center.z;
@ -1647,7 +1646,7 @@ void CollisionCheck_AC_CylVsJntSph(GlobalContext* globalCtx, CollisionCheckConte
if (func_8005DF74(&left->body, &rItem->body) == 1) {
continue;
}
if (func_800CFDA4(&rItem->dim.worldSphere, &left->dim, &sp9C, &sp98) != 0) {
if (Math3D_SphVsCylOverlapCenterDist(&rItem->dim.worldSphere, &left->dim, &sp9C, &sp98) != 0) {
sp7C.x = left->dim.pos.x;
sp7C.y = left->dim.pos.y;
sp7C.z = left->dim.pos.z;
@ -1698,7 +1697,7 @@ void CollisionCheck_AC_JntSphVsTris(GlobalContext* globalCtx, CollisionCheckCont
if (func_8005DF74(&lItem->body, &rItem->body) == 1) {
continue;
}
if (func_800CE934(&lItem->dim.worldSphere, &rItem->dim, &sp6C) == 1) {
if (Math3D_TriVsSphIntersect(&lItem->dim.worldSphere, &rItem->dim, &sp6C) == 1) {
sp60.x = lItem->dim.worldSphere.center.x;
sp60.y = lItem->dim.worldSphere.center.y;
sp60.z = lItem->dim.worldSphere.center.z;
@ -1735,7 +1734,7 @@ void CollisionCheck_AC_TrisVsJntSph(GlobalContext* globalCtx, CollisionCheckCont
if (func_8005DF74(&lItem->body, &rItem->body) == 1) {
continue;
}
if (func_800CE934(&rItem->dim.worldSphere, &lItem->dim, &sp7C) == 1) {
if (Math3D_TriVsSphIntersect(&rItem->dim.worldSphere, &lItem->dim, &sp7C) == 1) {
Math_Vec3s_ToVec3f(&sp64, &rItem->dim.worldSphere.center);
sp70.x = (lItem->dim.vtx[0].x + lItem->dim.vtx[1].x + lItem->dim.vtx[2].x) * (1.0f / 3);
sp70.y = (lItem->dim.vtx[0].y + lItem->dim.vtx[1].y + lItem->dim.vtx[2].y) * (1.0f / 3);
@ -1777,8 +1776,8 @@ void CollisionCheck_AC_JntSphVsQuad(GlobalContext* globalCtx, CollisionCheckCont
if (func_8005DF74(&lItem->body, &right->body) == 1) {
continue;
}
if (func_800CE934(&lItem->dim.worldSphere, &D_8015E230, &sp7C) == 1 ||
func_800CE934(&lItem->dim.worldSphere, &D_8015E268, &sp7C) == 1) {
if (Math3D_TriVsSphIntersect(&lItem->dim.worldSphere, &D_8015E230, &sp7C) == 1 ||
Math3D_TriVsSphIntersect(&lItem->dim.worldSphere, &D_8015E268, &sp7C) == 1) {
Math_Vec3s_ToVec3f(&sp6C, &lItem->dim.worldSphere.center);
sp60.x =
@ -1820,8 +1819,8 @@ void CollisionCheck_AC_QuadVsJntSph(GlobalContext* globalCtx, CollisionCheckCont
if (func_8005DF74(&left->body, &rItem->body) == 1) {
continue;
}
if (func_800CE934(&rItem->dim.worldSphere, &D_8015E2A0, &sp88) != 1 &&
func_800CE934(&rItem->dim.worldSphere, &D_8015E2D8, &sp88) != 1) {
if (Math3D_TriVsSphIntersect(&rItem->dim.worldSphere, &D_8015E2A0, &sp88) != 1 &&
Math3D_TriVsSphIntersect(&rItem->dim.worldSphere, &D_8015E2D8, &sp88) != 1) {
continue;
}
if (func_8005D218(globalCtx, left, &sp88) != 0) {
@ -1870,7 +1869,7 @@ void CollisionCheck_AC_CylVsCyl(GlobalContext* globalCtx, CollisionCheckContext*
if (func_8005DF74(&left->body, &right->body) == 1) {
return;
}
if (Math3D_CylinderOutCylinderDist(&left->dim, &right->dim, &sp6C, &sp68) == 1) {
if (Math3D_CylOutsideCylDist(&left->dim, &right->dim, &sp6C, &sp68) == 1) {
Math_Vec3s_ToVec3f(&sp50, &left->dim.pos);
Math_Vec3s_ToVec3f(&sp44, &right->dim.pos);
if (!(fabsf(sp68) < 0.008f)) {
@ -1904,7 +1903,7 @@ void CollisionCheck_AC_CylVsTris(GlobalContext* globalCtx, CollisionCheckContext
if (func_8005DF74(&left->body, &rItem->body) == 1) {
continue;
}
if (Math3D_CylTriTouchingIntersect(&left->dim, &rItem->dim, &sp68) == 1) {
if (Math3D_CylTriVsIntersect(&left->dim, &rItem->dim, &sp68) == 1) {
Math_Vec3s_ToVec3f(&sp5C, &left->dim.pos);
sp50.x = (rItem->dim.vtx[0].x + rItem->dim.vtx[1].x + rItem->dim.vtx[2].x) * (1.0f / 3);
@ -1938,7 +1937,7 @@ void CollisionCheck_AC_TrisVsCyl(GlobalContext* globalCtx, CollisionCheckContext
continue;
}
if (Math3D_CylTriTouchingIntersect(&right->dim, &lItem->dim, &D_8015E310) == 1) {
if (Math3D_CylTriVsIntersect(&right->dim, &lItem->dim, &D_8015E310) == 1) {
sp60.x = (lItem->dim.vtx[0].x + lItem->dim.vtx[1].x + lItem->dim.vtx[2].x) * (1.0f / 3);
sp60.y = (lItem->dim.vtx[0].y + lItem->dim.vtx[1].y + lItem->dim.vtx[2].y) * (1.0f / 3);
sp60.z = (lItem->dim.vtx[0].z + lItem->dim.vtx[1].z + lItem->dim.vtx[2].z) * (1.0f / 3);
@ -1974,7 +1973,7 @@ void CollisionCheck_AC_CylVsQuad(GlobalContext* globalCtx, CollisionCheckContext
}
Math3D_TriNorm(&D_8015E320, &right->dim.quad[2], &right->dim.quad[3], &right->dim.quad[1]);
Math3D_TriNorm(&D_8015E358, &right->dim.quad[1], &right->dim.quad[0], &right->dim.quad[2]);
if (Math3D_CylTriTouchingIntersect(&left->dim, &D_8015E320, &D_8015E390) == 1) {
if (Math3D_CylTriVsIntersect(&left->dim, &D_8015E320, &D_8015E390) == 1) {
Math_Vec3s_ToVec3f(&sp64, &left->dim.pos);
sp58.x =
(right->dim.quad[0].x + (right->dim.quad[1].x + (right->dim.quad[3].x + right->dim.quad[2].x))) * 0.25f;
@ -1985,7 +1984,7 @@ void CollisionCheck_AC_CylVsQuad(GlobalContext* globalCtx, CollisionCheckContext
func_8005E81C(globalCtx, &left->base, &left->body, &sp64, &right->base, &right->body, &sp58, &D_8015E390);
return;
}
if (Math3D_CylTriTouchingIntersect(&left->dim, &D_8015E358, &D_8015E390) == 1) {
if (Math3D_CylTriVsIntersect(&left->dim, &D_8015E358, &D_8015E390) == 1) {
Math_Vec3s_ToVec3f(&sp4C, &left->dim.pos);
sp40.x = (right->dim.quad[0].x + (right->dim.quad[1].x + (right->dim.quad[3].x + right->dim.quad[2].x))) *
(1.0f / 4);
@ -2020,7 +2019,7 @@ void CollisionCheck_AC_QuadVsCyl(GlobalContext* globalCtx, CollisionCheckContext
}
Math3D_TriNorm(&D_8015E3A0, &left->dim.quad[2], &left->dim.quad[3], &left->dim.quad[1]);
Math3D_TriNorm(&D_8015E3D8, &left->dim.quad[2], &left->dim.quad[1], &left->dim.quad[0]);
if (Math3D_CylTriTouchingIntersect(&right->dim, &D_8015E3A0, &D_8015E410) == 1) {
if (Math3D_CylTriVsIntersect(&right->dim, &D_8015E3A0, &D_8015E410) == 1) {
if (func_8005D218(globalCtx, left, &D_8015E410) != 0) {
sp64.x = (left->dim.quad[0].x + (left->dim.quad[1].x + (left->dim.quad[3].x + left->dim.quad[2].x))) *
(1.0f / 4);
@ -2033,7 +2032,7 @@ void CollisionCheck_AC_QuadVsCyl(GlobalContext* globalCtx, CollisionCheckContext
return;
}
}
if (Math3D_CylTriTouchingIntersect(&right->dim, &D_8015E3D8, &D_8015E410) == 1) {
if (Math3D_CylTriVsIntersect(&right->dim, &D_8015E3D8, &D_8015E410) == 1) {
if (func_8005D218(globalCtx, left, &D_8015E410) != 0) {
sp4C.x = (left->dim.quad[0].x + (left->dim.quad[1].x + (left->dim.quad[3].x + left->dim.quad[2].x))) *
(1.0f / 4);
@ -2071,7 +2070,7 @@ void CollisionCheck_AC_TrisVsTris(GlobalContext* globalCtx, CollisionCheckContex
if (func_8005DF74(&lItem->body, &rItem->body) == 1) {
continue;
}
if (Math3D_TrisIntersect(&lItem->dim, &rItem->dim, &D_8015E420) == 1) {
if (Math3D_TriVsTriIntersect(&lItem->dim, &rItem->dim, &D_8015E420) == 1) {
sp5C.x = (lItem->dim.vtx[0].x + lItem->dim.vtx[1].x + lItem->dim.vtx[2].x) * (1.0f / 3);
sp5C.y = (lItem->dim.vtx[0].y + lItem->dim.vtx[1].y + lItem->dim.vtx[2].y) * (1.0f / 3);
sp5C.z = (lItem->dim.vtx[0].z + lItem->dim.vtx[1].z + lItem->dim.vtx[2].z) * (1.0f / 3);
@ -2110,8 +2109,8 @@ void CollisionCheck_AC_TrisVsQuad(GlobalContext* globalCtx, CollisionCheckContex
if (func_8005DF74(&lItem->body, &right->body) == 1) {
continue;
}
if (Math3D_TrisIntersect(&D_8015E440, &lItem->dim, &D_8015E430) == 1 ||
Math3D_TrisIntersect(&D_8015E478, &lItem->dim, &D_8015E430) == 1) {
if (Math3D_TriVsTriIntersect(&D_8015E440, &lItem->dim, &D_8015E430) == 1 ||
Math3D_TriVsTriIntersect(&D_8015E478, &lItem->dim, &D_8015E430) == 1) {
sp68.x = (lItem->dim.vtx[0].x + lItem->dim.vtx[1].x + lItem->dim.vtx[2].x) * (1.0f / 3);
sp68.y = (lItem->dim.vtx[0].y + lItem->dim.vtx[1].y + lItem->dim.vtx[2].y) * (1.0f / 3);
sp68.z = (lItem->dim.vtx[0].z + lItem->dim.vtx[1].z + lItem->dim.vtx[2].z) * (1.0f / 3);
@ -2156,8 +2155,8 @@ void CollisionCheck_AC_QuadVsTris(GlobalContext* globalCtx, CollisionCheckContex
if (func_8005DF74(&left->body, &rItem->body) == 1) {
continue;
}
if (Math3D_TrisIntersect(&D_8015E4C0, &rItem->dim, &D_8015E4B0) == 1 ||
Math3D_TrisIntersect(&D_8015E4F8, &rItem->dim, &D_8015E4B0) == 1) {
if (Math3D_TriVsTriIntersect(&D_8015E4C0, &rItem->dim, &D_8015E4B0) == 1 ||
Math3D_TriVsTriIntersect(&D_8015E4F8, &rItem->dim, &D_8015E4B0) == 1) {
if (func_8005D218(globalCtx, left, &D_8015E4B0) != 0) {
sp5C.x = (rItem->dim.vtx[0].x + rItem->dim.vtx[1].x + rItem->dim.vtx[2].x) * (1.0f / 3);
sp5C.y = (rItem->dim.vtx[0].y + rItem->dim.vtx[1].y + rItem->dim.vtx[2].y) * (1.0f / 3);
@ -2209,7 +2208,7 @@ void CollisionCheck_AC_QuadVsQuad(GlobalContext* globalCtx, CollisionCheckContex
Math3D_TriNorm(&D_8015E530[1], &right->dim.quad[2], &right->dim.quad[1], &right->dim.quad[0]);
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
if (Math3D_TrisIntersect(&D_8015E5A8[j], &D_8015E530[i], &D_8015E598) == 1) {
if (Math3D_TriVsTriIntersect(&D_8015E5A8[j], &D_8015E530[i], &D_8015E598) == 1) {
if (func_8005D218(globalCtx, left, &D_8015E598) != 0) {
sp6C.x =
(left->dim.quad[0].x + (left->dim.quad[1].x + (left->dim.quad[3].x + left->dim.quad[2].x))) *
@ -2512,7 +2511,7 @@ void CollisionCheck_OC_JntSphVsJntSph(GlobalContext* globalCtx, CollisionCheckCo
if (!(rItem->body.ocFlags & 1)) {
continue;
}
if (Math3D_SpheresTouchingSurface(&lItem->dim.worldSphere, &rItem->dim.worldSphere, &sp74) == 1) {
if (Math3D_SphVsSphOverlap(&lItem->dim.worldSphere, &rItem->dim.worldSphere, &sp74) == 1) {
Math_Vec3s_ToVec3f(&sp68, &lItem->dim.worldSphere.center);
Math_Vec3s_ToVec3f(&sp5C, &rItem->dim.worldSphere.center);
func_800614A4(&left->base, &lItem->body, &sp68, &right->base, &rItem->body, &sp5C, sp74);
@ -2542,7 +2541,7 @@ void CollisionCheck_OC_JntSphVsCyl(GlobalContext* globalCtx, CollisionCheckConte
if (!(lItem->body.ocFlags & 1)) {
continue;
}
if (func_800CFD84(&lItem->dim.worldSphere, &right->dim, &sp78) == 1) {
if (Math3D_SphVsCylOverlapDist(&lItem->dim.worldSphere, &right->dim, &sp78) == 1) {
Math_Vec3s_ToVec3f(&sp6C, &lItem->dim.worldSphere.center);
Math_Vec3s_ToVec3f(&sp60, &right->dim.pos);
func_800614A4(&left->base, &lItem->body, &sp6C, &right->base, &right->body, &sp60, sp78);
@ -2569,7 +2568,7 @@ void CollisionCheck_OC_CylVsCyl(GlobalContext* globalCtx, CollisionCheckContext*
if (!(left->body.ocFlags & 1) || !(right->body.ocFlags & 1)) {
return;
}
if (Math3D_CylinderOutCylinder(&left->dim, &right->dim, &sp4C) == 1) {
if (Math3D_CylOutsideCyl(&left->dim, &right->dim, &sp4C) == 1) {
Math_Vec3s_ToVec3f(&sp40, &left->dim.pos);
Math_Vec3s_ToVec3f(&sp34, &right->dim.pos);
func_800614A4(&left->base, &left->body, &sp40, &right->base, &right->body, &sp34, sp4C);
@ -2787,7 +2786,7 @@ s32 CollisionCheck_generalLineOcCheck_JntSph(GlobalContext* globalCtx, Collision
}
D_8015E610.a = *arg3;
D_8015E610.b = *arg4;
if (func_800CE600(&item->dim.worldSphere, &D_8015E610) == 1) {
if (Math3D_LineVsSph(&item->dim.worldSphere, &D_8015E610) == 1) {
return 1;
}
}
@ -2803,7 +2802,7 @@ s32 CollisionCheck_generalLineOcCheck_Cyl(GlobalContext* globalCtx, CollisionChe
if (!(cylinder->body.ocFlags & 1)) {
return 0;
}
if (func_800CEE0C(&cylinder->dim, arg3, arg4, &D_8015E628, &D_8015E638) != 0) {
if (Math3D_CylVsLineSeg(&cylinder->dim, arg3, arg4, &D_8015E628, &D_8015E638) != 0) {
return 1;
}
return 0;
@ -2898,7 +2897,7 @@ void func_800627A0(ColliderTris* collider, s32 index, Vec3f* a, Vec3f* b, Vec3f*
Math_Vec3f_Copy(&item->dim.vtx[0], a);
Math_Vec3f_Copy(&item->dim.vtx[1], b);
Math_Vec3f_Copy(&item->dim.vtx[2], c);
func_800CC8B4(a, b, c, &sp40, &sp3C, &sp38, &sp34);
Math3D_DefPlane(a, b, c, &sp40, &sp3C, &sp38, &sp34);
item->dim.plane.normal.x = sp40;
item->dim.plane.normal.y = sp3C;
item->dim.plane.normal.z = sp38;

View file

@ -290,8 +290,8 @@ void EffectBlure_UpdateFlags(EffectBlureElement* elem) {
Math_Vec3s_DiffToVec3f(&sp4C, &next->p1, &elem->p1);
Math_Vec3s_DiffToVec3f(&sp40, &next->p2, &elem->p2);
if (func_800CB010(&sp64, &sp4C, &sp34) || func_800CB010(&sp58, &sp40, &sp30) ||
func_800CB010(&sp4C, &sp40, &sp2C)) {
if (Math3D_CosOut(&sp64, &sp4C, &sp34) || Math3D_CosOut(&sp58, &sp40, &sp30) ||
Math3D_CosOut(&sp4C, &sp40, &sp2C)) {
elem->flags &= ~3;
elem->flags |= 0;
} else if ((sp34 <= -0.5f) || (sp30 <= -0.5f) || (sp2C <= 0.7071f)) {

View file

@ -1,6 +1,9 @@
#include <ultra64.h>
#include <global.h>
/**
* Calculates the distances between `a` and `b`
*/
f32 OLib_Vec3fDist(Vec3f* a, Vec3f* b) {
f32 dx = a->x - b->x;
f32 dy = a->y - b->y;
@ -9,6 +12,11 @@ f32 OLib_Vec3fDist(Vec3f* a, Vec3f* b) {
return sqrtf(SQ(dx) + SQ(dy) + SQ(dz));
}
/**
* Calculates the distances between `a` and `b`, and outputs the vector
* created by the difference into `dest`
*/
f32 OLib_Vec3fDistOutDiff(Vec3f* a, Vec3f* b, Vec3f* dest) {
dest->x = a->x - b->x;
dest->y = a->y - b->y;
@ -17,38 +25,55 @@ f32 OLib_Vec3fDistOutDiff(Vec3f* a, Vec3f* b, Vec3f* dest) {
return sqrtf(SQ(dest->x) + SQ(dest->y) + SQ(dest->z));
}
/**
* Calculates the distances on the xz plane between `a` and `b`
*/
f32 OLib_Vec3fDistXZ(Vec3f* a, Vec3f* b) {
return sqrtf(SQ(a->x - b->x) + SQ(a->z - b->z));
}
f32 func_8007C058(f32 arg0, f32 arg1) {
return (arg1 <= fabsf(arg0)) ? arg0 : ((arg0 >= 0) ? arg1 : -arg1);
/**
* Clamps `val` to a maximum of -`min` as `val` approaches zero, and a minimum of
* `min` as `val` approaches zero
*/
f32 OLib_ClampMinDist(f32 val, f32 min) {
return (min <= fabsf(val)) ? val : ((val >= 0) ? min : -min);
}
f32 func_8007C0A8(f32 arg0, f32 arg1) {
return (fabsf(arg0) <= arg1) ? arg0 : ((arg0 >= 0) ? arg1 : -arg1);
/**
* Clamps `val` to a minimum of -`max` as `val` approaches -`max`, and a maximum of `max`
* as `val` approaches `max`
*/
f32 OLib_ClampMaxDist(f32 val, f32 max) {
return (fabsf(val) <= max) ? val : ((val >= 0) ? max : -max);
}
/**
* Takes the difference of points b and a, and creates a normal vector
*/
Vec3f* OLib_Vec3fDistNormalize(Vec3f* dest, Vec3f* a, Vec3f* b) {
Vec3f v1;
Vec3f v2;
f32 temp;
f32 dist;
v1.x = b->x - a->x;
v1.y = b->y - a->y;
v1.z = b->z - a->z;
temp = func_8007C058(sqrtf(SQ(v1.x) + SQ(v1.y) + SQ(v1.z)), 0.01f);
dist = OLib_ClampMinDist(sqrtf(SQ(v1.x) + SQ(v1.y) + SQ(v1.z)), 0.01f);
v2.x = v1.x / temp;
v2.y = v1.y / temp;
v2.z = v1.z / temp;
v2.x = v1.x / dist;
v2.y = v1.y / dist;
v2.z = v1.z / dist;
*dest = v2;
return dest;
}
/**
* Takes the spherical coordinate `sph`, and converts it into a x,y,z position
*/
Vec3f* OLib_VecSphToVec3f(Vec3f* dest, VecSph* sph) {
Vec3f v;
f32 sinPhi;
@ -56,10 +81,10 @@ Vec3f* OLib_VecSphToVec3f(Vec3f* dest, VecSph* sph) {
f32 sinTheta;
f32 cosTheta;
cosPhi = Math_Coss(sph->phi);
cosTheta = Math_Coss(sph->theta);
sinPhi = Math_Sins(sph->phi);
sinTheta = Math_Sins(sph->theta);
cosPhi = Math_Coss(sph->pitch);
cosTheta = Math_Coss(sph->yaw);
sinPhi = Math_Sins(sph->pitch);
sinTheta = Math_Sins(sph->yaw);
v.x = sph->r * sinPhi * sinTheta;
v.y = sph->r * cosPhi;
@ -70,16 +95,22 @@ Vec3f* OLib_VecSphToVec3f(Vec3f* dest, VecSph* sph) {
return dest;
}
void OLib_VecSphRot90ToVec3f(Vec3f* dest, VecSph* sph) {
VecSph src;
/**
* Takes the geographic point `sph` and converts it into a x,y,z position
*/
Vec3f* OLib_VecSphGeoToVec3f(Vec3f* dest, VecSph* sph) {
VecSph geo;
src.r = sph->r;
src.phi = 0x3FFF - sph->phi;
src.theta = sph->theta;
geo.r = sph->r;
geo.pitch = 0x3FFF - sph->pitch;
geo.yaw = sph->yaw;
OLib_VecSphToVec3f(dest, &src);
return OLib_VecSphToVec3f(dest, &geo);
}
/**
* Takes the point `vec`, and converts it into a spherical coordinate
*/
VecSph* OLib_Vec3fToVecSph(VecSph* dest, Vec3f* vec) {
VecSph sph;
@ -90,16 +121,16 @@ VecSph* OLib_Vec3fToVecSph(VecSph* dest, Vec3f* vec) {
dist = sqrtf(distSquared);
if ((dist == 0.0f) && (vec->y == 0.0f)) {
sph.phi = 0;
sph.pitch = 0;
} else {
sph.phi = Math_atan2f(dist, vec->y) * 57.295776f * 182.04167f + 0.5f;
sph.pitch = DEGF_TO_BINANG(RADF_TO_DEGF(Math_atan2f(dist, vec->y)));
}
sph.r = sqrtf(SQ(vec->y) + distSquared);
if ((vec->x == 0.0f) && (vec->z == 0.0f)) {
sph.theta = 0;
sph.yaw = 0;
} else {
sph.theta = Math_atan2f(vec->x, vec->z) * 57.295776f * 182.04167f + 0.5f;
sph.yaw = DEGF_TO_BINANG(RADF_TO_DEGF(Math_atan2f(vec->x, vec->z)));
}
*dest = sph;
@ -107,17 +138,23 @@ VecSph* OLib_Vec3fToVecSph(VecSph* dest, Vec3f* vec) {
return dest;
}
VecSph* OLib_Vec3fToVecSphRot90(VecSph* dest, Vec3f* vec) {
/**
* Takes the point `vec`, and converts it to a geographic coordinate
*/
VecSph* OLib_Vec3fToVecSphGeo(VecSph* dest, Vec3f* vec) {
VecSph sph;
OLib_Vec3fToVecSph(&sph, vec);
sph.phi = 0x3FFF - sph.phi;
sph.pitch = 0x3FFF - sph.pitch;
*dest = sph;
return dest;
}
/**
* Takes the differences of positions `a` and `b`, and converts them to spherical coordinates
*/
VecSph* OLib_Vec3fDiffToVecSph(VecSph* dest, Vec3f* a, Vec3f* b) {
Vec3f sph;
@ -128,55 +165,66 @@ VecSph* OLib_Vec3fDiffToVecSph(VecSph* dest, Vec3f* a, Vec3f* b) {
return OLib_Vec3fToVecSph(dest, &sph);
}
VecSph* OLib_Vec3fDiffToVecSphRot90(VecSph* dest, Vec3f* a, Vec3f* b) {
/**
* Takes the difference of positions `a` and `b`, and converts them to geographic coordinates
*/
VecSph* OLib_Vec3fDiffToVecSphGeo(VecSph* dest, Vec3f* a, Vec3f* b) {
Vec3f sph;
sph.x = b->x - a->x;
sph.y = b->y - a->y;
sph.z = b->z - a->z;
return OLib_Vec3fToVecSphRot90(dest, &sph);
return OLib_Vec3fToVecSphGeo(dest, &sph);
}
Vec3f* func_8007C4E0(Vec3f* dest, Vec3f* a, Vec3f* b) {
Vec3f var;
/**
* Gets the pitch/yaw of the vector formed from `b`-`a`, result is in radians
*/
Vec3f* OLib_Vec3fDiffRad(Vec3f* dest, Vec3f* a, Vec3f* b) {
Vec3f anglesRad;
var.x = Math_atan2f(b->z - a->z, b->y - a->y);
var.y = Math_atan2f(b->x - a->x, b->z - a->z);
var.z = 0;
anglesRad.x = Math_atan2f(b->z - a->z, b->y - a->y);
anglesRad.y = Math_atan2f(b->x - a->x, b->z - a->z);
anglesRad.z = 0;
*dest = var;
*dest = anglesRad;
return dest;
}
Vec3f* func_8007C574(Vec3f* arg0, Vec3f* arg1, Vec3f* arg2) {
Vec3f sp24;
Vec3f sp18;
/**
* Gets the pitch/yaw of the vector formed from `b`-`a`, result is in degrees
*/
Vec3f* OLib_Vec3fDiffDegF(Vec3f* dest, Vec3f* a, Vec3f* b) {
Vec3f anglesRad;
Vec3f anglesDegrees;
func_8007C4E0(&sp24, arg1, arg2);
OLib_Vec3fDiffRad(&anglesRad, a, b);
// ~180 / pi
sp18.x = sp24.x * 57.295776f;
sp18.y = sp24.y * 57.295776f;
sp18.z = 0.0f;
anglesDegrees.x = RADF_TO_DEGF(anglesRad.x);
anglesDegrees.y = RADF_TO_DEGF(anglesRad.y);
anglesDegrees.z = 0.0f;
*arg0 = sp18;
*dest = anglesDegrees;
return arg0;
return dest;
}
Vec3s* func_8007C5E0(Vec3s* arg0, Vec3f* arg1, Vec3f* arg2) {
Vec3f sp24;
Vec3s sp18;
/**
* Gets the pitch/yaw of the vector formed from `b`-`a`, result is in binary degrees
*/
Vec3s* OLib_Vec3fDiffBinAng(Vec3s* dest, Vec3f* a, Vec3f* b) {
Vec3f anglesRad;
Vec3s anglesBinAng;
func_8007C4E0(&sp24, arg1, arg2);
OLib_Vec3fDiffRad(&anglesRad, a, b);
sp18.x = (((sp24.x * 57.295776f)) * 182.04167f) + 0.5f;
sp18.y = (((sp24.y * 57.295776f)) * 182.04167f) + 0.5f;
sp18.z = 0.0f;
anglesBinAng.x = DEGF_TO_BINANG(RADF_TO_DEGF(anglesRad.x));
anglesBinAng.y = DEGF_TO_BINANG(RADF_TO_DEGF(anglesRad.y));
anglesBinAng.z = 0.0f;
*arg0 = sp18;
*dest = anglesBinAng;
return arg0;
return dest;
}

View file

@ -13,7 +13,7 @@ Vec3f* Quake_AddVec(Vec3f* dst, Vec3f* arg1, VecSph* arg2) {
Vec3f vec1;
Vec3f vec2;
OLib_VecSphRot90ToVec3f(&vec2, arg2);
OLib_VecSphGeoToVec3f(&vec2, arg2);
vec1.x = arg1->x + vec2.x;
vec1.y = arg1->y + vec2.y;
vec1.z = arg1->z + vec2.z;
@ -34,22 +34,22 @@ void Quake_UpdateShakeInfo(QuakeRequest* req, ShakeInfo* shake, f32 y, f32 x) {
vec.x = 0;
vec.y = 0;
vec.z = 0;
OLib_Vec3fDiffToVecSphRot90(&struc1, unk5C, unk50);
OLib_Vec3fDiffToVecSphGeo(&struc1, unk5C, unk50);
struc2.r = req->y * y;
struc2.phi = struc1.phi + req->unk_14.unk_00 + 0x4000;
struc2.theta = struc1.theta + req->unk_14.unk_02;
struc2.pitch = struc1.pitch + req->unk_14.unk_00 + 0x4000;
struc2.yaw = struc1.yaw + req->unk_14.unk_02;
Quake_AddVec(&vec, &vec, &struc2);
struc2.r = req->x * x;
struc2.phi = struc1.phi + req->unk_14.unk_00;
struc2.theta = struc1.theta + req->unk_14.unk_02 + 0x4000;
struc2.pitch = struc1.pitch + req->unk_14.unk_00;
struc2.yaw = struc1.yaw + req->unk_14.unk_02 + 0x4000;
Quake_AddVec(&vec, &vec, &struc2);
} else {
vec.x = 0;
vec.y = req->y * y;
vec.z = 0;
struc2.r = req->x * x;
struc2.phi = req->unk_14.unk_00;
struc2.theta = req->unk_14.unk_02;
struc2.pitch = req->unk_14.unk_00;
struc2.yaw = req->unk_14.unk_02;
Quake_AddVec(&vec, &vec, &struc2);
}