summaryrefslogtreecommitdiff
path: root/src/code/z_view.c
blob: 9ab4db07ee95f4cdc7600386e9217eb8a5ea6abb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
#include <ultra64.h>
#include <global.h>
#include <vt.h>

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;
}

View* View_New(GraphicsContext* gfxCtx) {
    View* view = SystemArena_MallocDebug(sizeof(View), "../z_view.c", 285);

    if (view != NULL) {
        func_80106860(view, 0, sizeof(View)); // memset
        View_Init(view, gfxCtx);
    }

    return view;
}

void View_Free(View* view) {
    SystemArena_FreeDebug(view, "../z_view.c", 297);
}

void View_Init(View* view, GraphicsContext* gfxCtx) {
    view->gfxCtx = gfxCtx;
    view->viewport.topY = 0;
    view->viewport.bottomY = SCREEN_HEIGHT;
    view->viewport.leftX = 0;
    view->viewport.rightX = SCREEN_WIDTH;
    view->magic = 0x56494557; // "VIEW"
    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;
    view->lookAt.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) {}
        osSyncPrintf("\nview: initialize ---\n");
        D_8012ABF0 = false;
    }

    view->unk_124 = 0;
    view->flags = 1 | 2 | 4;
    func_800AA7B8(view);
}

void func_800AA358(View* view, Vec3f* eye, Vec3f* lookAt, Vec3f* up) {
    if (eye->x == lookAt->x && eye->z == lookAt->z) {
        eye->x += 0.1f;
    }

    view->eye = *eye;
    view->lookAt = *lookAt;
    view->up = *up;
    view->flags |= 1;
}

void func_800AA3F0(View* view, Vec3f* eye, Vec3f* lookAt, Vec3f* up) {
    view->eye = *eye;
    view->lookAt = *lookAt;
    view->up = *up;
}

void View_SetScale(View* view, f32 scale) {
    view->flags |= 4;
    view->scale = scale;
}

void View_GetScale(View* view, f32* scale) {
    *scale = view->scale;
}

void func_800AA460(View* view, f32 fovy, f32 near, f32 far) {
    view->fovy = fovy;
    view->zNear = near;
    view->zFar = far;
    view->flags |= 4;
}

void func_800AA48C(View* view, f32* fovy, f32* near, f32* far) {
    *fovy = view->fovy;
    *near = view->zNear;
    *far = view->zFar;
}

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;
}

void func_800AA4E0(View* view, f32* fovy, f32* near, f32* far) {
    *fovy = view->fovy;
    *near = view->zNear;
    *far = view->zFar;
}

void View_SetViewport(View* view, Viewport* viewport) {
    view->viewport = *viewport;
    view->flags |= 2;
}

void View_GetViewport(View* view, Viewport* viewport) {
    *viewport = view->viewport;
}

void func_800AA550(View* view) {
    s32 varY;
    s32 varX;
    s32 pad;
    s32 ulx;
    s32 uly;
    s32 lrx;
    s32 lry;
    GraphicsContext* gfxCtx;
    Gfx* dispRefs[5];

    gfxCtx = view->gfxCtx;

    varY = ShrinkWindow_GetCurrentVal();

    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;
    }
    if (varY > SCREEN_HEIGHT / 2) {
        varY = SCREEN_HEIGHT / 2;
    }

    ulx = view->viewport.leftX + varX;
    uly = view->viewport.topY + varY;
    lrx = view->viewport.rightX - varX;
    lry = view->viewport.bottomY - varY;

    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);

    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);
}

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;
}

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;
}

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;

    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);

        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);

    return 1;
}

void func_800AAA50(View* view, s32 arg1) {
    arg1 = (view->flags & arg1) | arg1 >> 4;

    if (arg1 & 8) {
        func_800AB0A8(view);
    } else {
        func_800AAA9C(view);
    }
}

s32 func_800AAA9C(View* view) {
    f32 aspect;
    s32 width;
    s32 height;
    Vp* vp;
    Mtx* projection;
    Mtx* viewing;
    GraphicsContext* gfxCtx;
    Gfx* dispRefs[5];

    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;

    func_800AA550(view);

    gSPViewport(gfxCtx->polyOpa.p++, vp);
    gSPViewport(gfxCtx->polyXlu.p++, vp);

    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;
        }
        guPerspective(projection, &view->normal, HREG(83), HREG(84) / 10000.0f, HREG(85), HREG(86), HREG(87) / 100.0f);
    } else {
        guPerspective(projection, &view->normal, view->fovy, aspect, view->zNear, view->zFar, view->scale);
    }

    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);
        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]);
        }
        osSyncPrintf("\n");
    }

    view->projection = *projection;

    func_800AA890(view, projection);

    gSPPerspNormalize(gfxCtx->polyOpa.p++, view->normal);
    gSPMatrix(gfxCtx->polyOpa.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
    gSPPerspNormalize(gfxCtx->polyXlu.p++, view->normal);
    gSPMatrix(gfxCtx->polyXlu.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);

    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) {
        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->up.y, view->up.z);

    view->viewing = *viewing;

    if (QREG(88) & 2) {
        s32 i;
        MtxF mf;

        Matrix_MtxToMtxF(view->viewingPtr, &mf);
        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]);
        }
        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);

    return 1;
}

