2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-19 20:27:25 +00:00
|
|
|
void SkelCurve_Clear(SkelAnimeCurve* skelCurve) {
|
|
|
|
skelCurve->limbCount = 0;
|
|
|
|
skelCurve->limbList = NULL;
|
|
|
|
skelCurve->transUpdIdx = NULL;
|
|
|
|
skelCurve->animCurFrame = 0.0f;
|
|
|
|
skelCurve->animSpeed = 0.0f;
|
|
|
|
skelCurve->animFinalFrame = 0.0f;
|
|
|
|
skelCurve->transforms = NULL;
|
|
|
|
skelCurve->unk_0C = 0.0f;
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-19 20:27:25 +00:00
|
|
|
s32 SkelCurve_Init(GlobalContext* globalCtx, SkelAnimeCurve* skelCurve, SkelCurveLimbList* limbListSeg,
|
2020-12-07 17:48:29 +00:00
|
|
|
TransformUpdateIndex* transUpdIdx) {
|
2020-05-19 20:27:25 +00:00
|
|
|
SkelCurveLimb** limbs;
|
|
|
|
SkelCurveLimbList* limbList = SEGMENTED_TO_VIRTUAL(limbListSeg);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-19 20:27:25 +00:00
|
|
|
skelCurve->limbCount = limbList->limbCount;
|
|
|
|
skelCurve->limbList = SEGMENTED_TO_VIRTUAL(limbList->limbs);
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-19 20:27:25 +00:00
|
|
|
skelCurve->transforms = ZeldaArena_MallocDebug(sizeof(*skelCurve->transforms) * skelCurve->limbCount,
|
|
|
|
"../z_fcurve_data_skelanime.c", 125);
|
2021-04-29 18:39:46 +00:00
|
|
|
ASSERT(skelCurve->transforms != NULL, "this->now_joint != NULL", "../z_fcurve_data_skelanime.c", 127);
|
2020-05-19 20:27:25 +00:00
|
|
|
do {
|
|
|
|
skelCurve->animCurFrame = 0.0f;
|
|
|
|
} while (0);
|
|
|
|
return 1;
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-19 20:27:25 +00:00
|
|
|
void SkelCurve_Destroy(GlobalContext* globalCtx, SkelAnimeCurve* skelCurve) {
|
|
|
|
if (skelCurve->transforms != NULL) {
|
|
|
|
ZeldaArena_FreeDebug(skelCurve->transforms, "../z_fcurve_data_skelanime.c", 146);
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-19 20:27:25 +00:00
|
|
|
void SkelCurve_SetAnim(SkelAnimeCurve* skelCurve, TransformUpdateIndex* transUpdIdx, f32 arg2, f32 animFinalFrame,
|
|
|
|
f32 animCurFrame, f32 animSpeed) {
|
|
|
|
skelCurve->unk_0C = arg2 - skelCurve->animSpeed;
|
|
|
|
skelCurve->animFinalFrame = animFinalFrame;
|
|
|
|
skelCurve->animCurFrame = animCurFrame;
|
|
|
|
skelCurve->animSpeed = animSpeed;
|
|
|
|
skelCurve->transUpdIdx = transUpdIdx;
|
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-05-19 20:27:25 +00:00
|
|
|
s32 SkelCurve_Update(GlobalContext* globalCtx, SkelAnimeCurve* skelCurve) {
|
|
|
|
s16* transforms;
|
|
|
|
u8* transformRefIdx;
|
|
|
|
TransformUpdateIndex* transformIndex;
|
|
|
|
u16* transformCopyValues;
|
|
|
|
s32 i;
|
2021-02-14 00:49:40 +00:00
|
|
|
s32 ret = 0;
|
2020-05-19 20:27:25 +00:00
|
|
|
s32 k;
|
|
|
|
TransformData* transData;
|
|
|
|
f32 transformValue;
|
|
|
|
s32 j;
|
|
|
|
|
|
|
|
transformIndex = SEGMENTED_TO_VIRTUAL(skelCurve->transUpdIdx);
|
|
|
|
transformRefIdx = SEGMENTED_TO_VIRTUAL(transformIndex->refIndex);
|
|
|
|
transData = SEGMENTED_TO_VIRTUAL(transformIndex->transformData);
|
|
|
|
transformCopyValues = SEGMENTED_TO_VIRTUAL(transformIndex->copyValues);
|
|
|
|
transforms = (s16*)skelCurve->transforms;
|
|
|
|
|
|
|
|
skelCurve->animCurFrame += skelCurve->animSpeed * R_UPDATE_RATE * 0.5f;
|
|
|
|
|
|
|
|
if ((skelCurve->animSpeed >= 0.0f && skelCurve->animCurFrame > skelCurve->animFinalFrame) ||
|
|
|
|
(skelCurve->animSpeed < 0.0f && skelCurve->animCurFrame < skelCurve->animFinalFrame)) {
|
|
|
|
skelCurve->animCurFrame = skelCurve->animFinalFrame;
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < skelCurve->limbCount; i++) {
|
|
|
|
for (j = 0; j < 3; j++) {
|
|
|
|
for (k = 0; k < 3; k++, transformRefIdx++, transforms++) {
|
|
|
|
if (*transformRefIdx == 0) {
|
|
|
|
transformValue = *transformCopyValues;
|
|
|
|
*transforms = transformValue;
|
|
|
|
transformCopyValues++;
|
|
|
|
} else {
|
|
|
|
transformValue = func_8006C5A8(skelCurve->animCurFrame, transData, *transformRefIdx);
|
|
|
|
transData += *transformRefIdx;
|
|
|
|
if (j == 0) {
|
|
|
|
*transforms = transformValue * 1024.0f;
|
|
|
|
} else if (j == 1) {
|
|
|
|
*transforms = transformValue * (32768.0f / 180.0f);
|
|
|
|
} else {
|
|
|
|
*transforms = transformValue * 100.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SkelCurve_DrawLimb(GlobalContext* globalCtx, s32 limbIndex, SkelAnimeCurve* skelCurve,
|
2020-12-02 03:19:56 +00:00
|
|
|
OverrideCurveLimbDraw overrideLimbDraw, PostCurveLimbDraw postLimbDraw, s32 lod, void* data) {
|
2020-05-19 20:27:25 +00:00
|
|
|
SkelCurveLimb* limb = SEGMENTED_TO_VIRTUAL(skelCurve->limbList[limbIndex]);
|
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_fcurve_data_skelanime.c", 279);
|
2020-08-23 21:50:30 +00:00
|
|
|
|
2020-05-19 20:27:25 +00:00
|
|
|
Matrix_Push();
|
2020-08-23 21:50:30 +00:00
|
|
|
|
2020-05-19 20:27:25 +00:00
|
|
|
if (overrideLimbDraw == NULL ||
|
2020-12-02 03:19:56 +00:00
|
|
|
(overrideLimbDraw != NULL && overrideLimbDraw(globalCtx, skelCurve, limbIndex, data))) {
|
2020-08-23 21:50:30 +00:00
|
|
|
Vec3f scale;
|
|
|
|
Vec3s rot;
|
|
|
|
Vec3f pos;
|
|
|
|
Gfx* dList;
|
2021-02-14 00:49:40 +00:00
|
|
|
Vec3s* transform = (Vec3s*)&skelCurve->transforms[limbIndex];
|
2020-08-23 21:50:30 +00:00
|
|
|
|
2020-12-29 22:46:46 +00:00
|
|
|
scale.x = transform->x / 1024.0f;
|
|
|
|
scale.y = transform->y / 1024.0f;
|
|
|
|
scale.z = transform->z / 1024.0f;
|
2020-05-19 20:27:25 +00:00
|
|
|
transform++;
|
|
|
|
rot.x = transform->x;
|
|
|
|
rot.y = transform->y;
|
|
|
|
rot.z = transform->z;
|
|
|
|
transform++;
|
|
|
|
pos.x = transform->x;
|
|
|
|
pos.y = transform->y;
|
|
|
|
pos.z = transform->z;
|
2020-08-23 21:50:30 +00:00
|
|
|
|
2020-05-19 20:27:25 +00:00
|
|
|
Matrix_JointPosition(&pos, &rot);
|
|
|
|
Matrix_Scale(scale.x, scale.y, scale.z, MTXMODE_APPLY);
|
2020-08-23 21:50:30 +00:00
|
|
|
|
2020-05-19 20:27:25 +00:00
|
|
|
if (lod == 0) {
|
2020-08-23 21:50:30 +00:00
|
|
|
s32 pad1;
|
|
|
|
|
|
|
|
dList = limb->dList[0];
|
|
|
|
if (dList != NULL) {
|
2020-11-19 21:49:08 +00:00
|
|
|
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_fcurve_data_skelanime.c", 321),
|
2020-05-19 20:27:25 +00:00
|
|
|
G_MTX_LOAD | G_MTX_NOPUSH | G_MTX_MODELVIEW);
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPDisplayList(POLY_OPA_DISP++, dList);
|
2020-05-19 20:27:25 +00:00
|
|
|
}
|
|
|
|
} else if (lod == 1) {
|
2020-08-23 21:50:30 +00:00
|
|
|
s32 pad2;
|
|
|
|
|
|
|
|
dList = limb->dList[0];
|
|
|
|
if (dList != NULL) {
|
2020-11-19 21:49:08 +00:00
|
|
|
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_fcurve_data_skelanime.c", 332),
|
2020-05-19 20:27:25 +00:00
|
|
|
G_MTX_LOAD | G_MTX_NOPUSH | G_MTX_MODELVIEW);
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPDisplayList(POLY_OPA_DISP++, dList);
|
2020-05-19 20:27:25 +00:00
|
|
|
}
|
2020-08-23 21:50:30 +00:00
|
|
|
dList = limb->dList[1];
|
|
|
|
if (dList != NULL) {
|
2020-11-19 21:49:08 +00:00
|
|
|
gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_fcurve_data_skelanime.c", 338),
|
2020-05-19 20:27:25 +00:00
|
|
|
G_MTX_LOAD | G_MTX_NOPUSH | G_MTX_MODELVIEW);
|
2020-10-29 21:31:09 +00:00
|
|
|
gSPDisplayList(POLY_XLU_DISP++, dList);
|
2020-05-19 20:27:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// FcSkeletonInfo_draw_child (): Not supported
|
|
|
|
osSyncPrintf("FcSkeletonInfo_draw_child():未対応\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (postLimbDraw != NULL) {
|
2020-12-02 03:19:56 +00:00
|
|
|
postLimbDraw(globalCtx, skelCurve, limbIndex, data);
|
2020-05-19 20:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (limb->firstChildIdx != LIMB_DONE) {
|
2020-12-02 03:19:56 +00:00
|
|
|
SkelCurve_DrawLimb(globalCtx, limb->firstChildIdx, skelCurve, overrideLimbDraw, postLimbDraw, lod, data);
|
2020-05-19 20:27:25 +00:00
|
|
|
}
|
|
|
|
|
2021-02-24 19:28:04 +00:00
|
|
|
Matrix_Pop();
|
2020-05-19 20:27:25 +00:00
|
|
|
|
|
|
|
if (limb->nextLimbIdx != LIMB_DONE) {
|
2020-12-02 03:19:56 +00:00
|
|
|
SkelCurve_DrawLimb(globalCtx, limb->nextLimbIdx, skelCurve, overrideLimbDraw, postLimbDraw, lod, data);
|
2020-05-19 20:27:25 +00:00
|
|
|
}
|
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_fcurve_data_skelanime.c", 371);
|
2020-05-19 20:27:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkelCurve_Draw(Actor* actor, GlobalContext* globalCtx, SkelAnimeCurve* skelCurve,
|
2020-12-02 03:19:56 +00:00
|
|
|
OverrideCurveLimbDraw overrideLimbDraw, PostCurveLimbDraw postLimbDraw, s32 lod, void* data) {
|
2020-05-19 20:27:25 +00:00
|
|
|
if (skelCurve->transforms != NULL) {
|
2020-12-02 03:19:56 +00:00
|
|
|
SkelCurve_DrawLimb(globalCtx, 0, skelCurve, overrideLimbDraw, postLimbDraw, lod, data);
|
2020-05-19 20:27:25 +00:00
|
|
|
}
|
|
|
|
}
|