1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-21 04:24:43 +00:00

Rename Math3D_CylOutsideCyl and Math3D_CylOutsideCylDist (#1557)

* Rename Math3D_CylOutsideCyl and Math3D_CylOutsideCylDist

* radix -> radii

Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com>

* Make Math3D sphere/cylinder collision check function names more consistent

---------

Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com>
This commit is contained in:
cadmic 2023-10-07 16:42:28 -07:00 committed by GitHub
parent 181b438393
commit b3486b57ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 39 deletions

View File

@ -1419,11 +1419,11 @@ s32 Math3D_CylVsTri(Cylinder16* cyl, TriNorm* tri);
s32 Math3D_CylTriVsIntersect(Cylinder16* cyl, TriNorm* tri, Vec3f* intersect);
s32 Math3D_SphVsSph(Sphere16* sphereA, Sphere16* sphereB);
s32 Math3D_SphVsSphOverlap(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize);
s32 Math3D_SphVsSphOverlapCenter(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize, f32* centerDist);
s32 Math3D_SphVsCylOverlapDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize);
s32 Math3D_SphVsSphOverlapCenterDist(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize, f32* centerDist);
s32 Math3D_SphVsCylOverlap(Sphere16* sph, Cylinder16* cyl, f32* overlapSize);
s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize, f32* centerDist);
s32 Math3D_CylOutsideCyl(Cylinder16* ca, Cylinder16* cb, f32* deadSpace);
s32 Math3D_CylOutsideCylDist(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32* xzDist);
s32 Math3D_CylVsCylOverlap(Cylinder16* ca, Cylinder16* cb, f32* overlapSize);
s32 Math3D_CylVsCylOverlapCenterDist(Cylinder16* ca, Cylinder16* cb, f32* overlapSize, f32* centerDist);
s32 Math3D_TriVsTriIntersect(TriNorm* ta, TriNorm* tb, Vec3f* intersect);
s32 Math3D_XZInSphere(Sphere16* sphere, f32 x, f32 z);
s32 Math3D_XYInSphere(Sphere16* sphere, f32 x, f32 y);

View File

