Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/bgcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ typedef struct DynaLineTest {
/* 0x28 */ f32 chkDist; // distance from poly
} DynaLineTest;

void func_80038A28(CollisionPoly* poly, f32 tx, f32 ty, f32 tz, MtxF* dest);
void CollisionPoly_GetGroundMtxF(CollisionPoly* poly, f32 tx, f32 ty, f32 tz, MtxF* dest);
f32 CollisionPoly_GetPointDistanceFromPlane(CollisionPoly* poly, Vec3f* point);
void CollisionPoly_GetVerticesByBgId(CollisionPoly* poly, s32 bgId, CollisionContext* colCtx, Vec3f* dest);
void BgCheck_Allocate(CollisionContext* colCtx, struct PlayState* play, CollisionHeader* colHeader);
Expand Down
1 change: 1 addition & 0 deletions include/collision_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ s32 CollisionCheck_SetOC(struct PlayState* play, CollisionCheckContext* colChkCt
s32 CollisionCheck_SetOC_SAC(struct PlayState* play, CollisionCheckContext* colChkCtx, Collider* collider, s32 index);
s32 CollisionCheck_SetOCLine(struct PlayState* play, CollisionCheckContext* colChkCtx, OcLine* collider);
void CollisionCheck_BlueBlood(struct PlayState* play, Collider* collider, Vec3f* v);
void CollisionCheck_GreenBlood(struct PlayState* play, Collider* collider, Vec3f* v);
void CollisionCheck_AT(struct PlayState* play, CollisionCheckContext* colChkCtx);
void CollisionCheck_OC(struct PlayState* play, CollisionCheckContext* colChkCtx);
void CollisionCheck_InitInfo(CollisionCheckInfo* info);
Expand Down
6 changes: 3 additions & 3 deletions src/code/sys_math3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32
static InfiniteLine planeIntersectLine;
static Linef planeIntersectSeg;

Vec3f sp34; // unused
Vec3f _point; // discarded
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we dont do leading underscore for "discarded" arguments anywhere else. it goes against our convention, I dont want to introduce it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also maybe instead of closestPoint and point it should be planePoint and linePoint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cadmic can you or someone else explain your reasoning to me? I'm trying to wrap my head around the bigger picture what these two functions are doing because it could help name two functions in bgcheck:

Math3D_PlaneVsPlaneVsLineClosestPoint
Math3D_PlaneVsLineSegClosestPoint

Like to me, it seems like Math3D_PlaneVsLineSegClosestPoint should be named PlaneVsPlane as well.

Copy link
Contributor

@cadmic cadmic Jun 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The planePoint/linePoint comment was solely based on reading // closestPoint is a point on planeIntersect, sp34 is a point on linePointA, linePointB

But, looking at it harder, I think the comment on Math3D_PlaneVsPlaneVsLineClosestPoint is accurate, but Math3D_PlaneVsLineSegClosestPoint is actually comparing with a "line", not a "line segment". I'd suggest something like the following names:

Math3D_PlaneVsPlaneNewLine -> Math3D_PlaneIntersect
Math3D_PlaneVsPlaneVsLineClosestPoint -> Math3D_PlaneIntersectVsPoint
Math3D_PlaneVsLineSegClosestPoint -> Math3D_PlaneIntersectVsLine

Here PlaneIntersect means the line formed by the intersection of two planes. I didn't want to use Vs because I think that made Math3D_PlaneIntersectVsPoint and Math3D_PlaneIntersectVsLine too confusing

Copy link
Contributor

@cadmic cadmic Jun 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess if we want to be fully consistent about removing "ClosestPoint", there should be these renames too:

Math3D_LineClosestToPoint -> Math3D_LineVsPoint
Math3D_LineVsLineClosestTwoPoints -> Math3D_LineVsLine

the idea being that "vs" means any comparison, not necessarily and intersection test


if (!Math3D_PlaneVsPlaneNewLine(planeAA, planeAB, planeAC, planeADist, planeBA, planeBB, planeBC, planeBDist,
&planeIntersectLine)) {
Expand All @@ -44,9 +44,9 @@ s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32
planeIntersectSeg.b.y = (planeIntersectLine.dir.y * 100.0f) + planeIntersectLine.point.y;
planeIntersectSeg.b.z = (planeIntersectLine.dir.z * 100.0f) + planeIntersectLine.point.z;

// closestPoint is a point on planeIntersect, sp34 is a point on linePointA, linePointB
// closestPoint is a point on planeIntersect, _point is a point on linePointA, linePointB
if (!Math3D_LineVsLineClosestTwoPoints(&planeIntersectSeg.a, &planeIntersectSeg.b, linePointA, linePointB,
closestPoint, &sp34)) {
closestPoint, &_point)) {
return false;
}
return true;
Expand Down
5 changes: 3 additions & 2 deletions src/code/z_actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ void ActorShadow_Draw(Actor* actor, Lights* lights, PlayState* play, Gfx* dlist,
gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 0, 0, 0, (u32)(actor->shape.shadowAlpha * temp2) & 0xFF);
}

