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
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
|
#include "global.h"
static CutsceneCamera* sCurCsCamera;
typedef s16 (*CsCamInterpolateCallback)(Vec3f*, f32*, s16*, CsCmdCamPoint*, CsCmdCamMisc*, CutsceneCameraInterp*);
s16 CutsceneCamera_Interp_Off(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd, CsCmdCamMisc* miscCmd,
CutsceneCameraInterp* interpState);
s16 CutsceneCamera_Interp_None(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd, CsCmdCamMisc* miscCmd,
CutsceneCameraInterp* interpState);
s16 CutsceneCamera_Interp_MultiPointQuadratic(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd,
CsCmdCamMisc* miscCmd, CutsceneCameraInterp* interpState);
s16 CutsceneCamera_Interp_MultiPointCubic(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd,
CsCmdCamMisc* miscCmd, CutsceneCameraInterp* interpState);
s16 CutsceneCamera_Interp_Set(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd, CsCmdCamMisc* miscCmd,
CutsceneCameraInterp* interpState);
s16 CutsceneCamera_Interp_Linear(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd,
CsCmdCamMisc* miscCmd, CutsceneCameraInterp* interpState);
s16 CutsceneCamera_Interp_Scale(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd,
CsCmdCamMisc* miscCmd, CutsceneCameraInterp* interpState);
s16 CutsceneCamera_Interp_Geo(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd, CsCmdCamMisc* miscCmd,
CutsceneCameraInterp* interpState);
s16 CutsceneCamera_Interp_Unused(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd,
CsCmdCamMisc* miscCmd, CutsceneCameraInterp* interpState);
f32 func_80163660(Actor* actor);
s16 CutsceneCamera_Interp_Off(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd, CsCmdCamMisc* miscCmd,
CutsceneCameraInterp* interpState) {
return 0;
}
/**
* Initializes Cutscene Camera Info
*/
s32 CutsceneCamera_Init(Camera* camera, CutsceneCamera* csCamera) {
csCamera->camera = camera;
csCamera->nextSplineTimer = csCamera->updateSplineTimer = 0;
csCamera->cmdIndex = 0;
csCamera->splineIndex = 0xFFFF;
csCamera->splineNeedsInit = true;
csCamera->state = CS_CAM_STATE_UPDATE_ALL;
sCurCsCamera = csCamera;
__osMemset(&csCamera->eyeInterp, 0, sizeof(CutsceneCameraInterp));
__osMemset(&csCamera->atInterp, 0, sizeof(CutsceneCameraInterp));
csCamera->eyeInterp.type = csCamera->atInterp.type = CS_CAM_INTERP_OFF;
return 1;
}
CsCamInterpolateCallback CutsceneCamera_Interpolate(u8 interpType) {
switch (interpType) {
case CS_CAM_INTERP_OFF:
default:
return CutsceneCamera_Interp_Off;
case CS_CAM_INTERP_NONE:
return CutsceneCamera_Interp_None;
case CS_CAM_INTERP_MP_QUAD:
return CutsceneCamera_Interp_MultiPointQuadratic;
case CS_CAM_INTERP_MP_CUBIC:
return CutsceneCamera_Interp_MultiPointCubic;
case CS_CAM_INTERP_SET:
return CutsceneCamera_Interp_Set;
case CS_CAM_INTERP_LINEAR:
return CutsceneCamera_Interp_Linear;
case CS_CAM_INTERP_SCALE:
return CutsceneCamera_Interp_Scale;
case CS_CAM_INTERP_GEO:
return CutsceneCamera_Interp_Geo;
}
}
u8 CutsceneCamera_ProcessSpline(CutsceneCamera* csCamera) {
s32 sp5C;
f32* camFov;
s16* camRoll;
CsCamInterpolateCallback interpHandler;
Player* player;
Actor* target;
s16 numPoints;
sp5C = true;
if (csCamera->state == CS_CAM_STATE_DONE_SPLINE) {
return false;
}
player = GET_PLAYER(csCamera->camera->play);
target = csCamera->camera->target;
if (csCamera->eyeCmd[csCamera->atInterp.curPoint].interpType <
csCamera->atCmd[csCamera->eyeInterp.curPoint].interpType) {
sp5C = false;
}
csCamera->eyeInterp.curPos = csCamera->camera->eye;
csCamera->atInterp.curPos = csCamera->camera->at;
if (sp5C) {
camFov = NULL;
} else {
camFov = &csCamera->camera->fov;
}
if (sp5C) {
camRoll = NULL;
} else {
camRoll = &csCamera->camera->roll;
}
interpHandler = CutsceneCamera_Interpolate(csCamera->atCmd[csCamera->eyeInterp.curPoint].interpType);
switch (csCamera->atCmd[csCamera->eyeInterp.curPoint].relativeTo) {
case CS_CAM_REL_2:
OLib_Vec3fDiff(&player->actor.world, &csCamera->camera->at, &csCamera->camera->at, OLIB_DIFF);
break;
case CS_CAM_REL_3:
OLib_Vec3fDiff(&player->actor.world, &csCamera->camera->at, &csCamera->camera->at, OLIB_DIFF_OFFSET);
break;
case CS_CAM_REL_1:
OLib_Vec3fDiff(&player->actor.world, &csCamera->camera->at, &csCamera->camera->at, OLIB_DIFF_OFFSET);
break;
case CS_CAM_REL_4:
OLib_Vec3fDiff(&target->world, &csCamera->camera->at, &csCamera->camera->at, OLIB_DIFF_OFFSET);
break;
case CS_CAM_REL_5:
OLib_Vec3fDiff(&target->world, &csCamera->camera->at, &csCamera->camera->at, OLIB_DIFF);
break;
default: // CS_CAM_REL_0
break;
}
numPoints = interpHandler(&csCamera->camera->at, camFov, camRoll, &csCamera->atCmd[csCamera->eyeInterp.curPoint],
&csCamera->miscCmd[csCamera->eyeInterp.curPoint], &csCamera->eyeInterp);
switch (csCamera->atCmd[csCamera->eyeInterp.curPoint].relativeTo) {
case CS_CAM_REL_2:
OLib_Vec3fAdd(&player->actor.world, &csCamera->camera->at, &csCamera->camera->at, OLIB_ADD);
break;
case CS_CAM_REL_3:
OLib_Vec3fAdd(&player->actor.world, &csCamera->camera->at, &csCamera->camera->at, OLIB_ADD_OFFSET);
csCamera->camera->at.y += func_80163660(&player->actor);
break;
case CS_CAM_REL_1:
OLib_Vec3fAdd(&player->actor.world, &csCamera->camera->at, &csCamera->camera->at, OLIB_ADD_OFFSET);
break;
case CS_CAM_REL_4:
OLib_Vec3fAdd(&target->world, &csCamera->camera->at, &csCamera->camera->at, OLIB_ADD_OFFSET);
break;
case CS_CAM_REL_5:
OLib_Vec3fAdd(&target->world, &csCamera->camera->at, &csCamera->camera->at, OLIB_ADD);
break;
default: // CS_CAM_REL_0
break;
}
csCamera->eyeInterp.curPoint += numPoints;
if (sp5C) {
camFov = &csCamera->camera->fov;
} else {
camFov = NULL;
}
if (sp5C) {
camRoll = &csCamera->camera->roll;
} else {
camRoll = NULL;
}
interpHandler = CutsceneCamera_Interpolate(csCamera->eyeCmd[csCamera->atInterp.curPoint].interpType);
switch (csCamera->eyeCmd[csCamera->atInterp.curPoint].relativeTo) {
case CS_CAM_REL_2:
OLib_Vec3fDiff(&player->actor.world, &csCamera->camera->eye, &csCamera->camera->eye, OLIB_DIFF);
break;
case CS_CAM_REL_3:
OLib_Vec3fDiff(&player->actor.world, &csCamera->camera->eye, &csCamera->camera->eye, OLIB_DIFF_OFFSET);
break;
case CS_CAM_REL_1:
OLib_Vec3fDiff(&player->actor.world, &csCamera->camera->eye, &csCamera->camera->eye, OLIB_DIFF_OFFSET);
break;
case CS_CAM_REL_4:
OLib_Vec3fDiff(&target->world, &csCamera->camera->eye, &csCamera->camera->eye, OLIB_DIFF_OFFSET);
break;
case CS_CAM_REL_5:
OLib_Vec3fDiff(&target->world, &csCamera->camera->eye, &csCamera->camera->eye, OLIB_DIFF);
break;
default: // CS_CAM_REL_0
break;
}
numPoints = interpHandler(&csCamera->camera->eye, camFov, camRoll, &csCamera->eyeCmd[csCamera->atInterp.curPoint],
&csCamera->miscCmd[csCamera->atInterp.curPoint], &csCamera->atInterp);
switch (csCamera->eyeCmd[csCamera->atInterp.curPoint].relativeTo) {
case CS_CAM_REL_2:
OLib_Vec3fAdd(&player->actor.world, &csCamera->camera->eye, &csCamera->camera->eye, OLIB_ADD);
break;
case CS_CAM_REL_3:
OLib_Vec3fAdd(&player->actor.world, &csCamera->camera->eye, &csCamera->camera->eye, OLIB_ADD_OFFSET);
csCamera->camera->eye.y += func_80163660(&player->actor);
break;
case CS_CAM_REL_1:
OLib_Vec3fAdd(&player->actor.world, &csCamera->camera->eye, &csCamera->camera->eye, OLIB_ADD_OFFSET);
break;
case CS_CAM_REL_4:
OLib_Vec3fAdd(&target->world, &csCamera->camera->eye, &csCamera->camera->eye, OLIB_ADD_OFFSET);
break;
case CS_CAM_REL_5:
OLib_Vec3fAdd(&target->world, &csCamera->camera->eye, &csCamera->camera->eye, OLIB_ADD);
break;
default: // CS_CAM_REL_0
break;
}
csCamera->atInterp.curPoint += numPoints;
if ((csCamera->eyeInterp.curPoint >= csCamera->eyeInterp.numEntries) ||
(csCamera->atInterp.curPoint >= csCamera->atInterp.numEntries)) {
return false;
}
return true;
}
/**
* Processes camera cutscene commands
*/
s32 CutsceneCamera_UpdateSplines(u8* script, CutsceneCamera* csCamera) {
CsCmdCamSpline* spline;
switch (csCamera->state) {
case CS_CAM_STATE_DONE:
return 0;
case CS_CAM_STATE_PAUSE:
return csCamera->nextSplineTimer;
case CS_CAM_STATE_UPDATE_SPLINE:
if (csCamera->updateSplineTimer <= csCamera->duration) {
csCamera->updateSplineTimer++;
if (csCamera->updateSplineTimer <= csCamera->duration) {
// Process Spline
if (!CutsceneCamera_ProcessSpline(csCamera)) {
csCamera->state = CS_CAM_STATE_DONE_SPLINE;
}
}
}
break;
case CS_CAM_STATE_DONE_SPLINE:
break;
default: // CS_CAM_STATE_UPDATE_ALL
if (csCamera->splineNeedsInit == true) {
// Spline Header
spline = (CsCmdCamSpline*)&script[csCamera->cmdIndex];
csCamera->atInterp.numEntries = csCamera->eyeInterp.numEntries = spline->numEntries;
csCamera->duration = spline->duration;
csCamera->cmdIndex += sizeof(CsCmdCamSpline);
// At Point
csCamera->atCmd = (CsCmdCamPoint*)&script[csCamera->cmdIndex];
csCamera->cmdIndex += (s16)(csCamera->eyeInterp.numEntries * sizeof(CsCmdCamPoint));
// Misc Point
csCamera->eyeCmd = (CsCmdCamPoint*)&script[csCamera->cmdIndex];
csCamera->cmdIndex += (s16)(csCamera->eyeInterp.numEntries * sizeof(CsCmdCamPoint));
// Misc
csCamera->miscCmd = (CsCmdCamMisc*)&script[csCamera->cmdIndex];
csCamera->cmdIndex += (s16)(csCamera->eyeInterp.numEntries * sizeof(CsCmdCamMisc));
// Other Params
csCamera->eyeInterp.curPoint = 0;
csCamera->atInterp.curPoint = 0;
csCamera->splineNeedsInit = false;
//! FAKE: csCamera->splineIndex++;
csCamera->splineIndex = (csCamera->splineIndex & 0xFFFF) + 1;
csCamera->state = CS_CAM_STATE_UPDATE_ALL;
csCamera->nextSplineTimer = csCamera->updateSplineTimer = 0;
csCamera->eyeInterp.type = csCamera->atInterp.type = CS_CAM_INTERP_OFF;
}
csCamera->nextSplineTimer++;
if (csCamera->updateSplineTimer <= csCamera->duration) {
csCamera->updateSplineTimer++;
if (csCamera->updateSplineTimer <= csCamera->duration) {
// Process SubCommands
if (!CutsceneCamera_ProcessSpline(csCamera)) {
csCamera->state = CS_CAM_STATE_DONE_SPLINE;
}
}
}
break;
}
if (csCamera->nextSplineTimer > csCamera->duration) {
// Next Spline
csCamera->splineNeedsInit = true;
spline = (CsCmdCamSpline*)&script[csCamera->cmdIndex];
if (spline->numEntries == -1) {
csCamera->state = CS_CAM_STATE_DONE;
return 0;
}
}
return csCamera->nextSplineTimer;
}
// Unused
s16 func_80161BAC(void) {
return (sCurCsCamera->state == CS_CAM_STATE_PAUSE) || (sCurCsCamera->state == CS_CAM_STATE_UPDATE_SPLINE);
}
void CutsceneCamera_SetState(s16 state) {
if (sCurCsCamera->state == CS_CAM_STATE_UPDATE_ALL) {
sCurCsCamera->state = state;
}
}
void CutsceneCamera_Reset(void) {
sCurCsCamera->state = CS_CAM_STATE_UPDATE_ALL;
}
// Linear interpolation from initial values to cmd values. Set weight to 100 to go all the way to the cmd value.
s16 CutsceneCamera_Interp_Linear(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd,
CsCmdCamMisc* miscCmd, CutsceneCameraInterp* interpState) {
f32 lerp;
if (interpState->type != CS_CAM_INTERP_LINEAR) {
// Initialize
interpState->type = CS_CAM_INTERP_LINEAR;
interpState->waypoint = 0;
interpState->curFrame = 0;
interpState->duration = 1;
if (camPos != NULL) {
interpState->initPos.x = camPos->x;
interpState->initPos.y = camPos->y;
interpState->initPos.z = camPos->z;
}
if (camFov != NULL) {
interpState->initFov = *camFov;
}
if (camRoll != NULL) {
interpState->initRoll = *camRoll;
}
}
interpState->curFrame++;
lerp = ((f32)interpState->curFrame / pointCmd->duration) * (pointCmd->weight / 100.0f);
if (camPos != NULL) {
VEC3F_LERPIMPDST(camPos, &interpState->initPos, &pointCmd->pos, lerp);
}
if (camFov != NULL) {
*camFov = LERPIMP(interpState->initFov, miscCmd->fov, lerp);
}
if (camRoll != NULL) {
s16 targetRoll;
s16 rollDiffToTarget;
targetRoll = CAM_DEG_TO_BINANG(miscCmd->roll);
rollDiffToTarget = (s16)(targetRoll - (s16)interpState->initRoll);
*camRoll = (s16)interpState->initRoll + (s16)(rollDiffToTarget * lerp);
}
if (interpState->curFrame >= pointCmd->duration) {
// Finished
interpState->type = CS_CAM_INTERP_OFF;
return 1;
}
return 0;
}
s16 CutsceneCamera_Interp_Scale(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd,
CsCmdCamMisc* miscCmd, CutsceneCameraInterp* interpState) {
f32 lerp;
f32 tmp1;
f32 tmp2;
if (interpState->type != CS_CAM_INTERP_SCALE) {
// Initialize
interpState->type = CS_CAM_INTERP_SCALE;
interpState->waypoint = 0;
interpState->curFrame = 0;
interpState->duration = 1;
if (camPos != NULL) {
interpState->initPos.x = camPos->x;
interpState->initPos.y = camPos->y;
interpState->initPos.z = camPos->z;
}
if (camFov != NULL) {
interpState->initFov = *camFov;
}
if (camRoll != NULL) {
interpState->initRoll = *camRoll;
}
}
tmp2 = (((pointCmd->weight + 100) * (pointCmd->duration / 2)) +
(((pointCmd->weight + 100) / 2) * (pointCmd->duration & 1)));
if (pointCmd->duration < 2) {
lerp = 1.0f;
} else {
tmp1 = (f32)(pointCmd->weight - 100) / (pointCmd->duration - 1);
lerp = ((interpState->curFrame * tmp1) + 100.0f) / tmp2;
}
interpState->curFrame++;
if (camPos != NULL) {
camPos->x += (pointCmd->pos.x - interpState->initPos.x) * lerp;
camPos->y += (pointCmd->pos.y - interpState->initPos.y) * lerp;
camPos->z += (pointCmd->pos.z - interpState->initPos.z) * lerp;
}
if (camFov != NULL) {
*camFov += (miscCmd->fov - interpState->initFov) * lerp;
}
if (camRoll != NULL) {
s16 targetRoll;
s16 rollDiffToTarget;
targetRoll = CAM_DEG_TO_BINANG(miscCmd->roll);
rollDiffToTarget = (s16)(targetRoll - (s16)interpState->initRoll);
*camRoll += (s16)(rollDiffToTarget * lerp);
}
if (interpState->curFrame >= pointCmd->duration) {
// Finished
interpState->type = CS_CAM_INTERP_OFF;
return 1;
}
return 0;
}
s16 CutsceneCamera_Interp_Geo(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd, CsCmdCamMisc* miscCmd,
CutsceneCameraInterp* interpState) {
VecGeo sp40;
f32 lerp;
f32 tmp1;
f32 tmp2;
if (interpState->type != CS_CAM_INTERP_GEO) {
// Initialize
interpState->type = CS_CAM_INTERP_GEO;
interpState->waypoint = 0;
interpState->curFrame = 0;
interpState->duration = 1;
if (camPos != NULL) {
interpState->unk_20 = OLib_Vec3fDist(&interpState->curPos, camPos) * Math_FTanF(DEG_TO_RAD(*camFov));
}
if (camFov != NULL) {
interpState->initFov = *camFov;
}
if (camRoll != NULL) {
interpState->initRoll = *camRoll;
}
}
tmp2 = (((pointCmd->weight + 100) * (pointCmd->duration / 2)) +
(((pointCmd->weight + 100) / 2) * (pointCmd->duration & 1)));
if (pointCmd->duration < 2) {
lerp = 1.0f;
} else {
tmp1 = (f32)(pointCmd->weight - 100) / (pointCmd->duration - 1);
lerp = ((interpState->curFrame * tmp1) + 100.0f) / tmp2;
}
interpState->curFrame++;
if (camPos != NULL) {
sp40 = OLib_Vec3fDiffToVecGeo(&interpState->curPos, camPos);
sp40.r = interpState->unk_20 / Math_FTanF(DEG_TO_RAD(*camFov));
*camPos = OLib_AddVecGeoToVec3f(&interpState->curPos, &sp40);
}
if (camFov != NULL) {
*camFov += (miscCmd->fov - interpState->initFov) * lerp;
}
if (camRoll != NULL) {
s16 targetRoll;
s16 rollDiffToTarget;
targetRoll = CAM_DEG_TO_BINANG(miscCmd->roll);
rollDiffToTarget = (s16)(targetRoll - (s16)interpState->initRoll);
*camRoll += (s16)(rollDiffToTarget * lerp);
}
if (interpState->curFrame >= pointCmd->duration) {
// Finished
interpState->type = CS_CAM_INTERP_OFF;
return 1;
}
return 0;
}
// Updates the interpolation state but does not change the pos/fov/roll values
s16 CutsceneCamera_Interp_None(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd, CsCmdCamMisc* miscCmd,
CutsceneCameraInterp* interpState) {
if (interpState->type != CS_CAM_INTERP_NONE) {
// Initialize
interpState->type = CS_CAM_INTERP_NONE;
interpState->waypoint = 0;
interpState->curFrame = 0;
interpState->duration = 1;
}
interpState->curFrame++;
if (interpState->curFrame >= pointCmd->duration) {
// Finishes
interpState->type = CS_CAM_INTERP_OFF;
return 1;
}
return 0;
}
// Immediately sets the values
s16 CutsceneCamera_Interp_Set(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd, CsCmdCamMisc* miscCmd,
CutsceneCameraInterp* interpState) {
s16 pad;
if (interpState->type != CS_CAM_INTERP_SET) {
// Initialize
interpState->type = CS_CAM_INTERP_SET;
interpState->waypoint = 0;
interpState->curFrame = 0;
interpState->duration = 1;
if (camFov != NULL) {
*camFov = miscCmd->fov;
}
if (camRoll != NULL) {
*camRoll = CAM_DEG_TO_BINANG(miscCmd->roll);
}
}
if (camPos != NULL) {
camPos->x = pointCmd->pos.x;
camPos->y = pointCmd->pos.y;
camPos->z = pointCmd->pos.z;
}
interpState->curFrame++;
if (interpState->curFrame >= pointCmd->duration) {
// Finished
interpState->type = CS_CAM_INTERP_OFF;
return 1;
}
return 0;
}
void func_801624EC(f32 u, f32* coeff) {
f32 u1 = 1.0f - u;
coeff[0] = u1 * u1 * 0.5f;
coeff[1] = u * u1 + 0.5f;
coeff[2] = u * u * 0.5f;
}
s16 CutsceneCamera_Interp_MultiPointQuadratic(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd,
CsCmdCamMisc* miscCmd, CutsceneCameraInterp* interpState) {
f32 new_var;
f32 coeff[3];
s32 waypoints[3];
if (interpState->type != CS_CAM_INTERP_MP_QUAD) {
// Initialize
interpState->type = CS_CAM_INTERP_MP_QUAD;
interpState->waypoint = 0;
interpState->duration = pointCmd->duration;
interpState->curFrame = 0;
}
new_var = (f32)interpState->curFrame / pointCmd[interpState->waypoint + 1].duration;
if (interpState->waypoint < (interpState->duration - 1)) {
waypoints[0] = interpState->waypoint;
} else {
waypoints[0] = interpState->duration - 1;
}
if ((interpState->waypoint + 1) < (interpState->duration - 1)) {
waypoints[1] = interpState->waypoint + 1;
} else {
waypoints[1] = interpState->duration - 1;
}
if ((interpState->waypoint + 2) < (interpState->duration - 1)) {
waypoints[2] = interpState->waypoint + 2;
} else {
waypoints[2] = interpState->duration - 1;
}
func_801624EC(new_var, coeff);
if (camPos != NULL) {
camPos->x = (coeff[0] * pointCmd[waypoints[0]].pos.x) + (coeff[1] * pointCmd[waypoints[1]].pos.x) +
(coeff[2] * pointCmd[waypoints[2]].pos.x);
camPos->y = (coeff[0] * pointCmd[waypoints[0]].pos.y) + (coeff[1] * pointCmd[waypoints[1]].pos.y) +
(coeff[2] * pointCmd[waypoints[2]].pos.y);
camPos->z = (coeff[0] * pointCmd[waypoints[0]].pos.z) + (coeff[1] * pointCmd[waypoints[1]].pos.z) +
(coeff[2] * pointCmd[waypoints[2]].pos.z);
}
if (camFov != NULL) {
*camFov = (coeff[0] * miscCmd[waypoints[0]].fov) + (coeff[1] * miscCmd[waypoints[1]].fov) +
(coeff[2] * miscCmd[waypoints[2]].fov);
}
if (camRoll != NULL) {
s16 targetRolls[3];
s32 sp28[2];
s32 rollDiffToTarget;
targetRolls[0] = CAM_DEG_TO_BINANG(miscCmd[waypoints[0]].roll);
targetRolls[1] = CAM_DEG_TO_BINANG(miscCmd[waypoints[1]].roll);
targetRolls[2] = CAM_DEG_TO_BINANG(miscCmd[waypoints[2]].roll);
sp28[0] = (s16)(targetRolls[1] - targetRolls[0]);
sp28[1] = sp28[0] + (s16)(targetRolls[2] - targetRolls[1]);
rollDiffToTarget = ((coeff[1] * sp28[0]) + (coeff[2] * sp28[1]));
*camRoll = targetRolls[0] + rollDiffToTarget;
}
interpState->curFrame++;
if (interpState->curFrame == pointCmd[interpState->waypoint + 1].duration) {
interpState->waypoint++;
interpState->curFrame = 0;
if (interpState->waypoint >= (interpState->duration - 2)) {
interpState->type = CS_CAM_INTERP_OFF;
return interpState->duration;
}
}
return 0;
}
/**
* This code is very similar to the spline system in OoT's func_800BB0A0
* in that it is based on the Super Mario 64 cutscene camera movement
*/
void func_801629BC(f32 u, f32* coeff) {
coeff[0] = (1.0f - u) * (1.0f - u) * (1.0f - u) * (1.0f / 6.0f);
coeff[1] = ((u * u * u * 0.5f) - u * u) + (2.0f / 3.0f);
coeff[2] = (u * u * u * -0.5f) + (u * u * 0.5f) + (u * 0.5f) + (1.0f / 6.0f);
coeff[3] = u * u * u * (1.0f / 6.0f);
}
s16 CutsceneCamera_Interp_MultiPointCubic(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd,
CsCmdCamMisc* miscCmd, CutsceneCameraInterp* interpState) {
f32 new_var;
f32 coeff[4];
s32 waypoints[4];
if (interpState->type != CS_CAM_INTERP_MP_CUBIC) {
// Initialize
interpState->type = CS_CAM_INTERP_MP_CUBIC;
interpState->waypoint = 0;
interpState->duration = pointCmd->duration;
interpState->curFrame = 0;
}
new_var = (f32)interpState->curFrame / pointCmd[interpState->waypoint + 1].duration;
if (interpState->waypoint < (interpState->duration - 1)) {
waypoints[0] = interpState->waypoint;
} else {
waypoints[0] = interpState->duration - 1;
}
if ((interpState->waypoint + 1) < (interpState->duration - 1)) {
waypoints[1] = interpState->waypoint + 1;
} else {
waypoints[1] = interpState->duration - 1;
}
if ((interpState->waypoint + 2) < (interpState->duration - 1)) {
waypoints[2] = interpState->waypoint + 2;
} else {
waypoints[2] = interpState->duration - 1;
}
if ((interpState->waypoint + 3) < (interpState->duration - 1)) {
waypoints[3] = interpState->waypoint + 3;
} else {
waypoints[3] = interpState->duration - 1;
}
func_801629BC(new_var, coeff);
if (camPos != NULL) {
camPos->x = (coeff[0] * pointCmd[waypoints[0]].pos.x) + (coeff[1] * pointCmd[waypoints[1]].pos.x) +
(coeff[2] * pointCmd[waypoints[2]].pos.x) + (coeff[3] * pointCmd[waypoints[3]].pos.x);
camPos->y = (coeff[0] * pointCmd[waypoints[0]].pos.y) + (coeff[1] * pointCmd[waypoints[1]].pos.y) +
(coeff[2] * pointCmd[waypoints[2]].pos.y) + (coeff[3] * pointCmd[waypoints[3]].pos.y);
camPos->z = (coeff[0] * pointCmd[waypoints[0]].pos.z) + (coeff[1] * pointCmd[waypoints[1]].pos.z) +
(coeff[2] * pointCmd[waypoints[2]].pos.z) + (coeff[3] * pointCmd[waypoints[3]].pos.z);
}
if (camFov != NULL) {
*camFov = (coeff[0] * miscCmd[waypoints[0]].fov) + (coeff[1] * miscCmd[waypoints[1]].fov) +
(coeff[2] * miscCmd[waypoints[2]].fov) + (coeff[3] * miscCmd[waypoints[3]].fov);
}
if (camRoll != NULL) {
s16 targetRolls[4];
s32 sp2C[3];
s32 rollDiffToTarget;
targetRolls[0] = CAM_DEG_TO_BINANG(miscCmd[waypoints[0]].roll);
targetRolls[1] = CAM_DEG_TO_BINANG(miscCmd[waypoints[1]].roll);
targetRolls[2] = CAM_DEG_TO_BINANG(miscCmd[waypoints[2]].roll);
targetRolls[3] = CAM_DEG_TO_BINANG(miscCmd[waypoints[3]].roll);
sp2C[0] = (s16)(targetRolls[1] - targetRolls[0]);
sp2C[1] = sp2C[0] + (s16)(targetRolls[2] - targetRolls[1]);
sp2C[2] = sp2C[1] + (s16)(targetRolls[3] - targetRolls[2]);
rollDiffToTarget = ((coeff[1] * sp2C[0]) + (coeff[2] * sp2C[1]) + (coeff[3] * sp2C[2]));
*camRoll = targetRolls[0] + rollDiffToTarget;
}
interpState->curFrame++;
if (interpState->curFrame == pointCmd[interpState->waypoint + 1].duration) {
interpState->curFrame = 0;
interpState->waypoint++;
if (interpState->waypoint >= (interpState->duration - 3)) {
interpState->type = CS_CAM_INTERP_OFF;
return interpState->duration;
}
}
return 0;
}
static f32 sKnots[38];
// Only used by unused CutsceneCamera_Interp_Unused
void func_80162FF8(s16 arg0) {
f32 val = 0.0f;
s32 i;
sKnots[0] = 0.0f;
sKnots[1] = 0.0f;
sKnots[2] = 0.0f;
for (i = 3; i < arg0; i++) {
if (i == 3) {
val += 0.9f;
} else if ((i == 4) || (i == (arg0 - 1))) {
val += 0.6f;
} else {
val += 0.3f;
}
sKnots[i] = val;
}
val += 0.9f;
sKnots[i++] = val;
sKnots[i++] = val;
sKnots[i++] = val;
}
#define FUNC_801631DC_ORDER 3
// Only used by unused CutsceneCamera_Interp_Unused
void func_801631DC(f32 progress, s32 arg2, f32* coeff) {
f32 coeffTemp[4][4];
s32 i;
s32 j;
s32 k;
for (i = 0; i < FUNC_801631DC_ORDER + 1; i++) {
for (j = 0; j < FUNC_801631DC_ORDER + 1; j++) {
coeffTemp[i][j] = 0.0f;
}
}
coeffTemp[0][FUNC_801631DC_ORDER - 1] = 1.0f;
for (i = 1; i < FUNC_801631DC_ORDER; i++) {
for (j = arg2 - i, k = (FUNC_801631DC_ORDER - 1) - i; j <= arg2; j++, k++) {
if (sKnots[j + i] != sKnots[j]) {
coeffTemp[i][k] = ((progress - sKnots[j]) / (sKnots[j + i] - sKnots[j])) * coeffTemp[i - 1][k];
} else {
coeffTemp[i][k] = 0.0f;
}
if (sKnots[j + i + 1] != sKnots[j + 1]) {
coeffTemp[i][k] +=
((sKnots[j + i + 1] - progress) / (sKnots[j + i + 1] - sKnots[j + 1])) * coeffTemp[i - 1][k + 1];
}
}
}
for (j = 0; j < FUNC_801631DC_ORDER; j++) {
coeff[j] = coeffTemp[FUNC_801631DC_ORDER - 1][j];
}
}
s16 CutsceneCamera_Interp_Unused(Vec3f* camPos, f32* camFov, s16* camRoll, CsCmdCamPoint* pointCmd,
CsCmdCamMisc* miscCmd, CutsceneCameraInterp* interpState) {
s32 index;
f32 coeff[3];
if (interpState->type != CS_CAM_INTERP_MP_CUBIC) {
// Initialize
interpState->type = CS_CAM_INTERP_MP_CUBIC;
interpState->waypoint = 0;
interpState->duration = pointCmd->duration;
func_80162FF8(interpState->duration);
interpState->curFrame = 0;
}
index = interpState->waypoint + 2;
func_801631DC(F32_LERPIMP(sKnots[index], sKnots[index + 1],
(f32)interpState->curFrame / miscCmd[interpState->waypoint].unused0),
index, coeff);
if (camPos != NULL) {
camPos->x = (coeff[0] * pointCmd[interpState->waypoint].pos.x) +
(coeff[1] * pointCmd[interpState->waypoint + 1].pos.x) +
(coeff[2] * pointCmd[interpState->waypoint + 2].pos.x);
camPos->y = (coeff[0] * pointCmd[interpState->waypoint].pos.y) +
(coeff[1] * pointCmd[interpState->waypoint + 1].pos.y) +
(coeff[2] * pointCmd[interpState->waypoint + 2].pos.y);
camPos->z = (coeff[0] * pointCmd[interpState->waypoint].pos.z) +
(coeff[1] * pointCmd[interpState->waypoint + 1].pos.z) +
(coeff[2] * pointCmd[interpState->waypoint + 2].pos.z);
}
if (camFov != NULL) {
*camFov = (coeff[0] * miscCmd[interpState->waypoint].fov) +
(coeff[1] * miscCmd[interpState->waypoint + 1].fov) +
(coeff[2] * miscCmd[interpState->waypoint + 2].fov);
}
if (camRoll != NULL) {
*camRoll = CAM_DEG_TO_BINANG((coeff[0] * miscCmd[interpState->waypoint].roll) +
(coeff[1] * miscCmd[interpState->waypoint + 1].roll) +
(coeff[2] * miscCmd[interpState->waypoint + 2].roll));
}
interpState->curFrame++;
if (interpState->curFrame >= miscCmd[interpState->waypoint].unused0) {
interpState->waypoint++;
interpState->curFrame = 0;
if (interpState->waypoint >= (interpState->duration - 2)) {
interpState->type = CS_CAM_INTERP_OFF;
return interpState->duration;
}
}
return 0;
}
f32 func_80163660(Actor* actor) {
if (actor->category != ACTORCAT_PLAYER) {
return 38.0f - (actor->focus.pos.y - actor->world.pos.y);
}
switch (((Player*)actor)->transformation) {
case PLAYER_FORM_DEKU:
return -8.0f;
case PLAYER_FORM_GORON:
return 23.0f;
case PLAYER_FORM_ZORA:
return 27.0f;
case PLAYER_FORM_FIERCE_DEITY:
return 17.0f;
default:
return 0.0f;
}
}
|