Skip to content

Commit e51fd73

Browse files
authored
Fix misc 7 (zeldaret#1149)
* Fixup `Math3D_LineClosestToPoint` * `gDodongosCavernBossLavaFloorTex` is 32x64 * Name empty-dlist-making functions `_EmptyDList` * Fix typos * transitionRate -> morphFrames * Compare `xyzDistToPlayerSq` to squared values * Fix hookshot target/post collision header names being swapped * Fix description of `z_bg_mizu_movebg.c` * Add scene command comment to `func_80098508` to match other scene command handlers * Some fixup in `Camera_Demo5` * `1` -> `ALLOCTYPE_ABSOLUTE` in comment on `ActorContext.absoluteSpace`
1 parent a9526a3 commit e51fd73

File tree

34 files changed

+93
-87
lines changed

34 files changed

+93
-87
lines changed

assets/xml/objects/object_d_hsblock.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Root>
22
<File Name="object_d_hsblock" Segment="6">
3-
<Collision Name="gHookshotPostCol" Offset="0x578"/>
4-
<Collision Name="gHookshotTargetCol" Offset="0x730"/>
3+
<Collision Name="gHookshotTargetCol" Offset="0x578"/>
4+
<Collision Name="gHookshotPostCol" Offset="0x730"/>
55
<DList Name="gHookshotPostDL" Offset="0x210"/>
66
<DList Name="gHookshotTargetDL" Offset="0x470"/>
77
<Texture Name="gHookshotTargetTex" OutName="hookshot_target" Format="i4" Width="64" Height="64" Offset="0x760"/>

assets/xml/scenes/dungeons/ddan_boss.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Room Name="ddan_boss_room_0" Offset="0x0"/>
77
</File>
88
<File Name="ddan_boss_room_1" Segment="3">
9-
<Texture Name="gDodongosCavernBossLavaFloorTex" OutName="lava_floor" Format="rgba16" Width="64" Height="32" Offset="0x21D8"/>
9+
<Texture Name="gDodongosCavernBossLavaFloorTex" OutName="lava_floor" Format="rgba16" Width="32" Height="64" Offset="0x21D8"/>
1010
<Room Name="ddan_boss_room_1" Offset="0x0"/>
1111
</File>
1212
</Root>

include/functions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,7 @@ f32 Math_CosF(f32 angle);
16841684
s32 Math3D_PlaneVsLineSegClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA, f32 planeBB,
16851685
f32 planeBC, f32 planeBDist, Vec3f* linePointA, Vec3f* linePointB,
16861686
Vec3f* closestPoint);
1687-
void Math3D_LineClosestToPoint(Linef* line, Vec3f* pos, Vec3f* closestPoint);
1687+
void Math3D_LineClosestToPoint(InfiniteLine* line, Vec3f* pos, Vec3f* closestPoint);
16881688
s32 Math3D_PlaneVsPlaneVsLineClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA,
16891689
f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* point, Vec3f* closestPoint);
16901690
void Math3D_LineSplitRatio(Vec3f* v0, Vec3f* v1, f32 ratio, Vec3f* ret);

include/z64.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ typedef struct {
263263
} flags;
264264
/* 0x0128 */ TitleCardContext titleCtx;
265265
/* 0x0138 */ char unk_138[0x04];
266-
/* 0x013C */ void* absoluteSpace; // Space used to allocate actor overlays of alloc type 1
266+
/* 0x013C */ void* absoluteSpace; // Space used to allocate actor overlays with alloc type ALLOCTYPE_ABSOLUTE
267267
} ActorContext; // size = 0x140
268268

269269
typedef struct {

include/z64camera.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ typedef struct {
789789
{ flags, CAM_DATA_FLAGS }
790790

791791
typedef struct {
792-
/* 0x00 */ Linef unk_00;
792+
/* 0x00 */ InfiniteLine unk_00;
793793
/* 0x18 */ f32 unk_18;
794794
/* 0x1C */ f32 unk_1C;
795795
/* 0x20 */ f32 unk_20;
@@ -913,7 +913,7 @@ typedef struct {
913913
typedef struct {
914914
/* 0x00 */ Vec3f initalPos;
915915
/* 0x0C */ s16 animTimer;
916-
/* 0x10 */ Linef sceneCamPosPlayerLine;
916+
/* 0x10 */ InfiniteLine sceneCamPosPlayerLine;
917917
} Unique0Anim; // size = 0x28
918918

919919
typedef struct {

src/code/sys_math3d.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,27 @@ s32 Math3D_LineVsLineClosestTwoPoints(Vec3f* lineAPointA, Vec3f* lineAPointB, Ve
114114
* Determines the closest point on the line `line` to `pos`, by forming a line perpendicular from
115115
* `point` to `line` closest point is placed in `closestPoint`
116116
*/
117-
void Math3D_LineClosestToPoint(Linef* line, Vec3f* pos, Vec3f* closestPoint) {
118-
f32 dirVectorSize;
117+
void Math3D_LineClosestToPoint(InfiniteLine* line, Vec3f* pos, Vec3f* closestPoint) {
118+
f32 dirVectorLengthSq;
119119
f32 t;
120120

121-
dirVectorSize = Math3D_Vec3fMagnitudeSq(&line->b);
122-
if (IS_ZERO(dirVectorSize)) {
121+
dirVectorLengthSq = Math3D_Vec3fMagnitudeSq(&line->dir);
122+
if (IS_ZERO(dirVectorLengthSq)) {
123123
osSyncPrintf(VT_COL(YELLOW, BLACK));
124124
// "Math3D_lineVsPosSuisenCross(): No straight line length"
125125
osSyncPrintf("Math3D_lineVsPosSuisenCross():直線の長さがありません\n");
126126
osSyncPrintf("cross = pos を返します。\n"); // "Returns cross = pos."
127127
osSyncPrintf(VT_RST);
128128
Math_Vec3f_Copy(closestPoint, pos);
129+
//! @bug Missing early return
129130
}
130131

131-
t = (((pos->x - line->a.x) * line->b.x) + ((pos->y - line->a.y) * line->b.y) + ((pos->z - line->a.z) * line->b.z)) /
132-
dirVectorSize;
133-
closestPoint->x = (line->b.x * t) + line->a.x;
134-
closestPoint->y = (line->b.y * t) + line->a.y;
135-
closestPoint->z = (line->b.z * t) + line->a.z;
132+
t = (((pos->x - line->point.x) * line->dir.x) + ((pos->y - line->point.y) * line->dir.y) +
133+
((pos->z - line->point.z) * line->dir.z)) /
134+
dirVectorLengthSq;
135+
closestPoint->x = (line->dir.x * t) + line->point.x;
136+
closestPoint->y = (line->dir.y * t) + line->point.y;
137+
closestPoint->z = (line->dir.z * t) + line->point.z;
136138
}
137139

138140
void Math3D_FindPointOnPlaneIntersect(f32 planeAAxis1Norm, f32 planeAAxis2Norm, f32 planeBAxis1Norm,
@@ -195,10 +197,10 @@ s32 Math3D_PlaneVsPlaneNewLine(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeA
195197
*/
196198
s32 Math3D_PlaneVsPlaneVsLineClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC, f32 planeADist, f32 planeBA,
197199
f32 planeBB, f32 planeBC, f32 planeBDist, Vec3f* point, Vec3f* closestPoint) {
198-
static Linef planeIntersect;
200+
static InfiniteLine planeIntersect;
199201

200202
if (!Math3D_PlaneVsPlaneNewLine(planeAA, planeAB, planeAC, planeADist, planeBA, planeBB, planeBC, planeBDist,
201-
(InfiniteLine*)&planeIntersect)) {
203+
&planeIntersect)) {
202204
return false;
203205
}
204206
Math3D_LineClosestToPoint(&planeIntersect, point, closestPoint);

src/code/z_camera.c

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4291,23 +4291,23 @@ s32 Camera_Subj4(Camera* camera) {
42914291
sCameraInterfaceFlags = subj4->interfaceFlags;
42924292
if (camera->animState == 0) {
42934293
spA4 = Camera_GetCamBgDataUnderPlayer(camera, &spAA);
4294-
Camera_Vec3sToVec3f(&anim->unk_00.a, &spA4[1]);
4294+
Camera_Vec3sToVec3f(&anim->unk_00.point, &spA4[1]);
42954295
Camera_Vec3sToVec3f(&sp98, &spA4[spAA - 2]);
42964296

42974297
sp64.r = 10.0f;
42984298
// 0x238C ~ 50 degrees
42994299
sp64.pitch = 0x238C;
4300-
sp64.yaw = Camera_XZAngle(&sp98, &anim->unk_00.a);
4301-
sp88 = OLib_Vec3fDist(&playerPosRot->pos, &anim->unk_00.a);
4300+
sp64.yaw = Camera_XZAngle(&sp98, &anim->unk_00.point);
4301+
sp88 = OLib_Vec3fDist(&playerPosRot->pos, &anim->unk_00.point);
43024302
if (OLib_Vec3fDist(&playerPosRot->pos, &sp98) < sp88) {
4303-
anim->unk_00.b.x = anim->unk_00.a.x - sp98.x;
4304-
anim->unk_00.b.y = anim->unk_00.a.y - sp98.y;
4305-
anim->unk_00.b.z = anim->unk_00.a.z - sp98.z;
4306-
anim->unk_00.a = sp98;
4303+
anim->unk_00.dir.x = anim->unk_00.point.x - sp98.x;
4304+
anim->unk_00.dir.y = anim->unk_00.point.y - sp98.y;
4305+
anim->unk_00.dir.z = anim->unk_00.point.z - sp98.z;
4306+
anim->unk_00.point = sp98;
43074307
} else {
4308-
anim->unk_00.b.x = sp98.x - anim->unk_00.a.x;
4309-
anim->unk_00.b.y = sp98.y - anim->unk_00.a.y;
4310-
anim->unk_00.b.z = sp98.z - anim->unk_00.a.z;
4308+
anim->unk_00.dir.x = sp98.x - anim->unk_00.point.x;
4309+
anim->unk_00.dir.y = sp98.y - anim->unk_00.point.y;
4310+
anim->unk_00.dir.z = sp98.z - anim->unk_00.point.z;
43114311
sp64.yaw = BINANG_ROT180(sp64.yaw);
43124312
}
43134313
anim->unk_30 = sp64.yaw;
@@ -4340,9 +4340,9 @@ s32 Camera_Subj4(Camera* camera) {
43404340

43414341
Actor_GetWorldPosShapeRot(&sp6C, &camera->player->actor);
43424342
Math3D_LineClosestToPoint(&anim->unk_00, &sp6C.pos, eyeNext);
4343-
at->x = eyeNext->x + anim->unk_00.b.x;
4344-
at->y = eyeNext->y + anim->unk_00.b.y;
4345-
at->z = eyeNext->z + anim->unk_00.b.z;
4343+
at->x = eyeNext->x + anim->unk_00.dir.x;
4344+
at->y = eyeNext->y + anim->unk_00.dir.y;
4345+
at->z = eyeNext->z + anim->unk_00.dir.z;
43464346
*eye = *eyeNext;
43474347
sp64.yaw = anim->unk_30;
43484348
sp64.r = 5.0f;
@@ -4792,9 +4792,9 @@ s32 Camera_Unique0(Camera* camera) {
47924792
func_80043B60(camera);
47934793
camera->unk_14C &= ~4;
47944794
sceneCamData = Camera_GetCamBGData(camera);
4795-
Camera_Vec3sToVec3f(&anim->sceneCamPosPlayerLine.a, &BGCAM_POS(sceneCamData));
4795+
Camera_Vec3sToVec3f(&anim->sceneCamPosPlayerLine.point, &BGCAM_POS(sceneCamData));
47964796

4797-
*eye = camera->eyeNext = anim->sceneCamPosPlayerLine.a;
4797+
*eye = camera->eyeNext = anim->sceneCamPosPlayerLine.point;
47984798
sceneCamRot = BGCAM_ROT(sceneCamData);
47994799
fov = BGCAM_FOV(sceneCamData);
48004800
if (fov != -1) {
@@ -4807,7 +4807,7 @@ s32 Camera_Unique0(Camera* camera) {
48074807
atPlayerOffset.r = OLib_Vec3fDist(&playerPosWithOffset, eye);
48084808
atPlayerOffset.yaw = sceneCamRot.y;
48094809
atPlayerOffset.pitch = -sceneCamRot.x;
4810-
OLib_VecSphGeoToVec3f(&anim->sceneCamPosPlayerLine.b, &atPlayerOffset);
4810+
OLib_VecSphGeoToVec3f(&anim->sceneCamPosPlayerLine.dir, &atPlayerOffset);
48114811
Math3D_LineClosestToPoint(&anim->sceneCamPosPlayerLine, &playerPosRot->pos, &camera->at);
48124812
anim->initalPos = playerPosRot->pos;
48134813
camera->animState++;
@@ -5814,12 +5814,14 @@ s32 Camera_Demo5(Camera* camera) {
58145814
f32 sp90;
58155815
VecSph playerTargetGeo;
58165816
VecSph eyePlayerGeo;
5817-
VecSph sp78;
5817+
s16 targetScreenPosX;
5818+
s16 targetScreenPosY;
5819+
s32 pad1;
58185820
PosRot playerhead;
58195821
PosRot targethead;
58205822
Player* player;
58215823
s16 sp4A;
5822-
s32 pad;
5824+
s32 framesDiff;
58235825
s32 temp_v0;
58245826
s16 t;
58255827
s32 pad2;
@@ -5837,7 +5839,7 @@ s32 Camera_Demo5(Camera* camera) {
58375839
Actor_GetFocus(&camera->targetPosRot, camera->target);
58385840
OLib_Vec3fDiffToVecSphGeo(&playerTargetGeo, &camera->targetPosRot.pos, &camera->playerPosRot.pos);
58395841
D_8011D3AC = camera->target->category;
5840-
Actor_GetScreenPos(camera->globalCtx, camera->target, &sp78.yaw, &sp78.pitch);
5842+
Actor_GetScreenPos(camera->globalCtx, camera->target, &targetScreenPosX, &targetScreenPosY);
58415843
eyeTargetDist = OLib_Vec3fDist(&camera->targetPosRot.pos, &camera->eye);
58425844
OLib_Vec3fDiffToVecSphGeo(&eyePlayerGeo, &playerhead.pos, &camera->eyeNext);
58435845
sp4A = eyePlayerGeo.yaw - playerTargetGeo.yaw;
@@ -5869,7 +5871,8 @@ s32 Camera_Demo5(Camera* camera) {
58695871
// distance between player and target is less than 30 units.
58705872
ONEPOINT_CS_INFO(camera)->keyFrames = D_8011D79C;
58715873
ONEPOINT_CS_INFO(camera)->keyFrameCnt = ARRAY_COUNT(D_8011D79C);
5872-
if ((sp78.yaw < 0x15) || (sp78.yaw >= 0x12C) || (sp78.pitch < 0x29) || (sp78.pitch >= 0xC8)) {
5874+
if ((targetScreenPosX < 0x15) || (targetScreenPosX >= 0x12C) || (targetScreenPosY < 0x29) ||
5875+
(targetScreenPosY >= 0xC8)) {
58735876
D_8011D79C[0].actionFlags = 0x41;
58745877
D_8011D79C[0].atTargetInit.y = -30.0f;
58755878
D_8011D79C[0].atTargetInit.x = 0.0f;
@@ -5901,7 +5904,8 @@ s32 Camera_Demo5(Camera* camera) {
59015904
// The distance between the camera's current position and the target is less than 700 units
59025905
// and the angle between the camera's position and the player, and the player to the target
59035906
// is less than ~76.9 degrees
5904-
if (sp78.yaw >= 0x15 && sp78.yaw < 0x12C && sp78.pitch >= 0x29 && sp78.pitch < 0xC8 && eyePlayerGeo.r > 30.0f) {
5907+
if (targetScreenPosX >= 0x15 && targetScreenPosX < 0x12C && targetScreenPosY >= 0x29 &&
5908+
targetScreenPosY < 0xC8 && eyePlayerGeo.r > 30.0f) {
59055909
D_8011D88C[0].timerInit = camera->timer;
59065910
ONEPOINT_CS_INFO(camera)->keyFrames = D_8011D88C;
59075911
ONEPOINT_CS_INFO(camera)->keyFrameCnt = ARRAY_COUNT(D_8011D88C);
@@ -5997,8 +6001,8 @@ s32 Camera_Demo5(Camera* camera) {
59976001
}
59986002
}
59996003

6000-
pad = sDemo5PrevSfxFrame - camera->globalCtx->state.frames;
6001-
if ((pad >= 0x33) || (pad < -0x32)) {
6004+
framesDiff = sDemo5PrevSfxFrame - camera->globalCtx->state.frames;
6005+
if ((framesDiff > 50) || (framesDiff < -50)) {
60026006
func_80078884(camera->data1);
60036007
}
60046008

@@ -6012,11 +6016,11 @@ s32 Camera_Demo5(Camera* camera) {
60126016
} else {
60136017
sp4A = playerhead.rot.y - playerTargetGeo.yaw;
60146018
if (camera->target->category == ACTORCAT_PLAYER) {
6015-
pad = camera->globalCtx->state.frames - sDemo5PrevAction12Frame;
6019+
framesDiff = camera->globalCtx->state.frames - sDemo5PrevAction12Frame;
60166020
if (player->stateFlags1 & PLAYER_STATE1_11) {
60176021
// holding object over head.
60186022
func_8002DF54(camera->globalCtx, camera->target, 8);
6019-
} else if (ABS(pad) > 3000) {
6023+
} else if (ABS(framesDiff) > 3000) {
60206024
func_8002DF54(camera->globalCtx, camera->target, 12);
60216025
} else {
60226026
func_8002DF54(camera->globalCtx, camera->target, 69);

src/code/z_fbdemo_circle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "global.h"
22

33
// unused
4-
Gfx sCircleNullDList[] = {
4+
Gfx sCircleEmptyDList[] = {
55
gsSPEndDisplayList(),
66
};
77

src/code/z_lights.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void Lights_Draw(Lights* lights, GraphicsContext* gfxCtx) {
7676

7777
if (0) {}
7878

79-
i++; // abmient light is total number of lights + 1
79+
i++; // ambient light is total number of lights + 1
8080
gSPLight(POLY_OPA_DISP++, &lights->l.a, i);
8181
gSPLight(POLY_XLU_DISP++, &lights->l.a, i);
8282

src/code/z_scene.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ s32 Scene_ExecuteCommands(GlobalContext* globalCtx, SceneCmd* sceneCmd) {
182182
return 0;
183183
}
184184

185+
// Scene Command 0x00: Spawn List
185186
void func_80098508(GlobalContext* globalCtx, SceneCmd* cmd) {
186187
ActorEntry* linkEntry = globalCtx->linkActorEntry = (ActorEntry*)SEGMENTED_TO_VIRTUAL(cmd->spawnList.segment) +
187188
globalCtx->setupEntranceList[globalCtx->curSpawn].spawn;

0 commit comments

Comments
 (0)