mirror of
https://github.com/zeldaret/oot.git
synced 2025-07-04 15:04:31 +00:00
Small Skin system documentation pass (#1017)
* some docs * rename a bunch of callbacks * more cleanup * format * last cleanup * some updates * more docs * done i think * name flag and format * name unused variable * comments * revert unwanted change * z64skin.h * format * Address review * Rename PostLimbDraw callbacks to PostDraw and some PR addressing * add true/false for setTranslation * ahhhh * remove "you" Co-authored-by: fig02 <fig02srl@gmail.com>
This commit is contained in:
parent
e5ecdfd559
commit
9fec455805
21 changed files with 442 additions and 345 deletions
|
@ -63,10 +63,10 @@ void MapMark_Init(GlobalContext* globalCtx) {
|
|||
Overlay_Load(overlay->vromStart, overlay->vromEnd, overlay->vramStart, overlay->vramEnd, overlay->loadedRamAddr);
|
||||
|
||||
sLoadedMarkDataTable = gMapMarkDataTable;
|
||||
sLoadedMarkDataTable = (void*)(u32)(
|
||||
(overlay->vramTable != NULL)
|
||||
? (void*)((u32)overlay->vramTable - (s32)((u32)overlay->vramStart - (u32)overlay->loadedRamAddr))
|
||||
: NULL);
|
||||
sLoadedMarkDataTable = (void*)(u32)((overlay->vramTable != NULL)
|
||||
? (void*)((u32)overlay->vramTable -
|
||||
(s32)((u32)overlay->vramStart - (u32)overlay->loadedRamAddr))
|
||||
: NULL);
|
||||
}
|
||||
|
||||
void MapMark_ClearPointers(GlobalContext* globalCtx) {
|
||||
|
|
|
@ -1,149 +1,178 @@
|
|||
#include "global.h"
|
||||
|
||||
MtxF D_801600C0[60];
|
||||
char D_80160FC0[0x10];
|
||||
MtxF gSkinLimbMatrices[60]; // holds matrices for each limb of the skeleton currently being drawn
|
||||
|
||||
void func_800A57C0(MtxF* mtx, Struct_800A57C0* arg1, Struct_800A598C* arg2, Vtx* arg3, Vec3f* arg4) {
|
||||
Vtx* temp_s2;
|
||||
Struct_800A57C0* phi_s1;
|
||||
f32 temp_x;
|
||||
f32 temp_y;
|
||||
f32 temp_z;
|
||||
Vec3f sp70;
|
||||
static s32 sUnused;
|
||||
|
||||
void Skin_UpdateVertices(MtxF* mtx, SkinVertex* skinVertices, SkinLimbModif* modifEntry, Vtx* vtxBuf, Vec3f* pos) {
|
||||
Vtx* vtx;
|
||||
SkinVertex* vertexEntry;
|
||||
f32 xwTemp;
|
||||
f32 ywTemp;
|
||||
f32 zwTemp;
|
||||
Vec3f normal;
|
||||
Vec3f sp64;
|
||||
|
||||
for (phi_s1 = arg1; phi_s1 < arg1 + arg2->unk_0; phi_s1++) {
|
||||
temp_s2 = &arg3[phi_s1->unk_0];
|
||||
temp_s2->n.ob[0] = arg4->x;
|
||||
temp_s2->n.ob[1] = arg4->y;
|
||||
temp_s2->n.ob[2] = arg4->z;
|
||||
temp_x = mtx->xw;
|
||||
temp_y = mtx->yw;
|
||||
temp_z = mtx->zw;
|
||||
mtx->zw = 0.0f;
|
||||
mtx->yw = 0.0f;
|
||||
mtx->xw = 0.0f;
|
||||
sp64.x = phi_s1->unk_6;
|
||||
sp64.y = phi_s1->unk_7;
|
||||
sp64.z = phi_s1->unk_8;
|
||||
SkinMatrix_Vec3fMtxFMultXYZ(mtx, &sp64, &sp70);
|
||||
temp_s2->n.n[0] = sp70.x;
|
||||
temp_s2->n.n[1] = sp70.y;
|
||||
temp_s2->n.n[2] = sp70.z;
|
||||
mtx->xw = temp_x;
|
||||
mtx->yw = temp_y;
|
||||
mtx->zw = temp_z;
|
||||
for (vertexEntry = skinVertices; vertexEntry < &skinVertices[modifEntry->vtxCount]; vertexEntry++) {
|
||||
vtx = &vtxBuf[vertexEntry->index];
|
||||
|
||||
vtx->n.ob[0] = pos->x;
|
||||
vtx->n.ob[1] = pos->y;
|
||||
vtx->n.ob[2] = pos->z;
|
||||
|
||||
xwTemp = mtx->xw;
|
||||
ywTemp = mtx->yw;
|
||||
zwTemp = mtx->zw;
|
||||
|
||||
mtx->xw = mtx->yw = mtx->zw = 0.0f;
|
||||
|
||||
sp64.x = vertexEntry->normX;
|
||||
sp64.y = vertexEntry->normY;
|
||||
sp64.z = vertexEntry->normZ;
|
||||
|
||||
SkinMatrix_Vec3fMtxFMultXYZ(mtx, &sp64, &normal);
|
||||
|
||||
vtx->n.n[0] = normal.x;
|
||||
vtx->n.n[1] = normal.y;
|
||||
vtx->n.n[2] = normal.z;
|
||||
|
||||
mtx->xw = xwTemp;
|
||||
mtx->yw = ywTemp;
|
||||
mtx->zw = zwTemp;
|
||||
}
|
||||
}
|
||||
|
||||
void func_800A598C(GraphicsContext* gfxCtx, PSkinAwb* skin, s32 limbIndex, s32 arg3) {
|
||||
s32 temp_1;
|
||||
void Skin_ApplyLimbModifications(GraphicsContext* gfxCtx, Skin* skin, s32 limbIndex, s32 arg3) {
|
||||
s32 modifCount;
|
||||
SkinLimb** skeleton;
|
||||
SkinLimb* limb;
|
||||
Struct_800A5E28* data;
|
||||
Struct_800A598C* phi_s6;
|
||||
SkinAvb* avb;
|
||||
s32 temp_a0_2;
|
||||
f32 temp_f20;
|
||||
Struct_800A57C0* temp_v0;
|
||||
Struct_800A598C_2* temp_s3;
|
||||
Vtx* spEC;
|
||||
Struct_800A598C* temp_2;
|
||||
Vec3f spDC;
|
||||
SkinAnimatedLimbData* data;
|
||||
SkinLimbModif* modif;
|
||||
SkinLimbVtx* vtxEntry;
|
||||
s32 transformCount;
|
||||
f32 scale;
|
||||
SkinVertex* skinVertices;
|
||||
SkinTransformation* limbTransformations;
|
||||
Vtx* vtxBuf;
|
||||
SkinLimbModif* modifications;
|
||||
Vec3f vtxPoint;
|
||||
Vec3f spD0;
|
||||
Struct_800A598C_2* phi_s0;
|
||||
SkinTransformation* transformationEntry;
|
||||
|
||||
OPEN_DISPS(gfxCtx, "../z_skin.c", 254);
|
||||
|
||||
skeleton = (SkinLimb**)SEGMENTED_TO_VIRTUAL(skin->skeletonHeader->segment);
|
||||
data = SEGMENTED_TO_VIRTUAL(((SkinLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]))->segment);
|
||||
temp_2 = (Struct_800A598C*)SEGMENTED_TO_VIRTUAL(data->unk_4);
|
||||
modifications = (SkinLimbModif*)SEGMENTED_TO_VIRTUAL(data->limbModifications);
|
||||
|
||||
avb = &skin->avbTbl[limbIndex];
|
||||
vtxEntry = &skin->vtxTable[limbIndex];
|
||||
vtxBuf = vtxEntry->buf[vtxEntry->index];
|
||||
modifCount = data->limbModifCount;
|
||||
|
||||
spEC = avb->buf[avb->unk_0];
|
||||
temp_1 = data->unk_2;
|
||||
for (modif = modifications; modif < modifications + modifCount; modif++) {
|
||||
transformCount = modif->transformCount;
|
||||
skinVertices = (SkinVertex*)SEGMENTED_TO_VIRTUAL(modif->skinVertices);
|
||||
limbTransformations = (SkinTransformation*)SEGMENTED_TO_VIRTUAL(modif->limbTransformations);
|
||||
|
||||
for (phi_s6 = temp_2; phi_s6 < temp_2 + temp_1; phi_s6++) {
|
||||
temp_a0_2 = phi_s6->unk_2;
|
||||
temp_v0 = (Struct_800A57C0*)SEGMENTED_TO_VIRTUAL(phi_s6->unk_8);
|
||||
temp_s3 = (Struct_800A598C_2*)SEGMENTED_TO_VIRTUAL(phi_s6->unk_C);
|
||||
|
||||
if (temp_a0_2 == 1) {
|
||||
if (transformCount == 1) {
|
||||
Vec3f spAC;
|
||||
|
||||
spAC.x = temp_s3[0].x;
|
||||
spAC.y = temp_s3[0].y;
|
||||
spAC.z = temp_s3[0].z;
|
||||
SkinMatrix_Vec3fMtxFMultXYZ(&D_801600C0[temp_s3[0].unk_0], &spAC, &spDC);
|
||||
spAC.x = limbTransformations[0].x;
|
||||
spAC.y = limbTransformations[0].y;
|
||||
spAC.z = limbTransformations[0].z;
|
||||
|
||||
SkinMatrix_Vec3fMtxFMultXYZ(&gSkinLimbMatrices[limbTransformations[0].limbIndex], &spAC, &vtxPoint);
|
||||
} else if (arg3 == 1) {
|
||||
Vec3f spA0;
|
||||
|
||||
phi_s0 = &temp_s3[phi_s6->unk_4];
|
||||
transformationEntry = &limbTransformations[modif->unk_4];
|
||||
|
||||
spA0.x = phi_s0->x;
|
||||
spA0.y = phi_s0->y;
|
||||
spA0.z = phi_s0->z;
|
||||
SkinMatrix_Vec3fMtxFMultXYZ(&D_801600C0[phi_s0->unk_0], &spA0, &spDC);
|
||||
spA0.x = transformationEntry->x;
|
||||
spA0.y = transformationEntry->y;
|
||||
spA0.z = transformationEntry->z;
|
||||
|
||||
SkinMatrix_Vec3fMtxFMultXYZ(&gSkinLimbMatrices[transformationEntry->limbIndex], &spA0, &vtxPoint);
|
||||
} else {
|
||||
Vec3f phi_f20;
|
||||
Vec3f sp88;
|
||||
|
||||
phi_f20.x = phi_f20.y = phi_f20.z = 0.0f;
|
||||
|
||||
for (phi_s0 = &temp_s3[0]; phi_s0 < &temp_s3[temp_a0_2]; phi_s0++) {
|
||||
temp_f20 = phi_s0->unk_8 * 0.01f;
|
||||
for (transformationEntry = &limbTransformations[0];
|
||||
transformationEntry < &limbTransformations[transformCount]; transformationEntry++) {
|
||||
scale = transformationEntry->scale * 0.01f;
|
||||
|
||||
sp88.x = transformationEntry->x;
|
||||
sp88.y = transformationEntry->y;
|
||||
sp88.z = transformationEntry->z;
|
||||
|
||||
SkinMatrix_Vec3fMtxFMultXYZ(&gSkinLimbMatrices[transformationEntry->limbIndex], &sp88, &spD0);
|
||||
|
||||
spD0.x *= scale;
|
||||
spD0.y *= scale;
|
||||
spD0.z *= scale;
|
||||
|
||||
sp88.x = phi_s0->x;
|
||||
sp88.y = phi_s0->y;
|
||||
sp88.z = phi_s0->z;
|
||||
SkinMatrix_Vec3fMtxFMultXYZ(&D_801600C0[phi_s0->unk_0], &sp88, &spD0);
|
||||
spD0.x *= temp_f20;
|
||||
spD0.y *= temp_f20;
|
||||
spD0.z *= temp_f20;
|
||||
phi_f20.x += spD0.x;
|
||||
phi_f20.y += spD0.y;
|
||||
phi_f20.z += spD0.z;
|
||||
}
|
||||
spDC.x = phi_f20.x;
|
||||
spDC.y = phi_f20.y;
|
||||
spDC.z = phi_f20.z;
|
||||
}
|
||||
func_800A57C0(&D_801600C0[temp_s3[phi_s6->unk_4].unk_0], temp_v0, phi_s6, spEC, &spDC);
|
||||
}
|
||||
gSPSegment(POLY_OPA_DISP++, 0x08, avb->buf[avb->unk_0]);
|
||||
|
||||
avb->unk_0 = (avb->unk_0 == 0) ? 1 : 0;
|
||||
vtxPoint.x = phi_f20.x;
|
||||
vtxPoint.y = phi_f20.y;
|
||||
vtxPoint.z = phi_f20.z;
|
||||
}
|
||||
|
||||
Skin_UpdateVertices(&gSkinLimbMatrices[limbTransformations[modif->unk_4].limbIndex], skinVertices, modif,
|
||||
vtxBuf, &vtxPoint);
|
||||
}
|
||||
|
||||
gSPSegment(POLY_OPA_DISP++, 0x08, vtxEntry->buf[vtxEntry->index]);
|
||||
|
||||
vtxEntry->index = (vtxEntry->index == 0) ? 1 : 0;
|
||||
|
||||
CLOSE_DISPS(gfxCtx, "../z_skin.c", 344);
|
||||
}
|
||||
|
||||
void func_800A5E28(GraphicsContext* gfxCtx, PSkinAwb* skin, s32 limbIndex, s32 arg3, s32 arg4) {
|
||||
/**
|
||||
* Draw a limb of type SKIN_LIMB_TYPE_ANIMATED, of the skeleton `skin` at index `limbIndex`
|
||||
* The vertices of this limb are modified dynamically
|
||||
*/
|
||||
void Skin_DrawAnimatedLimb(GraphicsContext* gfxCtx, Skin* skin, s32 limbIndex, s32 arg3, s32 drawFlags) {
|
||||
SkinLimb** skeleton;
|
||||
Struct_800A5E28* temp_t9;
|
||||
SkinAnimatedLimbData* data;
|
||||
|
||||
OPEN_DISPS(gfxCtx, "../z_skin.c", 364);
|
||||
|
||||
skeleton = SEGMENTED_TO_VIRTUAL(skin->skeletonHeader->segment);
|
||||
temp_t9 = SEGMENTED_TO_VIRTUAL(((SkinLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]))->segment);
|
||||
if (!(arg4 & 1)) {
|
||||
func_800A598C(gfxCtx, skin, limbIndex, arg3);
|
||||
data = SEGMENTED_TO_VIRTUAL(((SkinLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]))->segment);
|
||||
|
||||
if (!(drawFlags & SKIN_DRAW_FLAG_CUSTOM_TRANSFORMS)) {
|
||||
Skin_ApplyLimbModifications(gfxCtx, skin, limbIndex, arg3);
|
||||
}
|
||||
gSPDisplayList(POLY_OPA_DISP++, temp_t9->unk_8);
|
||||
|
||||
gSPDisplayList(POLY_OPA_DISP++, data->dlist);
|
||||
|
||||
CLOSE_DISPS(gfxCtx, "../z_skin.c", 377);
|
||||
}
|
||||
|
||||
void func_800A5F60(GraphicsContext* gfxCtx, PSkinAwb* skin, s32 limbIndex, Gfx* arg3, s32 arg4) {
|
||||
Gfx* gfx = arg3;
|
||||
/**
|
||||
* Draw a limb of type SKIN_LIMB_TYPE_NORMAL, of the skeleton `skin` at index `limbIndex`
|
||||
*/
|
||||
void Skin_DrawLimb(GraphicsContext* gfxCtx, Skin* skin, s32 limbIndex, Gfx* dlistOverride, s32 drawFlags) {
|
||||
Gfx* gfx = dlistOverride;
|
||||
SkinLimb** skeleton;
|
||||
s32 pad;
|
||||
|
||||
OPEN_DISPS(gfxCtx, "../z_skin.c", 395);
|
||||
|
||||
skeleton = SEGMENTED_TO_VIRTUAL(skin->skeletonHeader->segment);
|
||||
if (arg3 == NULL) {
|
||||
|
||||
if (dlistOverride == NULL) {
|
||||
gfx = ((SkinLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]))->segment;
|
||||
}
|
||||
|
||||
if (gfx != NULL) {
|
||||
Mtx* mtx = SkinMatrix_MtxFToNewMtx(gfxCtx, &D_801600C0[limbIndex]);
|
||||
Mtx* mtx = SkinMatrix_MtxFToNewMtx(gfxCtx, &gSkinLimbMatrices[limbIndex]);
|
||||
|
||||
if (mtx != NULL) {
|
||||
gSPMatrix(POLY_OPA_DISP++, mtx, G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
|
||||
|
@ -152,74 +181,89 @@ void func_800A5F60(GraphicsContext* gfxCtx, PSkinAwb* skin, s32 limbIndex, Gfx*
|
|||
gDPPipeSync(POLY_OPA_DISP++);
|
||||
}
|
||||
}
|
||||
|
||||
CLOSE_DISPS(gfxCtx, "../z_skin.c", 433);
|
||||
}
|
||||
|
||||
void func_800A60D8(Actor* actor, GlobalContext* globalCtx, PSkinAwb* skin, SkinCallback callback, SkinCallback2 arg4,
|
||||
s32 arg5, s32 arg6, s32 arg7) {
|
||||
void Skin_DrawImpl(Actor* actor, GlobalContext* globalCtx, Skin* skin, SkinPostDraw postDraw,
|
||||
SkinOverrideLimbDraw overrideLimbDraw, s32 setTranslation, s32 arg6, s32 drawFlags) {
|
||||
s32 i;
|
||||
s32 dataType;
|
||||
s32 segmentType;
|
||||
SkinLimb** skeleton;
|
||||
GraphicsContext* gfxCtx = globalCtx->state.gfxCtx;
|
||||
s32 pad;
|
||||
|
||||
OPEN_DISPS(gfxCtx, "../z_skin.c", 471);
|
||||
if ((arg7 & 1) == 0) {
|
||||
func_800A6AC4(skin, &D_801600C0[0], actor, arg5);
|
||||
|
||||
if (!(drawFlags & SKIN_DRAW_FLAG_CUSTOM_TRANSFORMS)) {
|
||||
Skin_ApplyAnimTransformations(skin, gSkinLimbMatrices, actor, setTranslation);
|
||||
}
|
||||
|
||||
skeleton = SEGMENTED_TO_VIRTUAL(skin->skeletonHeader->segment);
|
||||
if ((arg7 & 2) == 0) {
|
||||
|
||||
if (!(drawFlags & SKIN_DRAW_FLAG_CUSTOM_MATRIX)) {
|
||||
Mtx* mtx;
|
||||
|
||||
gSPMatrix(POLY_OPA_DISP++, &gMtxClear, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
|
||||
mtx = SkinMatrix_MtxFToNewMtx(gfxCtx, &skin->mtx);
|
||||
|
||||
if (mtx == NULL) {
|
||||
goto close_disps;
|
||||
}
|
||||
|
||||
gSPMatrix(POLY_OPA_DISP++, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
|
||||
}
|
||||
for (i = 0; i < skin->skeletonHeader->limbCount; i++) {
|
||||
s32 phi_a0 = 1;
|
||||
|
||||
if (arg4 != NULL) {
|
||||
phi_a0 = arg4(actor, globalCtx, i, skin);
|
||||
for (i = 0; i < skin->skeletonHeader->limbCount; i++) {
|
||||
s32 shouldDraw = true;
|
||||
|
||||
if (overrideLimbDraw != NULL) {
|
||||
shouldDraw = overrideLimbDraw(actor, globalCtx, i, skin);
|
||||
}
|
||||
dataType = ((SkinLimb*)SEGMENTED_TO_VIRTUAL(skeleton[i]))->unk_8;
|
||||
if (dataType == 4 && phi_a0 == 1) {
|
||||
func_800A5E28(gfxCtx, skin, i, arg6, arg7);
|
||||
} else if (dataType == 0xB && phi_a0 == 1) {
|
||||
func_800A5F60(gfxCtx, skin, i, NULL, arg7);
|
||||
|
||||
segmentType = ((SkinLimb*)SEGMENTED_TO_VIRTUAL(skeleton[i]))->segmentType;
|
||||
|
||||
if (segmentType == SKIN_LIMB_TYPE_ANIMATED && shouldDraw == true) {
|
||||
Skin_DrawAnimatedLimb(gfxCtx, skin, i, arg6, drawFlags);
|
||||
} else if (segmentType == SKIN_LIMB_TYPE_NORMAL && shouldDraw == true) {
|
||||
Skin_DrawLimb(gfxCtx, skin, i, NULL, drawFlags);
|
||||
}
|
||||
}
|
||||
if (callback != NULL) {
|
||||
callback(actor, globalCtx, skin);
|
||||
|
||||
if (postDraw != NULL) {
|
||||
postDraw(actor, globalCtx, skin);
|
||||
}
|
||||
|
||||
close_disps:
|
||||
CLOSE_DISPS(gfxCtx, "../z_skin.c", 534);
|
||||
}
|
||||
|
||||
void func_800A6330(Actor* this, GlobalContext* globalCtx, PSkinAwb* skin, SkinCallback callback, s32 arg4) {
|
||||
func_800A60D8(this, globalCtx, skin, callback, NULL, arg4, 0, 0);
|
||||
// allows specifying PostLimbDraw and setTranslation
|
||||
void func_800A6330(Actor* actor, GlobalContext* globalCtx, Skin* skin, SkinPostDraw postDraw, s32 setTranslation) {
|
||||
Skin_DrawImpl(actor, globalCtx, skin, postDraw, NULL, setTranslation, false, 0);
|
||||
}
|
||||
|
||||
void func_800A6360(Actor* this, GlobalContext* globalCtx, PSkinAwb* skin, SkinCallback callback, SkinCallback2 arg4,
|
||||
s32 arg5) {
|
||||
func_800A60D8(this, globalCtx, skin, callback, arg4, arg5, 0, 0);
|
||||
// allows specifying OverrideLimbDraw, PostLimbDraw and setTranslation
|
||||
void func_800A6360(Actor* actor, GlobalContext* globalCtx, Skin* skin, SkinPostDraw postDraw,
|
||||
SkinOverrideLimbDraw overrideLimbDraw, s32 setTranslation) {
|
||||
Skin_DrawImpl(actor, globalCtx, skin, postDraw, overrideLimbDraw, setTranslation, false, 0);
|
||||
}
|
||||
|
||||
void func_800A6394(Actor* this, GlobalContext* globalCtx, PSkinAwb* skin, SkinCallback callback, SkinCallback2 arg4,
|
||||
s32 arg5, s32 arg6) {
|
||||
func_800A60D8(this, globalCtx, skin, callback, arg4, arg5, arg6, 0);
|
||||
// allows specifying OverrideLimbDraw, PostLimbDraw, setTranslation, and arg6
|
||||
void func_800A6394(Actor* actor, GlobalContext* globalCtx, Skin* skin, SkinPostDraw postDraw,
|
||||
SkinOverrideLimbDraw overrideLimbDraw, s32 setTranslation, s32 arg6) {
|
||||
Skin_DrawImpl(actor, globalCtx, skin, postDraw, overrideLimbDraw, setTranslation, arg6, 0);
|
||||
}
|
||||
|
||||
void func_800A63CC(Actor* this, GlobalContext* globalCtx, PSkinAwb* skin, SkinCallback callback, SkinCallback2 arg4,
|
||||
s32 arg5, s32 arg6, s32 arg7) {
|
||||
func_800A60D8(this, globalCtx, skin, callback, arg4, arg5, arg6, arg7);
|
||||
// allows specifying all variables
|
||||
void func_800A63CC(Actor* actor, GlobalContext* globalCtx, Skin* skin, SkinPostDraw postDraw,
|
||||
SkinOverrideLimbDraw overrideLimbDraw, s32 setTranslation, s32 arg6, s32 drawFlags) {
|
||||
Skin_DrawImpl(actor, globalCtx, skin, postDraw, overrideLimbDraw, setTranslation, arg6, drawFlags);
|
||||
}
|
||||
|
||||
void func_800A6408(PSkinAwb* skin, s32 joint, Vec3f* arg2, Vec3f* arg3) {
|
||||
MtxF sp18;
|
||||
void Skin_GetLimbPos(Skin* skin, s32 limbIndex, Vec3f* offset, Vec3f* dst) {
|
||||
MtxF mtxf;
|
||||
|
||||
SkinMatrix_MtxFMtxFMult(&skin->mtx, &D_801600C0[joint], &sp18);
|
||||
SkinMatrix_Vec3fMtxFMultXYZ(&sp18, arg2, arg3);
|
||||
SkinMatrix_MtxFMtxFMult(&skin->mtx, &gSkinLimbMatrices[limbIndex], &mtxf);
|
||||
SkinMatrix_Vec3fMtxFMultXYZ(&mtxf, offset, dst);
|
||||
}
|
||||
|
|
|
@ -1,131 +1,155 @@
|
|||
#include "global.h"
|
||||
#include "overlays/actors/ovl_En_fHG/z_en_fhg.h"
|
||||
|
||||
void func_800A6460(GlobalContext* globalCtx, PSkinAwb* skin, s32 limbIndex) {
|
||||
/**
|
||||
* Initialises the Vtx buffers used for limb at index `limbIndex`
|
||||
*/
|
||||
void Skin_InitAnimatedLimb(GlobalContext* globalCtx, Skin* skin, s32 limbIndex) {
|
||||
s32 i;
|
||||
SkinLimb** skeleton = SEGMENTED_TO_VIRTUAL(skin->skeletonHeader->segment);
|
||||
Struct_800A5E28* temp_v1 = SEGMENTED_TO_VIRTUAL(((SkinLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]))->segment);
|
||||
Struct_800A598C* temp_v0 = SEGMENTED_TO_VIRTUAL(temp_v1->unk_4);
|
||||
Struct_800A598C* phi_s0;
|
||||
Struct_800A57C0* temp_s1;
|
||||
SkinAnimatedLimbData* animatedLimbData =
|
||||
SEGMENTED_TO_VIRTUAL(((SkinLimb*)SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]))->segment);
|
||||
SkinLimbModif* limbModifications = SEGMENTED_TO_VIRTUAL(animatedLimbData->limbModifications);
|
||||
SkinLimbModif* modifEntry;
|
||||
SkinVertex* skinVtxEntry;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
Vtx* temp2 = skin->avbTbl[limbIndex].buf[i];
|
||||
for (i = 0; i < ARRAY_COUNT(skin->vtxTable->buf); i++) {
|
||||
Vtx* vtxBuf = skin->vtxTable[limbIndex].buf[i];
|
||||
|
||||
for (phi_s0 = temp_v0; phi_s0 < temp_v0 + temp_v1->unk_2; phi_s0++) {
|
||||
Struct_800A57C0* phi_s1 = SEGMENTED_TO_VIRTUAL(phi_s0->unk_8);
|
||||
for (modifEntry = limbModifications; modifEntry < limbModifications + animatedLimbData->limbModifCount;
|
||||
modifEntry++) {
|
||||
SkinVertex* skinVertices = SEGMENTED_TO_VIRTUAL(modifEntry->skinVertices);
|
||||
|
||||
for (temp_s1 = phi_s1; temp_s1 < phi_s1 + phi_s0->unk_0; temp_s1++) {
|
||||
Vtx* temp_t5_3 = &temp2[temp_s1->unk_0];
|
||||
for (skinVtxEntry = skinVertices; skinVtxEntry < &skinVertices[modifEntry->vtxCount]; skinVtxEntry++) {
|
||||
Vtx* vtx = &vtxBuf[skinVtxEntry->index];
|
||||
|
||||
temp_t5_3->v.flag = 0;
|
||||
temp_t5_3->v.tc[0] = temp_s1->unk_2;
|
||||
temp_t5_3->v.tc[1] = temp_s1->unk_4;
|
||||
temp_t5_3->v.cn[3] = temp_s1->unk_9;
|
||||
vtx->n.flag = 0;
|
||||
vtx->n.tc[0] = skinVtxEntry->s;
|
||||
vtx->n.tc[1] = skinVtxEntry->t;
|
||||
vtx->n.a = skinVtxEntry->alpha;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void func_800A663C(GlobalContext* globalCtx, PSkinAwb* skin, SkeletonHeader* skeletonHeader,
|
||||
AnimationHeader* animationHeader) {
|
||||
/**
|
||||
* Initializes a skin skeleton to looping animation, dynamically allocating the frame tables,
|
||||
* and dynamically allocating and initializing the Vtx and SkinLimbVtx buffers for its animated limbs
|
||||
*/
|
||||
void Skin_Init(GlobalContext* globalCtx, Skin* skin, SkeletonHeader* skeletonHeader, AnimationHeader* animationHeader) {
|
||||
s32 limbCount;
|
||||
s32 i;
|
||||
SkinLimb** skeleton;
|
||||
SkeletonHeader* virtSkelHeader = SEGMENTED_TO_VIRTUAL(skeletonHeader);
|
||||
|
||||
skin->avbCount = virtSkelHeader->limbCount;
|
||||
skin->limbCount = virtSkelHeader->limbCount;
|
||||
skin->skeletonHeader = virtSkelHeader;
|
||||
|
||||
skeleton = SEGMENTED_TO_VIRTUAL(skin->skeletonHeader->segment);
|
||||
limbCount = skin->skeletonHeader->limbCount;
|
||||
skin->avbTbl = ZeldaArena_MallocDebug(limbCount * sizeof(SkinAvb), "../z_skin_awb.c", 212);
|
||||
|
||||
ASSERT(skin->avbTbl != NULL, "pskin_awb->avb_tbl != NULL", "../z_skin_awb.c", 214);
|
||||
skin->vtxTable = ZeldaArena_MallocDebug(limbCount * sizeof(SkinLimbVtx), "../z_skin_awb.c", 212);
|
||||
|
||||
ASSERT(skin->vtxTable != NULL, "pskin_awb->avb_tbl != NULL", "../z_skin_awb.c", 214);
|
||||
|
||||
for (i = 0; i < limbCount; i++) {
|
||||
SkinAvb* avbEntry = &skin->avbTbl[i];
|
||||
SkinLimbVtx* vtxEntry = &skin->vtxTable[i];
|
||||
SkinLimb* limb = SEGMENTED_TO_VIRTUAL(skeleton[i]);
|
||||
|
||||
if ((limb->unk_8 != 4) || (limb->segment == NULL)) {
|
||||
avbEntry->unk_0 = 0;
|
||||
if ((limb->segmentType != SKIN_LIMB_TYPE_ANIMATED) || (limb->segment == NULL)) {
|
||||
vtxEntry->index = 0;
|
||||
|
||||
avbEntry->buf[0] = NULL;
|
||||
avbEntry->buf[1] = NULL;
|
||||
vtxEntry->buf[0] = NULL;
|
||||
vtxEntry->buf[1] = NULL;
|
||||
} else {
|
||||
Struct_800A5E28* temp_s1 = SEGMENTED_TO_VIRTUAL(((void)0, limb->segment));
|
||||
SkinAnimatedLimbData* animatedLimbData = SEGMENTED_TO_VIRTUAL(((void)0, limb->segment));
|
||||
|
||||
avbEntry->unk_0 = 0;
|
||||
avbEntry->buf[0] = ZeldaArena_MallocDebug(temp_s1->unk_0 * sizeof(Vtx), "../z_skin_awb.c", 235);
|
||||
ASSERT(avbEntry->buf[0] != NULL, "psavb->buf[0] != NULL", "../z_skin_awb.c", 237);
|
||||
avbEntry->buf[1] = ZeldaArena_MallocDebug(temp_s1->unk_0 * sizeof(Vtx), "../z_skin_awb.c", 240);
|
||||
ASSERT(avbEntry->buf[1] != NULL, "psavb->buf[1] != NULL", "../z_skin_awb.c", 242);
|
||||
func_800A6460(globalCtx, skin, i);
|
||||
vtxEntry->index = 0;
|
||||
|
||||
vtxEntry->buf[0] =
|
||||
ZeldaArena_MallocDebug(animatedLimbData->totalVtxCount * sizeof(Vtx), "../z_skin_awb.c", 235);
|
||||
ASSERT(vtxEntry->buf[0] != NULL, "psavb->buf[0] != NULL", "../z_skin_awb.c", 237);
|
||||
|
||||
vtxEntry->buf[1] =
|
||||
ZeldaArena_MallocDebug(animatedLimbData->totalVtxCount * sizeof(Vtx), "../z_skin_awb.c", 240);
|
||||
ASSERT(vtxEntry->buf[1] != NULL, "psavb->buf[1] != NULL", "../z_skin_awb.c", 242);
|
||||
|
||||
Skin_InitAnimatedLimb(globalCtx, skin, i);
|
||||
}
|
||||
if (1) {}
|
||||
}
|
||||
|
||||
SkelAnime_InitSkin(globalCtx, &skin->skelAnime, skeletonHeader, animationHeader);
|
||||
}
|
||||
|
||||
void func_800A6888(GlobalContext* globalCtx, PSkinAwb* arg1) {
|
||||
if (arg1->avbTbl != NULL) {
|
||||
/**
|
||||
* Frees the dynamically allocated Vtx and SkinLimbVtx buffers and tables
|
||||
*/
|
||||
void Skin_Free(GlobalContext* globalCtx, Skin* skin) {
|
||||
if (skin->vtxTable != NULL) {
|
||||
s32 i;
|
||||
|
||||
for (i = 0; i < arg1->avbCount; i++) {
|
||||
if (arg1->avbTbl[i].buf[0] != 0) {
|
||||
ZeldaArena_FreeDebug(arg1->avbTbl[i].buf[0], "../z_skin_awb.c", 276);
|
||||
arg1->avbTbl[i].buf[0] = 0;
|
||||
for (i = 0; i < skin->limbCount; i++) {
|
||||
if (skin->vtxTable[i].buf[0] != NULL) {
|
||||
ZeldaArena_FreeDebug(skin->vtxTable[i].buf[0], "../z_skin_awb.c", 276);
|
||||
skin->vtxTable[i].buf[0] = NULL;
|
||||
}
|
||||
if (arg1->avbTbl[i].buf[1] != 0) {
|
||||
ZeldaArena_FreeDebug(arg1->avbTbl[i].buf[1], "../z_skin_awb.c", 280);
|
||||
arg1->avbTbl[i].buf[1] = 0;
|
||||
if (skin->vtxTable[i].buf[1] != NULL) {
|
||||
ZeldaArena_FreeDebug(skin->vtxTable[i].buf[1], "../z_skin_awb.c", 280);
|
||||
skin->vtxTable[i].buf[1] = NULL;
|
||||
}
|
||||
}
|
||||
if (arg1->avbTbl != NULL) {
|
||||
ZeldaArena_FreeDebug(arg1->avbTbl, "../z_skin_awb.c", 286);
|
||||
|
||||
if (skin->vtxTable != NULL) {
|
||||
ZeldaArena_FreeDebug(skin->vtxTable, "../z_skin_awb.c", 286);
|
||||
}
|
||||
SkelAnime_Free(&arg1->skelAnime, globalCtx);
|
||||
|
||||
SkelAnime_Free(&skin->skelAnime, globalCtx);
|
||||
}
|
||||
}
|
||||
|
||||
s32 func_800A698C(PSkinAwb* skin, SkinLimb** skeleton, MtxF* mf, u8 parentIndex, u8 limbIndex) {
|
||||
s32 func_800A698C(Skin* skin, SkinLimb** skeleton, MtxF* limbMatrices, u8 parentIndex, u8 limbIndex) {
|
||||
s32 pad;
|
||||
SkinLimb* limb = SEGMENTED_TO_VIRTUAL(skeleton[limbIndex]);
|
||||
MtxF* mtx;
|
||||
s32 temp_ret;
|
||||
s32 ret;
|
||||
MtxF sp28;
|
||||
|
||||
if (parentIndex == 0xFF) {
|
||||
if (parentIndex == LIMB_DONE) {
|
||||
SkinMatrix_GetClear(&mtx);
|
||||
} else {
|
||||
mtx = &mf[(s32)parentIndex];
|
||||
mtx = &limbMatrices[(s32)parentIndex];
|
||||
}
|
||||
|
||||
SkinMatrix_MtxFMtxFMult(mtx, &mf[limbIndex], &sp28);
|
||||
SkinMatrix_MtxFCopy(&sp28, &mf[limbIndex]);
|
||||
SkinMatrix_MtxFMtxFMult(mtx, &limbMatrices[limbIndex], &sp28);
|
||||
SkinMatrix_MtxFCopy(&sp28, &limbMatrices[limbIndex]);
|
||||
|
||||
if (limb->child != 0xFF) {
|
||||
temp_ret = func_800A698C(skin, skeleton, mf, limbIndex, limb->child);
|
||||
if (temp_ret) { // func_800A698C only returns false
|
||||
return temp_ret;
|
||||
if (limb->child != LIMB_DONE) {
|
||||
ret = func_800A698C(skin, skeleton, limbMatrices, limbIndex, limb->child);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (limb->sibling != 0xFF) {
|
||||
temp_ret = func_800A698C(skin, skeleton, mf, parentIndex, limb->sibling);
|
||||
if (temp_ret) { // func_800A698C only returns false
|
||||
return temp_ret;
|
||||
if (limb->sibling != LIMB_DONE) {
|
||||
ret = func_800A698C(skin, skeleton, limbMatrices, parentIndex, limb->sibling);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
s32 func_800A6AC4(PSkinAwb* skin, MtxF* arg1, Actor* actor, s32 arg3) {
|
||||
/**
|
||||
* Recursively applies matrix tranformations to each limb
|
||||
*/
|
||||
s32 Skin_ApplyAnimTransformations(Skin* skin, MtxF* limbMatrices, Actor* actor, s32 setTranslation) {
|
||||
s32 i;
|
||||
s32 pad;
|
||||
f32 yRot;
|
||||
f32 xRot;
|
||||
f32 zRot;
|
||||
s32 temp_ret;
|
||||
s32 ret;
|
||||
f32 yTransl;
|
||||
f32 xTransl;
|
||||
f32 zTransl;
|
||||
|
@ -133,28 +157,33 @@ s32 func_800A6AC4(PSkinAwb* skin, MtxF* arg1, Actor* actor, s32 arg3) {
|
|||
Vec3s* jointRot = &skin->skelAnime.jointTable[0];
|
||||
|
||||
jointRot++;
|
||||
xRot = jointRot[0].x;
|
||||
yRot = jointRot[0].y;
|
||||
zRot = jointRot[0].z;
|
||||
|
||||
if (arg3 != 0) {
|
||||
xRot = jointRot->x;
|
||||
yRot = jointRot->y;
|
||||
zRot = jointRot->z;
|
||||
|
||||
if (setTranslation) {
|
||||
jointRot--; // access joint table entry 0 for translation data
|
||||
|
||||
xTransl = jointRot->x;
|
||||
yTransl = jointRot->y;
|
||||
zTransl = jointRot->z;
|
||||
|
||||
jointRot--;
|
||||
xTransl = jointRot[0].x;
|
||||
yTransl = jointRot[0].y;
|
||||
zTransl = jointRot[0].z;
|
||||
jointRot++;
|
||||
|
||||
if (arg3 == 0x23) {
|
||||
if (setTranslation == SKIN_TRANSFORM_IS_FHG) {
|
||||
EnfHG* horse = (EnfHG*)actor;
|
||||
|
||||
yRot += horse->turnRot;
|
||||
}
|
||||
SkinMatrix_SetTranslateRotateZYX(arg1, xRot, yRot, zRot, xTransl, yTransl, zTransl);
|
||||
|
||||
SkinMatrix_SetTranslateRotateZYX(&limbMatrices[0], xRot, yRot, zRot, xTransl, yTransl, zTransl);
|
||||
} else {
|
||||
SkinMatrix_SetTranslateRotateZYX(arg1, xRot, yRot, zRot, 0.0f, 0.0f, 0.0f);
|
||||
SkinMatrix_SetTranslateRotateZYX(&limbMatrices[0], xRot, yRot, zRot, 0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
jointRot++;
|
||||
|
||||
for (i = 1; i < skin->skeletonHeader->limbCount; i++) {
|
||||
SkinLimb* limb = SEGMENTED_TO_VIRTUAL(skeleton[i]);
|
||||
|
||||
|
@ -165,7 +194,7 @@ s32 func_800A6AC4(PSkinAwb* skin, MtxF* arg1, Actor* actor, s32 arg3) {
|
|||
yRot = jointRot->y;
|
||||
zRot = jointRot->z;
|
||||
jointRot++;
|
||||
SkinMatrix_SetTranslateRotateZYX(&arg1[i], xRot, yRot, zRot, xTransl, yTransl, zTransl);
|
||||
SkinMatrix_SetTranslateRotateZYX(&limbMatrices[i], xRot, yRot, zRot, xTransl, yTransl, zTransl);
|
||||
}
|
||||
|
||||
SkinMatrix_SetTranslateRotateYXZScale(
|
||||
|
@ -173,9 +202,10 @@ s32 func_800A6AC4(PSkinAwb* skin, MtxF* arg1, Actor* actor, s32 arg3) {
|
|||
actor->shape.rot.z, actor->world.pos.x, actor->world.pos.y + (actor->shape.yOffset * actor->scale.y),
|
||||
actor->world.pos.z);
|
||||
|
||||
temp_ret = func_800A698C(skin, SEGMENTED_TO_VIRTUAL(skin->skeletonHeader->segment), arg1, 0xFF, 0);
|
||||
if (!temp_ret) { // func_800A698C only returns false
|
||||
return temp_ret;
|
||||
ret = func_800A698C(skin, SEGMENTED_TO_VIRTUAL(skin->skeletonHeader->segment), limbMatrices, LIMB_DONE, 0);
|
||||
if (!ret) {
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue