2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
|
|
|
#include "vt.h"
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-10-03 15:22:44 +00:00
|
|
|
vu32 D_8012ABF0 = true;
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
void View_ViewportToVp(Vp* dest, Viewport* src) {
|
|
|
|
s32 width = src->rightX - src->leftX;
|
|
|
|
s32 height = src->bottomY - src->topY;
|
|
|
|
|
|
|
|
dest->vp.vscale[0] = width * 2;
|
|
|
|
dest->vp.vscale[1] = height * 2;
|
|
|
|
dest->vp.vscale[2] = 0x01FF;
|
|
|
|
dest->vp.vscale[3] = 0;
|
|
|
|
dest->vp.vtrans[0] = ((src->leftX * 2) + width) * 2;
|
|
|
|
dest->vp.vtrans[1] = ((src->topY * 2) + height) * 2;
|
|
|
|
dest->vp.vtrans[2] = 0x01FF;
|
|
|
|
dest->vp.vtrans[3] = 0;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
View* View_New(GraphicsContext* gfxCtx) {
|
2020-04-05 01:50:46 +00:00
|
|
|
View* view = SystemArena_MallocDebug(sizeof(View), "../z_view.c", 285);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-04-05 01:50:46 +00:00
|
|
|
if (view != NULL) {
|
2020-04-16 21:36:12 +00:00
|
|
|
func_80106860(view, 0, sizeof(View)); // memset
|
|
|
|
View_Init(view, gfxCtx);
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-04-05 01:50:46 +00:00
|
|
|
return view;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
void View_Free(View* view) {
|
2020-04-04 17:17:56 +00:00
|
|
|
SystemArena_FreeDebug(view, "../z_view.c", 297);
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
void View_Init(View* view, GraphicsContext* gfxCtx) {
|
2020-04-04 17:17:56 +00:00
|
|
|
view->gfxCtx = gfxCtx;
|
|
|
|
view->viewport.topY = 0;
|
2020-04-16 21:36:12 +00:00
|
|
|
view->viewport.bottomY = SCREEN_HEIGHT;
|
2020-04-04 17:17:56 +00:00
|
|
|
view->viewport.leftX = 0;
|
2020-04-16 21:36:12 +00:00
|
|
|
view->viewport.rightX = SCREEN_WIDTH;
|
|
|
|
view->magic = 0x56494557; // "VIEW"
|
2020-04-04 17:17:56 +00:00
|
|
|
view->eye.x = 0.0f;
|
|
|
|
view->eye.y = 0.0f;
|
2020-04-16 21:36:12 +00:00
|
|
|
view->scale = 1.0f;
|
|
|
|
view->fovy = 60.0f;
|
2020-04-19 01:40:27 +00:00
|
|
|
view->zNear = 10.0f;
|
|
|
|
view->zFar = 12800.0f;
|
2020-06-25 01:20:31 +00:00
|
|
|
view->lookAt.x = 0.0f;
|
|
|
|
view->up.x = 0.0f;
|
|
|
|
view->up.y = 1.0f;
|
|
|
|
view->up.z = 0.0f;
|
2020-04-04 17:17:56 +00:00
|
|
|
view->eye.z = -1.0f;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
if (D_8012ABF0) {
|
2021-02-14 00:49:40 +00:00
|
|
|
if (D_8012ABF0 == 0) {}
|
2020-04-16 21:36:12 +00:00
|
|
|
osSyncPrintf("\nview: initialize ---\n");
|
|
|
|
D_8012ABF0 = false;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
view->unk_124 = 0;
|
2020-04-16 21:36:12 +00:00
|
|
|
view->flags = 1 | 2 | 4;
|
2020-04-04 17:17:56 +00:00
|
|
|
func_800AA7B8(view);
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-06-25 01:20:31 +00:00
|
|
|
void func_800AA358(View* view, Vec3f* eye, Vec3f* lookAt, Vec3f* up) {
|
|
|
|
if (eye->x == lookAt->x && eye->z == lookAt->z) {
|
2020-04-16 21:36:12 +00:00
|
|
|
eye->x += 0.1f;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
view->eye = *eye;
|
2020-06-25 01:20:31 +00:00
|
|
|
view->lookAt = *lookAt;
|
|
|
|
view->up = *up;
|
2020-04-16 21:36:12 +00:00
|
|
|
view->flags |= 1;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-06-25 01:20:31 +00:00
|
|
|
void func_800AA3F0(View* view, Vec3f* eye, Vec3f* lookAt, Vec3f* up) {
|
2020-04-16 21:36:12 +00:00
|
|
|
view->eye = *eye;
|
2020-06-25 01:20:31 +00:00
|
|
|
view->lookAt = *lookAt;
|
|
|
|
view->up = *up;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
void View_SetScale(View* view, f32 scale) {
|
|
|
|
view->flags |= 4;
|
|
|
|
view->scale = scale;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
void View_GetScale(View* view, f32* scale) {
|
|
|
|
*scale = view->scale;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
void func_800AA460(View* view, f32 fovy, f32 near, f32 far) {
|
|
|
|
view->fovy = fovy;
|
2020-04-19 01:40:27 +00:00
|
|
|
view->zNear = near;
|
|
|
|
view->zFar = far;
|
2020-04-16 21:36:12 +00:00
|
|
|
view->flags |= 4;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
void func_800AA48C(View* view, f32* fovy, f32* near, f32* far) {
|
|
|
|
*fovy = view->fovy;
|
2020-04-19 01:40:27 +00:00
|
|
|
*near = view->zNear;
|
|
|
|
*far = view->zFar;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
void func_800AA4A8(View* view, f32 fovy, f32 near, f32 far) {
|
|
|
|
view->fovy = fovy;
|
2020-04-19 01:40:27 +00:00
|
|
|
view->zNear = near;
|
|
|
|
view->zFar = far;
|
2020-04-16 21:36:12 +00:00
|
|
|
view->flags |= 8;
|
|
|
|
view->scale = 1.0f;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
void func_800AA4E0(View* view, f32* fovy, f32* near, f32* far) {
|
|
|
|
*fovy = view->fovy;
|
2020-04-19 01:40:27 +00:00
|
|
|
*near = view->zNear;
|
|
|
|
*far = view->zFar;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
void View_SetViewport(View* view, Viewport* viewport) {
|
2020-04-04 17:17:56 +00:00
|
|
|
view->viewport = *viewport;
|
2020-04-16 21:36:12 +00:00
|
|
|
view->flags |= 2;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
void View_GetViewport(View* view, Viewport* viewport) {
|
2020-04-04 17:17:56 +00:00
|
|
|
*viewport = view->viewport;
|
|
|
|
}
|
|
|
|
|
|
|
|
void func_800AA550(View* view) {
|
2020-04-16 21:36:12 +00:00
|
|
|
s32 varY;
|
|
|
|
s32 varX;
|
2020-04-04 17:17:56 +00:00
|
|
|
s32 pad;
|
|
|
|
s32 ulx;
|
|
|
|
s32 uly;
|
|
|
|
s32 lrx;
|
|
|
|
s32 lry;
|
2021-02-14 00:49:40 +00:00
|
|
|
GraphicsContext* gfxCtx = view->gfxCtx;
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-07-09 01:54:39 +00:00
|
|
|
varY = ShrinkWindow_GetCurrentVal();
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
varX = -1; // The following is optimized to varX = 0 but affects codegen
|
|
|
|
|
|
|
|
if (varX < 0) {
|
|
|
|
varX = 0;
|
|
|
|
}
|
|
|
|
if (varX > SCREEN_WIDTH / 2) {
|
|
|
|
varX = SCREEN_WIDTH / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (varY < 0) {
|
|
|
|
varY = 0;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
if (varY > SCREEN_HEIGHT / 2) {
|
|
|
|
varY = SCREEN_HEIGHT / 2;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
ulx = view->viewport.leftX + varX;
|
|
|
|
uly = view->viewport.topY + varY;
|
|
|
|
lrx = view->viewport.rightX - varX;
|
|
|
|
lry = view->viewport.bottomY - varY;
|
|
|
|
|
2021-04-29 18:39:46 +00:00
|
|
|
ASSERT(ulx >= 0, "ulx >= 0", "../z_view.c", 454);
|
|
|
|
ASSERT(uly >= 0, "uly >= 0", "../z_view.c", 455);
|
|
|
|
ASSERT(lrx <= SCREEN_WIDTH, "lrx <= SCREEN_WD", "../z_view.c", 456);
|
|
|
|
ASSERT(lry <= SCREEN_HEIGHT, "lry <= SCREEN_HT", "../z_view.c", 457);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
OPEN_DISPS(gfxCtx, "../z_view.c", 459);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gDPPipeSync(POLY_OPA_DISP++);
|
|
|
|
gDPSetScissor(POLY_OPA_DISP++, G_SC_NON_INTERLACE, ulx, uly, lrx, lry);
|
|
|
|
gDPPipeSync(POLY_XLU_DISP++);
|
|
|
|
gDPSetScissor(POLY_XLU_DISP++, G_SC_NON_INTERLACE, ulx, uly, lrx, lry);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
CLOSE_DISPS(gfxCtx, "../z_view.c", 472);
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
void func_800AA76C(View* view, f32 x, f32 y, f32 z) {
|
|
|
|
view->unk_E8.x = x;
|
|
|
|
view->unk_E8.y = y;
|
|
|
|
view->unk_E8.z = z;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
void func_800AA78C(View* view, f32 x, f32 y, f32 z) {
|
|
|
|
view->unk_F4.x = x;
|
|
|
|
view->unk_F4.y = y;
|
|
|
|
view->unk_F4.z = z;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
2020-12-25 21:19:52 +00:00
|
|
|
s32 func_800AA7AC(View* view, f32 arg1) {
|
2020-04-04 17:17:56 +00:00
|
|
|
view->unk_100 = arg1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void func_800AA7B8(View* view) {
|
|
|
|
view->unk_E8.x = 0.0f;
|
|
|
|
view->unk_E8.y = 0.0f;
|
|
|
|
view->unk_E8.z = 0.0f;
|
|
|
|
view->unk_F4.x = 1.0f;
|
|
|
|
view->unk_F4.y = 1.0f;
|
|
|
|
view->unk_F4.z = 1.0f;
|
|
|
|
view->unk_104 = view->unk_E8;
|
|
|
|
view->unk_110 = view->unk_F4;
|
|
|
|
view->unk_100 = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void func_800AA814(View* view) {
|
|
|
|
view->unk_E8.x = 0.0f;
|
|
|
|
view->unk_E8.y = 0.0f;
|
|
|
|
view->unk_E8.z = 0.0f;
|
|
|
|
view->unk_F4.x = 1.0f;
|
|
|
|
view->unk_F4.y = 1.0f;
|
|
|
|
view->unk_F4.z = 1.0f;
|
|
|
|
view->unk_100 = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void func_800AA840(View* view, Vec3f vec1, Vec3f vec2, f32 arg3) {
|
|
|
|
view->unk_E8 = vec1;
|
|
|
|
view->unk_F4 = vec2;
|
|
|
|
view->unk_100 = arg3;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 func_800AA890(View* view, Mtx* mtx) {
|
2020-04-16 21:36:12 +00:00
|
|
|
MtxF mf;
|
2020-04-04 17:17:56 +00:00
|
|
|
|
|
|
|
if (view->unk_100 == 0.0f) {
|
|
|
|
return 0;
|
|
|
|
} else if (view->unk_100 == 1.0f) {
|
|
|
|
view->unk_104 = view->unk_E8;
|
|
|
|
view->unk_110 = view->unk_F4;
|
|
|
|
view->unk_100 = 0.0f;
|
|
|
|
} else {
|
|
|
|
view->unk_104.x += ((view->unk_E8.x - view->unk_104.x) * view->unk_100);
|
|
|
|
view->unk_104.y += ((view->unk_E8.y - view->unk_104.y) * view->unk_100);
|
|
|
|
view->unk_104.z += ((view->unk_E8.z - view->unk_104.z) * view->unk_100);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
view->unk_110.x += ((view->unk_F4.x - view->unk_110.x) * view->unk_100);
|
|
|
|
view->unk_110.y += ((view->unk_F4.y - view->unk_110.y) * view->unk_100);
|
|
|
|
view->unk_110.z += ((view->unk_F4.z - view->unk_110.z) * view->unk_100);
|
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
Matrix_MtxToMtxF(mtx, &mf);
|
|
|
|
Matrix_Put(&mf);
|
|
|
|
Matrix_RotateX(view->unk_104.x, MTXMODE_APPLY);
|
|
|
|
Matrix_RotateY(view->unk_104.y, MTXMODE_APPLY);
|
|
|
|
Matrix_RotateZ(view->unk_104.z, MTXMODE_APPLY);
|
2020-04-05 02:08:01 +00:00
|
|
|
Matrix_Scale(view->unk_110.x, view->unk_110.y, view->unk_110.z, MTXMODE_APPLY);
|
2020-04-16 21:36:12 +00:00
|
|
|
Matrix_RotateZ(-view->unk_104.z, MTXMODE_APPLY);
|
|
|
|
Matrix_RotateY(-view->unk_104.y, MTXMODE_APPLY);
|
|
|
|
Matrix_RotateX(-view->unk_104.x, MTXMODE_APPLY);
|
2020-04-04 22:39:53 +00:00
|
|
|
Matrix_ToMtx(mtx, "../z_view.c", 566);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
void func_800AAA50(View* view, s32 arg1) {
|
2020-12-25 21:19:52 +00:00
|
|
|
arg1 = (view->flags & arg1) | (arg1 >> 4);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
if (arg1 & 8) {
|
|
|
|
func_800AB0A8(view);
|
|
|
|
} else {
|
|
|
|
func_800AAA9C(view);
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
s32 func_800AAA9C(View* view) {
|
2020-04-16 21:36:12 +00:00
|
|
|
f32 aspect;
|
|
|
|
s32 width;
|
|
|
|
s32 height;
|
|
|
|
Vp* vp;
|
2020-04-04 17:17:56 +00:00
|
|
|
Mtx* projection;
|
2020-04-16 21:36:12 +00:00
|
|
|
Mtx* viewing;
|
2021-02-14 00:49:40 +00:00
|
|
|
GraphicsContext* gfxCtx = view->gfxCtx;
|
2020-08-29 23:00:17 +00:00
|
|
|
|
|
|
|
OPEN_DISPS(gfxCtx, "../z_view.c", 596);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
vp = Graph_Alloc(gfxCtx, sizeof(Vp));
|
|
|
|
LogUtils_CheckNullPointer("vp", vp, "../z_view.c", 601);
|
|
|
|
View_ViewportToVp(vp, &view->viewport);
|
|
|
|
view->vp = *vp;
|
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
func_800AA550(view);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPViewport(POLY_OPA_DISP++, vp);
|
|
|
|
gSPViewport(POLY_XLU_DISP++, vp);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
|
2020-04-04 22:39:53 +00:00
|
|
|
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 616);
|
2020-04-16 21:36:12 +00:00
|
|
|
view->projectionPtr = projection;
|
|
|
|
|
|
|
|
width = view->viewport.rightX - view->viewport.leftX;
|
|
|
|
height = view->viewport.bottomY - view->viewport.topY;
|
|
|
|
aspect = (f32)width / (f32)height;
|
|
|
|
|
|
|
|
if (HREG(80) == 11) {
|
|
|
|
if (HREG(94) != 11) {
|
|
|
|
HREG(94) = 11;
|
|
|
|
HREG(83) = 60;
|
|
|
|
HREG(84) = 13333;
|
|
|
|
HREG(85) = 10;
|
|
|
|
HREG(86) = 12800;
|
|
|
|
HREG(87) = 100;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
guPerspective(projection, &view->normal, HREG(83), HREG(84) / 10000.0f, HREG(85), HREG(86), HREG(87) / 100.0f);
|
2020-04-04 17:17:56 +00:00
|
|
|
} else {
|
2020-04-19 01:40:27 +00:00
|
|
|
guPerspective(projection, &view->normal, view->fovy, aspect, view->zNear, view->zFar, view->scale);
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-04-05 01:50:46 +00:00
|
|
|
if (QREG(88) & 1) {
|
2020-04-16 21:36:12 +00:00
|
|
|
s32 i;
|
|
|
|
MtxF mf;
|
|
|
|
|
2020-04-19 01:40:27 +00:00
|
|
|
osSyncPrintf("fovy %f near %f far %f scale %f aspect %f normal %08x\n", view->fovy, view->zNear, view->zFar,
|
2020-04-16 21:36:12 +00:00
|
|
|
view->scale, aspect, view->normal);
|
|
|
|
|
|
|
|
Matrix_MtxToMtxF(projection, &mf);
|
2020-04-04 17:17:56 +00:00
|
|
|
osSyncPrintf("projection\n");
|
|
|
|
for (i = 0; i < 4; i++) {
|
2020-04-16 21:36:12 +00:00
|
|
|
osSyncPrintf(" %f %f %f %f\n", mf.mf[i][0], mf.mf[i][1], mf.mf[i][2], mf.mf[i][3]);
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
|
|
|
osSyncPrintf("\n");
|
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
view->projection = *projection;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
func_800AA890(view, projection);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPPerspNormalize(POLY_OPA_DISP++, view->normal);
|
|
|
|
gSPMatrix(POLY_OPA_DISP++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
|
|
|
gSPPerspNormalize(POLY_XLU_DISP++, view->normal);
|
|
|
|
gSPMatrix(POLY_XLU_DISP++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
viewing = Graph_Alloc(gfxCtx, sizeof(Mtx));
|
2020-04-04 22:39:53 +00:00
|
|
|
LogUtils_CheckNullPointer("viewing", viewing, "../z_view.c", 667);
|
2020-04-16 21:36:12 +00:00
|
|
|
view->viewingPtr = viewing;
|
|
|
|
|
2020-06-25 01:20:31 +00:00
|
|
|
if (view->eye.x == view->lookAt.x && view->eye.y == view->lookAt.y && view->eye.z == view->lookAt.z) {
|
2020-04-04 17:17:56 +00:00
|
|
|
view->eye.x += 1.0f;
|
|
|
|
view->eye.y += 1.0f;
|
|
|
|
view->eye.z += 1.0f;
|
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
func_800ABE74(view->eye.x, view->eye.y, view->eye.z);
|
2020-06-30 18:44:07 +00:00
|
|
|
guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->lookAt.x, view->lookAt.y, view->lookAt.z, view->up.x,
|
|
|
|
view->up.y, view->up.z);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
view->viewing = *viewing;
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-04-05 02:08:01 +00:00
|
|
|
if (QREG(88) & 2) {
|
2020-04-16 21:36:12 +00:00
|
|
|
s32 i;
|
|
|
|
MtxF mf;
|
|
|
|
|
|
|
|
Matrix_MtxToMtxF(view->viewingPtr, &mf);
|
2020-04-04 17:17:56 +00:00
|
|
|
osSyncPrintf("viewing\n");
|
|
|
|
for (i = 0; i < 4; i++) {
|
2020-04-16 21:36:12 +00:00
|
|
|
osSyncPrintf(" %f %f %f %f\n", mf.mf[i][0], mf.mf[i][1], mf.mf[i][2], mf.mf[i][3]);
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
|
|
|
osSyncPrintf("\n");
|
|
|
|
}
|
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPMatrix(POLY_OPA_DISP++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
|
|
|
|
gSPMatrix(POLY_XLU_DISP++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
CLOSE_DISPS(gfxCtx, "../z_view.c", 711);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 func_800AB0A8(View* view) {
|
2020-04-16 21:36:12 +00:00
|
|
|
Vp* vp;
|
2020-04-04 17:17:56 +00:00
|
|
|
Mtx* projection;
|
2021-02-14 00:49:40 +00:00
|
|
|
GraphicsContext* gfxCtx = view->gfxCtx;
|
2020-08-29 23:00:17 +00:00
|
|
|
|
|
|
|
OPEN_DISPS(gfxCtx, "../z_view.c", 726);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
vp = Graph_Alloc(gfxCtx, sizeof(Vp));
|
|
|
|
LogUtils_CheckNullPointer("vp", vp, "../z_view.c", 730);
|
|
|
|
View_ViewportToVp(vp, &view->viewport);
|
|
|
|
view->vp = *vp;
|
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
func_800AA550(view);
|
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPViewport(POLY_OPA_DISP++, vp);
|
|
|
|
gSPViewport(POLY_XLU_DISP++, vp);
|
|
|
|
gSPViewport(OVERLAY_DISP++, vp);
|
2020-04-04 17:17:56 +00:00
|
|
|
|
|
|
|
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
|
|
|
|
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 744);
|
2020-04-16 21:36:12 +00:00
|
|
|
view->projectionPtr = projection;
|
|
|
|
|
2020-05-27 07:48:07 +00:00
|
|
|
guOrtho(projection, -(f32)gScreenWidth * 0.5f, (f32)gScreenWidth * 0.5f, -(f32)gScreenHeight * 0.5f,
|
|
|
|
(f32)gScreenHeight * 0.5f, view->zNear, view->zFar, view->scale);
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
view->projection = *projection;
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPMatrix(POLY_OPA_DISP++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
|
|
|
gSPMatrix(POLY_XLU_DISP++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
CLOSE_DISPS(gfxCtx, "../z_view.c", 762);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 func_800AB2C4(View* view) {
|
2020-04-16 21:36:12 +00:00
|
|
|
Vp* vp;
|
2020-04-04 17:17:56 +00:00
|
|
|
Mtx* projection;
|
|
|
|
GraphicsContext* gfxCtx;
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
if (1) {} // Necessary to match
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
gfxCtx = view->gfxCtx;
|
2020-08-29 23:00:17 +00:00
|
|
|
|
|
|
|
OPEN_DISPS(gfxCtx, "../z_view.c", 777);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
vp = Graph_Alloc(gfxCtx, sizeof(Vp));
|
|
|
|
LogUtils_CheckNullPointer("vp", vp, "../z_view.c", 781);
|
|
|
|
View_ViewportToVp(vp, &view->viewport);
|
|
|
|
view->vp = *vp;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gDPPipeSync(OVERLAY_DISP++);
|
2020-11-19 21:49:08 +00:00
|
|
|
gDPSetScissor(OVERLAY_DISP++, G_SC_NON_INTERLACE, view->viewport.leftX, view->viewport.topY, view->viewport.rightX,
|
|
|
|
view->viewport.bottomY);
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPViewport(OVERLAY_DISP++, vp);
|
2020-04-04 17:17:56 +00:00
|
|
|
|
|
|
|
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
|
|
|
|
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 791);
|
2020-04-16 21:36:12 +00:00
|
|
|
view->projectionPtr = projection;
|
|
|
|
|
2020-05-27 07:48:07 +00:00
|
|
|
guOrtho(projection, -(f32)gScreenWidth * 0.5f, (f32)gScreenWidth * 0.5f, -(f32)gScreenHeight * 0.5f,
|
|
|
|
(f32)gScreenHeight * 0.5f, view->zNear, view->zFar, view->scale);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
view->projection = *projection;
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPMatrix(OVERLAY_DISP++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
CLOSE_DISPS(gfxCtx, "../z_view.c", 801);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 func_800AB560(View* view) {
|
2020-04-16 21:36:12 +00:00
|
|
|
s32 pad[2];
|
2020-04-04 17:17:56 +00:00
|
|
|
f32 aspect;
|
2020-04-16 21:36:12 +00:00
|
|
|
s32 width;
|
|
|
|
s32 height;
|
|
|
|
Vp* vp;
|
|
|
|
Mtx* projection;
|
|
|
|
Mtx* viewing;
|
2021-02-14 00:49:40 +00:00
|
|
|
GraphicsContext* gfxCtx = view->gfxCtx;
|
2020-08-29 23:00:17 +00:00
|
|
|
|
|
|
|
OPEN_DISPS(gfxCtx, "../z_view.c", 816);
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
vp = Graph_Alloc(gfxCtx, sizeof(Vp));
|
|
|
|
LogUtils_CheckNullPointer("vp", vp, "../z_view.c", 821);
|
|
|
|
View_ViewportToVp(vp, &view->viewport);
|
|
|
|
view->vp = *vp;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gDPPipeSync(OVERLAY_DISP++);
|
2020-11-19 21:49:08 +00:00
|
|
|
gDPSetScissor(OVERLAY_DISP++, G_SC_NON_INTERLACE, view->viewport.leftX, view->viewport.topY, view->viewport.rightX,
|
|
|
|
view->viewport.bottomY);
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPViewport(OVERLAY_DISP++, vp);
|
2020-04-04 17:17:56 +00:00
|
|
|
|
|
|
|
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
|
|
|
|
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 833);
|
2020-04-16 21:36:12 +00:00
|
|
|
view->projectionPtr = projection;
|
|
|
|
|
|
|
|
width = view->viewport.rightX - view->viewport.leftX;
|
|
|
|
height = view->viewport.bottomY - view->viewport.topY;
|
|
|
|
|
|
|
|
aspect = (f32)width / (f32)height;
|
2020-04-19 01:40:27 +00:00
|
|
|
guPerspective(projection, &view->normal, view->fovy, aspect, view->zNear, view->zFar, view->scale);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
view->projection = *projection;
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPPerspNormalize(OVERLAY_DISP++, view->normal);
|
|
|
|
gSPMatrix(OVERLAY_DISP++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
viewing = Graph_Alloc(gfxCtx, sizeof(Mtx));
|
2020-04-04 17:17:56 +00:00
|
|
|
LogUtils_CheckNullPointer("viewing", viewing, "../z_view.c", 848);
|
2020-04-16 21:36:12 +00:00
|
|
|
view->viewingPtr = viewing;
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-06-25 01:20:31 +00:00
|
|
|
if (view->eye.x == view->lookAt.x && view->eye.y == view->lookAt.y && view->eye.z == view->lookAt.z) {
|
2020-04-04 17:17:56 +00:00
|
|
|
view->eye.x += 1.0f;
|
|
|
|
view->eye.y += 1.0f;
|
|
|
|
view->eye.z += 1.0f;
|
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
func_800ABE74(view->eye.x, view->eye.y, view->eye.z);
|
2020-06-30 18:44:07 +00:00
|
|
|
guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->lookAt.x, view->lookAt.y, view->lookAt.z, view->up.x,
|
|
|
|
view->up.y, view->up.z);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
view->viewing = *viewing;
|
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPMatrix(OVERLAY_DISP++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
CLOSE_DISPS(gfxCtx, "../z_view.c", 871);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 func_800AB944(View* view) {
|
2020-08-29 23:00:17 +00:00
|
|
|
OPEN_DISPS(view->gfxCtx, "../z_view.c", 878);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
func_800ABE74(view->eye.x, view->eye.y, view->eye.z);
|
2020-06-25 01:20:31 +00:00
|
|
|
guLookAt(view->viewingPtr, view->eye.x, view->eye.y, view->eye.z, view->lookAt.x, view->lookAt.y, view->lookAt.z,
|
|
|
|
view->up.x, view->up.y, view->up.z);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
CLOSE_DISPS(view->gfxCtx, "../z_view.c", 886);
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
s32 func_800AB9EC(View* view, s32 arg1, Gfx** gfxp) {
|
|
|
|
Gfx* gfx = *gfxp;
|
2020-06-30 18:44:07 +00:00
|
|
|
GraphicsContext* gfxCtx = view->gfxCtx;
|
|
|
|
s32 width;
|
|
|
|
s32 height;
|
|
|
|
Vp* vp;
|
|
|
|
Mtx* projection;
|
|
|
|
Mtx* viewing;
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-08-23 21:50:30 +00:00
|
|
|
arg1 = (view->flags & arg1) | (arg1 >> 4);
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
if (arg1 & 2) {
|
2020-08-23 21:50:30 +00:00
|
|
|
vp = Graph_Alloc(gfxCtx, sizeof(Vp));
|
2020-04-16 21:36:12 +00:00
|
|
|
LogUtils_CheckNullPointer("vp", vp, "../z_view.c", 910);
|
|
|
|
View_ViewportToVp(vp, &view->viewport);
|
2020-06-30 18:44:07 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
view->vp = *vp;
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
gDPPipeSync(gfx++);
|
|
|
|
gDPSetScissor(gfx++, G_SC_NON_INTERLACE, view->viewport.leftX, view->viewport.topY, view->viewport.rightX,
|
2020-04-04 17:17:56 +00:00
|
|
|
view->viewport.bottomY);
|
2020-04-16 21:36:12 +00:00
|
|
|
gSPViewport(gfx++, vp);
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
if (arg1 & 8) {
|
2020-06-30 18:44:07 +00:00
|
|
|
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
|
2020-04-04 17:17:56 +00:00
|
|
|
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 921);
|
2020-04-16 21:36:12 +00:00
|
|
|
view->projectionPtr = projection;
|
|
|
|
|
2020-05-27 07:48:07 +00:00
|
|
|
guOrtho(projection, -(f32)gScreenWidth * 0.5f, (f32)gScreenWidth * 0.5f, -(f32)gScreenHeight * 0.5f,
|
|
|
|
(f32)gScreenHeight * 0.5f, view->zNear, view->zFar, view->scale);
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
view->projection = *projection;
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
gSPMatrix(gfx++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
2020-04-04 17:17:56 +00:00
|
|
|
} else if (arg1 & 6) {
|
2020-06-30 18:44:07 +00:00
|
|
|
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
|
2020-04-16 21:36:12 +00:00
|
|
|
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 932);
|
|
|
|
view->projectionPtr = projection;
|
|
|
|
|
|
|
|
width = view->viewport.rightX - view->viewport.leftX;
|
|
|
|
height = view->viewport.bottomY - view->viewport.topY;
|
|
|
|
|
2020-04-19 01:40:27 +00:00
|
|
|
guPerspective(projection, &view->normal, view->fovy, (f32)width / (f32)height, view->zNear, view->zFar,
|
2020-04-16 21:36:12 +00:00
|
|
|
view->scale);
|
|
|
|
|
|
|
|
view->projection = *projection;
|
|
|
|
|
|
|
|
gSPPerspNormalize(gfx++, view->normal);
|
|
|
|
gSPMatrix(gfx++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
if (arg1 & 1) {
|
2020-06-30 18:44:07 +00:00
|
|
|
viewing = Graph_Alloc(gfxCtx, sizeof(Mtx));
|
2020-04-04 17:17:56 +00:00
|
|
|
LogUtils_CheckNullPointer("viewing", viewing, "../z_view.c", 948);
|
2020-04-16 21:36:12 +00:00
|
|
|
view->viewingPtr = viewing;
|
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
func_800ABE74(view->eye.x, view->eye.y, view->eye.z);
|
2020-06-25 01:20:31 +00:00
|
|
|
guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->lookAt.x, view->lookAt.y, view->lookAt.z,
|
|
|
|
view->up.x, view->up.y, view->up.z);
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
view->viewing = *viewing;
|
2020-04-04 17:17:56 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
gSPMatrix(gfx++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
view->flags = 0;
|
|
|
|
*gfxp = gfx;
|
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 func_800ABE74(f32 eyeX, f32 eyeY, f32 eyeZ) {
|
2020-04-16 21:36:12 +00:00
|
|
|
s32 error = 0;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-16 21:36:12 +00:00
|
|
|
if (SQ(eyeX) + SQ(eyeY) + SQ(eyeZ) > SQ(32767.0f)) {
|
|
|
|
error = 3;
|
2020-04-04 17:17:56 +00:00
|
|
|
} else {
|
2020-04-16 21:36:12 +00:00
|
|
|
f32 absEyeX = ABS(eyeX);
|
|
|
|
f32 absEyeY = ABS(eyeY);
|
|
|
|
f32 absEyeZ = ABS(eyeZ);
|
|
|
|
|
2020-04-04 17:17:56 +00:00
|
|
|
if (((18900.0f < absEyeX) || (18900.0f < absEyeY)) || (18900.0f < absEyeZ)) {
|
2020-04-16 21:36:12 +00:00
|
|
|
error = 2;
|
2020-04-04 17:17:56 +00:00
|
|
|
} else if (((16000.0f < absEyeX) || (16000.0f < absEyeY)) || (16000.0f < absEyeZ)) {
|
2020-04-16 21:36:12 +00:00
|
|
|
error = 1;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
if (error != 0) {
|
2020-04-05 15:06:55 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(RED));
|
2020-04-16 21:36:12 +00:00
|
|
|
// "Is too large"
|
|
|
|
osSyncPrintf("eye が大きすぎます eye=[%8.3f %8.3f %8.3f] error=%d\n", eyeX, eyeY, eyeZ, error);
|
2020-04-05 01:50:46 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|
2020-04-16 21:36:12 +00:00
|
|
|
|
|
|
|
return error;
|
2020-04-04 17:17:56 +00:00
|
|
|
}
|