77
88#include " iCutscene.h"
99#include " iModel.h"
10+ #include " zCamera.h"
11+ #include " zGlobals.h"
12+ #include " iAnim.h"
1013
1114#include < types.h>
1215#include < string.h>
@@ -144,6 +147,37 @@ S32 xCutscene_LoadStart(xCutscene* csn)
144147 return 1 ;
145148}
146149
150+ F32 xCutsceneConvertBreak (float param_1, xCutsceneBreak* param_2, U32 param_3, int param_4)
151+ {
152+ int i = 0 ;
153+ if (param_3 == 0 )
154+ {
155+ return param_1;
156+ }
157+ while (true )
158+ {
159+ if (param_4 != param_2[i].Index )
160+ {
161+ break ;
162+ }
163+ if (param_2[i].Time - param_1 <= 0 .0f )
164+ {
165+ break ;
166+ }
167+ if (0 .03333333f <= param_2[i].Time - param_1)
168+ {
169+ break ;
170+ }
171+ i++;
172+ param_3--;
173+ if (param_3 == 0 )
174+ {
175+ return param_1;
176+ }
177+ }
178+ return param_2[i].Time - 0 .03333333f ;
179+ }
180+
147181S32 xCutscene_Update (xCutscene* csn, F32 dt)
148182{
149183 if ((csn->SndStarted == FALSE ) && (csn->SndNumChannel != 0 ))
@@ -231,7 +265,7 @@ void xCutscene_SetSpeed(xCutscene* csn, F32 speed)
231265 csn->PlaybackSpeed = speed;
232266
233267 F32 semitones;
234- if (speed != 0 . 0f )
268+ if (speed)
235269 {
236270 semitones = xlog (speed) / 0 .057762269f ;
237271 }
@@ -256,42 +290,154 @@ float std::logf(float x)
256290 return (float )log ((double )x);
257291}
258292
259- void xVec3Lerp (xVec3* out, const xVec3* a, const xVec3* b, float alpha)
293+ // TODO: general pointer/index mismatching in here
294+ // instructions and control flow should be close match though
295+ void xCutscene_SetCamera (xCutscene* csn, xCamera* cam)
260296{
261- out->x = a->x + (b->x - a->x ) * alpha;
262- out->y = a->y + (b->y - a->y ) * alpha;
263- out->z = a->z + (b->z - a->z ) * alpha;
297+ xCutsceneData* data = (xCutsceneData*)&csn->Play [1 ];
298+ for (U32 i = 0 ; i < csn->Play ->NumData ; i++)
299+ {
300+ if (data[i].DataType == XCUTSCENEDATA_TYPE_CAMERA)
301+ {
302+ U32 dataIndex = data[i + 1 ].DataType ;
303+ S32 frame = std::floorf (30 .0f * csn->CamTime );
304+ zFlyKey* keys = (zFlyKey*)((char *)&data[i] + 0x14 );
305+
306+ F32 lerp;
307+ if (keys[i + 1 ].frame < frame)
308+ {
309+ lerp = 0 .0f ;
310+ }
311+ else if (keys[i].frame >= frame)
312+ {
313+ lerp = 1 .0f ;
314+ keys += keys[i].frame - 2 ;
315+ }
316+ else
317+ {
318+ lerp = 30 .0f * csn->CamTime - std::floorf (30 .0f * csn->CamTime );
319+ keys += keys[i].frame - frame;
320+ }
321+
322+ F32 invlerp = 1 .0f - lerp;
323+
324+ xMat4x3 camMat;
325+ xMat3x3 tmpMat;
326+ xQuat quats[2 ];
327+ for (U32 j = 0 ; j < 2 ; j++)
328+ {
329+ tmpMat.right .x = -keys[j].matrix [0 ];
330+ tmpMat.right .y = -keys[j].matrix [1 ];
331+ tmpMat.right .z = -keys[j].matrix [2 ];
332+ tmpMat.up .x = keys[j].matrix [3 ];
333+ tmpMat.up .y = keys[j].matrix [4 ];
334+ tmpMat.up .z = keys[j].matrix [5 ];
335+ tmpMat.at .x = -keys[j].matrix [6 ];
336+ tmpMat.at .y = -keys[j].matrix [7 ];
337+ tmpMat.at .z = -keys[j].matrix [8 ];
338+ xQuatFromMat (&quats[j], &tmpMat);
339+ }
340+
341+ xQuat qresult;
342+ xQuatSlerp (&qresult, &quats[0 ], &quats[1 ], lerp);
343+ xQuatToMat (&qresult, &camMat);
344+ xVec3Lerp (&camMat.pos , (xVec3*)&keys[0 ].matrix [9 ], (xVec3*)&keys[1 ].matrix [9 ], lerp);
345+
346+ U32 count;
347+
348+ F32 camFOV = 114 .59155f *
349+ std::atan ((12 .7f * (keys[0 ].aperture [0 ] * lerp + keys[1 ].aperture [0 ] * invlerp)) /
350+ (keys[0 ].focal * lerp + keys[1 ].focal * invlerp));
351+ cam->mat = camMat;
352+ gCameraLastFov = 0 .0f ;
353+ xCameraSetFOV (&xglobals->camera , camFOV);
354+ }
355+ }
264356}
265357
266- F32 xCutsceneConvertBreak (float param_1, xCutsceneBreak* param_2, U32 param_3, int param_4)
358+ static void xcsCalcAnimMatrices (RwMatrixTag* animMat, RpAtomic* model, xCutsceneAnimHdr* ahdr,
359+ F32 time, U32 tworoot)
267360{
268- int i = 0 ;
269- if (param_3 == 0 )
270- {
271- return param_1;
272- }
273- while (true )
361+ xQuat quatresult[65 ];
362+ xVec3 tranresult[65 ];
363+
364+ void * afile = &ahdr[1 ];
365+ iAnimEval (afile, time, 0x0 , tranresult, quatresult);
366+
367+ if (iModelNumBones (model) != 0 )
274368 {
275- if (param_4 != param_2[i].Index )
276- {
277- break ;
278- }
279- if (param_2[i].Time - param_1 <= 0 .0f )
280- {
281- break ;
282- }
283- if (0 .03333333f <= param_2[i].Time - param_1)
369+ xMat4x3Identity ((xMat4x3*)animMat);
370+ animMat->pos .x = ahdr->Translate [0 ];
371+ animMat->pos .y = ahdr->Translate [1 ];
372+ animMat->pos .z = ahdr->Translate [2 ];
373+
374+ if (tworoot)
284375 {
285- break ;
376+ xMat4x3 m1;
377+ xMat4x3 m2;
378+
379+ quatresult[1 ].s = -quatresult[1 ].s ;
380+ quatresult[2 ].s = -quatresult[2 ].s ;
381+ xQuatToMat (&quatresult[1 ], &m1);
382+ xQuatToMat (&quatresult[2 ], &m2);
383+
384+ m1.pos = tranresult[1 ];
385+ m2.pos = tranresult[2 ];
386+
387+ xMat4x3Mul (&m1, &m2, &m1);
388+
389+ tranresult[2 ].x = 0 .0f ;
390+ tranresult[2 ].y = 0 .0f ;
391+ tranresult[2 ].z = 0 .0f ;
392+ quatresult[2 ].v .x = 0 .0f ;
393+ quatresult[2 ].v .y = 0 .0f ;
394+ quatresult[2 ].v .z = 0 .0f ;
395+ quatresult[2 ].s = 1 .0f ;
396+
397+ xQuatFromMat (&quatresult[1 ], &m1);
398+
399+ quatresult[1 ].s = -quatresult[1 ].s ;
400+ m1.pos = tranresult[1 ];
286401 }
287- i++;
288- param_3--;
289- if (param_3 == 0 )
402+
403+ U32 numbone = iModelNumBones (model);
404+ U32 boneidx = 0 ;
405+ xQuat* qqq = quatresult;
406+ xVec3* ttt = tranresult;
407+ while (boneidx < numbone && boneidx <= ahdr->RootIndex )
290408 {
291- return param_1;
409+ animMat->pos .x += tranresult[boneidx].x ;
410+ animMat->pos .y += tranresult[boneidx].y ;
411+ animMat->pos .z += tranresult[boneidx].z ;
412+
413+ tranresult[boneidx].x = 0 .0f ;
414+ tranresult[boneidx].y = 0 .0f ;
415+ tranresult[boneidx].z = 0 .0f ;
416+
417+ if (FABS (quatresult[boneidx].s ) < 0 .9999f )
418+ {
419+ break ;
420+ }
421+
422+ boneidx++;
292423 }
424+
425+ iModelAnimMatrices (model, quatresult, tranresult, &animMat[1 ]);
426+ }
427+ else
428+ {
429+ xQuatToMat (quatresult, (xMat4x3*)animMat);
430+ animMat->pos .x = tranresult[0 ].x + ahdr->Translate [0 ];
431+ animMat->pos .y = tranresult[0 ].y + ahdr->Translate [1 ];
432+ animMat->pos .z = tranresult[0 ].z + ahdr->Translate [2 ];
293433 }
294- return param_2[i].Time - 0 .03333333f ;
434+ }
435+
436+ void xVec3Lerp (xVec3* out, const xVec3* a, const xVec3* b, float alpha)
437+ {
438+ out->x = a->x + (b->x - a->x ) * alpha;
439+ out->y = a->y + (b->y - a->y ) * alpha;
440+ out->z = a->z + (b->z - a->z ) * alpha;
295441}
296442
297443void CutsceneShadowRender (CutsceneShadowModel* smod)
@@ -310,19 +456,11 @@ void CutsceneShadowRender(CutsceneShadowModel* smod)
310456 }
311457}
312458
313- void xCutscene_Render (xCutscene*, xEnt**, S32*, F32*)
459+ void xCutscene_Render (xCutscene* csn , xEnt**, S32*, F32*)
314460{
315461}
316462
317463xCutscene* xCutscene_CurrentCutscene ()
318464{
319465 return &sActiveCutscene ;
320466}
321-
322- void XCSNNosey::CanRenderNow ()
323- {
324- }
325-
326- void XCSNNosey::UpdatedAnimated (RpAtomic*, RwMatrixTag*, U32, U32)
327- {
328- }
0 commit comments