summaryrefslogtreecommitdiff
path: root/src/code
diff options
context:
space:
mode:
authorRobin Allen <r@foon.uk>2022-04-08 23:50:28 +0100
committerGitHub <noreply@github.com>2022-04-09 00:50:28 +0200
commit9984c267d9d7a8ab207e092b9fa9aa87c894f808 (patch)
treeb78d3755af000095a90dd443bb109c1c8e10cef0 /src/code
parentb9b40805f7f63d0a6cb3c33e55ac420710acef70 (diff)
Names for some view things (#1191)
* Names for some view things * Review: ORTHOGRAPHIC → ORTHO * Review: dirty → dirtyFlags * Review: Doc comment style * Review: Define constants in terms of each other * Review: Rename the ApplyToOverlay functions * Update include/z64.h Co-authored-by: fig02 <fig02srl@gmail.com> * Review: Better View_LookAtInternal doc * arg1 → mask * View_LookAtInternal → View_LookAtUnsafe * Review: View_SanityCheckEyePosition → View_ErrorCheckEyePosition * sViewNotInitialized → sLogOnNextViewInit * Remove VIEW_FORCE_ALL * near/far → zNear/zFar Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * lookAt → at Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * near/far → zNear/zFar * View_ApplyPerspective/Ortho: Remove from header instead of commenting * lookAt → at * Add fwd decls * Fix external view->at accesses * Missed these somehow * lookAt → at * Omit "Apply" in comments * dirtyFlags → flags * View_ApplyScissor → View_ApplyShrinkWindow * Update src/code/z_view.c Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com> Co-authored-by: fig02 <fig02srl@gmail.com> Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com>
Diffstat (limited to 'src/code')
-rw-r--r--src/code/speed_meter.c8
-rw-r--r--src/code/z_actor.c2
-rw-r--r--src/code/z_camera.c10
-rw-r--r--src/code/z_kankyo.c16
-rw-r--r--src/code/z_message_PAL.c2
-rw-r--r--src/code/z_onepointdemo.c30
-rw-r--r--src/code/z_parameter.c8
-rw-r--r--src/code/z_play.c10
-rw-r--r--src/code/z_sample.c8
-rw-r--r--src/code/z_view.c147
10 files changed, 136 insertions, 105 deletions
diff --git a/src/code/speed_meter.c b/src/code/speed_meter.c
index 7d768d090..204ac000d 100644
--- a/src/code/speed_meter.c
+++ b/src/code/speed_meter.c
@@ -70,12 +70,12 @@ void SpeedMeter_DrawTimeEntries(SpeedMeter* this, GraphicsContext* gfxCtx) {
}
View_Init(&view, gfxCtx);
- view.flags = 0xA;
+ view.flags = VIEW_VIEWPORT | VIEW_PROJECTION_ORTHO;
SET_FULLSCREEN_VIEWPORT(&view);
gfx = OVERLAY_DISP;
- func_800AB9EC(&view, 0xF, &gfx);
+ View_ApplyTo(&view, VIEW_ALL, &gfx);
gDPPipeSync(gfx++);
gDPSetOtherMode(gfx++,
@@ -126,12 +126,12 @@ void SpeedMeter_DrawAllocEntry(SpeedMeterAllocEntry* this, GraphicsContext* gfxC
OPEN_DISPS(gfxCtx, "../speed_meter.c", 318);
View_Init(&view, gfxCtx);
- view.flags = 0xA;
+ view.flags = VIEW_VIEWPORT | VIEW_PROJECTION_ORTHO;
SET_FULLSCREEN_VIEWPORT(&view);
gfx = OVERLAY_DISP;
- func_800AB9EC(&view, 0xF, &gfx);
+ View_ApplyTo(&view, VIEW_ALL, &gfx);
gDPPipeSync(gfx++);
gDPSetOtherMode(gfx++,
diff --git a/src/code/z_actor.c b/src/code/z_actor.c
index 5e02e65f3..2b4887818 100644
--- a/src/code/z_actor.c
+++ b/src/code/z_actor.c
@@ -1319,7 +1319,7 @@ Gfx* func_8002E830(Vec3f* object, Vec3f* eye, Vec3f* lightDir, GraphicsContext*
eye->x, eye->y, eye->z, object->x, object->y, object->z, lightDir->x, lightDir->y, lightDir->z);
}
- func_800ABE74(correctedEyeX, eye->y, eye->z);
+ View_ErrorCheckEyePosition(correctedEyeX, eye->y, eye->z);
guLookAtHilite(&D_8015BBA8, lookAt, *hilite, correctedEyeX, eye->y, eye->z, object->x, object->y, object->z, 0.0f,
1.0f, 0.0f, lightDir->x, lightDir->y, lightDir->z, lightDir->x, lightDir->y, lightDir->z, 0x10,
0x10);
diff --git a/src/code/z_camera.c b/src/code/z_camera.c
index 48b07f187..975a32ff5 100644
--- a/src/code/z_camera.c
+++ b/src/code/z_camera.c
@@ -5097,9 +5097,9 @@ s32 Camera_Unique9(Camera* camera) {
anim->atTarget = anim->curKeyFrame->atTargetInit;
} else if (atInitFlags == 2) {
if (anim->isNewKeyFrame) {
- anim->atTarget.x = camera->globalCtx->view.lookAt.x + anim->curKeyFrame->atTargetInit.x;
- anim->atTarget.y = camera->globalCtx->view.lookAt.y + anim->curKeyFrame->atTargetInit.y;
- anim->atTarget.z = camera->globalCtx->view.lookAt.z + anim->curKeyFrame->atTargetInit.z;
+ anim->atTarget.x = camera->globalCtx->view.at.x + anim->curKeyFrame->atTargetInit.x;
+ anim->atTarget.y = camera->globalCtx->view.at.y + anim->curKeyFrame->atTargetInit.y;
+ anim->atTarget.z = camera->globalCtx->view.at.z + anim->curKeyFrame->atTargetInit.z;
}
} else if (atInitFlags == 3) {
if (anim->isNewKeyFrame) {
@@ -7473,7 +7473,7 @@ Vec3s Camera_Update(Camera* camera) {
if (gDbgCamEnabled) {
camera->globalCtx->view.fovy = D_8015BD80.fov;
DbCamera_Update(&D_8015BD80, camera);
- func_800AA358(&camera->globalCtx->view, &D_8015BD80.eye, &D_8015BD80.at, &D_8015BD80.unk_1C);
+ View_LookAt(&camera->globalCtx->view, &D_8015BD80.eye, &D_8015BD80.at, &D_8015BD80.unk_1C);
if (R_DBG_CAM_UPDATE) {
osSyncPrintf("camera: debug out\n");
}
@@ -7524,7 +7524,7 @@ Vec3s Camera_Update(Camera* camera) {
View_SetScale(&camera->globalCtx->view, 1.0f);
}
camera->globalCtx->view.fovy = viewFov;
- func_800AA358(&camera->globalCtx->view, &viewEye, &viewAt, &viewUp);
+ View_LookAt(&camera->globalCtx->view, &viewEye, &viewAt, &viewUp);
camera->camDir.x = eyeAtAngle.pitch;
camera->camDir.y = eyeAtAngle.yaw;
camera->camDir.z = 0;
diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c
index 62dba8d28..5bc7a99a1 100644
--- a/src/code/z_kankyo.c
+++ b/src/code/z_kankyo.c
@@ -1408,9 +1408,9 @@ void Environment_DrawLensFlare(GlobalContext* globalCtx, EnvironmentContext* env
dist = Math3D_Vec3f_DistXYZ(&pos, &view->eye) / 12.0f;
// compute a unit vector in the look direction
- tempX = view->lookAt.x - view->eye.x;
- tempY = view->lookAt.y - view->eye.y;
- tempZ = view->lookAt.z - view->eye.z;
+ tempX = view->at.x - view->eye.x;
+ tempY = view->at.y - view->eye.y;
+ tempZ = view->at.z - view->eye.z;
length = sqrtf(SQ(tempX) + SQ(tempY) + SQ(tempZ));
@@ -1584,9 +1584,9 @@ void Environment_DrawRain(GlobalContext* globalCtx, View* view, GraphicsContext*
if (!(globalCtx->cameraPtrs[0]->unk_14C & 0x100) && (globalCtx->envCtx.unk_EE[2] == 0)) {
OPEN_DISPS(gfxCtx, "../z_kankyo.c", 2799);
- vec.x = view->lookAt.x - view->eye.x;
- vec.y = view->lookAt.y - view->eye.y;
- vec.z = view->lookAt.z - view->eye.z;
+ vec.x = view->at.x - view->eye.x;
+ vec.y = view->at.y - view->eye.y;
+ vec.z = view->at.z - view->eye.z;
length = sqrtf(SQXYZ(vec));
@@ -1859,8 +1859,8 @@ void Environment_DrawLightning(GlobalContext* globalCtx, s32 unused) {
for (i = 0; i < ARRAY_COUNT(sLightningBolts); i++) {
switch (sLightningBolts[i].state) {
case LIGHTNING_BOLT_START:
- dx = globalCtx->view.lookAt.x - globalCtx->view.eye.x;
- dz = globalCtx->view.lookAt.z - globalCtx->view.eye.z;
+ dx = globalCtx->view.at.x - globalCtx->view.eye.x;
+ dz = globalCtx->view.at.z - globalCtx->view.eye.z;
x = dx / sqrtf(SQ(dx) + SQ(dz));
z = dz / sqrtf(SQ(dx) + SQ(dz));
diff --git a/src/code/z_message_PAL.c b/src/code/z_message_PAL.c
index f07145ac8..7d3fe7325 100644
--- a/src/code/z_message_PAL.c
+++ b/src/code/z_message_PAL.c
@@ -1936,7 +1936,7 @@ void Message_DrawTextBox(GlobalContext* globalCtx, Gfx** p) {
void Message_SetView(View* view) {
SET_FULLSCREEN_VIEWPORT(view);
- func_800AB2C4(view);
+ View_ApplyOrthoToOverlay(view);
}
/**
diff --git a/src/code/z_onepointdemo.c b/src/code/z_onepointdemo.c
index 056c47cd0..cb399782e 100644
--- a/src/code/z_onepointdemo.c
+++ b/src/code/z_onepointdemo.c
@@ -75,7 +75,7 @@ s32 OnePointCutscene_SetInfo(GlobalContext* globalCtx, s16 camIdx, s16 csId, Act
if (timer < 20) {
timer = 20;
}
- D_801208EC[0].atTargetInit = globalCtx->view.lookAt;
+ D_801208EC[0].atTargetInit = globalCtx->view.at;
D_801208EC[0].eyeTargetInit = globalCtx->view.eye;
D_801208EC[0].fovTargetInit = globalCtx->view.fovy;
D_801208EC[1].atTargetInit = mainCam->at;
@@ -91,7 +91,7 @@ s32 OnePointCutscene_SetInfo(GlobalContext* globalCtx, s16 camIdx, s16 csId, Act
func_800C0808(globalCtx, camIdx, player, CAM_SET_CS_C);
break;
case 1030:
- D_80120964[0].atTargetInit = globalCtx->view.lookAt;
+ D_80120964[0].atTargetInit = globalCtx->view.at;
D_80120964[0].eyeTargetInit = globalCtx->view.eye;
D_80120964[0].fovTargetInit = globalCtx->view.fovy;
OLib_Vec3fDiffToVecSphGeo(&spD0, &mainCam->at, &mainCam->eye);
@@ -104,7 +104,7 @@ s32 OnePointCutscene_SetInfo(GlobalContext* globalCtx, s16 camIdx, s16 csId, Act
func_800C0808(globalCtx, camIdx, player, CAM_SET_CS_C);
break;
case 5000:
- D_801209B4[0].atTargetInit = D_801209B4[1].atTargetInit = globalCtx->view.lookAt;
+ D_801209B4[0].atTargetInit = D_801209B4[1].atTargetInit = globalCtx->view.at;
D_801209B4[0].eyeTargetInit = globalCtx->view.eye;
D_801209B4[0].fovTargetInit = D_801209B4[2].fovTargetInit = globalCtx->view.fovy;
OLib_Vec3fDiffToVecSphGeo(&spD0, &actor->focus.pos, &mainCam->at);
@@ -232,9 +232,9 @@ s32 OnePointCutscene_SetInfo(GlobalContext* globalCtx, s16 camIdx, s16 csId, Act
if ((sp82 > 0) && (sp82 < 320) && (sp7E > 0) && (sp7E < 240) && (sp80 > 0) && (sp80 < 320) && (sp7C > 0) &&
(sp7C < 240) &&
!OnePointCutscene_BgCheckLineTest(&globalCtx->colCtx, &actor->focus.pos, &player->actor.focus.pos)) {
- D_80121184[0].atTargetInit.x = (globalCtx->view.lookAt.x + actor->focus.pos.x) * 0.5f;
- D_80121184[0].atTargetInit.y = (globalCtx->view.lookAt.y + actor->focus.pos.y) * 0.5f;
- D_80121184[0].atTargetInit.z = (globalCtx->view.lookAt.z + actor->focus.pos.z) * 0.5f;
+ D_80121184[0].atTargetInit.x = (globalCtx->view.at.x + actor->focus.pos.x) * 0.5f;
+ D_80121184[0].atTargetInit.y = (globalCtx->view.at.y + actor->focus.pos.y) * 0.5f;
+ D_80121184[0].atTargetInit.z = (globalCtx->view.at.z + actor->focus.pos.z) * 0.5f;
D_80121184[0].eyeTargetInit = globalCtx->view.eye;
D_80121184[0].eyeTargetInit.y = player->actor.focus.pos.y + 20.0f;
D_80121184[0].fovTargetInit = mainCam->fov * 0.75f;
@@ -490,7 +490,7 @@ s32 OnePointCutscene_SetInfo(GlobalContext* globalCtx, s16 camIdx, s16 csId, Act
csCam->unk_14C |= 2;
break;
case 3140:
- D_80121C24[0].atTargetInit = globalCtx->view.lookAt;
+ D_80121C24[0].atTargetInit = globalCtx->view.at;
D_80121C24[0].eyeTargetInit = globalCtx->view.eye;
D_80121C24[0].fovTargetInit = globalCtx->view.fovy;
@@ -674,7 +674,7 @@ s32 OnePointCutscene_SetInfo(GlobalContext* globalCtx, s16 camIdx, s16 csId, Act
Quake_SetCountdown(i, timer);
break;
case 3290:
- D_80121F1C[0].atTargetInit = globalCtx->view.lookAt;
+ D_80121F1C[0].atTargetInit = globalCtx->view.at;
D_80121F1C[0].eyeTargetInit = globalCtx->view.eye;
D_80121F1C[0].fovTargetInit = globalCtx->view.fovy;
Actor_GetFocus(&spA0, actor);
@@ -691,7 +691,7 @@ s32 OnePointCutscene_SetInfo(GlobalContext* globalCtx, s16 camIdx, s16 csId, Act
Quake_SetCountdown(i, 5);
break;
case 3340:
- D_80121FBC[0].atTargetInit = globalCtx->view.lookAt;
+ D_80121FBC[0].atTargetInit = globalCtx->view.at;
D_80121FBC[0].eyeTargetInit = globalCtx->view.eye;
D_80121FBC[0].fovTargetInit = globalCtx->view.fovy;
@@ -714,7 +714,7 @@ s32 OnePointCutscene_SetInfo(GlobalContext* globalCtx, s16 camIdx, s16 csId, Act
func_800C0808(globalCtx, camIdx, player, CAM_SET_CS_C);
break;
case 3350:
- D_801220D4[0].atTargetInit = globalCtx->view.lookAt;
+ D_801220D4[0].atTargetInit = globalCtx->view.at;
D_801220D4[0].eyeTargetInit = globalCtx->view.eye;
D_801220D4[0].fovTargetInit = globalCtx->view.fovy;
if (actor->world.pos.x > 0.0f) {
@@ -996,7 +996,7 @@ s32 OnePointCutscene_SetInfo(GlobalContext* globalCtx, s16 camIdx, s16 csId, Act
}
break;
case 1000:
- D_801232A4[0].atTargetInit = globalCtx->view.lookAt;
+ D_801232A4[0].atTargetInit = globalCtx->view.at;
D_801232A4[0].eyeTargetInit = globalCtx->view.eye;
D_801232A4[0].fovTargetInit = globalCtx->view.fovy;
@@ -1057,7 +1057,7 @@ s32 OnePointCutscene_SetInfo(GlobalContext* globalCtx, s16 camIdx, s16 csId, Act
func_800C0808(globalCtx, camIdx, player, CAM_SET_CS_C);
break;
case 9703:
- D_80123894[0].atTargetInit = globalCtx->view.lookAt;
+ D_80123894[0].atTargetInit = globalCtx->view.at;
D_80123894[0].eyeTargetInit = globalCtx->view.eye;
D_80123894[0].fovTargetInit = globalCtx->view.fovy;
if (LINK_IS_ADULT) {
@@ -1071,7 +1071,7 @@ s32 OnePointCutscene_SetInfo(GlobalContext* globalCtx, s16 camIdx, s16 csId, Act
func_800C0808(globalCtx, camIdx, player, CAM_SET_CS_C);
break;
case 9704:
- D_8012390C[0].atTargetInit = globalCtx->view.lookAt;
+ D_8012390C[0].atTargetInit = globalCtx->view.at;
D_8012390C[0].eyeTargetInit = globalCtx->view.eye;
D_8012390C[0].fovTargetInit = globalCtx->view.fovy;
@@ -1081,7 +1081,7 @@ s32 OnePointCutscene_SetInfo(GlobalContext* globalCtx, s16 camIdx, s16 csId, Act
func_800C0808(globalCtx, camIdx, player, CAM_SET_CS_C);
break;
case 9705:
- D_8012395C[0].atTargetInit = globalCtx->view.lookAt;
+ D_8012395C[0].atTargetInit = globalCtx->view.at;
D_8012395C[0].eyeTargetInit = globalCtx->view.eye;
D_8012395C[0].fovTargetInit = globalCtx->view.fovy;
@@ -1178,7 +1178,7 @@ s16 OnePointCutscene_Init(GlobalContext* globalCtx, s16 csId, s16 timer, Actor*
csCam->timer = timer;
csCam->target = actor;
- csCam->at = globalCtx->view.lookAt;
+ csCam->at = globalCtx->view.at;
csCam->eye = globalCtx->view.eye;
csCam->fov = globalCtx->view.fovy;
diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c
index 18d77312a..f8e7766da 100644
--- a/src/code/z_parameter.c
+++ b/src/code/z_parameter.c
@@ -2975,7 +2975,7 @@ void func_8008A8B8(GlobalContext* globalCtx, s32 topY, s32 bottomY, s32 leftX, s
up.x = up.z = 0.0f;
up.y = 1.0f;
- func_800AA358(&interfaceCtx->view, &eye, &lookAt, &up);
+ View_LookAt(&interfaceCtx->view, &eye, &lookAt, &up);
interfaceCtx->viewport.topY = topY;
interfaceCtx->viewport.bottomY = bottomY;
@@ -2983,13 +2983,13 @@ void func_8008A8B8(GlobalContext* globalCtx, s32 topY, s32 bottomY, s32 leftX, s
interfaceCtx->viewport.rightX = rightX;
View_SetViewport(&interfaceCtx->view, &interfaceCtx->viewport);
- func_800AA460(&interfaceCtx->view, 60.0f, 10.0f, 60.0f);
- func_800AB560(&interfaceCtx->view);
+ View_SetPerspective(&interfaceCtx->view, 60.0f, 10.0f, 60.0f);
+ View_ApplyPerspectiveToOverlay(&interfaceCtx->view);
}
void func_8008A994(InterfaceContext* interfaceCtx) {
SET_FULLSCREEN_VIEWPORT(&interfaceCtx->view);
- func_800AB2C4(&interfaceCtx->view);
+ View_ApplyOrthoToOverlay(&interfaceCtx->view);
}
void Interface_Draw(GlobalContext* globalCtx) {
diff --git a/src/code/z_play.c b/src/code/z_play.c
index daacbe019..7a3fed57c 100644
--- a/src/code/z_play.c
+++ b/src/code/z_play.c
@@ -1086,8 +1086,8 @@ void Gameplay_Draw(GlobalContext* globalCtx) {
POLY_OPA_DISP = Gameplay_SetFog(globalCtx, POLY_OPA_DISP);
POLY_XLU_DISP = Gameplay_SetFog(globalCtx, POLY_XLU_DISP);
- func_800AA460(&globalCtx->view, globalCtx->view.fovy, globalCtx->view.zNear, globalCtx->lightCtx.fogFar);
- func_800AAA50(&globalCtx->view, 15);
+ View_SetPerspective(&globalCtx->view, globalCtx->view.fovy, globalCtx->view.zNear, globalCtx->lightCtx.fogFar);
+ View_Apply(&globalCtx->view, VIEW_ALL);
// The billboard matrix temporarily stores the viewing matrix
Matrix_MtxToMtxF(&globalCtx->view.viewing, &globalCtx->billboardMtxF);
@@ -1118,11 +1118,11 @@ void Gameplay_Draw(GlobalContext* globalCtx) {
View view;
View_Init(&view, gfxCtx);
- view.flags = 2 | 8;
+ view.flags = VIEW_VIEWPORT | VIEW_PROJECTION_ORTHO;
SET_FULLSCREEN_VIEWPORT(&view);
- func_800AB9EC(&view, 15, &gfxP);
+ View_ApplyTo(&view, VIEW_ALL, &gfxP);
globalCtx->transitionCtx.draw(&globalCtx->transitionCtx.data, &gfxP);
}
@@ -1305,7 +1305,7 @@ void Gameplay_Draw(GlobalContext* globalCtx) {
if (globalCtx->view.unk_124 != 0) {
Camera_Update(GET_ACTIVE_CAM(globalCtx));
- func_800AB944(&globalCtx->view);
+ View_UpdateViewingMatrix(&globalCtx->view);
globalCtx->view.unk_124 = 0;
if (globalCtx->skyboxId && (globalCtx->skyboxId != SKYBOX_UNSET_1D) && !globalCtx->envCtx.skyboxDisabled) {
SkyboxDraw_UpdateMatrix(&globalCtx->skyboxCtx, globalCtx->view.eye.x, globalCtx->view.eye.y,
diff --git a/src/code/z_sample.c b/src/code/z_sample.c
index 6e999787c..79f396885 100644
--- a/src/code/z_sample.c
+++ b/src/code/z_sample.c
@@ -18,8 +18,8 @@ void Sample_Draw(SampleContext* this) {
func_80095248(gfxCtx, 0, 0, 0);
- view->flags = 1 | 2 | 4;
- func_800AAA50(view, 15);
+ view->flags = VIEW_VIEWING | VIEW_VIEWPORT | VIEW_PROJECTION_PERSPECTIVE;
+ View_Apply(view, VIEW_ALL);
{
Mtx* mtx = Graph_Alloc(gfxCtx, sizeof(Mtx));
@@ -55,7 +55,7 @@ void Sample_SetupView(SampleContext* this) {
View_Init(view, gfxCtx);
SET_FULLSCREEN_VIEWPORT(view);
- func_800AA460(view, 60.0f, 10.0f, 12800.0f);
+ View_SetPerspective(view, 60.0f, 10.0f, 12800.0f);
{
Vec3f eye;
@@ -72,7 +72,7 @@ void Sample_SetupView(SampleContext* this) {
up.z = 0.0f;
up.y = 1.0f;
- func_800AA358(view, &eye, &lookAt, &up);
+ View_LookAt(view, &eye, &lookAt, &up);
}
}
diff --git a/src/code/z_view.c b/src/code/z_view.c
index 340d15aea..eb2b04c19 100644
--- a/src/code/z_view.c
+++ b/src/code/z_view.c
@@ -1,7 +1,10 @@
#include "global.h"
#include "vt.h"
-vu32 D_8012ABF0 = true;
+vu32 sLogOnNextViewInit = true;
+
+s32 View_ApplyPerspective(View*);
+s32 View_ApplyOrtho(View*);
void View_ViewportToVp(Vp* dest, Viewport* src) {
s32 width = src->rightX - src->leftX;
@@ -45,42 +48,46 @@ void View_Init(View* view, GraphicsContext* gfxCtx) {
view->fovy = 60.0f;
view->zNear = 10.0f;
view->zFar = 12800.0f;
- view->lookAt.x = 0.0f;
+ view->at.x = 0.0f;
view->up.x = 0.0f;
view->up.y = 1.0f;
view->up.z = 0.0f;
view->eye.z = -1.0f;
- if (D_8012ABF0) {
- if (D_8012ABF0 == 0) {}
+ if (sLogOnNextViewInit) {
+ if (sLogOnNextViewInit == false) {}
osSyncPrintf("\nview: initialize ---\n");
- D_8012ABF0 = false;
+ sLogOnNextViewInit = false;
}
view->unk_124 = 0;
- view->flags = 1 | 2 | 4;
+ view->flags = VIEW_VIEWING | VIEW_VIEWPORT | VIEW_PROJECTION_PERSPECTIVE;
View_InitDistortion(view);
}
-void func_800AA358(View* view, Vec3f* eye, Vec3f* lookAt, Vec3f* up) {
- if (eye->x == lookAt->x && eye->z == lookAt->z) {
+void View_LookAt(View* view, Vec3f* eye, Vec3f* at, Vec3f* up) {
+ if (eye->x == at->x && eye->z == at->z) {
eye->x += 0.1f;
}
view->eye = *eye;
- view->lookAt = *lookAt;
+ view->at = *at;
view->up = *up;
- view->flags |= 1;
+ view->flags |= VIEW_VIEWING;
}
-void func_800AA3F0(View* view, Vec3f* eye, Vec3f* lookAt, Vec3f* up) {
+/*
+ * Unused. View_LookAt is always used instead. This version is similar but
+ * is missing the input sanitization and the update to the flags.
+ */
+void View_LookAtUnsafe(View* view, Vec3f* eye, Vec3f* at, Vec3f* up) {
view->eye = *eye;
- view->lookAt = *lookAt;
+ view->at = *at;
view->up = *up;
}
void View_SetScale(View* view, f32 scale) {
- view->flags |= 4;
+ view->flags |= VIEW_PROJECTION_PERSPECTIVE;
view->scale = scale;
}
@@ -88,43 +95,47 @@ void View_GetScale(View* view, f32* scale) {
*scale = view->scale;
}
-void func_800AA460(View* view, f32 fovy, f32 near, f32 far) {
+void View_SetPerspective(View* view, f32 fovy, f32 zNear, f32 zFar) {
view->fovy = fovy;
- view->zNear = near;
- view->zFar = far;
- view->flags |= 4;
+ view->zNear = zNear;
+ view->zFar = zFar;
+ view->flags |= VIEW_PROJECTION_PERSPECTIVE;
}
-void func_800AA48C(View* view, f32* fovy, f32* near, f32* far) {
+void View_GetPerspective(View* view, f32* fovy, f32* zNear, f32* zFar) {
*fovy = view->fovy;
- *near = view->zNear;
- *far = view->zFar;
+ *zNear = view->zNear;
+ *zFar = view->zFar;
}
-void func_800AA4A8(View* view, f32 fovy, f32 near, f32 far) {
+void View_SetOrtho(View* view, f32 fovy, f32 zNear, f32 zFar) {
view->fovy = fovy;
- view->zNear = near;
- view->zFar = far;
- view->flags |= 8;
+ view->zNear = zNear;
+ view->zFar = zFar;
+ view->flags |= VIEW_PROJECTION_ORTHO;
view->scale = 1.0f;
}
-void func_800AA4E0(View* view, f32* fovy, f32* near, f32* far) {
+/*
+ * Identical to View_GetPerspective, and never called.
+ * Named as it seems to fit the "set, get" pattern.
+ */
+void View_GetOrtho(View* view, f32* fovy, f32* zNear, f32* zFar) {
*fovy = view->fovy;
- *near = view->zNear;
- *far = view->zFar;
+ *zNear = view->zNear;
+ *zFar = view->zFar;
}
void View_SetViewport(View* view, Viewport* viewport) {
view->viewport = *viewport;
- view->flags |= 2;
+ view->flags |= VIEW_VIEWPORT;
}
void View_GetViewport(View* view, Viewport* viewport) {
*viewport = view->viewport;
}
-void func_800AA550(View* view) {
+void View_ApplyShrinkWindow(View* view) {
s32 varY;
s32 varX;
s32 pad;
@@ -255,17 +266,20 @@ s32 View_StepDistortion(View* view, Mtx* projectionMtx) {
return true;
}
-void func_800AAA50(View* view, s32 arg1) {
- arg1 = (view->flags & arg1) | (arg1 >> 4);
+/**
+ * Apply view to POLY_OPA_DISP, POLY_XLU_DISP (and OVERLAY_DISP if ortho)
+ */
+void View_Apply(View* view, s32 mask) {
+ mask = (view->flags & mask) | (mask >> 4);
- if (arg1 & 8) {
- func_800AB0A8(view);
+ if (mask & VIEW_PROJECTION_ORTHO) {
+ View_ApplyOrtho(view);
} else {
- func_800AAA9C(view);
+ View_ApplyPerspective(view);
}
}
-s32 func_800AAA9C(View* view) {
+s32 View_ApplyPerspective(View* view) {
f32 aspect;
s32 width;
s32 height;
@@ -276,16 +290,18 @@ s32 func_800AAA9C(View* view) {
OPEN_DISPS(gfxCtx, "../z_view.c", 596);
+ // Viewport
vp = Graph_Alloc(gfxCtx, sizeof(Vp));
LogUtils_CheckNullPointer("vp", vp, "../z_view.c", 601);
View_ViewportToVp(vp, &view->viewport);
view->vp = *vp;
- func_800AA550(view);
+ View_ApplyShrinkWindow(view);
gSPViewport(POLY_OPA_DISP++, vp);
gSPViewport(POLY_XLU_DISP++, vp);
+ // Perspective projection
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 616);
view->projectionPtr = projection;
@@ -332,22 +348,24 @@ s32 func_800AAA9C(View* view) {
gSPPerspNormalize(POLY_XLU_DISP++, view->normal);
gSPMatrix(POLY_XLU_DISP++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
+ // View matrix (look-at)
viewing = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("viewing", viewing, "../z_view.c", 667);
view->viewingPtr = viewing;
- if (view->eye.x == view->lookAt.x && view->eye.y == view->lookAt.y && view->eye.z == view->lookAt.z) {
+ if (view->eye.x == view->at.x && view->eye.y == view->at.y && view->eye.z == view->at.z) {
view->eye.x += 1.0f;
view->eye.y += 1.0f;
view->eye.z += 1.0f;
}
- func_800ABE74(view->eye.x, view->eye.y, view->eye.z);
- guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->lookAt.x, view->lookAt.y, view->lookAt.z, view->up.x,
+ View_ErrorCheckEyePosition(view->eye.x, view->eye.y, view->eye.z);
+ guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->at.x, view->at.y, view->at.z, view->up.x,
view->up.y, view->up.z);
view->viewing = *viewing;
+ // Debug print view matrix
if (QREG(88) & 2) {
s32 i;
MtxF mf;
@@ -368,7 +386,7 @@ s32 func_800AAA9C(View* view) {
return 1;
}
-s32 func_800AB0A8(View* view) {
+s32 View_ApplyOrtho(View* view) {
Vp* vp;
Mtx* projection;
GraphicsContext* gfxCtx = view->gfxCtx;
@@ -380,7 +398,7 @@ s32 func_800AB0A8(View* view) {
View_ViewportToVp(vp, &view->viewport);
view->vp = *vp;
- func_800AA550(view);
+ View_ApplyShrinkWindow(view);
gSPViewport(POLY_OPA_DISP++, vp);
gSPViewport(POLY_XLU_DISP++, vp);
@@ -403,7 +421,10 @@ s32 func_800AB0A8(View* view) {
return 1;
}
-s32 func_800AB2C4(View* view) {
+/**
+ * Apply scissor, viewport and projection (ortho) to OVERLAY_DISP.
+ */
+s32 View_ApplyOrthoToOverlay(View* view) {
Vp* vp;
Mtx* projection;
GraphicsContext* gfxCtx;
@@ -438,7 +459,10 @@ s32 func_800AB2C4(View* view) {
return 1;
}
-s32 func_800AB560(View* view) {
+/**
+ * Apply scissor, viewport, view and projection (perspective) to OVERLAY_DISP.
+ */
+s32 View_ApplyPerspectiveToOverlay(View* view) {
s32 pad[2];
f32 aspect;
s32 width;
@@ -479,14 +503,15 @@ s32 func_800AB560(View* view) {
LogUtils_CheckNullPointer("viewing", viewing, "../z_view.c", 848);
view->viewingPtr = viewing;
- if (view->eye.x == view->lookAt.x && view->eye.y == view->lookAt.y && view->eye.z == view->lookAt.z) {
+ // This check avoids a divide-by-zero in guLookAt if eye == at
+ if (view->eye.x == view->at.x && view->eye.y == view->at.y && view->eye.z == view->at.z) {
view->eye.x += 1.0f;
view->eye.y += 1.0f;
view->eye.z += 1.0f;
}
- func_800ABE74(view->eye.x, view->eye.y, view->eye.z);
- guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->lookAt.x, view->lookAt.y, view->lookAt.z, view->up.x,
+ View_ErrorCheckEyePosition(view->eye.x, view->eye.y, view->eye.z);
+ guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->at.x, view->at.y, view->at.z, view->up.x,
view->up.y, view->up.z);
view->viewing = *viewing;
@@ -498,11 +523,14 @@ s32 func_800AB560(View* view) {
return 1;
}
-s32 func_800AB944(View* view) {
+/**
+ * Just updates view's view matrix from its eye/at/up vectors. Opens disps but doesn't use them.
+ */
+s32 View_UpdateViewingMatrix(View* view) {
OPEN_DISPS(view->gfxCtx, "../z_view.c", 878);
- func_800ABE74(view->eye.x, view->eye.y, view->eye.z);
- guLookAt(view->viewingPtr, view->eye.x, view->eye.y, view->eye.z, view->lookAt.x, view->lookAt.y, view->lookAt.z,
+ View_ErrorCheckEyePosition(view->eye.x, view->eye.y, view->eye.z);
+ guLookAt(view->viewingPtr, view->eye.x, view->eye.y, view->eye.z, view->at.x, view->at.y, view->at.z,
view->up.x, view->up.y, view->up.z);
CLOSE_DISPS(view->gfxCtx, "../z_view.c", 886);
@@ -510,7 +538,7 @@ s32 func_800AB944(View* view) {
return 1;
}
-s32 func_800AB9EC(View* view, s32 arg1, Gfx** gfxp) {
+s32 View_ApplyTo(View* view, s32 mask, Gfx** gfxp) {
Gfx* gfx = *gfxp;
GraphicsContext* gfxCtx = view->gfxCtx;
s32 width;
@@ -519,9 +547,9 @@ s32 func_800AB9EC(View* view, s32 arg1, Gfx** gfxp) {
Mtx* projection;
Mtx* viewing;
- arg1 = (view->flags & arg1) | (arg1 >> 4);
+ mask = (view->flags & mask) | (mask >> 4);
- if (arg1 & 2) {
+ if (mask & VIEW_VIEWPORT) {
vp = Graph_Alloc(gfxCtx, sizeof(Vp));
LogUtils_CheckNullPointer("vp", vp, "../z_view.c", 910);
View_ViewportToVp(vp, &view->viewport);
@@ -534,7 +562,7 @@ s32 func_800AB9EC(View* view, s32 arg1, Gfx** gfxp) {
gSPViewport(gfx++, vp);
}
- if (arg1 & 8) {
+ if (mask & VIEW_PROJECTION_ORTHO) {
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 921);
view->projectionPtr = projection;
@@ -545,7 +573,7 @@ s32 func_800AB9EC(View* view, s32 arg1, Gfx** gfxp) {
view->projection = *projection;
gSPMatrix(gfx++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
- } else if (arg1 & 6) {
+ } else if (mask & (VIEW_PROJECTION_PERSPECTIVE | VIEW_VIEWPORT)) {
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 932);
view->projectionPtr = projection;
@@ -562,13 +590,13 @@ s32 func_800AB9EC(View* view, s32 arg1, Gfx** gfxp) {
gSPMatrix(gfx++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
}
- if (arg1 & 1) {
+ if (mask & VIEW_VIEWING) {
viewing = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("viewing", viewing, "../z_view.c", 948);
view->viewingPtr = viewing;
- func_800ABE74(view->eye.x, view->eye.y, view->eye.z);
- guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->lookAt.x, view->lookAt.y, view->lookAt.z,
+ View_ErrorCheckEyePosition(view->eye.x, view->eye.y, view->eye.z);
+ guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->at.x, view->at.y, view->at.z,
view->up.x, view->up.y, view->up.z);
view->viewing = *viewing;
@@ -582,7 +610,10 @@ s32 func_800AB9EC(View* view, s32 arg1, Gfx** gfxp) {
return 1;
}
-s32 func_800ABE74(f32 eyeX, f32 eyeY, f32 eyeZ) {
+/**
+ * Logs an error and returns nonzero if camera is too far from the origin.
+ */
+s32 View_ErrorCheckEyePosition(f32 eyeX, f32 eyeY, f32 eyeZ) {
s32 error = 0;
if (SQ(eyeX) + SQ(eyeY) + SQ(eyeZ) > SQ(32767.0f)) {