s32 func_800AB0A8(View* view) {
    Vp* vp;
    Mtx* projection;
    GraphicsContext* gfxCtx;
    Gfx* dispRefs[5];

    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;

    func_800AA550(view);

    gSPViewport(gfxCtx->polyOpa.p++, vp);
    gSPViewport(gfxCtx->polyXlu.p++, vp);
    gSPViewport(gfxCtx->overlay.p++, vp);

    projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
    LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 744);
    view->projectionPtr = projection;

    guOrtho(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;

    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);

    return 1;
}

s32 func_800AB2C4(View* view) {
    Vp* vp;
    Mtx* projection;
    GraphicsContext* gfxCtx;
    Gfx* dispRefs[5];

    if (1) {} // Necessary to match

    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;

    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);

    projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
    LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 791);
    view->projectionPtr = projection;

    guOrtho(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;

    gSPMatrix(gfxCtx->overlay.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);

    Graph_CloseDisps(dispRefs, gfxCtx, "../z_view.c", 801);

    return 1;
}

s32 func_800AB560(View* view) {
    s32 pad[2];
    f32 aspect;
    s32 width;
    s32 height;
    Vp* vp;
    Mtx* projection;
    Mtx* viewing;
    GraphicsContext* gfxCtx;
    Gfx* dispRefs[5];

    gfxCtx = view->gfxCtx;
    Graph_OpenDisps(dispRefs, gfxCtx, "../z_view.c", 816);

    vp = Graph_Alloc(gfxCtx, sizeof(Vp));
    LogUtils_CheckNullPointer("vp", vp, "../z_view.c", 821);
    View_ViewportToVp(vp, &view->viewport);
    view->vp = *vp;

    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);

    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;

    gSPPerspNormalize(gfxCtx->overlay.p++, view->normal);
    gSPMatrix(gfxCtx->overlay.p++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);

    viewing = Graph_Alloc(gfxCtx, sizeof(Mtx));
    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) {
        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->up.y, view->up.z);

    view->viewing = *viewing;

    gSPMatrix(gfxCtx->overlay.p++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);

    Graph_CloseDisps(dispRefs, gfxCtx, "../z_view.c", 871);

    return 1;
}

s32 func_800AB944(View* view) {
    Gfx* dispRefs[5];

    Graph_OpenDisps(dispRefs, 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->up.x, view->up.y, view->up.z);

    Graph_CloseDisps(dispRefs, view->gfxCtx, "../z_view.c", 886);

    return 1;
}

#ifdef NON_MATCHING
// regalloc differences
s32 func_800AB9EC(View* view, s32 arg1, Gfx** gfxp) {
    Gfx* gfx = *gfxp;
    GraphicsContext* gfxCtx = view->gfxCtx;
    s32 width;
    s32 height;
    Vp* vp;
    Mtx* projection;
    Mtx* viewing;

    arg1 = (view->flags & arg1) | (arg1 >> 4);

    if (arg1 & 2) {
        vp = Graph_Alloc(gfxCtx, sizeof(Vp));
        LogUtils_CheckNullPointer("vp", vp, "../z_view.c", 910);
        View_ViewportToVp(vp, &view->viewport);

        view->vp = *vp;

        gDPPipeSync(gfx++);
        gDPSetScissor(gfx++, G_SC_NON_INTERLACE, view->viewport.leftX, view->viewport.topY, view->viewport.rightX,
                      view->viewport.bottomY);
        gSPViewport(gfx++, vp);
    }

    if (arg1 & 8) {
        projection = Graph_Alloc(gfxCtx, sizeof(Mtx));
        LogUtils_CheckNullPointer("projection", projection, "../z_view.c", 921);
        view->projectionPtr = projection;

        guOrtho(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;

        gSPMatrix(gfx++, projection, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
    } else if (arg1 & 6) {
        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);
    }

    if (arg1 & 1) {
        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->up.x, view->up.y, view->up.z);

        view->viewing = *viewing;

        gSPMatrix(gfx++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
    }

    view->flags = 0;
    *gfxp = gfx;

    return 1;
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/z_view/func_800AB9EC.s")
#endif

s32 func_800ABE74(f32 eyeX, f32 eyeY, f32 eyeZ) {
    s32 error = 0;

    if (SQ(eyeX) + SQ(eyeY) + SQ(eyeZ) > SQ(32767.0f)) {
        error = 3;
    } else {
        f32 absEyeX = ABS(eyeX);
        f32 absEyeY = ABS(eyeY);
        f32 absEyeZ = ABS(eyeZ);

        if (((18900.0f < absEyeX) || (18900.0f < absEyeY)) || (18900.0f < absEyeZ)) {
            error = 2;
        } else if (((16000.0f < absEyeX) || (16000.0f < absEyeY)) || (16000.0f < absEyeZ)) {
            error = 1;
        }
    }

    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);
        osSyncPrintf(VT_RST);
    }

    return error;
}