|
7 | 7 |
|
8 | 8 | #include "iCutscene.h" |
9 | 9 | #include "iModel.h" |
| 10 | +#include "zCamera.h" |
| 11 | +#include "zGlobals.h" |
| 12 | +#include "iAnim.h" |
10 | 13 |
|
11 | 14 | #include <types.h> |
12 | 15 | #include <string.h> |
@@ -287,6 +290,84 @@ float std::logf(float x) |
287 | 290 | return (float)log((double)x); |
288 | 291 | } |
289 | 292 |
|
| 293 | +static void xcsCalcAnimMatrices(RwMatrixTag* animMat, RpAtomic* model, xCutsceneAnimHdr* ahdr, F32 time, U32 tworoot) |
| 294 | +{ |
| 295 | + xQuat quatresult[65]; |
| 296 | + xVec3 tranresult[65]; |
| 297 | + |
| 298 | + void* afile = &ahdr[1]; |
| 299 | + iAnimEval(afile, time, 0x0, tranresult, quatresult); |
| 300 | + |
| 301 | + if (iModelNumBones(model) != 0) |
| 302 | + { |
| 303 | + xMat4x3Identity((xMat4x3*)animMat); |
| 304 | + animMat->pos.x = ahdr->Translate[0]; |
| 305 | + animMat->pos.y = ahdr->Translate[1]; |
| 306 | + animMat->pos.z = ahdr->Translate[2]; |
| 307 | + |
| 308 | + |
| 309 | + if (tworoot) |
| 310 | + { |
| 311 | + xMat4x3 m1; |
| 312 | + xMat4x3 m2; |
| 313 | + |
| 314 | + quatresult[1].s = -quatresult[1].s; |
| 315 | + quatresult[2].s = -quatresult[2].s; |
| 316 | + xQuatToMat(&quatresult[1], &m1); |
| 317 | + xQuatToMat(&quatresult[2], &m2); |
| 318 | + |
| 319 | + m1.pos = tranresult[1]; |
| 320 | + m2.pos = tranresult[2]; |
| 321 | + |
| 322 | + xMat4x3Mul(&m1, &m2, &m1); |
| 323 | + |
| 324 | + tranresult[2].x = 0.0f; |
| 325 | + tranresult[2].y = 0.0f; |
| 326 | + tranresult[2].z = 0.0f; |
| 327 | + quatresult[2].v.x = 0.0f; |
| 328 | + quatresult[2].v.y = 0.0f; |
| 329 | + quatresult[2].v.z = 0.0f; |
| 330 | + quatresult[2].s = 1.0f; |
| 331 | + |
| 332 | + xQuatFromMat(&quatresult[1], &m1); |
| 333 | + |
| 334 | + quatresult[1].s = -quatresult[1].s; |
| 335 | + m1.pos = tranresult[1]; |
| 336 | + } |
| 337 | + |
| 338 | + U32 numbone = iModelNumBones(model); |
| 339 | + U32 boneidx = 0; |
| 340 | + xQuat* qqq = quatresult; |
| 341 | + xVec3* ttt = tranresult; |
| 342 | + while (boneidx < numbone && boneidx <= ahdr->RootIndex) |
| 343 | + { |
| 344 | + animMat->pos.x += tranresult[boneidx].x; |
| 345 | + animMat->pos.y += tranresult[boneidx].y; |
| 346 | + animMat->pos.z += tranresult[boneidx].z; |
| 347 | + |
| 348 | + tranresult[boneidx].x = 0.0f; |
| 349 | + tranresult[boneidx].y = 0.0f; |
| 350 | + tranresult[boneidx].z = 0.0f; |
| 351 | + |
| 352 | + if (FABS(quatresult[boneidx].s) < 0.9999f) |
| 353 | + { |
| 354 | + break; |
| 355 | + } |
| 356 | + |
| 357 | + boneidx++; |
| 358 | + } |
| 359 | + |
| 360 | + iModelAnimMatrices(model, quatresult, tranresult, &animMat[1]); |
| 361 | + } |
| 362 | + else |
| 363 | + { |
| 364 | + xQuatToMat(quatresult, (xMat4x3*)animMat); |
| 365 | + animMat->pos.x = tranresult[0].x + ahdr->Translate[0]; |
| 366 | + animMat->pos.y = tranresult[0].y + ahdr->Translate[1]; |
| 367 | + animMat->pos.z = tranresult[0].z + ahdr->Translate[2]; |
| 368 | + } |
| 369 | +} |
| 370 | + |
290 | 371 | void xVec3Lerp(xVec3* out, const xVec3* a, const xVec3* b, float alpha) |
291 | 372 | { |
292 | 373 | out->x = a->x + (b->x - a->x) * alpha; |
|
0 commit comments