1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-22 21:35:27 +00:00
oot/src/code/z_view.c

628 lines
18 KiB
C
Raw Normal View History

2020-03-17 04:31:30 +00:00
#include <ultra64.h>
#include <global.h>
2020-04-05 01:50:46 +00:00
#include <vt.h>
2020-03-17 04:31:30 +00:00
volatile u32 D_8012ABF0 = true;
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
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-05 01:50:46 +00:00
if (view != NULL) {
func_80106860(view, 0, sizeof(View)); // memset
View_Init(view, gfxCtx);
2020-04-04 17:17:56 +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
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
void View_Init(View* view, GraphicsContext* gfxCtx) {
2020-04-04 17:17:56 +00:00
view->gfxCtx = gfxCtx;
view->viewport.topY = 0;
view->viewport.bottomY = SCREEN_HEIGHT;
2020-04-04 17:17:56 +00:00
view->viewport.leftX = 0;
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;
view->scale = 1.0f;
view->fovy = 60.0f;
view->zNear = 10.0f;
view->zFar = 12800.0f;
2020-04-04 17:17:56 +00:00
view->unk_34.x = 0.0f;
view->unk_40.x = 0.0f;
view->unk_40.y = 1.0f;
view->unk_40.z = 0.0f;
view->eye.z = -1.0f;
2020-03-17 04:31:30 +00:00
if (D_8012ABF0) {
2020-04-04 17:17:56 +00:00
if (&D_8012ABF0) {}
osSyncPrintf("\nview: initialize ---\n");
D_8012ABF0 = false;
2020-04-04 17:17:56 +00:00
}
2020-04-04 17:17:56 +00:00
view->unk_124 = 0;
view->flags = 1 | 2 | 4;
2020-04-04 17:17:56 +00:00
func_800AA7B8(view);
}
2020-03-17 04:31:30 +00:00
void func_800AA358(View* view, Vec3f* eye, Vec3f* vec2, Vec3f* vec3) {
if (eye->x == vec2->x && eye->z == vec2->z) {
eye->x += 0.1f;
2020-04-04 17:17:56 +00:00
}
view->eye = *eye;
2020-04-04 17:17:56 +00:00
view->unk_34 = *vec2;
view->unk_40 = *vec3;
view->flags |= 1;
2020-04-04 17:17:56 +00:00
}
2020-03-17 04:31:30 +00:00
void func_800AA3F0(View* view, Vec3f* eye, Vec3f* vec2, Vec3f* vec3) {
view->eye = *eye;
2020-04-04 17:17:56 +00:00
view->unk_34 = *vec2;
view->unk_40 = *vec3;
}
2020-03-17 04:31:30 +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
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
void func_800AA460(View* view, f32 fovy, f32 near, f32 far) {
view->fovy = fovy;
view->zNear = near;
view->zFar = far;
view->flags |= 4;
2020-04-04 17:17:56 +00:00
}
2020-03-17 04:31:30 +00:00
void func_800AA48C(View* view, f32* fovy, f32* near, f32* far) {
*fovy = view->fovy;
*near = view->zNear;
*far = view->zFar;
2020-04-04 17:17:56 +00:00
}
2020-03-17 04:31:30 +00:00
void func_800AA4A8(View* view, f32 fovy, f32 near, f32 far) {
view->fovy = fovy;
view->zNear = near;
view->zFar = far;
view->flags |= 8;
view->scale = 1.0f;
2020-04-04 17:17:56 +00:00
}
2020-03-17 04:31:30 +00:00
void func_800AA4E0(View* view, f32* fovy, f32* near, f32* far) {
*fovy = view->fovy;
*near = view->zNear;
*far = view->zFar;
2020-04-04 17:17:56 +00:00
}
void View_SetViewport(View* view, Viewport* viewport) {
2020-04-04 17:17:56 +00:00
view->viewport = *viewport;
view->flags |= 2;
2020-04-04 17:17:56 +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) {
s32 varY;
s32 varX;
2020-04-04 17:17:56 +00:00
s32 pad;
s32 ulx;
s32 uly;
s32 lrx;
s32 lry;
GraphicsContext* gfxCtx;
Gfx* dispRefs[5];
2020-04-04 17:17:56 +00:00
gfxCtx = view->gfxCtx;
varY = func_800B38FC();
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
}
if (varY > SCREEN_HEIGHT / 2) {
varY = SCREEN_HEIGHT / 2;
2020-04-04 17:17:56 +00:00
}
ulx = view->viewport.leftX + varX;
uly = view->viewport.topY + varY;
lrx = view->viewport.rightX - varX;
lry = view->viewport.bottomY - varY;
2020-04-04 17:17:56 +00:00
if (ulx < 0) {
__assert("ulx >= 0", "../z_view.c", 454);
}
if (uly < 0) {
__assert("uly >= 0", "../z_view.c", 455);
}
if (lrx > SCREEN_WIDTH) {
__assert("lrx <= SCREEN_WD", "../z_view.c", 456);
}
if (lry > SCREEN_HEIGHT) {
__assert("lry <= SCREEN_HT", "../z_view.c", 457);
}
Graph_OpenDisps(dispRefs, gfxCtx, "../z_view.c", 459);
2020-04-04 17:17:56 +00:00
gDPPipeSync(gfxCtx->polyOpa.p++);
gDPSetScissor(gfxCtx->polyOpa.p++, G_SC_NON_INTERLACE, ulx, uly, lrx, lry);
gDPPipeSync(gfxCtx->polyXlu.p++);
gDPSetScissor(gfxCtx->polyXlu.p++, G_SC_NON_INTERLACE, ulx, uly, lrx, lry);
Graph_CloseDisps(dispRefs, gfxCtx, "../z_view.c", 472);
2020-04-04 17:17:56 +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
}
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
}
void func_800AA7AC(View* view, f32 arg1) {
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) {
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);
}
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);
Matrix_Scale(view->unk_110.x, view->unk_110.y, view->unk_110.z, MTXMODE_APPLY);
Matrix_RotateZ(-view->unk_104.z, MTXMODE_APPLY);
Matrix_RotateY(-view->unk_104.y, MTXMODE_APPLY);
Matrix_RotateX(-view->unk_104.x, MTXMODE_APPLY);
Matrix_ToMtx(mtx, "../z_view.c", 566);
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) {
arg1 = (view->flags & arg1) | arg1 >> 4;
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) {
f32 aspect;
s32 width;
s32 height;
Vp* vp;
2020-04-04 17:17:56 +00:00
Mtx* projection;
Mtx* viewing;
2020-04-04 17:17:56 +00:00
GraphicsContext* gfxCtx;
Gfx* dispRefs[5];
2020-03-17 04:31:30 +00:00
2020-04-04 17:17:56 +00:00
gfxCtx = view->gfxCtx;
Graph_OpenDisps(dispRefs, gfxCtx, "../z_view.c", 596);
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
gSPViewport(gfxCtx->polyOpa.p++, vp);
gSPViewport(gfxCtx->polyXlu.p++, vp);
2020-03-17 04:31:30 +00:00
2020-04-04 17:17:56 +00:00
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 616);
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
}
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 {
guPerspective(projection, &view->normal, view->fovy, aspect, view->zNear, view->zFar, view->scale);
2020-04-04 17:17:56 +00:00
}
2020-04-05 01:50:46 +00:00
if (QREG(88) & 1) {
s32 i;
MtxF mf;
osSyncPrintf("fovy %f near %f far %f scale %f aspect %f normal %08x\n", view->fovy, view->zNear, view->zFar,
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++) {
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");
}
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
gSPPerspNormalize(gfxCtx->polyOpa.p++, view->normal);
2020-04-04 17:17:56 +00:00
gSPMatrix(gfxCtx->polyOpa.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
gSPPerspNormalize(gfxCtx->polyXlu.p++, view->normal);
2020-04-04 17:17:56 +00:00
gSPMatrix(gfxCtx->polyXlu.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
2020-03-17 04:31:30 +00:00
viewing = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("viewing", viewing, "../z_view.c", 667);
view->viewingPtr = viewing;
2020-04-04 17:17:56 +00:00
if (view->eye.x == view->unk_34.x && view->eye.y == view->unk_34.y && view->eye.z == view->unk_34.z) {
view->eye.x += 1.0f;
view->eye.y += 1.0f;
view->eye.z += 1.0f;
}
2020-04-04 17:17:56 +00:00
func_800ABE74(view->eye.x, view->eye.y, view->eye.z);
guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->unk_34.x, view->unk_34.y, view->unk_34.z,
view->unk_40.x, view->unk_40.y, view->unk_40.z);
view->viewing = *viewing;
2020-04-04 17:17:56 +00:00
if (QREG(88) & 2) {
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++) {
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");
}
gSPMatrix(gfxCtx->polyOpa.p++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
gSPMatrix(gfxCtx->polyXlu.p++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
Graph_CloseDisps(dispRefs, gfxCtx, "../z_view.c", 711);
2020-04-04 17:17:56 +00:00
return 1;
}
s32 func_800AB0A8(View* view) {
Vp* vp;
2020-04-04 17:17:56 +00:00
Mtx* projection;
GraphicsContext* gfxCtx;
Gfx* dispRefs[5];
2020-04-04 17:17:56 +00:00
gfxCtx = view->gfxCtx;
Graph_OpenDisps(dispRefs, gfxCtx, "../z_view.c", 726);
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);
gSPViewport(gfxCtx->polyOpa.p++, vp);
gSPViewport(gfxCtx->polyXlu.p++, vp);
gSPViewport(gfxCtx->overlay.p++, vp);
2020-04-04 17:17:56 +00:00
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 744);
view->projectionPtr = projection;
func_801045A4(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
view->projection = *projection;
2020-04-04 17:17:56 +00:00
gSPMatrix(gfxCtx->polyOpa.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
gSPMatrix(gfxCtx->polyXlu.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
Graph_CloseDisps(dispRefs, gfxCtx, "../z_view.c", 762);
2020-04-04 17:17:56 +00:00
return 1;
}
s32 func_800AB2C4(View* view) {
Vp* vp;
2020-04-04 17:17:56 +00:00
Mtx* projection;
GraphicsContext* gfxCtx;
Gfx* dispRefs[5];
if (1) {} // Necessary to match
2020-03-17 04:31:30 +00:00
2020-04-04 17:17:56 +00:00
gfxCtx = view->gfxCtx;
Graph_OpenDisps(dispRefs, gfxCtx, "../z_view.c", 777);
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-04-04 17:17:56 +00:00
gDPPipeSync(gfxCtx->overlay.p++);
gDPSetScissor(gfxCtx->overlay.p++, G_SC_NON_INTERLACE, view->viewport.leftX, view->viewport.topY,
view->viewport.rightX, view->viewport.bottomY);
gSPViewport(gfxCtx->overlay.p++, vp);
2020-04-04 17:17:56 +00:00
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 791);
view->projectionPtr = projection;
func_801045A4(projection, -(f32)gScreenWidth * 0.5f, (f32)gScreenWidth * 0.5f, -(f32)gScreenHeight * 0.5f,
(f32)gScreenHeight * 0.5f, view->zNear, view->zFar, view->scale);
view->projection = *projection;
2020-04-04 17:17:56 +00:00
gSPMatrix(gfxCtx->overlay.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
Graph_CloseDisps(dispRefs, gfxCtx, "../z_view.c", 801);
2020-04-04 17:17:56 +00:00
return 1;
}
s32 func_800AB560(View* view) {
s32 pad[2];
2020-04-04 17:17:56 +00:00
f32 aspect;
s32 width;
s32 height;
Vp* vp;
Mtx* projection;
Mtx* viewing;
GraphicsContext* gfxCtx;
Gfx* dispRefs[5];
2020-04-04 17:17:56 +00:00
gfxCtx = view->gfxCtx;
Graph_OpenDisps(dispRefs, gfxCtx, "../z_view.c", 816);
2020-04-04 17:17:56 +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-04-04 17:17:56 +00:00
gDPPipeSync(gfxCtx->overlay.p++);
gDPSetScissor(gfxCtx->overlay.p++, G_SC_NON_INTERLACE, view->viewport.leftX, view->viewport.topY,
view->viewport.rightX, view->viewport.bottomY);
gSPViewport(gfxCtx->overlay.p++, vp);
2020-04-04 17:17:56 +00:00
projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 833);
view->projectionPtr = projection;
width = view->viewport.rightX - view->viewport.leftX;
height = view->viewport.bottomY - view->viewport.topY;
aspect = (f32)width / (f32)height;
guPerspective(projection, &view->normal, view->fovy, aspect, view->zNear, view->zFar, view->scale);
view->projection = *projection;
2020-04-04 17:17:56 +00:00
gSPPerspNormalize(gfxCtx->overlay.p++, view->normal);
2020-04-04 17:17:56 +00:00
gSPMatrix(gfxCtx->overlay.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
viewing = Graph_Alloc(gfxCtx, sizeof(Mtx));
2020-04-04 17:17:56 +00:00
LogUtils_CheckNullPointer("viewing", viewing, "../z_view.c", 848);
view->viewingPtr = viewing;
2020-04-04 17:17:56 +00:00
if (view->eye.x == view->unk_34.x && view->eye.y == view->unk_34.y && view->eye.z == view->unk_34.z) {
view->eye.x += 1.0f;
view->eye.y += 1.0f;
view->eye.z += 1.0f;
}
2020-04-04 17:17:56 +00:00
func_800ABE74(view->eye.x, view->eye.y, view->eye.z);
guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->unk_34.x, view->unk_34.y, view->unk_34.z,
view->unk_40.x, view->unk_40.y, view->unk_40.z);
view->viewing = *viewing;
2020-04-04 17:17:56 +00:00
gSPMatrix(gfxCtx->overlay.p++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
Graph_CloseDisps(dispRefs, gfxCtx, "../z_view.c", 871);
2020-04-04 17:17:56 +00:00
return 1;
}
s32 func_800AB944(View* view) {
Gfx* dispRefs[5];
2020-03-17 04:31:30 +00:00
Graph_OpenDisps(dispRefs, view->gfxCtx, "../z_view.c", 878);
2020-04-04 17:17:56 +00:00
func_800ABE74(view->eye.x, view->eye.y, view->eye.z);
guLookAt(view->viewingPtr, view->eye.x, view->eye.y, view->eye.z, view->unk_34.x, view->unk_34.y, view->unk_34.z,
view->unk_40.x, view->unk_40.y, view->unk_40.z);
2020-03-17 04:31:30 +00:00
Graph_CloseDisps(dispRefs, view->gfxCtx, "../z_view.c", 886);
2020-04-04 17:17:56 +00:00
return 1;
}
#ifdef NON_MATCHING
// saved register usage is wrong, relatively minor reorderings, regalloc
s32 func_800AB9EC(View* view, s32 arg1, Gfx** gfxp) {
GraphicsContext* gfxCtx = view->gfxCtx;
Gfx* gfx = *gfxp;
2020-04-04 17:17:56 +00:00
arg1 = (view->flags & arg1) | arg1 >> 4;
2020-04-04 17:17:56 +00:00
if (arg1 & 2) {
Vp* vp = Graph_Alloc(view->gfxCtx, sizeof(Vp));
LogUtils_CheckNullPointer("vp", vp, "../z_view.c", 910);
View_ViewportToVp(vp, &view->viewport);
view->vp = *vp;
2020-04-04 17:17:56 +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);
gSPViewport(gfx++, vp);
2020-04-04 17:17:56 +00:00
}
2020-04-04 17:17:56 +00:00
if (arg1 & 8) {
Mtx* projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
2020-04-04 17:17:56 +00:00
LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 921);
view->projectionPtr = projection;
func_801045A4(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
view->projection = *projection;
2020-04-04 17:17:56 +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) {
s32 width;
s32 height;
Mtx* projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
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;
guPerspective(projection, &view->normal, view->fovy, (f32)width / (f32)height, view->zNear, view->zFar,
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-04 17:17:56 +00:00
if (arg1 & 1) {
Mtx* viewing = Graph_Alloc(gfxCtx, sizeof(Mtx));
2020-04-04 17:17:56 +00:00
LogUtils_CheckNullPointer("viewing", viewing, "../z_view.c", 948);
view->viewingPtr = viewing;
2020-04-04 17:17:56 +00:00
func_800ABE74(view->eye.x, view->eye.y, view->eye.z);
guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->unk_34.x, view->unk_34.y, view->unk_34.z,
view->unk_40.x, view->unk_40.y, view->unk_40.z);
2020-04-04 17:17:56 +00:00
view->viewing = *viewing;
2020-04-04 17:17:56 +00:00
gSPMatrix(gfx++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
2020-04-04 17:17:56 +00:00
}
view->flags = 0;
*gfxp = gfx;
2020-04-04 17:17:56 +00:00
return 1;
}
#else
2020-03-17 04:31:30 +00:00
#pragma GLOBAL_ASM("asm/non_matchings/code/z_view/func_800AB9EC.s")
2020-04-04 17:17:56 +00:00
#endif
s32 func_800ABE74(f32 eyeX, f32 eyeY, f32 eyeZ) {
s32 error = 0;
2020-03-17 04:31:30 +00:00
if (SQ(eyeX) + SQ(eyeY) + SQ(eyeZ) > SQ(32767.0f)) {
error = 3;
2020-04-04 17:17:56 +00:00
} else {
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)) {
error = 2;
2020-04-04 17:17:56 +00:00
} else if (((16000.0f < absEyeX) || (16000.0f < absEyeY)) || (16000.0f < absEyeZ)) {
error = 1;
2020-04-04 17:17:56 +00:00
}
}
if (error != 0) {
osSyncPrintf(VT_FGCOL(RED));
// "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
}
return error;
2020-04-04 17:17:56 +00:00
}