@@ -290,7 +290,73 @@ float std::logf(float x)
290290 return (float )log ((double )x);
291291}
292292
293- static void xcsCalcAnimMatrices (RwMatrixTag* animMat, RpAtomic* model, xCutsceneAnimHdr* ahdr, F32 time, U32 tworoot)
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)
296+ {
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+ }
356+ }
357+
358+ static void xcsCalcAnimMatrices (RwMatrixTag* animMat, RpAtomic* model, xCutsceneAnimHdr* ahdr,
359+ F32 time, U32 tworoot)
294360{
295361 xQuat quatresult[65 ];
296362 xVec3 tranresult[65 ];
@@ -305,7 +371,6 @@ static void xcsCalcAnimMatrices(RwMatrixTag* animMat, RpAtomic* model, xCutscene
305371 animMat->pos .y = ahdr->Translate [1 ];
306372 animMat->pos .z = ahdr->Translate [2 ];
307373
308-
309374 if (tworoot)
310375 {
311376 xMat4x3 m1;
@@ -344,11 +409,11 @@ static void xcsCalcAnimMatrices(RwMatrixTag* animMat, RpAtomic* model, xCutscene
344409 animMat->pos .x += tranresult[boneidx].x ;
345410 animMat->pos .y += tranresult[boneidx].y ;
346411 animMat->pos .z += tranresult[boneidx].z ;
347-
412+
348413 tranresult[boneidx].x = 0 .0f ;
349414 tranresult[boneidx].y = 0 .0f ;
350415 tranresult[boneidx].z = 0 .0f ;
351-
416+
352417 if (FABS (quatresult[boneidx].s ) < 0 .9999f )
353418 {
354419 break ;
@@ -391,7 +456,7 @@ void CutsceneShadowRender(CutsceneShadowModel* smod)
391456 }
392457}
393458
394- void xCutscene_Render (xCutscene*, xEnt**, S32*, F32*)
459+ void xCutscene_Render (xCutscene* csn , xEnt**, S32*, F32*)
395460{
396461}
397462
0 commit comments