2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
|
|
|
#include "vt.h"
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
#define ANIM_INTERP 1
|
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
s32 LinkAnimation_Loop(PlayState* play, SkelAnime* skelAnime);
|
|
|
|
s32 LinkAnimation_Once(PlayState* play, SkelAnime* skelAnime);
|
2020-12-29 22:46:46 +00:00
|
|
|
s32 SkelAnime_LoopFull(SkelAnime* skelAnime);
|
|
|
|
s32 SkelAnime_Once(SkelAnime* skelAnime);
|
|
|
|
s32 SkelAnime_LoopPartial(SkelAnime* skelAnime);
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
static u32 sDisableAnimQueueFlags = 0;
|
|
|
|
static u32 sAnimQueueFlags;
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2020-12-02 03:19:56 +00:00
|
|
|
* Draw a limb of type `LodLimb`
|
|
|
|
* Near or far display list is specified via `lod`
|
2020-04-01 01:19:21 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void SkelAnime_DrawLimbLod(PlayState* play, s32 limbIndex, void** skeleton, Vec3s* jointTable,
|
2020-12-02 03:19:56 +00:00
|
|
|
OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg, s32 lod) {
|
|
|
|
LodLimb* limb;
|
2020-03-20 21:12:26 +00:00
|
|
|
Gfx* dList;
|
2020-03-21 02:51:12 +00:00
|
|
|
Vec3f pos;
|
|
|
|
Vec3s rot;
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
OPEN_DISPS(play->state.gfxCtx, "../z_skelanime.c", 773);
|
2020-08-29 23:00:17 +00:00
|
|
|
|
2020-03-20 21:12:26 +00:00
|
|
|
Matrix_Push();
|
2020-12-02 03:19:56 +00:00
|
|
|
limb = (LodLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]);
|
2020-03-20 21:12:26 +00:00
|
|
|
limbIndex++;
|
2020-12-29 22:46:46 +00:00
|
|
|
rot = jointTable[limbIndex];
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
pos.x = limb->jointPos.x;
|
|
|
|
pos.y = limb->jointPos.y;
|
|
|
|
pos.z = limb->jointPos.z;
|
|
|
|
|
|
|
|
dList = limb->dLists[lod];
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
if ((overrideLimbDraw == NULL) || !overrideLimbDraw(play, limbIndex, &dList, &pos, &rot, arg)) {
|
2021-11-17 10:52:26 +00:00
|
|
|
Matrix_TranslateRotateZYX(&pos, &rot);
|
2020-03-24 17:16:13 +00:00
|
|
|
if (dList != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx, "../z_skelanime.c", 805), G_MTX_LOAD);
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPDisplayList(POLY_OPA_DISP++, dList);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
if (1) {}
|
|
|
|
|
2020-04-18 18:08:12 +00:00
|
|
|
if (postLimbDraw != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
postLimbDraw(play, limbIndex, &dList, &rot, arg);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
if (limb->child != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
SkelAnime_DrawLimbLod(play, limb->child, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg, lod);
|
2020-03-21 02:51:12 +00:00
|
|
|
}
|
|
|
|
|
2021-02-24 19:28:04 +00:00
|
|
|
Matrix_Pop();
|
2020-03-21 02:51:12 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
if (limb->sibling != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
SkelAnime_DrawLimbLod(play, limb->sibling, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg, lod);
|
2020-03-21 02:51:12 +00:00
|
|
|
}
|
2020-03-24 16:52:12 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
CLOSE_DISPS(play->state.gfxCtx, "../z_skelanime.c", 821);
|
2020-03-21 02:51:12 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2020-12-02 03:19:56 +00:00
|
|
|
* Draw all limbs of type `LodLimb` in a given skeleton
|
|
|
|
* Near or far display list is specified via `lod`
|
2020-04-01 01:19:21 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void SkelAnime_DrawLod(PlayState* play, void** skeleton, Vec3s* jointTable, OverrideLimbDrawOpa overrideLimbDraw,
|
|
|
|
PostLimbDrawOpa postLimbDraw, void* arg, s32 lod) {
|
2020-12-02 03:19:56 +00:00
|
|
|
LodLimb* rootLimb;
|
|
|
|
s32 pad;
|
2020-03-21 02:51:12 +00:00
|
|
|
Gfx* dList;
|
|
|
|
Vec3f pos;
|
|
|
|
Vec3s rot;
|
|
|
|
|
2020-03-25 15:51:25 +00:00
|
|
|
if (skeleton == NULL) {
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(RED));
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("Si2_Lod_draw():skelがNULLです。\n"); // "skel is NULL."
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-21 02:51:12 +00:00
|
|
|
return;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-08-29 23:00:17 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
OPEN_DISPS(play->state.gfxCtx, "../z_skelanime.c", 849);
|
2020-08-29 23:00:17 +00:00
|
|
|
|
2020-03-21 02:51:12 +00:00
|
|
|
Matrix_Push();
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
rootLimb = (LodLimb*)SEGMENTED_TO_VIRTUAL(skeleton[0]);
|
2020-12-29 22:46:46 +00:00
|
|
|
pos.x = jointTable[0].x;
|
|
|
|
pos.y = jointTable[0].y;
|
|
|
|
pos.z = jointTable[0].z;
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
rot = jointTable[1];
|
2020-12-02 03:19:56 +00:00
|
|
|
dList = rootLimb->dLists[lod];
|
2020-03-21 02:51:12 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
if ((overrideLimbDraw == NULL) || !overrideLimbDraw(play, 1, &dList, &pos, &rot, arg)) {
|
2021-11-17 10:52:26 +00:00
|
|
|
Matrix_TranslateRotateZYX(&pos, &rot);
|
2020-03-24 17:16:13 +00:00
|
|
|
if (dList != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx, "../z_skelanime.c", 881), G_MTX_LOAD);
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPDisplayList(POLY_OPA_DISP++, dList);
|
2020-03-21 02:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-18 18:08:12 +00:00
|
|
|
if (postLimbDraw != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
postLimbDraw(play, 1, &dList, &rot, arg);
|
2020-03-21 02:51:12 +00:00
|
|
|
}
|
2020-03-24 16:52:12 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
if (rootLimb->child != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
SkelAnime_DrawLimbLod(play, rootLimb->child, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg, lod);
|
2020-03-21 02:51:12 +00:00
|
|
|
}
|
2020-03-24 16:52:12 +00:00
|
|
|
|
2021-02-24 19:28:04 +00:00
|
|
|
Matrix_Pop();
|
2020-08-29 23:00:17 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
CLOSE_DISPS(play->state.gfxCtx, "../z_skelanime.c", 894);
|
2020-03-21 02:51:12 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2020-12-02 03:19:56 +00:00
|
|
|
* Draw a limb of type `LodLimb` contained within a flexible skeleton
|
|
|
|
* Near or far display list is specified via `lod`
|
2020-04-01 01:19:21 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void SkelAnime_DrawFlexLimbLod(PlayState* play, s32 limbIndex, void** skeleton, Vec3s* jointTable,
|
2020-12-02 03:19:56 +00:00
|
|
|
OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg, s32 lod,
|
|
|
|
Mtx** mtx) {
|
|
|
|
LodLimb* limb;
|
|
|
|
Gfx* newDList;
|
|
|
|
Gfx* limbDList;
|
2020-03-21 02:51:12 +00:00
|
|
|
Vec3f pos;
|
|
|
|
Vec3s rot;
|
|
|
|
|
|
|
|
Matrix_Push();
|
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
limb = (LodLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]);
|
2020-03-21 02:51:12 +00:00
|
|
|
limbIndex++;
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
rot = jointTable[limbIndex];
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
pos.x = limb->jointPos.x;
|
|
|
|
pos.y = limb->jointPos.y;
|
|
|
|
pos.z = limb->jointPos.z;
|
|
|
|
|
|
|
|
newDList = limbDList = limb->dLists[lod];
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
if ((overrideLimbDraw == NULL) || !overrideLimbDraw(play, limbIndex, &newDList, &pos, &rot, arg)) {
|
2021-11-17 10:52:26 +00:00
|
|
|
Matrix_TranslateRotateZYX(&pos, &rot);
|
2020-12-02 03:19:56 +00:00
|
|
|
if (newDList != NULL) {
|
2020-03-24 17:16:13 +00:00
|
|
|
Matrix_ToMtx(*mtx, "../z_skelanime.c", 945);
|
2020-12-02 03:19:56 +00:00
|
|
|
{
|
2022-05-21 18:23:43 +00:00
|
|
|
OPEN_DISPS(play->state.gfxCtx, "../z_skelanime.c", 946);
|
2020-12-02 03:19:56 +00:00
|
|
|
gSPMatrix(POLY_OPA_DISP++, *mtx, G_MTX_LOAD);
|
|
|
|
gSPDisplayList(POLY_OPA_DISP++, newDList);
|
2022-05-21 18:23:43 +00:00
|
|
|
CLOSE_DISPS(play->state.gfxCtx, "../z_skelanime.c", 949);
|
2020-12-02 03:19:56 +00:00
|
|
|
}
|
2020-03-21 02:51:12 +00:00
|
|
|
(*mtx)++;
|
2020-12-02 03:19:56 +00:00
|
|
|
} else if (limbDList != NULL) {
|
2020-03-21 02:51:12 +00:00
|
|
|
Matrix_ToMtx(*mtx, "../z_skelanime.c", 954);
|
|
|
|
(*mtx)++;
|
|
|
|
}
|
|
|
|
}
|
2020-04-18 18:08:12 +00:00
|
|
|
if (postLimbDraw != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
postLimbDraw(play, limbIndex, &limbDList, &rot, arg);
|
2020-03-21 02:51:12 +00:00
|
|
|
}
|
2020-12-02 03:19:56 +00:00
|
|
|
if (limb->child != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
SkelAnime_DrawFlexLimbLod(play, limb->child, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg, lod,
|
|
|
|
mtx);
|
2020-03-21 02:51:12 +00:00
|
|
|
}
|
2020-03-18 03:15:19 +00:00
|
|
|
|
2021-02-24 19:28:04 +00:00
|
|
|
Matrix_Pop();
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
if (limb->sibling != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
SkelAnime_DrawFlexLimbLod(play, limb->sibling, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg, lod,
|
|
|
|
mtx);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2020-12-02 03:19:56 +00:00
|
|
|
* Draws all limbs of type `LodLimb` in a given flexible skeleton
|
|
|
|
* Limbs in a flexible skeleton have meshes that can stretch to line up with other limbs.
|
|
|
|
* An array of matrices is dynamically allocated so each limb can access any transform to ensure its meshes line up.
|
2020-04-01 01:19:21 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void SkelAnime_DrawFlexLod(PlayState* play, void** skeleton, Vec3s* jointTable, s32 dListCount,
|
2020-12-02 03:19:56 +00:00
|
|
|
OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg, s32 lod) {
|
|
|
|
LodLimb* rootLimb;
|
|
|
|
s32 pad;
|
|
|
|
Gfx* newDList;
|
|
|
|
Gfx* limbDList;
|
2020-03-21 02:51:12 +00:00
|
|
|
Vec3f pos;
|
|
|
|
Vec3s rot;
|
2022-05-21 18:23:43 +00:00
|
|
|
Mtx* mtx = Graph_Alloc(play->state.gfxCtx, dListCount * sizeof(Mtx));
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-03-25 15:51:25 +00:00
|
|
|
if (skeleton == NULL) {
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(RED));
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("Si2_Lod_draw_SV():skelがNULLです。\n"); // "skel is NULL."
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-21 02:51:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-08-29 23:00:17 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
OPEN_DISPS(play->state.gfxCtx, "../z_skelanime.c", 1000);
|
2020-08-29 23:00:17 +00:00
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPSegment(POLY_OPA_DISP++, 0xD, mtx);
|
2020-03-21 02:51:12 +00:00
|
|
|
Matrix_Push();
|
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
rootLimb = (LodLimb*)SEGMENTED_TO_VIRTUAL(skeleton[0]);
|
2020-12-29 22:46:46 +00:00
|
|
|
pos.x = jointTable[0].x;
|
|
|
|
pos.y = jointTable[0].y;
|
|
|
|
pos.z = jointTable[0].z;
|
2020-03-21 02:51:12 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
rot = jointTable[1];
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
newDList = limbDList = rootLimb->dLists[lod];
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
if ((overrideLimbDraw == 0) || !overrideLimbDraw(play, 1, &newDList, &pos, &rot, arg)) {
|
2021-11-17 10:52:26 +00:00
|
|
|
Matrix_TranslateRotateZYX(&pos, &rot);
|
2020-12-02 03:19:56 +00:00
|
|
|
if (newDList != NULL) {
|
2020-03-23 21:31:24 +00:00
|
|
|
Matrix_ToMtx(mtx, "../z_skelanime.c", 1033);
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPMatrix(POLY_OPA_DISP++, mtx, G_MTX_LOAD);
|
2020-12-02 03:19:56 +00:00
|
|
|
gSPDisplayList(POLY_OPA_DISP++, newDList);
|
2020-03-21 02:51:12 +00:00
|
|
|
mtx++;
|
2020-12-02 03:19:56 +00:00
|
|
|
} else if (limbDList != NULL) {
|
2020-03-25 15:51:25 +00:00
|
|
|
Matrix_ToMtx(mtx, "../z_skelanime.c", 1040);
|
|
|
|
mtx++;
|
2020-03-21 02:51:12 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-04-18 18:08:12 +00:00
|
|
|
if (postLimbDraw != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
postLimbDraw(play, 1, &limbDList, &rot, arg);
|
2020-03-21 02:51:12 +00:00
|
|
|
}
|
2020-12-02 03:19:56 +00:00
|
|
|
if (rootLimb->child != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
SkelAnime_DrawFlexLimbLod(play, rootLimb->child, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg, lod,
|
|
|
|
&mtx);
|
2020-03-21 02:51:12 +00:00
|
|
|
}
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2021-02-24 19:28:04 +00:00
|
|
|
Matrix_Pop();
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
CLOSE_DISPS(play->state.gfxCtx, "../z_skelanime.c", 1053);
|
2020-03-21 02:51:12 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2020-12-02 03:19:56 +00:00
|
|
|
* Draw a limb of type `StandardLimb` to the polyOpa buffer
|
2020-04-01 01:19:21 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void SkelAnime_DrawLimbOpa(PlayState* play, s32 limbIndex, void** skeleton, Vec3s* jointTable,
|
2020-12-02 03:19:56 +00:00
|
|
|
OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg) {
|
|
|
|
StandardLimb* limb;
|
2020-03-20 21:12:26 +00:00
|
|
|
Gfx* dList;
|
2020-03-23 21:31:24 +00:00
|
|
|
Vec3f pos;
|
|
|
|
Vec3s rot;
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
OPEN_DISPS(play->state.gfxCtx, "../z_skelanime.c", 1076);
|
2020-03-20 21:12:26 +00:00
|
|
|
Matrix_Push();
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
limb = (StandardLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]);
|
2020-03-20 21:12:26 +00:00
|
|
|
limbIndex++;
|
2020-12-29 22:46:46 +00:00
|
|
|
rot = jointTable[limbIndex];
|
2020-12-02 03:19:56 +00:00
|
|
|
pos.x = limb->jointPos.x;
|
|
|
|
pos.y = limb->jointPos.y;
|
|
|
|
pos.z = limb->jointPos.z;
|
|
|
|
dList = limb->dList;
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
if ((overrideLimbDraw == NULL) || !overrideLimbDraw(play, limbIndex, &dList, &pos, &rot, arg)) {
|
2021-11-17 10:52:26 +00:00
|
|
|
Matrix_TranslateRotateZYX(&pos, &rot);
|
2020-03-24 17:16:13 +00:00
|
|
|
if (dList != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx, "../z_skelanime.c", 1103), G_MTX_LOAD);
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPDisplayList(POLY_OPA_DISP++, dList);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
if (1) {}
|
|
|
|
|
2020-04-18 18:08:12 +00:00
|
|
|
if (postLimbDraw != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
postLimbDraw(play, limbIndex, &dList, &rot, arg);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
if (limb->child != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
SkelAnime_DrawLimbOpa(play, limb->child, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-02-24 19:28:04 +00:00
|
|
|
Matrix_Pop();
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
if (limb->sibling != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
SkelAnime_DrawLimbOpa(play, limb->sibling, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2022-05-21 18:23:43 +00:00
|
|
|
CLOSE_DISPS(play->state.gfxCtx, "../z_skelanime.c", 1121);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2020-12-02 03:19:56 +00:00
|
|
|
* Draw all limbs of type `StandardLimb` in a given skeleton to the polyOpa buffer
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void SkelAnime_DrawOpa(PlayState* play, void** skeleton, Vec3s* jointTable, OverrideLimbDrawOpa overrideLimbDraw,
|
|
|
|
PostLimbDrawOpa postLimbDraw, void* arg) {
|
2020-12-02 03:19:56 +00:00
|
|
|
StandardLimb* rootLimb;
|
|
|
|
s32 pad;
|
2020-03-20 21:12:26 +00:00
|
|
|
Gfx* dList;
|
2020-03-23 21:31:24 +00:00
|
|
|
Vec3f pos;
|
|
|
|
Vec3s rot;
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-03-25 15:51:25 +00:00
|
|
|
if (skeleton == NULL) {
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(RED));
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("Si2_draw():skelがNULLです。\n"); // "skel is NULL."
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-20 21:12:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
OPEN_DISPS(play->state.gfxCtx, "../z_skelanime.c", 1148);
|
2020-03-20 21:12:26 +00:00
|
|
|
|
|
|
|
Matrix_Push();
|
2020-12-02 03:19:56 +00:00
|
|
|
rootLimb = (StandardLimb*)SEGMENTED_TO_VIRTUAL(skeleton[0]);
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
pos.x = jointTable[0].x;
|
|
|
|
pos.y = jointTable[0].y;
|
|
|
|
pos.z = jointTable[0].z;
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
rot = jointTable[1];
|
2020-12-02 03:19:56 +00:00
|
|
|
dList = rootLimb->dList;
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
if ((overrideLimbDraw == NULL) || !overrideLimbDraw(play, 1, &dList, &pos, &rot, arg)) {
|
2021-11-17 10:52:26 +00:00
|
|
|
Matrix_TranslateRotateZYX(&pos, &rot);
|
2020-03-24 17:16:13 +00:00
|
|
|
if (dList != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(play->state.gfxCtx, "../z_skelanime.c", 1176), G_MTX_LOAD);
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPDisplayList(POLY_OPA_DISP++, dList);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-18 18:08:12 +00:00
|
|
|
if (postLimbDraw != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
postLimbDraw(play, 1, &dList, &rot, arg);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
if (rootLimb->child != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
SkelAnime_DrawLimbOpa(play, rootLimb->child, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-02-24 19:28:04 +00:00
|
|
|
Matrix_Pop();
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
CLOSE_DISPS(play->state.gfxCtx, "../z_skelanime.c", 1190);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2020-12-02 03:19:56 +00:00
|
|
|
* Draw a limb of type `StandardLimb` contained within a flexible skeleton to the polyOpa buffer
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void SkelAnime_DrawFlexLimbOpa(PlayState* play, s32 limbIndex, void** skeleton, Vec3s* jointTable,
|
2020-12-02 03:19:56 +00:00
|
|
|
OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg,
|
2022-02-20 13:22:29 +00:00
|
|
|
Mtx** limbMatrices) {
|
2020-12-02 03:19:56 +00:00
|
|
|
StandardLimb* limb;
|
|
|
|
Gfx* newDList;
|
|
|
|
Gfx* limbDList;
|
2020-03-25 15:51:25 +00:00
|
|
|
Vec3f pos;
|
|
|
|
Vec3s rot;
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
OPEN_DISPS(play->state.gfxCtx, "../z_skelanime.c", 1214);
|
2020-08-29 23:00:17 +00:00
|
|
|
|
2020-03-20 21:12:26 +00:00
|
|
|
Matrix_Push();
|
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
limb = (StandardLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]);
|
2020-03-25 15:51:25 +00:00
|
|
|
limbIndex++;
|
2020-12-29 22:46:46 +00:00
|
|
|
rot = jointTable[limbIndex];
|
2020-03-25 15:51:25 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
pos.x = limb->jointPos.x;
|
|
|
|
pos.y = limb->jointPos.y;
|
|
|
|
pos.z = limb->jointPos.z;
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
newDList = limbDList = limb->dList;
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
if ((overrideLimbDraw == NULL) || !overrideLimbDraw(play, limbIndex, &newDList, &pos, &rot, arg)) {
|
2021-11-17 10:52:26 +00:00
|
|
|
Matrix_TranslateRotateZYX(&pos, &rot);
|
2020-12-02 03:19:56 +00:00
|
|
|
if (newDList != NULL) {
|
2022-02-20 13:22:29 +00:00
|
|
|
Matrix_ToMtx(*limbMatrices, "../z_skelanime.c", 1242);
|
|
|
|
gSPMatrix(POLY_OPA_DISP++, *limbMatrices, G_MTX_LOAD);
|
2020-12-02 03:19:56 +00:00
|
|
|
gSPDisplayList(POLY_OPA_DISP++, newDList);
|
2022-02-20 13:22:29 +00:00
|
|
|
(*limbMatrices)++;
|
2020-12-02 03:19:56 +00:00
|
|
|
} else if (limbDList != NULL) {
|
2022-02-20 13:22:29 +00:00
|
|
|
Matrix_ToMtx(*limbMatrices, "../z_skelanime.c", 1249);
|
|
|
|
(*limbMatrices)++;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-18 18:08:12 +00:00
|
|
|
if (postLimbDraw != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
postLimbDraw(play, limbIndex, &limbDList, &rot, arg);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
if (limb->child != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
SkelAnime_DrawFlexLimbOpa(play, limb->child, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg,
|
2022-02-20 13:22:29 +00:00
|
|
|
limbMatrices);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-02-24 19:28:04 +00:00
|
|
|
Matrix_Pop();
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
if (limb->sibling != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
SkelAnime_DrawFlexLimbOpa(play, limb->sibling, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg,
|
2022-02-20 13:22:29 +00:00
|
|
|
limbMatrices);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2022-05-21 18:23:43 +00:00
|
|
|
CLOSE_DISPS(play->state.gfxCtx, "../z_skelanime.c", 1265);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2020-12-02 03:19:56 +00:00
|
|
|
* Draw all limbs of type `StandardLimb` in a given flexible skeleton to the polyOpa buffer
|
|
|
|
* Limbs in a flexible skeleton have meshes that can stretch to line up with other limbs.
|
|
|
|
* An array of matrices is dynamically allocated so each limb can access any transform to ensure its meshes line up.
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void SkelAnime_DrawFlexOpa(PlayState* play, void** skeleton, Vec3s* jointTable, s32 dListCount,
|
2020-12-02 03:19:56 +00:00
|
|
|
OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* arg) {
|
|
|
|
StandardLimb* rootLimb;
|
|
|
|
s32 pad;
|
|
|
|
Gfx* newDList;
|
|
|
|
Gfx* limbDList;
|
2020-03-20 21:12:26 +00:00
|
|
|
Vec3f pos;
|
|
|
|
Vec3s rot;
|
2022-05-21 18:23:43 +00:00
|
|
|
Mtx* mtx = Graph_Alloc(play->state.gfxCtx, dListCount * sizeof(Mtx));
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-03-25 15:51:25 +00:00
|
|
|
if (skeleton == NULL) {
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(RED));
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("Si2_draw_SV():skelがNULLです。\n"); // "skel is NULL."
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-20 21:12:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
OPEN_DISPS(play->state.gfxCtx, "../z_skelanime.c", 1294);
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPSegment(POLY_OPA_DISP++, 0xD, mtx);
|
2020-03-25 15:51:25 +00:00
|
|
|
|
2020-03-20 21:12:26 +00:00
|
|
|
Matrix_Push();
|
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
rootLimb = SEGMENTED_TO_VIRTUAL(skeleton[0]);
|
2020-03-25 15:51:25 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
pos.x = jointTable[0].x;
|
|
|
|
pos.y = jointTable[0].y;
|
|
|
|
pos.z = jointTable[0].z;
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
rot = jointTable[1];
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
newDList = limbDList = rootLimb->dList;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
if ((overrideLimbDraw == NULL) || !overrideLimbDraw(play, 1, &newDList, &pos, &rot, arg)) {
|
2021-11-17 10:52:26 +00:00
|
|
|
Matrix_TranslateRotateZYX(&pos, &rot);
|
2020-12-02 03:19:56 +00:00
|
|
|
if (newDList != NULL) {
|
2020-03-25 15:51:25 +00:00
|
|
|
Matrix_ToMtx(mtx, "../z_skelanime.c", 1327);
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPMatrix(POLY_OPA_DISP++, mtx, G_MTX_LOAD);
|
2020-12-02 03:19:56 +00:00
|
|
|
gSPDisplayList(POLY_OPA_DISP++, newDList);
|
|
|
|
mtx++;
|
|
|
|
} else if (limbDList != NULL) {
|
|
|
|
Matrix_ToMtx(mtx, "../z_skelanime.c", 1334);
|
2020-03-25 15:51:25 +00:00
|
|
|
mtx++;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-18 18:08:12 +00:00
|
|
|
if (postLimbDraw != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
postLimbDraw(play, 1, &limbDList, &rot, arg);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
if (rootLimb->child != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
SkelAnime_DrawFlexLimbOpa(play, rootLimb->child, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg,
|
2020-12-29 22:46:46 +00:00
|
|
|
&mtx);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-02-24 19:28:04 +00:00
|
|
|
Matrix_Pop();
|
2022-05-21 18:23:43 +00:00
|
|
|
CLOSE_DISPS(play->state.gfxCtx, "../z_skelanime.c", 1347);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
|
|
|
* Copies frame data from the frame data table, indexed by the joint index table.
|
|
|
|
* Indices below limit are copied from that entry in the static frame data table.
|
|
|
|
* Indices above limit are offsets to a frame data array indexed by the frame.
|
2020-03-24 17:16:13 +00:00
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void SkelAnime_GetFrameData(AnimationHeader* animation, s32 frame, s32 limbCount, Vec3s* frameTable) {
|
|
|
|
AnimationHeader* animHeader = SEGMENTED_TO_VIRTUAL(animation);
|
|
|
|
JointIndex* jointIndices = SEGMENTED_TO_VIRTUAL(animHeader->jointIndices);
|
|
|
|
s16* frameData = SEGMENTED_TO_VIRTUAL(animHeader->frameData);
|
|
|
|
s16* staticData = &frameData[0];
|
|
|
|
s16* dynamicData = &frameData[frame];
|
|
|
|
u16 staticIndexMax = animHeader->staticIndexMax;
|
2020-03-23 01:24:00 +00:00
|
|
|
s32 i;
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
for (i = 0; i < limbCount; i++, frameTable++, jointIndices++) {
|
|
|
|
if ((frameTable == NULL) || (jointIndices == NULL) || (dynamicData == NULL) || (staticData == NULL)) {
|
|
|
|
LOG_ADDRESS("out", frameTable, "../z_skelanime.c", 1392);
|
|
|
|
LOG_ADDRESS("ref_tbl", jointIndices, "../z_skelanime.c", 1393);
|
|
|
|
LOG_ADDRESS("frame_tbl", dynamicData, "../z_skelanime.c", 1394);
|
|
|
|
LOG_ADDRESS("tbl", staticData, "../z_skelanime.c", 1395);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-23 01:24:00 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
frameTable->x =
|
|
|
|
(jointIndices->x >= staticIndexMax) ? dynamicData[jointIndices->x] : staticData[jointIndices->x];
|
|
|
|
frameTable->y =
|
|
|
|
(jointIndices->y >= staticIndexMax) ? dynamicData[jointIndices->y] : staticData[jointIndices->y];
|
|
|
|
frameTable->z =
|
|
|
|
(jointIndices->z >= staticIndexMax) ? dynamicData[jointIndices->z] : staticData[jointIndices->z];
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
s16 Animation_GetLength(void* animation) {
|
|
|
|
AnimationHeaderCommon* common = SEGMENTED_TO_VIRTUAL(animation);
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
return common->frameCount;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
s16 Animation_GetLastFrame(void* animation) {
|
|
|
|
AnimationHeaderCommon* common = SEGMENTED_TO_VIRTUAL(animation);
|
2020-03-30 22:53:26 +00:00
|
|
|
// Loads an unsigned half for some reason.
|
2020-12-29 22:46:46 +00:00
|
|
|
return (u16)common->frameCount - 1;
|
2020-03-18 03:15:19 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2020-12-02 03:19:56 +00:00
|
|
|
* Draw a limb of type `StandardLimb` to the specified display buffer
|
2020-04-01 01:19:21 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
Gfx* SkelAnime_DrawLimb(PlayState* play, s32 limbIndex, void** skeleton, Vec3s* jointTable,
|
2020-12-02 03:19:56 +00:00
|
|
|
OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, void* arg, Gfx* gfx) {
|
|
|
|
StandardLimb* limb;
|
2020-03-23 21:31:24 +00:00
|
|
|
Gfx* dList;
|
|
|
|
Vec3f pos;
|
|
|
|
Vec3s rot;
|
|
|
|
|
|
|
|
Matrix_Push();
|
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
limb = (StandardLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]);
|
2020-03-23 21:31:24 +00:00
|
|
|
limbIndex++;
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
rot = jointTable[limbIndex];
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
pos.x = limb->jointPos.x;
|
|
|
|
pos.y = limb->jointPos.y;
|
|
|
|
pos.z = limb->jointPos.z;
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
dList = limb->dList;
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
if ((overrideLimbDraw == NULL) || !overrideLimbDraw(play, limbIndex, &dList, &pos, &rot, arg, &gfx)) {
|
2021-11-17 10:52:26 +00:00
|
|
|
Matrix_TranslateRotateZYX(&pos, &rot);
|
2020-03-24 17:16:13 +00:00
|
|
|
if (dList != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx, "../z_skelanime.c", 1489), G_MTX_LOAD);
|
2020-03-23 21:31:24 +00:00
|
|
|
gSPDisplayList(gfx++, dList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-18 18:08:12 +00:00
|
|
|
if (postLimbDraw != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
postLimbDraw(play, limbIndex, &dList, &rot, arg, &gfx);
|
2020-03-23 21:31:24 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
if (limb->child != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
gfx = SkelAnime_DrawLimb(play, limb->child, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg, gfx);
|
2020-03-23 21:31:24 +00:00
|
|
|
}
|
|
|
|
|
2021-02-24 19:28:04 +00:00
|
|
|
Matrix_Pop();
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
if (limb->sibling != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
gfx = SkelAnime_DrawLimb(play, limb->sibling, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg, gfx);
|
2020-03-23 21:31:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return gfx;
|
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2020-12-02 03:19:56 +00:00
|
|
|
* Draw all limbs of type `StandardLimb` in a given skeleton to the specified display buffer
|
2020-04-01 01:19:21 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
Gfx* SkelAnime_Draw(PlayState* play, void** skeleton, Vec3s* jointTable, OverrideLimbDraw overrideLimbDraw,
|
2020-12-02 03:19:56 +00:00
|
|
|
PostLimbDraw postLimbDraw, void* arg, Gfx* gfx) {
|
|
|
|
StandardLimb* rootLimb;
|
|
|
|
s32 pad;
|
2020-03-25 15:51:25 +00:00
|
|
|
Gfx* dList;
|
2020-03-23 21:31:24 +00:00
|
|
|
Vec3f pos;
|
|
|
|
Vec3s rot;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-25 15:51:25 +00:00
|
|
|
if (skeleton == NULL) {
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(RED));
|
2021-09-04 13:33:19 +00:00
|
|
|
// "skel is NULL. Returns NULL."
|
2021-01-09 22:07:17 +00:00
|
|
|
osSyncPrintf("Si2_draw2():skelがNULLです。NULLを返します。\n");
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-23 21:31:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Matrix_Push();
|
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
rootLimb = (StandardLimb*)SEGMENTED_TO_VIRTUAL(skeleton[0]);
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
pos.x = jointTable[0].x;
|
|
|
|
pos.y = jointTable[0].y;
|
|
|
|
pos.z = jointTable[0].z;
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
rot = jointTable[1];
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
dList = rootLimb->dList;
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
if ((overrideLimbDraw == NULL) || !overrideLimbDraw(play, 1, &dList, &pos, &rot, arg, &gfx)) {
|
2021-11-17 10:52:26 +00:00
|
|
|
Matrix_TranslateRotateZYX(&pos, &rot);
|
2020-03-24 17:16:13 +00:00
|
|
|
if (dList != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
gSPMatrix(gfx++, Matrix_NewMtx(play->state.gfxCtx, "../z_skelanime.c", 1558), G_MTX_LOAD);
|
2020-03-23 21:31:24 +00:00
|
|
|
gSPDisplayList(gfx++, dList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-18 18:08:12 +00:00
|
|
|
if (postLimbDraw != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
postLimbDraw(play, 1, &dList, &rot, arg, &gfx);
|
2020-03-23 21:31:24 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
if (rootLimb->child != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
gfx = SkelAnime_DrawLimb(play, rootLimb->child, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg, gfx);
|
2020-03-23 21:31:24 +00:00
|
|
|
}
|
|
|
|
|
2021-02-24 19:28:04 +00:00
|
|
|
Matrix_Pop();
|
2020-03-23 21:31:24 +00:00
|
|
|
|
|
|
|
return gfx;
|
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2020-12-02 03:19:56 +00:00
|
|
|
* Draw a limb of type `StandardLimb` contained within a flexible skeleton to the specified display buffer
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
Gfx* SkelAnime_DrawFlexLimb(PlayState* play, s32 limbIndex, void** skeleton, Vec3s* jointTable,
|
2020-12-02 03:19:56 +00:00
|
|
|
OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, void* arg, Mtx** mtx,
|
|
|
|
Gfx* gfx) {
|
|
|
|
StandardLimb* limb;
|
|
|
|
Gfx* newDList;
|
|
|
|
Gfx* limbDList;
|
2020-03-23 21:31:24 +00:00
|
|
|
Vec3f pos;
|
|
|
|
Vec3s rot;
|
|
|
|
|
|
|
|
Matrix_Push();
|
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
limb = (StandardLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]);
|
2020-03-23 21:31:24 +00:00
|
|
|
limbIndex++;
|
2020-12-29 22:46:46 +00:00
|
|
|
rot = jointTable[limbIndex];
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
pos.x = limb->jointPos.x;
|
|
|
|
pos.y = limb->jointPos.y;
|
|
|
|
pos.z = limb->jointPos.z;
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
newDList = limbDList = limb->dList;
|
2022-05-21 18:23:43 +00:00
|
|
|
if ((overrideLimbDraw == NULL) || !overrideLimbDraw(play, limbIndex, &newDList, &pos, &rot, arg, &gfx)) {
|
2021-11-17 10:52:26 +00:00
|
|
|
Matrix_TranslateRotateZYX(&pos, &rot);
|
2020-12-02 03:19:56 +00:00
|
|
|
if (newDList != NULL) {
|
2020-03-24 18:06:15 +00:00
|
|
|
Matrix_ToMtx(*mtx, "../z_skelanime.c", 1623);
|
2020-03-23 21:31:24 +00:00
|
|
|
gSPMatrix(gfx++, *mtx, G_MTX_LOAD);
|
2020-12-02 03:19:56 +00:00
|
|
|
gSPDisplayList(gfx++, newDList);
|
|
|
|
(*mtx)++;
|
|
|
|
} else if (limbDList != NULL) {
|
|
|
|
Matrix_ToMtx(*mtx, "../z_skelanime.c", 1630);
|
2020-03-23 21:31:24 +00:00
|
|
|
(*mtx)++;
|
|
|
|
}
|
|
|
|
}
|
2020-04-18 18:08:12 +00:00
|
|
|
if (postLimbDraw != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
postLimbDraw(play, limbIndex, &limbDList, &rot, arg, &gfx);
|
2020-03-23 21:31:24 +00:00
|
|
|
}
|
2020-12-02 03:19:56 +00:00
|
|
|
if (limb->child != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
gfx = SkelAnime_DrawFlexLimb(play, limb->child, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg, mtx,
|
|
|
|
gfx);
|
2020-03-23 21:31:24 +00:00
|
|
|
}
|
|
|
|
|
2021-02-24 19:28:04 +00:00
|
|
|
Matrix_Pop();
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
if (limb->sibling != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
gfx = SkelAnime_DrawFlexLimb(play, limb->sibling, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg,
|
|
|
|
mtx, gfx);
|
2020-03-23 21:31:24 +00:00
|
|
|
}
|
2020-03-24 16:52:12 +00:00
|
|
|
|
2020-03-23 21:31:24 +00:00
|
|
|
return gfx;
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2020-12-02 03:19:56 +00:00
|
|
|
* Draw all limbs of type `StandardLimb` in a given flexible skeleton to the specified display buffer
|
|
|
|
* Limbs in a flexible skeleton have meshes that can stretch to line up with other limbs.
|
|
|
|
* An array of matrices is dynamically allocated so each limb can access any transform to ensure its meshes line up.
|
2020-04-01 01:19:21 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
Gfx* SkelAnime_DrawFlex(PlayState* play, void** skeleton, Vec3s* jointTable, s32 dListCount,
|
2020-12-02 03:19:56 +00:00
|
|
|
OverrideLimbDraw overrideLimbDraw, PostLimbDraw postLimbDraw, void* arg, Gfx* gfx) {
|
|
|
|
StandardLimb* rootLimb;
|
|
|
|
s32 pad;
|
|
|
|
Gfx* newDList;
|
|
|
|
Gfx* limbDList;
|
2020-03-23 01:24:00 +00:00
|
|
|
Vec3f pos;
|
|
|
|
Vec3s rot;
|
2022-05-21 18:23:43 +00:00
|
|
|
Mtx* mtx = Graph_Alloc(play->state.gfxCtx, dListCount * sizeof(*mtx));
|
2020-03-23 01:24:00 +00:00
|
|
|
|
2020-03-25 15:51:25 +00:00
|
|
|
if (skeleton == NULL) {
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(RED));
|
2021-09-04 13:33:19 +00:00
|
|
|
// "skel is NULL. Returns NULL."
|
2021-01-09 22:07:17 +00:00
|
|
|
osSyncPrintf("Si2_draw2_SV():skelがNULLです。NULLを返します。\n");
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-23 01:24:00 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2020-03-24 16:52:12 +00:00
|
|
|
|
2020-03-23 01:24:00 +00:00
|
|
|
gSPSegment(gfx++, 0xD, mtx);
|
|
|
|
Matrix_Push();
|
2020-12-02 03:19:56 +00:00
|
|
|
rootLimb = (StandardLimb*)SEGMENTED_TO_VIRTUAL(skeleton[0]);
|
2020-03-23 01:24:00 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
pos.x = jointTable[0].x;
|
|
|
|
pos.y = jointTable[0].y;
|
|
|
|
pos.z = jointTable[0].z;
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
rot = jointTable[1];
|
2020-03-23 01:24:00 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
newDList = limbDList = rootLimb->dList;
|
2020-03-23 01:24:00 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
if ((overrideLimbDraw == NULL) || !overrideLimbDraw(play, 1, &newDList, &pos, &rot, arg, &gfx)) {
|
2021-11-17 10:52:26 +00:00
|
|
|
Matrix_TranslateRotateZYX(&pos, &rot);
|
2020-12-02 03:19:56 +00:00
|
|
|
if (newDList != NULL) {
|
2020-03-24 18:06:15 +00:00
|
|
|
Matrix_ToMtx(mtx, "../z_skelanime.c", 1710);
|
2020-03-23 01:24:00 +00:00
|
|
|
gSPMatrix(gfx++, mtx, G_MTX_LOAD);
|
2020-12-02 03:19:56 +00:00
|
|
|
gSPDisplayList(gfx++, newDList);
|
|
|
|
mtx++;
|
|
|
|
} else if (limbDList != NULL) {
|
|
|
|
Matrix_ToMtx(mtx, "../z_skelanime.c", 1717);
|
2020-03-23 01:24:00 +00:00
|
|
|
mtx++;
|
|
|
|
}
|
|
|
|
}
|
2020-04-18 18:08:12 +00:00
|
|
|
if (postLimbDraw != NULL) {
|
2022-05-21 18:23:43 +00:00
|
|
|
postLimbDraw(play, 1, &limbDList, &rot, arg, &gfx);
|
2020-03-23 01:24:00 +00:00
|
|
|
}
|
2020-12-02 03:19:56 +00:00
|
|
|
if (rootLimb->child != LIMB_DONE) {
|
2022-05-21 18:23:43 +00:00
|
|
|
gfx = SkelAnime_DrawFlexLimb(play, rootLimb->child, skeleton, jointTable, overrideLimbDraw, postLimbDraw, arg,
|
|
|
|
&mtx, gfx);
|
2020-03-23 01:24:00 +00:00
|
|
|
}
|
2020-03-24 16:52:12 +00:00
|
|
|
|
2021-02-24 19:28:04 +00:00
|
|
|
Matrix_Pop();
|
2020-03-24 16:52:12 +00:00
|
|
|
|
2020-03-23 01:24:00 +00:00
|
|
|
return gfx;
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Unpacks frame data for the animation at the given frame into frameTable
|
|
|
|
* Used by the legacy animation format
|
|
|
|
*/
|
2021-06-14 18:12:34 +00:00
|
|
|
s32 SkelAnime_GetFrameDataLegacy(LegacyAnimationHeader* animation, s32 frame, Vec3s* frameTable) {
|
|
|
|
LegacyAnimationHeader* animHeader = SEGMENTED_TO_VIRTUAL(animation);
|
2020-12-29 22:46:46 +00:00
|
|
|
s32 limbCount = animHeader->limbCount;
|
|
|
|
JointKey* key = SEGMENTED_TO_VIRTUAL(animHeader->jointKey);
|
|
|
|
s16* frameData = SEGMENTED_TO_VIRTUAL(animHeader->frameData);
|
|
|
|
s16* staticData = &frameData[0];
|
|
|
|
s16* dynamicData = &frameData[frame];
|
|
|
|
s32 i;
|
|
|
|
|
|
|
|
frameTable->x = frame < key->xMax ? dynamicData[key->x] : staticData[key->x];
|
|
|
|
frameTable->y = frame < key->yMax ? dynamicData[key->y] : staticData[key->y];
|
|
|
|
frameTable->z = frame < key->zMax ? dynamicData[key->z] : staticData[key->z];
|
|
|
|
|
|
|
|
frameTable++;
|
|
|
|
key++;
|
|
|
|
|
2021-06-14 18:12:34 +00:00
|
|
|
for (i = 1; i <= limbCount; i++, key++, frameTable++) {
|
|
|
|
frameTable->x = frame < key->xMax ? dynamicData[key->x] : staticData[key->x];
|
|
|
|
frameTable->y = frame < key->yMax ? dynamicData[key->y] : staticData[key->y];
|
|
|
|
frameTable->z = frame < key->zMax ? dynamicData[key->z] : staticData[key->z];
|
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
return limbCount;
|
2020-03-31 23:29:09 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
|
|
|
* Used by legacy animation format
|
|
|
|
*/
|
2021-06-14 18:12:34 +00:00
|
|
|
s16 Animation_GetLimbCountLegacy(LegacyAnimationHeader* animation) {
|
|
|
|
LegacyAnimationHeader* animHeader = SEGMENTED_TO_VIRTUAL(animation);
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
return animHeader->limbCount;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
|
|
|
* Used by legacy animation format
|
2020-04-01 01:19:21 +00:00
|
|
|
*/
|
2021-06-14 18:12:34 +00:00
|
|
|
s16 Animation_GetLengthLegacy(LegacyAnimationHeader* animation) {
|
|
|
|
LegacyAnimationHeader* animHeader = SEGMENTED_TO_VIRTUAL(animation);
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
return animHeader->frameCount;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
|
|
|
* Used by legacy animation format
|
2020-04-01 01:19:21 +00:00
|
|
|
*/
|
2021-06-14 18:12:34 +00:00
|
|
|
s16 Animation_GetLastFrameLegacy(LegacyAnimationHeader* animation) {
|
|
|
|
LegacyAnimationHeader* animHeader = SEGMENTED_TO_VIRTUAL(animation);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
return animHeader->frameCount - 1;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2021-01-09 22:07:17 +00:00
|
|
|
* Linearly interpolates the start and target frame tables with the given weight, putting the result in dst
|
2020-12-29 22:46:46 +00:00
|
|
|
*/
|
2021-01-09 22:07:17 +00:00
|
|
|
void SkelAnime_InterpFrameTable(s32 limbCount, Vec3s* dst, Vec3s* start, Vec3s* target, f32 weight) {
|
2020-03-30 22:53:26 +00:00
|
|
|
s32 i;
|
2020-12-29 22:46:46 +00:00
|
|
|
s16 diff;
|
|
|
|
s16 base;
|
|
|
|
|
|
|
|
if (weight < 1.0f) {
|
|
|
|
for (i = 0; i < limbCount; i++, dst++, start++, target++) {
|
|
|
|
base = start->x;
|
|
|
|
diff = target->x - base;
|
|
|
|
dst->x = (s16)(diff * weight) + base;
|
|
|
|
base = start->y;
|
|
|
|
diff = target->y - base;
|
|
|
|
dst->y = (s16)(diff * weight) + base;
|
|
|
|
base = start->z;
|
|
|
|
diff = target->z - base;
|
|
|
|
dst->z = (s16)(diff * weight) + base;
|
2020-03-25 19:38:16 +00:00
|
|
|
}
|
2020-04-01 01:19:21 +00:00
|
|
|
} else {
|
2020-12-29 22:46:46 +00:00
|
|
|
for (i = 0; i < limbCount; i++, dst++, target++) {
|
|
|
|
dst->x = target->x;
|
|
|
|
dst->y = target->y;
|
|
|
|
dst->z = target->z;
|
2020-03-25 19:38:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* zeroes out the current request count
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void AnimationContext_Reset(AnimationContext* animationCtx) {
|
2020-03-25 19:38:16 +00:00
|
|
|
animationCtx->animationCount = 0;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Shifts the queue flag to the next queue
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void AnimationContext_SetNextQueue(PlayState* play) {
|
2020-12-29 22:46:46 +00:00
|
|
|
sAnimQueueFlags <<= 1;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Disables the current animation queue. Only load and move actor requests will be processed for that queue.
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void AnimationContext_DisableQueue(PlayState* play) {
|
2020-12-29 22:46:46 +00:00
|
|
|
sDisableAnimQueueFlags |= sAnimQueueFlags;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
AnimationEntry* AnimationContext_AddEntry(AnimationContext* animationCtx, AnimationType type) {
|
2020-03-24 17:16:13 +00:00
|
|
|
AnimationEntry* entry;
|
2020-03-20 21:12:26 +00:00
|
|
|
s16 index = animationCtx->animationCount;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-25 15:51:25 +00:00
|
|
|
if (index >= ANIMATION_ENTRY_MAX) {
|
2020-03-20 21:12:26 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2021-02-14 00:49:40 +00:00
|
|
|
|
2020-03-20 21:12:26 +00:00
|
|
|
animationCtx->animationCount = index + 1;
|
|
|
|
entry = &animationCtx->entries[index];
|
2020-03-23 01:24:00 +00:00
|
|
|
entry->type = type;
|
2020-03-20 21:12:26 +00:00
|
|
|
return entry;
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2021-01-09 22:07:17 +00:00
|
|
|
* Requests loading frame data from the Link animation into frameTable
|
2020-12-29 22:46:46 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void AnimationContext_SetLoadFrame(PlayState* play, LinkAnimationHeader* animation, s32 frame, s32 limbCount,
|
2020-12-29 22:46:46 +00:00
|
|
|
Vec3s* frameTable) {
|
2022-05-21 18:23:43 +00:00
|
|
|
AnimationEntry* entry = AnimationContext_AddEntry(&play->animationCtx, ANIMENTRY_LOADFRAME);
|
2020-03-24 16:52:12 +00:00
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
if (entry != NULL) {
|
2021-01-09 22:07:17 +00:00
|
|
|
LinkAnimationHeader* linkAnimHeader = SEGMENTED_TO_VIRTUAL(animation);
|
2020-12-29 22:46:46 +00:00
|
|
|
u32 ram = frameTable;
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
osCreateMesgQueue(&entry->data.load.msgQueue, &entry->data.load.msg, 1);
|
|
|
|
DmaMgr_SendRequest2(&entry->data.load.req, ram,
|
2020-12-02 03:19:56 +00:00
|
|
|
LINK_ANIMATION_OFFSET(linkAnimHeader->segment, ((sizeof(Vec3s) * limbCount + 2) * frame)),
|
2020-12-29 22:46:46 +00:00
|
|
|
sizeof(Vec3s) * limbCount + 2, 0, &entry->data.load.msgQueue, NULL, "../z_skelanime.c",
|
2020-12-02 03:19:56 +00:00
|
|
|
2004);
|
2020-03-23 01:24:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-24 16:52:12 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2021-01-09 22:07:17 +00:00
|
|
|
* Requests copying all vectors from src frame table into dst frame table
|
2020-12-29 22:46:46 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void AnimationContext_SetCopyAll(PlayState* play, s32 vecCount, Vec3s* dst, Vec3s* src) {
|
|
|
|
AnimationEntry* entry = AnimationContext_AddEntry(&play->animationCtx, ANIMENTRY_COPYALL);
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
if (entry != NULL) {
|
2020-12-29 22:46:46 +00:00
|
|
|
entry->data.copy.queueFlag = sAnimQueueFlags;
|
|
|
|
entry->data.copy.vecCount = vecCount;
|
|
|
|
entry->data.copy.dst = dst;
|
|
|
|
entry->data.copy.src = src;
|
2020-03-23 01:24:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-24 16:52:12 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2021-01-09 22:07:17 +00:00
|
|
|
* Requests interpolating between base and mod frame tables with the given weight, placing the result in base
|
2020-12-29 22:46:46 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void AnimationContext_SetInterp(PlayState* play, s32 vecCount, Vec3s* base, Vec3s* mod, f32 weight) {
|
|
|
|
AnimationEntry* entry = AnimationContext_AddEntry(&play->animationCtx, ANIMENTRY_INTERP);
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
if (entry != NULL) {
|
2020-12-29 22:46:46 +00:00
|
|
|
entry->data.interp.queueFlag = sAnimQueueFlags;
|
|
|
|
entry->data.interp.vecCount = vecCount;
|
|
|
|
entry->data.interp.base = base;
|
|
|
|
entry->data.interp.mod = mod;
|
|
|
|
entry->data.interp.weight = weight;
|
2020-03-23 01:24:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-24 16:52:12 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2021-01-09 22:07:17 +00:00
|
|
|
* Requests copying vectors from src frame table to dst frame table whose copy flag is true
|
2020-12-29 22:46:46 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void AnimationContext_SetCopyTrue(PlayState* play, s32 vecCount, Vec3s* dst, Vec3s* src, u8* copyFlag) {
|
|
|
|
AnimationEntry* entry = AnimationContext_AddEntry(&play->animationCtx, ANIMENTRY_COPYTRUE);
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
if (entry != NULL) {
|
2020-12-29 22:46:46 +00:00
|
|
|
entry->data.copy1.queueFlag = sAnimQueueFlags;
|
|
|
|
entry->data.copy1.vecCount = vecCount;
|
|
|
|
entry->data.copy1.dst = dst;
|
|
|
|
entry->data.copy1.src = src;
|
|
|
|
entry->data.copy1.copyFlag = copyFlag;
|
2020-03-23 01:24:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-24 16:52:12 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2021-01-09 22:07:17 +00:00
|
|
|
* Requests copying vectors from src frame table to dst frame table whose copy flag is false
|
2020-12-29 22:46:46 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void AnimationContext_SetCopyFalse(PlayState* play, s32 vecCount, Vec3s* dst, Vec3s* src, u8* copyFlag) {
|
|
|
|
AnimationEntry* entry = AnimationContext_AddEntry(&play->animationCtx, ANIMENTRY_COPYFALSE);
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
if (entry != NULL) {
|
2020-12-29 22:46:46 +00:00
|
|
|
entry->data.copy0.queueFlag = sAnimQueueFlags;
|
|
|
|
entry->data.copy0.vecCount = vecCount;
|
|
|
|
entry->data.copy0.dst = dst;
|
|
|
|
entry->data.copy0.src = src;
|
|
|
|
entry->data.copy0.copyFlag = copyFlag;
|
2020-03-23 01:24:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-24 16:52:12 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
|
|
|
* Requests moving an actor according to the translation of its root limb
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void AnimationContext_SetMoveActor(PlayState* play, Actor* actor, SkelAnime* skelAnime, f32 arg3) {
|
|
|
|
AnimationEntry* entry = AnimationContext_AddEntry(&play->animationCtx, ANIMENTRY_MOVEACTOR);
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
if (entry != NULL) {
|
2020-12-29 22:46:46 +00:00
|
|
|
entry->data.move.actor = actor;
|
|
|
|
entry->data.move.skelAnime = skelAnime;
|
|
|
|
entry->data.move.unk_08 = arg3;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
|
|
|
* Receives the request for Link's animation frame data
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void AnimationContext_LoadFrame(PlayState* play, AnimationEntryData* data) {
|
2020-12-29 22:46:46 +00:00
|
|
|
AnimEntryLoadFrame* entry = &data->load;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-23 01:24:00 +00:00
|
|
|
osRecvMesg(&entry->msgQueue, NULL, OS_MESG_BLOCK);
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2021-01-09 22:07:17 +00:00
|
|
|
* If the entry's queue is enabled, copies all vectors from src frame table to dst frame table
|
2020-12-29 22:46:46 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void AnimationContext_CopyAll(PlayState* play, AnimationEntryData* data) {
|
2020-12-29 22:46:46 +00:00
|
|
|
AnimEntryCopyAll* entry = &data->copy;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if (!(entry->queueFlag & sDisableAnimQueueFlags)) {
|
2020-12-02 03:19:56 +00:00
|
|
|
Vec3s* dst = entry->dst;
|
|
|
|
Vec3s* src = entry->src;
|
|
|
|
s32 i;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
for (i = 0; i < entry->vecCount; i++) {
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
2020-03-23 01:24:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2021-01-09 22:07:17 +00:00
|
|
|
* If the entry's queue is enabled, interpolates between the base and mod frame tables, placing the result in base
|
2020-12-29 22:46:46 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void AnimationContext_Interp(PlayState* play, AnimationEntryData* data) {
|
2020-12-29 22:46:46 +00:00
|
|
|
AnimEntryInterp* entry = &data->interp;
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if (!(entry->queueFlag & sDisableAnimQueueFlags)) {
|
2021-01-09 22:07:17 +00:00
|
|
|
SkelAnime_InterpFrameTable(entry->vecCount, entry->base, entry->base, entry->mod, entry->weight);
|
2020-03-23 01:24:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2021-01-09 22:07:17 +00:00
|
|
|
* If the entry's queue is enabled, copies all vectors from src frame table to dst frame table whose copy flag is true
|
2020-12-29 22:46:46 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void AnimationContext_CopyTrue(PlayState* play, AnimationEntryData* data) {
|
2020-12-29 22:46:46 +00:00
|
|
|
AnimEntryCopyTrue* entry = &data->copy1;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if (!(entry->queueFlag & sDisableAnimQueueFlags)) {
|
2020-12-02 03:19:56 +00:00
|
|
|
Vec3s* dst = entry->dst;
|
|
|
|
Vec3s* src = entry->src;
|
2020-12-29 22:46:46 +00:00
|
|
|
u8* copyFlag = entry->copyFlag;
|
2020-12-02 03:19:56 +00:00
|
|
|
s32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < entry->vecCount; i++, dst++, src++) {
|
2020-12-29 22:46:46 +00:00
|
|
|
if (*copyFlag++) {
|
2020-03-23 01:24:00 +00:00
|
|
|
*dst = *src;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2021-01-09 22:07:17 +00:00
|
|
|
* If the entry's queue is enabled, copies all vectors from src frame table to dst frame table whose copy flag is false
|
2020-12-29 22:46:46 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void AnimationContext_CopyFalse(PlayState* play, AnimationEntryData* data) {
|
2020-12-29 22:46:46 +00:00
|
|
|
AnimEntryCopyFalse* entry = &data->copy0;
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if (!(entry->queueFlag & sDisableAnimQueueFlags)) {
|
2020-12-02 03:19:56 +00:00
|
|
|
Vec3s* dst = entry->dst;
|
|
|
|
Vec3s* src = entry->src;
|
2020-12-29 22:46:46 +00:00
|
|
|
u8* copyFlag = entry->copyFlag;
|
2020-12-02 03:19:56 +00:00
|
|
|
s32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < entry->vecCount; i++, dst++, src++) {
|
2020-12-29 22:46:46 +00:00
|
|
|
if (!(*copyFlag++)) {
|
2020-03-23 01:24:00 +00:00
|
|
|
*dst = *src;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
|
|
|
* Moves an actor according to the translation of its root limb
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void AnimationContext_MoveActor(PlayState* play, AnimationEntryData* data) {
|
2020-12-29 22:46:46 +00:00
|
|
|
AnimEntryMoveActor* entry = &data->move;
|
2020-03-23 01:24:00 +00:00
|
|
|
Actor* actor = entry->actor;
|
2020-12-29 22:46:46 +00:00
|
|
|
Vec3f diff;
|
2020-03-18 03:15:19 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
SkelAnime_UpdateTranslation(entry->skelAnime, &diff, actor->shape.rot.y);
|
2021-01-18 21:04:04 +00:00
|
|
|
actor->world.pos.x += diff.x * actor->scale.x;
|
|
|
|
actor->world.pos.y += diff.y * actor->scale.y * entry->unk_08;
|
|
|
|
actor->world.pos.z += diff.z * actor->scale.z;
|
2020-03-18 03:15:19 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
|
|
|
* Performs all requests in the animation queue, then resets the queue flags.
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void AnimationContext_Update(PlayState* play, AnimationContext* animationCtx) {
|
2020-12-29 22:46:46 +00:00
|
|
|
static AnimationEntryCallback animFuncs[] = {
|
|
|
|
AnimationContext_LoadFrame, AnimationContext_CopyAll, AnimationContext_Interp,
|
|
|
|
AnimationContext_CopyTrue, AnimationContext_CopyFalse, AnimationContext_MoveActor,
|
2020-12-02 03:19:56 +00:00
|
|
|
};
|
2020-03-20 21:12:26 +00:00
|
|
|
AnimationEntry* entry;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
for (entry = animationCtx->entries; animationCtx->animationCount != 0; entry++, animationCtx->animationCount--) {
|
2022-05-21 18:23:43 +00:00
|
|
|
animFuncs[entry->type](play, &entry->data);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
sAnimQueueFlags = 1;
|
|
|
|
sDisableAnimQueueFlags = 0;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Initializes a skeleton to be used with Link animations to a looping animation, dynamically allocating the frame
|
|
|
|
* tables if not given.
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void SkelAnime_InitLink(PlayState* play, SkelAnime* skelAnime, FlexSkeletonHeader* skeletonHeaderSeg,
|
2021-01-09 22:07:17 +00:00
|
|
|
LinkAnimationHeader* animation, s32 flags, Vec3s* jointTable, Vec3s* morphTable,
|
2020-12-29 22:46:46 +00:00
|
|
|
s32 limbBufCount) {
|
2020-12-02 03:19:56 +00:00
|
|
|
FlexSkeletonHeader* skeletonHeader = SEGMENTED_TO_VIRTUAL(skeletonHeaderSeg);
|
|
|
|
s32 headerJointCount = skeletonHeader->sh.limbCount;
|
2020-03-23 21:31:24 +00:00
|
|
|
s32 limbCount;
|
2020-12-02 03:19:56 +00:00
|
|
|
size_t allocSize;
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-03-26 03:01:24 +00:00
|
|
|
skelAnime->initFlags = flags;
|
2020-12-02 03:19:56 +00:00
|
|
|
limbCount = (flags & 2) ? headerJointCount : 1;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-24 19:01:00 +00:00
|
|
|
if (flags & 1) {
|
2020-12-02 03:19:56 +00:00
|
|
|
limbCount += headerJointCount;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-24 19:01:00 +00:00
|
|
|
if (flags & 4) {
|
2020-12-02 03:19:56 +00:00
|
|
|
limbCount += headerJointCount;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-25 15:51:25 +00:00
|
|
|
skelAnime->limbCount = limbCount;
|
|
|
|
skelAnime->dListCount = skeletonHeader->dListCount;
|
2020-03-23 21:31:24 +00:00
|
|
|
|
|
|
|
allocSize = limbCount * sizeof(Vec3s);
|
2020-12-02 03:19:56 +00:00
|
|
|
skelAnime->skeleton = SEGMENTED_TO_VIRTUAL(skeletonHeader->sh.segment);
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-03-24 19:01:00 +00:00
|
|
|
if (flags & 8) {
|
2020-03-23 21:31:24 +00:00
|
|
|
allocSize += 2;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if (jointTable == NULL) {
|
|
|
|
skelAnime->jointTable = ZeldaArena_MallocDebug(allocSize, "../z_skelanime.c", 2364);
|
|
|
|
skelAnime->morphTable = ZeldaArena_MallocDebug(allocSize, "../z_skelanime.c", 2365);
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2021-04-29 18:39:46 +00:00
|
|
|
ASSERT(limbBufCount == limbCount, "joint_buff_num == joint_num", "../z_skelanime.c", 2369);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->jointTable = (Vec3s*)ALIGN16((u32)jointTable);
|
|
|
|
skelAnime->morphTable = (Vec3s*)ALIGN16((u32)morphTable);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if ((skelAnime->jointTable == NULL) || (skelAnime->morphTable == NULL)) {
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(RED));
|
2021-09-04 13:33:19 +00:00
|
|
|
// "Memory allocation error"
|
2021-01-09 22:07:17 +00:00
|
|
|
osSyncPrintf("Skeleton_Info_Rom_SV_ct メモリアロケーションエラー\n");
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
LinkAnimation_Change(play, skelAnime, animation, 1.0f, 0.0f, 0.0f, ANIMMODE_LOOP, 0.0f);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Sets the update function of a SkelAnime that uses Link animations based on its mode
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void LinkAnimation_SetUpdateFunction(SkelAnime* skelAnime) {
|
|
|
|
if (skelAnime->mode <= ANIMMODE_LOOP_INTERP) {
|
|
|
|
skelAnime->update = LinkAnimation_Loop;
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->update = LinkAnimation_Once;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->morphWeight = 0.0f;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Advances the current Link animation and updates all frame tables. If the animation plays once, returns true when it
|
|
|
|
* finishes.
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
s32 LinkAnimation_Update(PlayState* play, SkelAnime* skelAnime) {
|
|
|
|
return skelAnime->update(play, skelAnime);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Requests an interpolation between the pose in jointTable to the one in morphTable, advancing the morph but not the
|
|
|
|
* animation frame
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
s32 LinkAnimation_Morph(PlayState* play, SkelAnime* skelAnime) {
|
2020-12-29 22:46:46 +00:00
|
|
|
f32 prevMorphWeight = skelAnime->morphWeight;
|
2020-03-23 21:31:24 +00:00
|
|
|
f32 updateRate = R_UPDATE_RATE * 0.5f;
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->morphWeight -= skelAnime->morphRate * updateRate;
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if (skelAnime->morphWeight <= 0.0f) {
|
|
|
|
LinkAnimation_SetUpdateFunction(skelAnime);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
AnimationContext_SetInterp(play, skelAnime->limbCount, skelAnime->jointTable, skelAnime->morphTable,
|
2020-12-29 22:46:46 +00:00
|
|
|
1.0f - (skelAnime->morphWeight / prevMorphWeight));
|
2020-03-20 21:12:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Requests a load of the next frame of a Link animation, advances the morph, and requests an interpolation between
|
|
|
|
* jointTable and morphTable
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void LinkAnimation_AnimateFrame(PlayState* play, SkelAnime* skelAnime) {
|
|
|
|
AnimationContext_SetLoadFrame(play, skelAnime->animation, skelAnime->curFrame, skelAnime->limbCount,
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->jointTable);
|
|
|
|
if (skelAnime->morphWeight != 0) {
|
2020-12-02 03:19:56 +00:00
|
|
|
f32 updateRate = R_UPDATE_RATE * 0.5f;
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->morphWeight -= skelAnime->morphRate * updateRate;
|
|
|
|
if (skelAnime->morphWeight <= 0.0f) {
|
|
|
|
skelAnime->morphWeight = 0.0f;
|
2020-12-02 03:19:56 +00:00
|
|
|
} else {
|
2022-05-21 18:23:43 +00:00
|
|
|
AnimationContext_SetInterp(play, skelAnime->limbCount, skelAnime->jointTable, skelAnime->morphTable,
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->morphWeight);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Advances a Link animation that loops over its full length
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
s32 LinkAnimation_Loop(PlayState* play, SkelAnime* skelAnime) {
|
2020-03-20 21:12:26 +00:00
|
|
|
f32 updateRate = R_UPDATE_RATE * 0.5f;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->curFrame += skelAnime->playSpeed * updateRate;
|
|
|
|
if (skelAnime->curFrame < 0.0f) {
|
|
|
|
skelAnime->curFrame += skelAnime->animLength;
|
|
|
|
} else if (skelAnime->animLength <= skelAnime->curFrame) {
|
|
|
|
skelAnime->curFrame -= skelAnime->animLength;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2022-05-21 18:23:43 +00:00
|
|
|
LinkAnimation_AnimateFrame(play, skelAnime);
|
2020-03-20 21:12:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Advances a Link animation that stops at endFrame and returns true when it is reached.
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
s32 LinkAnimation_Once(PlayState* play, SkelAnime* skelAnime) {
|
2020-03-20 21:12:26 +00:00
|
|
|
f32 updateRate = R_UPDATE_RATE * 0.5f;
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if (skelAnime->curFrame == skelAnime->endFrame) {
|
2022-05-21 18:23:43 +00:00
|
|
|
LinkAnimation_AnimateFrame(play, skelAnime);
|
2020-03-20 21:12:26 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->curFrame += skelAnime->playSpeed * updateRate;
|
|
|
|
if ((skelAnime->curFrame - skelAnime->endFrame) * skelAnime->playSpeed > 0.0f) {
|
|
|
|
skelAnime->curFrame = skelAnime->endFrame;
|
|
|
|
} else if (skelAnime->curFrame < 0.0f) {
|
|
|
|
skelAnime->curFrame += skelAnime->animLength;
|
|
|
|
} else if (skelAnime->animLength <= skelAnime->curFrame) {
|
|
|
|
skelAnime->curFrame -= skelAnime->animLength;
|
2020-03-23 21:31:24 +00:00
|
|
|
}
|
2022-05-21 18:23:43 +00:00
|
|
|
LinkAnimation_AnimateFrame(play, skelAnime);
|
2020-03-20 21:12:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Sets a new morph and resets the morph weight for the current animation.
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void Animation_SetMorph(PlayState* play, SkelAnime* skelAnime, f32 morphFrames) {
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->morphWeight = 1.0f;
|
|
|
|
skelAnime->morphRate = 1.0f / morphFrames;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* General way to set a new Link animation, allowing choice of playback speed, start frame, end frame, play mode, and
|
|
|
|
* number of transition frames. Positive morph frames morph from the current pose to the start pose of the new
|
|
|
|
* animation, then start the new animation. Negative morph frames start the new animation immediately, modified by the
|
|
|
|
* pose immediately before the animation change.
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void LinkAnimation_Change(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation, f32 playSpeed,
|
2020-12-29 22:46:46 +00:00
|
|
|
f32 startFrame, f32 endFrame, u8 mode, f32 morphFrames) {
|
|
|
|
skelAnime->mode = mode;
|
2021-01-09 22:07:17 +00:00
|
|
|
if ((morphFrames != 0.0f) && ((animation != skelAnime->animation) || (startFrame != skelAnime->curFrame))) {
|
2020-12-29 22:46:46 +00:00
|
|
|
if (morphFrames < 0) {
|
|
|
|
LinkAnimation_SetUpdateFunction(skelAnime);
|
2021-01-09 22:07:17 +00:00
|
|
|
SkelAnime_CopyFrameTable(skelAnime, skelAnime->morphTable, skelAnime->jointTable);
|
2020-12-29 22:46:46 +00:00
|
|
|
morphFrames = -morphFrames;
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->update = LinkAnimation_Morph;
|
2022-05-21 18:23:43 +00:00
|
|
|
AnimationContext_SetLoadFrame(play, animation, (s32)startFrame, skelAnime->limbCount,
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->morphTable);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->morphWeight = 1.0f;
|
|
|
|
skelAnime->morphRate = 1.0f / morphFrames;
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-12-29 22:46:46 +00:00
|
|
|
LinkAnimation_SetUpdateFunction(skelAnime);
|
2022-05-21 18:23:43 +00:00
|
|
|
AnimationContext_SetLoadFrame(play, animation, (s32)startFrame, skelAnime->limbCount, skelAnime->jointTable);
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->morphWeight = 0.0f;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
skelAnime->animation = animation;
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->curFrame = 0.0f;
|
|
|
|
skelAnime->startFrame = startFrame;
|
|
|
|
skelAnime->curFrame = startFrame;
|
|
|
|
skelAnime->endFrame = endFrame;
|
2021-01-09 22:07:17 +00:00
|
|
|
skelAnime->animLength = Animation_GetLength(animation);
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->playSpeed = playSpeed;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Immediately changes to a Link animation that plays once at the default speed.
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void LinkAnimation_PlayOnce(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation) {
|
|
|
|
LinkAnimation_Change(play, skelAnime, animation, 1.0f, 0.0f, Animation_GetLastFrame(animation), ANIMMODE_ONCE,
|
2020-12-29 22:46:46 +00:00
|
|
|
0.0f);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Immediately changes to a Link animation that plays once at the specified speed.
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void LinkAnimation_PlayOnceSetSpeed(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation,
|
2020-12-29 22:46:46 +00:00
|
|
|
f32 playSpeed) {
|
2022-05-21 18:23:43 +00:00
|
|
|
LinkAnimation_Change(play, skelAnime, animation, playSpeed, 0.0f, Animation_GetLastFrame(animation), ANIMMODE_ONCE,
|
|
|
|
0.0f);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Immediately changes to a Link animation that loops at the default speed.
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void LinkAnimation_PlayLoop(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation) {
|
|
|
|
LinkAnimation_Change(play, skelAnime, animation, 1.0f, 0.0f, Animation_GetLastFrame(animation), ANIMMODE_LOOP,
|
2020-12-29 22:46:46 +00:00
|
|
|
0.0f);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Immediately changes to a Link animation that loops at the specified speed.
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void LinkAnimation_PlayLoopSetSpeed(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation,
|
2020-12-29 22:46:46 +00:00
|
|
|
f32 playSpeed) {
|
2022-05-21 18:23:43 +00:00
|
|
|
LinkAnimation_Change(play, skelAnime, animation, playSpeed, 0.0f, Animation_GetLastFrame(animation), ANIMMODE_LOOP,
|
|
|
|
0.0f);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
|
|
|
* Requests copying jointTable to morphTable
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void LinkAnimation_CopyJointToMorph(PlayState* play, SkelAnime* skelAnime) {
|
|
|
|
AnimationContext_SetCopyAll(play, skelAnime->limbCount, skelAnime->morphTable, skelAnime->jointTable);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
|
|
|
* Requests copying morphTable to jointTable
|
|
|
|
* unused
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void LinkAnimation_CopyMorphToJoint(PlayState* play, SkelAnime* skelAnime) {
|
|
|
|
AnimationContext_SetCopyAll(play, skelAnime->limbCount, skelAnime->jointTable, skelAnime->morphTable);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2021-01-09 22:07:17 +00:00
|
|
|
* Requests loading frame data from the Link animation into morphTable
|
2020-12-29 22:46:46 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void LinkAnimation_LoadToMorph(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation, f32 frame) {
|
|
|
|
AnimationContext_SetLoadFrame(play, animation, (s32)frame, skelAnime->limbCount, skelAnime->morphTable);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2021-01-09 22:07:17 +00:00
|
|
|
* Requests loading frame data from the Link animation into jointTable
|
2020-12-29 22:46:46 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void LinkAnimation_LoadToJoint(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation, f32 frame) {
|
|
|
|
AnimationContext_SetLoadFrame(play, animation, (s32)frame, skelAnime->limbCount, skelAnime->jointTable);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
|
|
|
* Requests interpolating between jointTable and morphTable, placing the result in jointTable
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void LinkAnimation_InterpJointMorph(PlayState* play, SkelAnime* skelAnime, f32 weight) {
|
|
|
|
AnimationContext_SetInterp(play, skelAnime->limbCount, skelAnime->jointTable, skelAnime->morphTable, weight);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2021-01-09 22:07:17 +00:00
|
|
|
* Requests loading frame data from the Link animations and blending them, placing the result in jointTable
|
2020-12-29 22:46:46 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void LinkAnimation_BlendToJoint(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation1, f32 frame1,
|
|
|
|
LinkAnimationHeader* animation2, f32 frame2, f32 blendWeight, Vec3s* blendTable) {
|
2020-12-29 22:46:46 +00:00
|
|
|
Vec3s* alignedBlendTable;
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
AnimationContext_SetLoadFrame(play, animation1, (s32)frame1, skelAnime->limbCount, skelAnime->jointTable);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
alignedBlendTable = (Vec3s*)ALIGN16((u32)blendTable);
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
AnimationContext_SetLoadFrame(play, animation2, (s32)frame2, skelAnime->limbCount, alignedBlendTable);
|
|
|
|
AnimationContext_SetInterp(play, skelAnime->limbCount, skelAnime->jointTable, alignedBlendTable, blendWeight);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
2021-01-09 22:07:17 +00:00
|
|
|
* Requests loading frame data from the Link animations and blending them, placing the result in morphTable
|
2020-12-29 22:46:46 +00:00
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void LinkAnimation_BlendToMorph(PlayState* play, SkelAnime* skelAnime, LinkAnimationHeader* animation1, f32 frame1,
|
|
|
|
LinkAnimationHeader* animation2, f32 frame2, f32 blendWeight, Vec3s* blendTable) {
|
2020-12-29 22:46:46 +00:00
|
|
|
Vec3s* alignedBlendTable;
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
AnimationContext_SetLoadFrame(play, animation1, (s32)frame1, skelAnime->limbCount, skelAnime->morphTable);
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
alignedBlendTable = (Vec3s*)ALIGN16((u32)blendTable);
|
2020-03-23 21:31:24 +00:00
|
|
|
|
2022-05-21 18:23:43 +00:00
|
|
|
AnimationContext_SetLoadFrame(play, animation2, (s32)frame2, skelAnime->limbCount, alignedBlendTable);
|
|
|
|
AnimationContext_SetInterp(play, skelAnime->limbCount, skelAnime->morphTable, alignedBlendTable, blendWeight);
|
2020-03-23 21:31:24 +00:00
|
|
|
}
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Changes a looping animation to one that stops at the end. Unused
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void LinkAnimation_EndLoop(SkelAnime* skelAnime) {
|
|
|
|
skelAnime->mode = ANIMMODE_ONCE;
|
|
|
|
LinkAnimation_SetUpdateFunction(skelAnime);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Checks if the current frame is after frame and the previous frame was before it.
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
s32 Animation_OnFrameImpl(SkelAnime* skelAnime, f32 frame, f32 updateRate) {
|
|
|
|
f32 updateSpeed = skelAnime->playSpeed * updateRate;
|
|
|
|
f32 prevFrame = skelAnime->curFrame - updateSpeed;
|
|
|
|
f32 curFrameDiff;
|
|
|
|
f32 prevFrameDiff;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if (prevFrame < 0.0f) {
|
|
|
|
prevFrame += skelAnime->animLength;
|
|
|
|
} else if (prevFrame >= skelAnime->animLength) {
|
|
|
|
prevFrame -= skelAnime->animLength;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-31 23:29:09 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if ((frame == 0.0f) && (updateSpeed > 0.0f)) {
|
|
|
|
frame = skelAnime->animLength;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-31 23:29:09 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
curFrameDiff = prevFrame + updateSpeed - frame;
|
|
|
|
prevFrameDiff = curFrameDiff - updateSpeed;
|
|
|
|
if ((curFrameDiff * updateSpeed >= 0.0f) && (prevFrameDiff * updateSpeed < 0.0f)) {
|
|
|
|
return true;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
return false;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Checks if the current Link animation has reached the specified frame
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
s32 LinkAnimation_OnFrame(SkelAnime* skelAnime, f32 frame) {
|
2020-03-20 21:12:26 +00:00
|
|
|
f32 updateRate = R_UPDATE_RATE * 0.5f;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
return Animation_OnFrameImpl(skelAnime, frame, updateRate);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Initializes a normal skeleton to a looping animation, dynamically allocating the frame tables if not provided.
|
|
|
|
*/
|
2022-06-03 16:51:23 +00:00
|
|
|
BAD_RETURN(s32)
|
|
|
|
SkelAnime_Init(PlayState* play, SkelAnime* skelAnime, SkeletonHeader* skeletonHeaderSeg, AnimationHeader* animation,
|
|
|
|
Vec3s* jointTable, Vec3s* morphTable, s32 limbCount) {
|
2020-12-02 03:19:56 +00:00
|
|
|
SkeletonHeader* skeletonHeader = SEGMENTED_TO_VIRTUAL(skeletonHeaderSeg);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-25 15:51:25 +00:00
|
|
|
skelAnime->limbCount = skeletonHeader->limbCount + 1;
|
2020-12-02 03:19:56 +00:00
|
|
|
skelAnime->skeleton = SEGMENTED_TO_VIRTUAL(skeletonHeader->segment);
|
2020-12-29 22:46:46 +00:00
|
|
|
if (jointTable == NULL) {
|
|
|
|
skelAnime->jointTable =
|
|
|
|
ZeldaArena_MallocDebug(skelAnime->limbCount * sizeof(*skelAnime->jointTable), "../z_skelanime.c", 2968);
|
|
|
|
skelAnime->morphTable =
|
|
|
|
ZeldaArena_MallocDebug(skelAnime->limbCount * sizeof(*skelAnime->morphTable), "../z_skelanime.c", 2969);
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2021-04-29 18:39:46 +00:00
|
|
|
ASSERT(limbCount == skelAnime->limbCount, "joint_buff_num == this->joint_num", "../z_skelanime.c", 2973);
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->jointTable = jointTable;
|
|
|
|
skelAnime->morphTable = morphTable;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
if ((skelAnime->jointTable == NULL) || (skelAnime->morphTable == NULL)) {
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(RED));
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("Skeleton_Info2_ct メモリアロケーションエラー\n"); // "Memory allocation error"
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if (animation != NULL) {
|
|
|
|
Animation_PlayLoop(skelAnime, animation);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-24 16:52:12 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Initializes a flex skeleton to a looping animation, dynamically allocating the frame tables if not given.
|
|
|
|
*/
|
2022-06-03 16:51:23 +00:00
|
|
|
BAD_RETURN(s32)
|
|
|
|
SkelAnime_InitFlex(PlayState* play, SkelAnime* skelAnime, FlexSkeletonHeader* skeletonHeaderSeg,
|
|
|
|
AnimationHeader* animation, Vec3s* jointTable, Vec3s* morphTable, s32 limbCount) {
|
2020-12-02 03:19:56 +00:00
|
|
|
FlexSkeletonHeader* skeletonHeader = SEGMENTED_TO_VIRTUAL(skeletonHeaderSeg);
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-02 03:19:56 +00:00
|
|
|
skelAnime->limbCount = skeletonHeader->sh.limbCount + 1;
|
2020-03-25 15:51:25 +00:00
|
|
|
skelAnime->dListCount = skeletonHeader->dListCount;
|
2020-12-02 03:19:56 +00:00
|
|
|
skelAnime->skeleton = SEGMENTED_TO_VIRTUAL(skeletonHeader->sh.segment);
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if (jointTable == NULL) {
|
|
|
|
skelAnime->jointTable =
|
|
|
|
ZeldaArena_MallocDebug(skelAnime->limbCount * sizeof(*skelAnime->jointTable), "../z_skelanime.c", 3047);
|
2020-03-24 16:52:12 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->morphTable =
|
|
|
|
ZeldaArena_MallocDebug(skelAnime->limbCount * sizeof(*skelAnime->morphTable), "../z_skelanime.c", 3048);
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2021-04-29 18:39:46 +00:00
|
|
|
ASSERT(limbCount == skelAnime->limbCount, "joint_buff_num == this->joint_num", "../z_skelanime.c", 3052);
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->jointTable = jointTable;
|
|
|
|
skelAnime->morphTable = morphTable;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
if ((skelAnime->jointTable == NULL) || (skelAnime->morphTable == NULL)) {
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(RED));
|
2021-09-04 13:33:19 +00:00
|
|
|
// "Memory allocation error"
|
2021-01-09 22:07:17 +00:00
|
|
|
osSyncPrintf("Skeleton_Info_Rom_SV_ct メモリアロケーションエラー\n");
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if (animation != NULL) {
|
|
|
|
Animation_PlayLoop(skelAnime, animation);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-24 16:52:12 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Initializes a skeleton with SkinLimbs to a looping animation, dynamically allocating the frame tables.
|
|
|
|
*/
|
2022-06-03 16:51:23 +00:00
|
|
|
BAD_RETURN(s32)
|
|
|
|
SkelAnime_InitSkin(PlayState* play, SkelAnime* skelAnime, SkeletonHeader* skeletonHeaderSeg,
|
|
|
|
AnimationHeader* animation) {
|
2020-12-02 03:19:56 +00:00
|
|
|
SkeletonHeader* skeletonHeader = SEGMENTED_TO_VIRTUAL(skeletonHeaderSeg);
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-03-25 15:51:25 +00:00
|
|
|
skelAnime->limbCount = skeletonHeader->limbCount + 1;
|
2020-12-02 03:19:56 +00:00
|
|
|
skelAnime->skeleton = SEGMENTED_TO_VIRTUAL(skeletonHeader->segment);
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->jointTable =
|
|
|
|
ZeldaArena_MallocDebug(skelAnime->limbCount * sizeof(*skelAnime->jointTable), "../z_skelanime.c", 3120);
|
|
|
|
skelAnime->morphTable =
|
|
|
|
ZeldaArena_MallocDebug(skelAnime->limbCount * sizeof(*skelAnime->morphTable), "../z_skelanime.c", 3121);
|
|
|
|
if ((skelAnime->jointTable == NULL) || (skelAnime->morphTable == NULL)) {
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_FGCOL(RED));
|
2021-09-04 13:33:19 +00:00
|
|
|
// "Memory allocation error"
|
2021-01-09 22:07:17 +00:00
|
|
|
osSyncPrintf("Skeleton_Info2_skin2_ct メモリアロケーションエラー\n");
|
2020-03-24 18:06:15 +00:00
|
|
|
osSyncPrintf(VT_RST);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if (animation != NULL) {
|
|
|
|
Animation_PlayLoop(skelAnime, animation);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Sets the SkelAnime's update function based on its current mode.
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void SkelAnime_SetUpdate(SkelAnime* skelAnime) {
|
|
|
|
if (skelAnime->mode <= ANIMMODE_LOOP_INTERP) {
|
|
|
|
skelAnime->update = SkelAnime_LoopFull;
|
|
|
|
} else if (skelAnime->mode <= ANIMMODE_ONCE_INTERP) {
|
|
|
|
skelAnime->update = SkelAnime_Once;
|
2020-03-24 19:01:00 +00:00
|
|
|
} else {
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->update = SkelAnime_LoopPartial;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Advances the current animation and updates all frame tables. If the animation plays once, returns true when it
|
|
|
|
* finishes.
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
s32 SkelAnime_Update(SkelAnime* skelAnime) {
|
2020-12-02 03:19:56 +00:00
|
|
|
return skelAnime->update(skelAnime);
|
2020-03-18 03:15:19 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Morphs from the pose in jointTable to the one in morphTable, advancing the morph but not the animation frame
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
s32 SkelAnime_Morph(SkelAnime* skelAnime) {
|
|
|
|
f32 prevMorphWeight = skelAnime->morphWeight;
|
2020-12-02 03:19:56 +00:00
|
|
|
f32 updateRate = R_UPDATE_RATE * (1.0f / 3.0f);
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->morphWeight -= skelAnime->morphRate * updateRate;
|
|
|
|
if (skelAnime->morphWeight <= 0.0f) {
|
|
|
|
SkelAnime_SetUpdate(skelAnime);
|
|
|
|
skelAnime->morphWeight = 0.0f;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2021-01-09 22:07:17 +00:00
|
|
|
SkelAnime_InterpFrameTable(skelAnime->limbCount, skelAnime->jointTable, skelAnime->jointTable,
|
|
|
|
skelAnime->morphTable, 1.0f - (skelAnime->morphWeight / prevMorphWeight));
|
2020-03-20 21:12:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Performs a tapered morph from the pose in jointTable to the one in morphTable, advancing the morph but not the
|
|
|
|
* animation frame
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
s32 SkelAnime_MorphTaper(SkelAnime* skelAnime) {
|
|
|
|
s16 prevPhase = skelAnime->morphWeight * 0x4000;
|
|
|
|
s16 curPhase;
|
|
|
|
f32 prevWeight;
|
|
|
|
f32 curWeight;
|
2020-12-02 03:19:56 +00:00
|
|
|
f32 updateRate = R_UPDATE_RATE * (1.0f / 3.0f);
|
2020-03-20 21:12:26 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->morphWeight -= skelAnime->morphRate * updateRate;
|
|
|
|
if (skelAnime->morphWeight <= 0.0f) {
|
|
|
|
SkelAnime_SetUpdate(skelAnime);
|
|
|
|
skelAnime->morphWeight = 0.0f;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
curPhase = skelAnime->morphWeight * 0x4000;
|
|
|
|
if (skelAnime->taper <= ANIMTAPER_DECEL) {
|
|
|
|
prevWeight = 1.0f - Math_CosS(prevPhase);
|
|
|
|
curWeight = 1.0f - Math_CosS(curPhase);
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-12-29 22:46:46 +00:00
|
|
|
prevWeight = Math_SinS(prevPhase);
|
|
|
|
curWeight = Math_SinS(curPhase);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
if (curWeight != 0.0f) {
|
|
|
|
curWeight /= prevWeight;
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-12-29 22:46:46 +00:00
|
|
|
curWeight = 0.0f;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2021-01-09 22:07:17 +00:00
|
|
|
SkelAnime_InterpFrameTable(skelAnime->limbCount, skelAnime->jointTable, skelAnime->jointTable,
|
|
|
|
skelAnime->morphTable, 1.0f - curWeight);
|
2020-03-20 21:12:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Gets frame data for the current frame as modified by morphTable and advances the morph
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void SkelAnime_AnimateFrame(SkelAnime* skelAnime) {
|
|
|
|
Vec3s nextjointTable[100];
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
SkelAnime_GetFrameData(skelAnime->animation, skelAnime->curFrame, skelAnime->limbCount, skelAnime->jointTable);
|
|
|
|
if (skelAnime->mode & ANIM_INTERP) {
|
|
|
|
s32 frame = skelAnime->curFrame;
|
|
|
|
f32 partialFrame = skelAnime->curFrame - frame;
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if (++frame >= (s32)skelAnime->animLength) {
|
|
|
|
frame = 0;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
SkelAnime_GetFrameData(skelAnime->animation, frame, skelAnime->limbCount, nextjointTable);
|
2021-01-09 22:07:17 +00:00
|
|
|
SkelAnime_InterpFrameTable(skelAnime->limbCount, skelAnime->jointTable, skelAnime->jointTable, nextjointTable,
|
|
|
|
partialFrame);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
if (skelAnime->morphWeight != 0) {
|
2020-12-02 03:19:56 +00:00
|
|
|
f32 updateRate = R_UPDATE_RATE * (1.0f / 3.0f);
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->morphWeight -= skelAnime->morphRate * updateRate;
|
|
|
|
if (skelAnime->morphWeight <= 0.0f) {
|
|
|
|
skelAnime->morphWeight = 0.0f;
|
2020-12-02 03:19:56 +00:00
|
|
|
} else {
|
2021-01-09 22:07:17 +00:00
|
|
|
SkelAnime_InterpFrameTable(skelAnime->limbCount, skelAnime->jointTable, skelAnime->jointTable,
|
|
|
|
skelAnime->morphTable, skelAnime->morphWeight);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Advances an animation that loops over its full length and updates the frame tables
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
s32 SkelAnime_LoopFull(SkelAnime* skelAnime) {
|
2020-04-02 17:44:19 +00:00
|
|
|
f32 updateRate = R_UPDATE_RATE * (1.0f / 3.0f);
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->curFrame += skelAnime->playSpeed * updateRate;
|
|
|
|
if (skelAnime->curFrame < 0.0f) {
|
|
|
|
skelAnime->curFrame += skelAnime->animLength;
|
|
|
|
} else if (skelAnime->animLength <= skelAnime->curFrame) {
|
|
|
|
skelAnime->curFrame -= skelAnime->animLength;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
SkelAnime_AnimateFrame(skelAnime);
|
2020-03-20 21:12:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Advances an animation that loops over part of its length and updates the frame tables
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
s32 SkelAnime_LoopPartial(SkelAnime* skelAnime) {
|
2020-04-02 17:44:19 +00:00
|
|
|
f32 updateRate = R_UPDATE_RATE * (1.0f / 3.0f);
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->curFrame += skelAnime->playSpeed * updateRate;
|
|
|
|
if (skelAnime->curFrame < skelAnime->startFrame) {
|
|
|
|
skelAnime->curFrame = (skelAnime->curFrame - skelAnime->startFrame) + skelAnime->endFrame;
|
|
|
|
} else if (skelAnime->endFrame <= skelAnime->curFrame) {
|
|
|
|
skelAnime->curFrame = (skelAnime->curFrame - skelAnime->endFrame) + skelAnime->startFrame;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-25 15:51:25 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
SkelAnime_AnimateFrame(skelAnime);
|
2020-03-20 21:12:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Advances an animation that stops at endFrame and returns true when it is reached.
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
s32 SkelAnime_Once(SkelAnime* skelAnime) {
|
2020-12-02 03:19:56 +00:00
|
|
|
f32 updateRate = R_UPDATE_RATE * (1.0f / 3.0f);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if (skelAnime->curFrame == skelAnime->endFrame) {
|
|
|
|
SkelAnime_GetFrameData(skelAnime->animation, (s32)skelAnime->curFrame, skelAnime->limbCount,
|
|
|
|
skelAnime->jointTable);
|
|
|
|
SkelAnime_AnimateFrame(skelAnime);
|
2020-03-20 21:12:26 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->curFrame += skelAnime->playSpeed * updateRate;
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if ((skelAnime->curFrame - skelAnime->endFrame) * skelAnime->playSpeed > 0.0f) {
|
|
|
|
skelAnime->curFrame = skelAnime->endFrame;
|
|
|
|
} else if (skelAnime->curFrame < 0.0f) {
|
|
|
|
skelAnime->curFrame += skelAnime->animLength;
|
|
|
|
} else if (skelAnime->animLength <= skelAnime->curFrame) {
|
|
|
|
skelAnime->curFrame -= skelAnime->animLength;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
SkelAnime_AnimateFrame(skelAnime);
|
2020-03-20 21:12:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Fully general way to set a new animation, allowing choice of playback speed, start frame, end frame, play mode,
|
|
|
|
* number of transition frames, and tapering of the transition. Positive morph frames morph from the current pose to the
|
|
|
|
* start pose of the new animation, then start the new animation. Negative morph frames start the new animation
|
|
|
|
* immediately, modified by the pose immediately before the animation change.
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void Animation_ChangeImpl(SkelAnime* skelAnime, AnimationHeader* animation, f32 playSpeed, f32 startFrame, f32 endFrame,
|
|
|
|
u8 mode, f32 morphFrames, s8 taper) {
|
|
|
|
skelAnime->mode = mode;
|
|
|
|
if ((morphFrames != 0.0f) && ((animation != skelAnime->animation) || (startFrame != skelAnime->curFrame))) {
|
|
|
|
if (morphFrames < 0) {
|
|
|
|
SkelAnime_SetUpdate(skelAnime);
|
2021-01-09 22:07:17 +00:00
|
|
|
SkelAnime_CopyFrameTable(skelAnime, skelAnime->morphTable, skelAnime->jointTable);
|
2020-12-29 22:46:46 +00:00
|
|
|
morphFrames = -morphFrames;
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-12-29 22:46:46 +00:00
|
|
|
if (taper != ANIMTAPER_NONE) {
|
|
|
|
skelAnime->update = SkelAnime_MorphTaper;
|
|
|
|
skelAnime->taper = taper;
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->update = SkelAnime_Morph;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
SkelAnime_GetFrameData(animation, startFrame, skelAnime->limbCount, skelAnime->morphTable);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->morphWeight = 1.0f;
|
|
|
|
skelAnime->morphRate = 1.0f / morphFrames;
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-12-29 22:46:46 +00:00
|
|
|
SkelAnime_SetUpdate(skelAnime);
|
|
|
|
SkelAnime_GetFrameData(animation, startFrame, skelAnime->limbCount, skelAnime->jointTable);
|
|
|
|
skelAnime->morphWeight = 0.0f;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->animation = animation;
|
|
|
|
skelAnime->startFrame = startFrame;
|
|
|
|
skelAnime->endFrame = endFrame;
|
|
|
|
skelAnime->animLength = Animation_GetLength(animation);
|
|
|
|
if (skelAnime->mode >= ANIMMODE_LOOP_PARTIAL) {
|
|
|
|
skelAnime->curFrame = 0.0f;
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->curFrame = startFrame;
|
|
|
|
if (skelAnime->mode <= ANIMMODE_LOOP_INTERP) {
|
|
|
|
skelAnime->endFrame = skelAnime->animLength - 1.0f;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->playSpeed = playSpeed;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* General way to set a new animation, allowing choice of playback speed, start frame, end frame, play mode, and number
|
|
|
|
* of transition frames. Positive morph frames morph from the current pose to the start pose of the new animation, then
|
|
|
|
* start the new animation. Negative morph frames start the new animation immediately, modified by the pose immediately
|
|
|
|
* before the animation change.
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void Animation_Change(SkelAnime* skelAnime, AnimationHeader* animation, f32 playSpeed, f32 startFrame, f32 endFrame,
|
|
|
|
u8 mode, f32 morphFrames) {
|
|
|
|
Animation_ChangeImpl(skelAnime, animation, playSpeed, startFrame, endFrame, mode, morphFrames, ANIMTAPER_NONE);
|
2020-03-18 03:15:19 +00:00
|
|
|
}
|
2020-03-31 23:29:09 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Immediately changes to an animation that plays once at the default speed.
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void Animation_PlayOnce(SkelAnime* skelAnime, AnimationHeader* animation) {
|
|
|
|
Animation_Change(skelAnime, animation, 1.0f, 0.0f, Animation_GetLastFrame(animation), ANIMMODE_ONCE, 0.0f);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Smoothly transitions to an animation that plays once at the default speed.
|
|
|
|
* Positive morph frames morph from the current pose to the start pose of the new animation, then start the new
|
|
|
|
* animation. Negative morph frames start the new animation immediately, modified by the pose immediately before the
|
|
|
|
* animation change.
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void Animation_MorphToPlayOnce(SkelAnime* skelAnime, AnimationHeader* animation, f32 morphFrames) {
|
|
|
|
Animation_Change(skelAnime, animation, 1.0f, 0.0f, Animation_GetLastFrame(animation), ANIMMODE_ONCE, morphFrames);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-31 23:29:09 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Immediately changes to an animation that plays once at the specified speed.
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void Animation_PlayOnceSetSpeed(SkelAnime* skelAnime, AnimationHeader* animation, f32 playSpeed) {
|
|
|
|
Animation_Change(skelAnime, animation, playSpeed, 0.0f, Animation_GetLastFrame(animation), ANIMMODE_ONCE, 0.0f);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Immediately changes to an animation that loops at the default.
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void Animation_PlayLoop(SkelAnime* skelAnime, AnimationHeader* animation) {
|
|
|
|
Animation_Change(skelAnime, animation, 1.0f, 0.0f, Animation_GetLastFrame(animation), ANIMMODE_LOOP, 0.0f);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Smoothly transitions to a looping animation, specifying the number of frames for the transition.
|
|
|
|
* Positive morph frames morph from the current pose to the start pose of the new animation, then start the new
|
|
|
|
* animation. Negative morph frames start the new animation immediately, modified by the pose immediately before the
|
|
|
|
* animation change.
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void Animation_MorphToLoop(SkelAnime* skelAnime, AnimationHeader* animation, f32 morphFrames) {
|
|
|
|
Animation_Change(skelAnime, animation, 1.0f, 0.0f, 0.0f, ANIMMODE_LOOP, morphFrames);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Immediately changes to an animation that loops at the specified speed.
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void Animation_PlayLoopSetSpeed(SkelAnime* skelAnime, AnimationHeader* animation, f32 playSpeed) {
|
|
|
|
Animation_Change(skelAnime, animation, playSpeed, 0.0f, Animation_GetLastFrame(animation), ANIMMODE_LOOP, 0.0f);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Changes a looping animation to one that stops at the end. Unused
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void Animation_EndLoop(SkelAnime* skelAnime) {
|
|
|
|
skelAnime->mode = ANIMMODE_ONCE;
|
|
|
|
skelAnime->endFrame = skelAnime->animLength;
|
|
|
|
SkelAnime_SetUpdate(skelAnime);
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Reverses the current animation.
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void Animation_Reverse(SkelAnime* skelAnime) {
|
|
|
|
f32 startFrame = skelAnime->startFrame;
|
2020-03-31 23:29:09 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->startFrame = skelAnime->endFrame;
|
|
|
|
skelAnime->playSpeed = -skelAnime->playSpeed;
|
|
|
|
skelAnime->endFrame = startFrame;
|
2020-03-20 21:12:26 +00:00
|
|
|
}
|
2020-03-23 01:57:25 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Copies the src frame table to the dst frame table if copyFlag for that limb is true.
|
|
|
|
* Used only by En_Test
|
|
|
|
*/
|
|
|
|
void SkelAnime_CopyFrameTableTrue(SkelAnime* skelAnime, Vec3s* dst, Vec3s* src, u8* copyFlag) {
|
2020-03-23 01:57:25 +00:00
|
|
|
s32 i;
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
for (i = 0; i < skelAnime->limbCount; i++, dst++, src++) {
|
2020-12-29 22:46:46 +00:00
|
|
|
if (*copyFlag++) {
|
2020-03-23 01:57:25 +00:00
|
|
|
*dst = *src;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Copies the src frame table to the dst frame table if copyFlag for that limb is false.
|
|
|
|
* Unused.
|
|
|
|
*/
|
|
|
|
void SkelAnime_CopyFrameTableFalse(SkelAnime* skelAnime, Vec3s* dst, Vec3s* src, u8* copyFlag) {
|
2020-03-23 01:57:25 +00:00
|
|
|
s32 i;
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
for (i = 0; i < skelAnime->limbCount; i++, dst++, src++) {
|
2020-12-29 22:46:46 +00:00
|
|
|
if (!*copyFlag++) {
|
2020-03-23 01:57:25 +00:00
|
|
|
*dst = *src;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
/**
|
|
|
|
* Updates translation of the root limb and calculates `pos`, the difference between
|
|
|
|
* the old and new positions of the root limb as rotated by `angle`. Used to allow
|
|
|
|
* animations to change an actor's position.
|
2020-04-01 01:19:21 +00:00
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
void SkelAnime_UpdateTranslation(SkelAnime* skelAnime, Vec3f* diff, s16 angle) {
|
2020-03-23 01:57:25 +00:00
|
|
|
f32 x;
|
|
|
|
f32 z;
|
|
|
|
f32 sin;
|
|
|
|
f32 cos;
|
2020-03-18 03:15:19 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if (skelAnime->moveFlags & ANIM_FLAG_NOMOVE) {
|
|
|
|
diff->x = diff->z = 0.0f;
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-12-29 22:46:46 +00:00
|
|
|
x = skelAnime->jointTable[0].x;
|
|
|
|
z = skelAnime->jointTable[0].z;
|
2020-12-26 10:44:53 +00:00
|
|
|
sin = Math_SinS(angle);
|
|
|
|
cos = Math_CosS(angle);
|
2020-12-29 22:46:46 +00:00
|
|
|
diff->x = x * cos + z * sin;
|
|
|
|
diff->z = z * cos - x * sin;
|
|
|
|
x = skelAnime->prevTransl.x;
|
|
|
|
z = skelAnime->prevTransl.z;
|
|
|
|
sin = Math_SinS(skelAnime->prevRot);
|
|
|
|
cos = Math_CosS(skelAnime->prevRot);
|
|
|
|
diff->x -= x * cos + z * sin;
|
|
|
|
diff->z -= z * cos - x * sin;
|
|
|
|
}
|
|
|
|
|
|
|
|
skelAnime->prevRot = angle;
|
|
|
|
skelAnime->prevTransl.x = skelAnime->jointTable[0].x;
|
|
|
|
skelAnime->jointTable[0].x = skelAnime->baseTransl.x;
|
|
|
|
skelAnime->prevTransl.z = skelAnime->jointTable[0].z;
|
|
|
|
skelAnime->jointTable[0].z = skelAnime->baseTransl.z;
|
|
|
|
if (skelAnime->moveFlags & ANIM_FLAG_UPDATEY) {
|
|
|
|
if (skelAnime->moveFlags & ANIM_FLAG_NOMOVE) {
|
|
|
|
diff->y = 0.0f;
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-12-29 22:46:46 +00:00
|
|
|
diff->y = skelAnime->jointTable[0].y - skelAnime->prevTransl.y;
|
2020-03-23 01:57:25 +00:00
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->prevTransl.y = skelAnime->jointTable[0].y;
|
|
|
|
skelAnime->jointTable[0].y = skelAnime->baseTransl.y;
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2020-12-29 22:46:46 +00:00
|
|
|
diff->y = 0.0f;
|
|
|
|
skelAnime->prevTransl.y = skelAnime->jointTable[0].y;
|
2020-03-23 01:57:25 +00:00
|
|
|
}
|
2020-12-29 22:46:46 +00:00
|
|
|
skelAnime->moveFlags &= ~ANIM_FLAG_NOMOVE;
|
2020-03-23 01:57:25 +00:00
|
|
|
}
|
2020-03-18 03:15:19 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Checks if the current animation is at the specified frame
|
|
|
|
*/
|
2020-12-29 22:46:46 +00:00
|
|
|
s32 Animation_OnFrame(SkelAnime* skelAnime, f32 frame) {
|
|
|
|
return Animation_OnFrameImpl(skelAnime, frame, 1.0f);
|
2020-03-23 01:57:25 +00:00
|
|
|
}
|
2020-03-18 03:15:19 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Frees the frame tables for a skelAnime with dynamically allocated tables.
|
|
|
|
*/
|
2022-05-21 18:23:43 +00:00
|
|
|
void SkelAnime_Free(SkelAnime* skelAnime, PlayState* play) {
|
2020-12-29 22:46:46 +00:00
|
|
|
if (skelAnime->jointTable != NULL) {
|
|
|
|
ZeldaArena_FreeDebug(skelAnime->jointTable, "../z_skelanime.c", 3729);
|
2020-03-24 17:16:13 +00:00
|
|
|
} else {
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("now_joint あきまへん!!\n"); // "now_joint is freed! !"
|
2020-03-23 01:57:25 +00:00
|
|
|
}
|
2020-03-24 19:01:00 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
if (skelAnime->morphTable != NULL) {
|
|
|
|
ZeldaArena_FreeDebug(skelAnime->morphTable, "../z_skelanime.c", 3731);
|
2020-03-24 19:01:00 +00:00
|
|
|
} else {
|
2021-09-04 13:33:19 +00:00
|
|
|
osSyncPrintf("morf_joint あきまへん!!\n"); // "morf_joint is freed !!"
|
2020-03-23 01:57:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-18 03:15:19 +00:00
|
|
|
|
2021-01-09 22:07:17 +00:00
|
|
|
/**
|
|
|
|
* Copies the src frame table to the dst frame table.
|
|
|
|
*/
|
|
|
|
void SkelAnime_CopyFrameTable(SkelAnime* skelAnime, Vec3s* dst, Vec3s* src) {
|
2020-03-23 01:57:25 +00:00
|
|
|
s32 i;
|
2020-12-02 03:19:56 +00:00
|
|
|
|
2020-03-24 17:16:13 +00:00
|
|
|
for (i = 0; i < skelAnime->limbCount; i++) {
|
2020-03-23 01:57:25 +00:00
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
|
|
|
}
|