func_80038A28(actor->floorPoly, actor->world.pos.x, actor->floorHeight, actor->world.pos.z, &sp60);
CollisionPoly_GetGroundMtxF(actor->floorPoly, actor->world.pos.x, actor->floorHeight, actor->world.pos.z,
&sp60);
Matrix_Put(&sp60);

if (dlist != gCircleShadowDL) {
Expand Down Expand Up @@ -4055,7 +4056,7 @@ void func_80033C30(Vec3f* arg0, Vec3f* arg1, u8 alpha, PlayState* play) {
yIntersect = BgCheck_EntityRaycastDown2(play, &play->colCtx, &groundPoly, &checkPos);

if (groundPoly != NULL) {
func_80038A28(groundPoly, arg0->x, yIntersect, arg0->z, &sp60);
CollisionPoly_GetGroundMtxF(groundPoly, arg0->x, yIntersect, arg0->z, &sp60);
Matrix_Put(&sp60);
} else {
Matrix_Translate(arg0->x, arg0->y, arg0->z, MTXMODE_NEW);
Expand Down
7 changes: 5 additions & 2 deletions src/code/z_bgcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void CollisionPoly_GetNormalF(CollisionPoly* poly, f32* nx, f32* ny, f32* nz) {
/**
* Compute transform matrix mapping +y (up) to the collision poly's normal
*/
void func_80038A28(CollisionPoly* poly, f32 tx, f32 ty, f32 tz, MtxF* dest) {
void CollisionPoly_GetGroundMtxF(CollisionPoly* poly, f32 tx, f32 ty, f32 tz, MtxF* dest) {
f32 nx;
f32 ny;
f32 nz;
Expand Down Expand Up @@ -3919,7 +3919,10 @@ void CollisionHeader_GetVirtual(void* colHeader, CollisionHeader** dest) {
}

/**
* SEGMENT_TO_VIRTUAL all active BgActor CollisionHeaders
* SEGMENTED_TO_VIRTUAL all active BgActor CollisionHeaders
*
* When the game is paused, object data is clobbered to make space for the pause menu assets.
* Once the object data is restored, pointers in the CollisionHeader must be linked again before the game can resume.
*/
void func_800418D0(CollisionContext* colCtx, PlayState* play) {
DynaCollisionContext* dyna = &colCtx->dyna;
Expand Down
8 changes: 4 additions & 4 deletions src/code/z_camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ s32 func_80045508(Camera* camera, VecGeo* diffGeo, CamColChk* eyeChk, CamColChk*

eyeChk->geoNorm = OLib_Vec3fToVecGeo(&eyeChk->norm);

if (eyeChk->geoNorm.pitch >= 0x2EE1) {
if (eyeChk->geoNorm.pitch > 0x2EE0) {
eyeChk->geoNorm.yaw = diffGeo->yaw;
}

Expand Down Expand Up @@ -1042,7 +1042,7 @@ s32 func_80045508(Camera* camera, VecGeo* diffGeo, CamColChk* eyeChk, CamColChk*

atChk->geoNorm = OLib_Vec3fToVecGeo(&atChk->norm);

if (atChk->geoNorm.pitch >= 0x2EE1) {
if (atChk->geoNorm.pitch > 0x2EE0) {
atChk->geoNorm.yaw = diffGeo->yaw - 0x7FFF;
}

Expand Down Expand Up @@ -1961,7 +1961,7 @@ s32 Camera_Normal2(Camera* camera) {
camera->dist = adjGeo.r = Camera_ClampDist(camera, sp90.r, roData->unk_04, roData->unk_08, 0);

if (!(rwData->unk_28 & 1)) {
if (adjGeo.pitch >= 0xE39) {
if (adjGeo.pitch > 0xE38) {
adjGeo.pitch += ((s16)(0xE38 - adjGeo.pitch) >> 2);
}

Expand Down Expand Up @@ -5684,7 +5684,7 @@ s32 Camera_Unique9(Camera* camera) {
scratchGeo.yaw += CAM_DEG_TO_BINANG(rwData->curKeyFrame->eyeTargetInit.y);

// 3A98 ~ 82.40 degrees
if (scratchGeo.pitch >= 0x3A99) {
if (scratchGeo.pitch > 0x3A98) {
scratchGeo.pitch = 0x3A98;
}

Expand Down
3 changes: 2 additions & 1 deletion src/overlays/actors/ovl_En_Dekubaba/z_en_dekubaba.c
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,8 @@ void EnDekubaba_DrawBaseShadow(EnDekubaba* this, PlayState* play) {

gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 0, 0, 0, 255);

func_80038A28(this->boundFloor, this->actor.home.pos.x, this->actor.home.pos.y, this->actor.home.pos.z, &mtx);
CollisionPoly_GetGroundMtxF(this->boundFloor, this->actor.home.pos.x, this->actor.home.pos.y,
this->actor.home.pos.z, &mtx);
Matrix_Mult(&mtx, MTXMODE_NEW);

horizontalScale = this->size * 0.15f;
Expand Down
3 changes: 2 additions & 1 deletion src/overlays/actors/ovl_En_Karebaba/z_en_karebaba.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,8 @@ void EnKarebaba_DrawBaseShadow(EnKarebaba* this, PlayState* play) {
Gfx_SetupDL_44Xlu(play->state.gfxCtx);

gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 0, 0, 0, 255);
func_80038A28(this->boundFloor, this->actor.home.pos.x, this->actor.home.pos.y, this->actor.home.pos.z, &mf);
CollisionPoly_GetGroundMtxF(this->boundFloor, this->actor.home.pos.x, this->actor.home.pos.y,
this->actor.home.pos.z, &mf);
Matrix_Mult(&mf, MTXMODE_NEW);
Matrix_Scale(0.15f, 1.0f, 0.15f, MTXMODE_APPLY);
MATRIX_FINALIZE_AND_LOAD(POLY_XLU_DISP++, play->state.gfxCtx, "../z_en_karebaba.c", 1029);
Expand Down
2 changes: 1 addition & 1 deletion src/overlays/actors/ovl_En_Nwc/z_en_nwc.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void EnNwc_DrawChicks(EnNwc* this, PlayState* play) {

for (i = 0; i < this->count; i++, chick++) {
if ((chick->type != CHICK_NONE) && (chick->floorPoly != NULL)) {
func_80038A28(chick->floorPoly, chick->pos.x, chick->floorY, chick->pos.z, &floorMat);
CollisionPoly_GetGroundMtxF(chick->floorPoly, chick->pos.x, chick->floorY, chick->pos.z, &floorMat);
Matrix_Put(&floorMat);
Matrix_RotateY(BINANG_TO_RAD(chick->rot.y), MTXMODE_APPLY);
Matrix_Scale(1.0f, 1.0f, 1.0f, MTXMODE_APPLY);
Expand Down
4 changes: 2 additions & 2 deletions src/overlays/actors/ovl_En_Wallmas/z_en_wallmas.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,8 @@ void EnWallmas_DrawXlu(EnWallmas* this, PlayState* play) {
Gfx_SetupDL_44Xlu(play->state.gfxCtx);
gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 0, 0, 0, 255);

func_80038A28(this->actor.floorPoly, this->actor.world.pos.x, this->actor.floorHeight, this->actor.world.pos.z,
&mf);
CollisionPoly_GetGroundMtxF(this->actor.floorPoly, this->actor.world.pos.x, this->actor.floorHeight,
this->actor.world.pos.z, &mf);
Matrix_Mult(&mf, MTXMODE_NEW);

if ((this->actionFunc != EnWallmas_WaitToDrop) && (this->actionFunc != EnWallmas_ReturnToCeiling) &&
Expand Down
4 changes: 2 additions & 2 deletions src/overlays/effects/ovl_Effect_Ss_Dead_Ds/z_eff_ss_dead_ds.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ void EffectSsDeadDs_Draw(PlayState* play, u32 index, EffectSs* this) {
prevPos.z = pos.z - this->velocity.z;

if (BgCheck_EntitySphVsWall1(&play->colCtx, &this->pos, &pos, &prevPos, 1.5f, &groundPoly, 1.0f)) {
func_80038A28(groundPoly, this->pos.x, this->pos.y, this->pos.z, &mf);
CollisionPoly_GetGroundMtxF(groundPoly, this->pos.x, this->pos.y, this->pos.z, &mf);
Matrix_Put(&mf);
} else {
pos.y++;
yIntersect = BgCheck_EntityRaycastDown1(&play->colCtx, &groundPoly, &pos);

if (groundPoly != NULL) {
func_80038A28(groundPoly, this->pos.x, yIntersect + 1.5f, this->pos.z, &mf);
CollisionPoly_GetGroundMtxF(groundPoly, this->pos.x, yIntersect + 1.5f, this->pos.z, &mf);
Matrix_Put(&mf);
} else {
Matrix_Translate(this->pos.x, this->pos.y, this->pos.z, MTXMODE_NEW);
Expand Down