@ -1925,14 +1925,14 @@ s32 Math3D_SphVsSph(Sphere16* sphereA, Sphere16* sphereB) {
s32 Math3D_SphVsSphOverlap(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize) {
f32 centerDist;
return Math3D_SphVsSphOverlapCenter(sphereA, sphereB, overlapSize, &centerDist);
return Math3D_SphVsSphOverlapCenterDist(sphereA, sphereB, overlapSize, &centerDist);
}
/*
* Determines if two spheres are touching The distance from the centers is placed in `centerDist`,
* and the amount that they're overlapping is placed in `overlapSize`
*/
s32 Math3D_SphVsSphOverlapCenter(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize, f32* centerDist) {
s32 Math3D_SphVsSphOverlapCenterDist(Sphere16* sphereA, Sphere16* sphereB, f32* overlapSize, f32* centerDist) {
Vec3f diff;
diff.x = (f32)sphereA->center.x - (f32)sphereB->center.x;
@ -1951,9 +1951,9 @@ s32 Math3D_SphVsSphOverlapCenter(Sphere16* sphereA, Sphere16* sphereB, f32* over
}
/**
* Checks if `sph` and `cyl` are touching, output the amount of overlap to `overlapSize`
* Checks if `sph` and `cyl` are touching, output the amount of xz overlap to `overlapSize`
*/
s32 Math3D_SphVsCylOverlapDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize) {
s32 Math3D_SphVsCylOverlap(Sphere16* sph, Cylinder16* cyl, f32* overlapSize) {
f32 centerDist;
return Math3D_SphVsCylOverlapCenterDist(sph, cyl, overlapSize, &centerDist);
@ -1961,7 +1961,7 @@ s32 Math3D_SphVsCylOverlapDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize)
/**
* Checks if `sph` and `cyl` are touching, output the xz distance of the centers to `centerDist`, and the amount of
* overlap to `overlapSize`
* xz overlap to `overlapSize`
*/
s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overlapSize, f32* centerDist) {
static Cylinderf cylf;
@ -2007,22 +2007,20 @@ s32 Math3D_SphVsCylOverlapCenterDist(Sphere16* sph, Cylinder16* cyl, f32* overla
return false;
}
/*
* returns 1 if cylinder `ca` is outside cylinder `cb`.
* Sets `deadSpace` to the mininum space between the cylinders not occupied by the other.
/**
* Checks if `ca` and `cb` are touching, output the amount of xz overlap to `overlapSize`
*/
s32 Math3D_CylOutsideCyl(Cylinder16* ca, Cylinder16* cb, f32* deadSpace) {
s32 Math3D_CylVsCylOverlap(Cylinder16* ca, Cylinder16* cb, f32* overlapSize) {
f32 xzDist;
return Math3D_CylOutsideCylDist(ca, cb, deadSpace, &xzDist);
return Math3D_CylVsCylOverlapCenterDist(ca, cb, overlapSize, &xzDist);
}
/*
* returns 1 if cylinder `ca` is outside cylinder `cb`.
* Sets `xzDist` to the xz distance between the centers of the cylinders.
* Sets `deadSpace` to the minimum space between the cylinders not occupied by the other.
/**
* Checks if `ca` and `cb` are touching, output the xz distance of the centers to `centerDist`, and the amount of
* xz overlap to `overlapSize`
*/
s32 Math3D_CylOutsideCylDist(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32* xzDist) {
s32 Math3D_CylVsCylOverlapCenterDist(Cylinder16* ca, Cylinder16* cb, f32* overlapSize, f32* centerDist) {
static Cylinderf caf;
static Cylinderf cbf;
@ -2036,10 +2034,10 @@ s32 Math3D_CylOutsideCylDist(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32
cbf.yShift = cb->yShift;
cbf.height = cb->height;
*xzDist = sqrtf(SQ(caf.pos.x - cbf.pos.x) + SQ(caf.pos.z - cbf.pos.z));
*centerDist = sqrtf(SQ(caf.pos.x - cbf.pos.x) + SQ(caf.pos.z - cbf.pos.z));
// The combined radix are within the xz distance
if ((caf.radius + cbf.radius) < *xzDist) {
// The combined radii are within the xz distance
if ((caf.radius + cbf.radius) < *centerDist) {
return false;
}
@ -2049,7 +2047,7 @@ s32 Math3D_CylOutsideCylDist(Cylinder16* ca, Cylinder16* cb, f32* deadSpace, f32
return false;
}
*deadSpace = caf.radius + cbf.radius - *xzDist;
*overlapSize = caf.radius + cbf.radius - *centerDist;
return true;
}

View File

@ -1745,8 +1745,8 @@ void CollisionCheck_AC_JntSphVsJntSph(PlayState* play, CollisionCheckContext* co
if (CollisionCheck_NoSharedFlags(&atItem->info, &acElem->info) == true) {
continue;
}
if (Math3D_SphVsSphOverlapCenter(&atItem->dim.worldSphere, &acElem->dim.worldSphere, &overlapSize,
&centerDist) == true) {
if (Math3D_SphVsSphOverlapCenterDist(&atItem->dim.worldSphere, &acElem->dim.worldSphere, &overlapSize,
&centerDist) == true) {
f32 acToHit;
Vec3f hitPos;
Vec3f atPos;
@ -2070,8 +2070,8 @@ void CollisionCheck_AC_QuadVsJntSph(PlayState* play, CollisionCheckContext* colC
void CollisionCheck_AC_CylVsCyl(PlayState* play, CollisionCheckContext* colChkCtx, Collider* colAT, Collider* colAC) {
ColliderCylinder* at = (ColliderCylinder*)colAT;
ColliderCylinder* ac = (ColliderCylinder*)colAC;
f32 deadSpace;
f32 centerDistXZ;
f32 overlapSize;
f32 centerDist;
Vec3f hitPos;
if (at->dim.radius > 0 && at->dim.height > 0 && ac->dim.radius > 0 && ac->dim.height > 0) {
@ -2084,15 +2084,15 @@ void CollisionCheck_AC_CylVsCyl(PlayState* play, CollisionCheckContext* colChkCt
if (CollisionCheck_NoSharedFlags(&at->info, &ac->info) == true) {
return;
}
if (Math3D_CylOutsideCylDist(&at->dim, &ac->dim, &deadSpace, &centerDistXZ) == true) {
if (Math3D_CylVsCylOverlapCenterDist(&at->dim, &ac->dim, &overlapSize, &centerDist) == true) {
Vec3f atPos;
Vec3f acPos;
f32 acToHit;
Math_Vec3s_ToVec3f(&atPos, &at->dim.pos);
Math_Vec3s_ToVec3f(&acPos, &ac->dim.pos);
if (!IS_ZERO(centerDistXZ)) {
acToHit = ac->dim.radius / centerDistXZ;
if (!IS_ZERO(centerDist)) {
acToHit = ac->dim.radius / centerDist;
hitPos.y = (f32)ac->dim.pos.y + ac->dim.yShift + ac->dim.height * 0.5f;
hitPos.x = ((f32)at->dim.pos.x - ac->dim.pos.x) * acToHit + ac->dim.pos.x;
hitPos.z = ((f32)at->dim.pos.z - ac->dim.pos.z) * acToHit + ac->dim.pos.z;
@ -2732,7 +2732,7 @@ void CollisionCheck_OC_JntSphVsJntSph(PlayState* play, CollisionCheckContext* co
ColliderJntSphElement* leftElem;
ColliderJntSph* right = (ColliderJntSph*)r;
ColliderJntSphElement* rightElem;
f32 overlap;
f32 overlapSize;
if (left->count > 0 && left->elements != NULL && right->count > 0 && right->elements != NULL) {
for (leftElem = left->elements; leftElem < left->elements + left->count; leftElem++) {
@ -2743,14 +2743,15 @@ void CollisionCheck_OC_JntSphVsJntSph(PlayState* play, CollisionCheckContext* co
if (!(rightElem->info.ocElemFlags & OCELEM_ON)) {
continue;
}
if (Math3D_SphVsSphOverlap(&leftElem->dim.worldSphere, &rightElem->dim.worldSphere, &overlap) == true) {
if (Math3D_SphVsSphOverlap(&leftElem->dim.worldSphere, &rightElem->dim.worldSphere, &overlapSize) ==
true) {
Vec3f leftPos;
Vec3f rightPos;
Math_Vec3s_ToVec3f(&leftPos, &leftElem->dim.worldSphere.center);
Math_Vec3s_ToVec3f(&rightPos, &rightElem->dim.worldSphere.center);
CollisionCheck_SetOCvsOC(&left->base, &leftElem->info, &leftPos, &right->base, &rightElem->info,
&rightPos, overlap);
&rightPos, overlapSize);
}
}
}
@ -2764,7 +2765,7 @@ void CollisionCheck_OC_JntSphVsCyl(PlayState* play, CollisionCheckContext* colCh
ColliderJntSph* left = (ColliderJntSph*)l;
ColliderJntSphElement* leftElem;
ColliderCylinder* right = (ColliderCylinder*)r;
f32 overlap;
f32 overlapSize;
if (left->count > 0 && left->elements != NULL) {
if ((right->base.ocFlags1 & OC1_ON) && (right->info.ocElemFlags & OCELEM_ON)) {
@ -2772,14 +2773,14 @@ void CollisionCheck_OC_JntSphVsCyl(PlayState* play, CollisionCheckContext* colCh
if (!(leftElem->info.ocElemFlags & OCELEM_ON)) {
continue;
}
if (Math3D_SphVsCylOverlapDist(&leftElem->dim.worldSphere, &right->dim, &overlap) == true) {
if (Math3D_SphVsCylOverlap(&leftElem->dim.worldSphere, &right->dim, &overlapSize) == true) {
Vec3f leftPos;
Vec3f rightPos;
Math_Vec3s_ToVec3f(&leftPos, &leftElem->dim.worldSphere.center);
Math_Vec3s_ToVec3f(&rightPos, &right->dim.pos);
CollisionCheck_SetOCvsOC(&left->base, &leftElem->info, &leftPos, &right->base, &right->info,
&rightPos, overlap);
&rightPos, overlapSize);
}
}
}
@ -2799,18 +2800,18 @@ void CollisionCheck_OC_CylVsJntSph(PlayState* play, CollisionCheckContext* colCh
void CollisionCheck_OC_CylVsCyl(PlayState* play, CollisionCheckContext* colChkCtx, Collider* l, Collider* r) {
ColliderCylinder* left = (ColliderCylinder*)l;
ColliderCylinder* right = (ColliderCylinder*)r;
f32 deadSpace;
f32 overlapSize;
if ((left->base.ocFlags1 & OC1_ON) && (right->base.ocFlags1 & OC1_ON)) {
if ((left->info.ocElemFlags & OCELEM_ON) && (right->info.ocElemFlags & OCELEM_ON)) {
if (Math3D_CylOutsideCyl(&left->dim, &right->dim, &deadSpace) == true) {
if (Math3D_CylVsCylOverlap(&left->dim, &right->dim, &overlapSize) == true) {
Vec3f leftPos;
Vec3f rightPos;
Math_Vec3s_ToVec3f(&leftPos, &left->dim.pos);
Math_Vec3s_ToVec3f(&rightPos, &right->dim.pos);
CollisionCheck_SetOCvsOC(&left->base, &left->info, &leftPos, &right->base, &right->info, &rightPos,
deadSpace);
overlapSize);
}
}
}