1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-07-14 11:54:39 +00:00

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>
This commit is contained in:
Robin Allen 2022-04-08 23:50:28 +01:00 committed by GitHub
parent b9b40805f7
commit 9984c267d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 210 additions and 170 deletions

View file

@ -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)) {