Skip to content

Commit b82375e

Browse files
authored
Merge pull request #695 from JoshSanch/xCutscene
xCutscene: Progress and Cleanup
2 parents adfaab8 + 896767c commit b82375e

File tree

6 files changed

+206
-44
lines changed

6 files changed

+206
-44
lines changed

configure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def MatchingFor(*versions):
418418
Object(Matching, "SB/Core/x/xCollideFast.cpp"),
419419
Object(Matching, "SB/Core/x/xColor.cpp"),
420420
Object(Matching, "SB/Core/x/xCounter.cpp"),
421-
Object(NonMatching, "SB/Core/x/xCutscene.cpp"),
421+
Object(NonMatching, "SB/Core/x/xCutscene.cpp", extra_cflags=["-sym on"]),
422422
Object(NonMatching, "SB/Core/x/xDebug.cpp", extra_cflags=["-sym on"]),
423423
Object(Equivalent, "SB/Core/x/xEnt.cpp", extra_cflags=["-sym on"]),
424424
Object(Equivalent, "SB/Core/x/xEntDrive.cpp", extra_cflags=["-sym on"]),

src/PowerPC_EABI_Support/include/PowerPC_EABI_Support/MSL_C/MSL_Common/cmath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace std
99

1010
#ifndef INLINE
1111
float atan2f(float y, float x);
12+
float atan(float x);
1213
float sinf(float x);
1314
float cosf(float x);
1415
float tanf(float x);
@@ -25,6 +26,11 @@ namespace std
2526
return (float)atan2((double)y, (double)x);
2627
}
2728

29+
inline float atan(float x)
30+
{
31+
return (float)atan((double)x);
32+
}
33+
2834
inline float sinf(float x)
2935
{
3036
return (float)sin((double)x);

src/SB/Core/gc/iCutscene.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ S32 iCSLoadStep(xCutscene* csn)
232232

233233
while (csn->DataLoading < (S32)csn->Info->NumData)
234234
{
235-
if (csn->Data[csn->DataLoading].DataType == XCUTSCENEDATA_TYPE_6)
235+
if (csn->Data[csn->DataLoading].DataType == XCUTSCENEDATA_TYPE_JDELTAMODEL)
236236
{
237237
foundModel = NULL;
238238
}
@@ -260,7 +260,7 @@ S32 iCSLoadStep(xCutscene* csn)
260260

261261
if (csn->GotData)
262262
{
263-
if (csn->Data[csn->DataLoading].DataType == XCUTSCENEDATA_TYPE_6)
263+
if (csn->Data[csn->DataLoading].DataType == XCUTSCENEDATA_TYPE_JDELTAMODEL)
264264
{
265265
csn->Data[csn->DataLoading].DataPtr =
266266
RwMalloc(csn->Data[csn->DataLoading].ChunkSize);

src/SB/Core/x/xCamera.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ extern RpAtomic* sInvisWallHack;
6666
extern xMat4x3 sCameraFXMatOld;
6767
extern cameraFX sCameraFX[10];
6868
extern cameraFXTableEntry sCameraFXTable[3];
69+
extern F32 gCameraLastFov;
6970

7071
struct xScene;
7172

src/SB/Core/x/xCutscene.cpp

Lines changed: 174 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
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+
147181
S32 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

297443
void 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

317463
xCutscene* 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-
}

src/SB/Core/x/xCutscene.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@
33

44
#include "xFile.h"
55
#include "rpworld.h"
6+
#include "xCamera.h"
7+
8+
#define XCUTSCENEDATA_TYPE_RW_MODEL 1
9+
#define XCUTSCENEDATA_TYPE_ANIMATION 2
10+
#define XCUTSCENEDATA_TYPE_CAMERA 3
11+
#define XCUTSCENEDATA_TYPE_MORPHTARGET 4
12+
#define XCUTSCENEDATA_TYPE_SOUND 5
13+
#define XCUTSCENEDATA_TYPE_JDELTAMODEL 6
14+
#define XCUTSCENEDATA_TYPE_JDELTAANIM 7
15+
16+
struct xCutsceneAnimHdr {
17+
U32 RootIndex;
18+
F32 Translate[3];
19+
};
620

721
struct xCutsceneInfo
822
{
@@ -34,9 +48,6 @@ struct xCutsceneData
3448
};
3549
};
3650

37-
#define XCUTSCENEDATA_TYPE_SOUND 5
38-
#define XCUTSCENEDATA_TYPE_6 6
39-
4051
struct xCutsceneBreak
4152
{
4253
F32 Time;
@@ -56,8 +67,13 @@ struct XCSNNosey
5667
void* userdata;
5768
S32 flg_nosey;
5869

59-
void CanRenderNow();
60-
void UpdatedAnimated(RpAtomic*, RwMatrixTag*, U32, U32);
70+
void CanRenderNow()
71+
{
72+
}
73+
74+
void UpdatedAnimated(RpAtomic*, RwMatrixTag*, U32, U32)
75+
{
76+
}
6177
};
6278

6379
struct xCutscene
@@ -115,6 +131,7 @@ xCutscene* xCutscene_Create(U32 id);
115131
S32 xCutscene_Destroy(xCutscene* csn);
116132
S32 xCutscene_LoadStart(xCutscene* csn);
117133
void xCutscene_SetSpeed(xCutscene* csn, F32 speed);
134+
void xCutscene_SetCamera(xCutscene* csn, xCamera* cam);
118135
F32 xCutsceneConvertBreak(float time, xCutsceneBreak* breaklist, U32 breakcount, int idx);
119136
S32 xCutscene_Update(xCutscene* csn, F32 dt);
120137
void CutsceneShadowRender(CutsceneShadowModel* smod);

0 commit comments

Comments
 (0)