2021-09-15 23:24:19 +00:00
# ifndef Z64_ANIMATION_H
# define Z64_ANIMATION_H
2020-03-23 01:24:00 +00:00
2020-10-03 15:22:44 +00:00
# include "ultra64.h"
# include "z64dma.h"
# include "z64math.h"
2020-03-23 01:24:00 +00:00
2022-05-21 18:23:43 +00:00
struct PlayState ;
2020-03-23 01:24:00 +00:00
struct Actor ;
2020-12-02 03:19:56 +00:00
struct SkelAnime ;
# define LINK_ANIMATION_OFFSET(addr, offset) \
2022-11-17 02:57:02 +00:00
( ( ( uintptr_t ) _link_animetionSegmentRomStart ) + ( ( uintptr_t ) ( addr ) ) - ( ( uintptr_t ) _link_animetionSegmentStart ) + ( offset ) )
2020-12-02 03:19:56 +00:00
# define LIMB_DONE 0xFF
# define ANIMATION_ENTRY_MAX 50
2020-12-29 22:46:46 +00:00
# define ANIM_FLAG_UPDATEY (1 << 1)
# define ANIM_FLAG_NOMOVE (1 << 4)
typedef enum {
/* 0 */ ANIMMODE_LOOP ,
/* 1 */ ANIMMODE_LOOP_INTERP ,
/* 2 */ ANIMMODE_ONCE ,
/* 3 */ ANIMMODE_ONCE_INTERP ,
/* 4 */ ANIMMODE_LOOP_PARTIAL ,
/* 5 */ ANIMMODE_LOOP_PARTIAL_INTERP
2022-03-16 21:14:56 +00:00
} AnimationMode ;
2020-12-29 22:46:46 +00:00
2022-01-23 23:09:02 +00:00
typedef enum {
/* -1 */ ANIMTAPER_DECEL = - 1 ,
/* 0 */ ANIMTAPER_NONE ,
2020-12-29 22:46:46 +00:00
/* 1 */ ANIMTAPER_ACCEL
} AnimationTapers ;
2020-03-23 01:24:00 +00:00
2020-03-24 17:16:13 +00:00
typedef struct {
2020-12-02 03:19:56 +00:00
/* 0x00 */ Vec3s jointPos ; // Root is position in model space, children are relative to parent
/* 0x06 */ u8 child ;
/* 0x07 */ u8 sibling ;
/* 0x08 */ Gfx * dList ;
} StandardLimb ; // size = 0xC
2020-03-23 01:24:00 +00:00
2020-03-24 17:16:13 +00:00
typedef struct {
2020-12-02 03:19:56 +00:00
/* 0x00 */ Vec3s jointPos ; // Root is position in model space, children are relative to parent
/* 0x06 */ u8 child ;
/* 0x07 */ u8 sibling ;
/* 0x08 */ Gfx * dLists [ 2 ] ; // Near and far
} LodLimb ; // size = 0x10
2020-03-25 15:51:25 +00:00
2021-06-14 18:12:34 +00:00
typedef struct LegacyLimb {
/* 0x000 */ Gfx * dList ;
/* 0x004 */ Vec3f trans ;
/* 0x010 */ Vec3s rot ;
/* 0x018 */ struct LegacyLimb * sibling ;
/* 0x01C */ struct LegacyLimb * child ;
} LegacyLimb ; // size = 0x20
2020-12-02 03:19:56 +00:00
// Model has limbs with only rigid meshes
typedef struct {
/* 0x00 */ void * * segment ;
/* 0x04 */ u8 limbCount ;
} SkeletonHeader ; // size = 0x8
2020-03-23 01:24:00 +00:00
2020-12-02 03:19:56 +00:00
// Model has limbs with flexible meshes
2020-03-24 17:16:13 +00:00
typedef struct {
2020-12-02 03:19:56 +00:00
/* 0x00 */ SkeletonHeader sh ;
/* 0x08 */ u8 dListCount ;
} FlexSkeletonHeader ; // size = 0xC
2020-03-23 01:24:00 +00:00
2022-01-23 23:09:02 +00:00
// Index into the frame data table.
2020-03-24 17:16:13 +00:00
typedef struct {
2020-12-29 22:46:46 +00:00
/* 0x00 */ u16 x ;
/* 0x02 */ u16 y ;
/* 0x04 */ u16 z ;
} JointIndex ; // size = 0x06
2020-03-25 15:51:25 +00:00
typedef struct {
2020-12-29 22:46:46 +00:00
/* 0x00 */ s16 frameCount ;
} AnimationHeaderCommon ;
2020-03-23 01:24:00 +00:00
2020-12-02 03:19:56 +00:00
typedef struct {
2020-12-29 22:46:46 +00:00
/* 0x00 */ AnimationHeaderCommon common ;
2021-11-09 02:15:37 +00:00
/* 0x04 */ void * segment ;
2020-12-02 03:19:56 +00:00
} LinkAnimationHeader ; // size = 0x8
2020-12-29 22:46:46 +00:00
typedef struct {
/* 0x00 */ AnimationHeaderCommon common ;
2021-11-30 23:40:42 +00:00
/* 0x04 */ s16 * frameData ; // "tbl"
2020-12-29 22:46:46 +00:00
/* 0x08 */ JointIndex * jointIndices ; // "ref_tbl"
/* 0x0C */ u16 staticIndexMax ;
} AnimationHeader ; // size = 0x10
// Unused
typedef struct {
/* 0x00 */ s16 xMax ;
/* 0x02 */ s16 x ;
/* 0x04 */ s16 yMax ;
/* 0x06 */ s16 y ;
/* 0x08 */ s16 zMax ;
2021-06-14 18:12:34 +00:00
/* 0x0A */ s16 z ;
} JointKey ; // size = 0x0C
2020-12-29 22:46:46 +00:00
// Unused
typedef struct {
/* 0x00 */ s16 frameCount ;
/* 0x02 */ s16 limbCount ;
/* 0x04 */ s16 * frameData ;
/* 0x08 */ JointKey * jointKey ;
2021-06-14 18:12:34 +00:00
} LegacyAnimationHeader ; // size = 0xC
2020-12-29 22:46:46 +00:00
2022-05-21 18:23:43 +00:00
typedef s32 ( * OverrideLimbDrawOpa ) ( struct PlayState * play , s32 limbIndex , Gfx * * dList , Vec3f * pos , Vec3s * rot ,
2020-12-02 03:19:56 +00:00
void * ) ;
2022-05-21 18:23:43 +00:00
typedef void ( * PostLimbDrawOpa ) ( struct PlayState * play , s32 limbIndex , Gfx * * dList , Vec3s * rot , void * ) ;
2020-12-02 03:19:56 +00:00
2022-05-21 18:23:43 +00:00
typedef s32 ( * OverrideLimbDraw ) ( struct PlayState * play , s32 limbIndex , Gfx * * dList , Vec3f * pos , Vec3s * rot ,
2020-12-02 03:19:56 +00:00
void * , Gfx * * gfx ) ;
2022-05-21 18:23:43 +00:00
typedef void ( * PostLimbDraw ) ( struct PlayState * play , s32 limbIndex , Gfx * * dList , Vec3s * rot , void * , Gfx * * gfx ) ;
2020-12-02 03:19:56 +00:00
2020-03-23 01:24:00 +00:00
typedef enum {
2020-12-29 22:46:46 +00:00
ANIMENTRY_LOADFRAME ,
ANIMENTRY_COPYALL ,
ANIMENTRY_INTERP ,
ANIMENTRY_COPYTRUE ,
ANIMENTRY_COPYFALSE ,
ANIMENTRY_MOVEACTOR
2020-03-23 01:24:00 +00:00
} AnimationType ;
2020-03-24 17:16:13 +00:00
typedef struct {
2020-03-24 16:52:12 +00:00
/* 0x000 */ DmaRequest req ;
/* 0x020 */ OSMesgQueue msgQueue ;
/* 0x038 */ OSMesg msg ;
2020-12-29 22:46:46 +00:00
} AnimEntryLoadFrame ; // size = 0x3C
2020-03-23 01:24:00 +00:00
2020-03-24 17:16:13 +00:00
typedef struct {
2020-12-29 22:46:46 +00:00
/* 0x000 */ u8 queueFlag ;
2020-03-24 16:52:12 +00:00
/* 0x001 */ u8 vecCount ;
/* 0x004 */ Vec3s * dst ;
/* 0x008 */ Vec3s * src ;
2020-12-29 22:46:46 +00:00
} AnimEntryCopyAll ; // size = 0xC
2020-03-23 01:24:00 +00:00
2020-03-24 17:16:13 +00:00
typedef struct {
2020-12-29 22:46:46 +00:00
/* 0x000 */ u8 queueFlag ;
/* 0x001 */ u8 vecCount ;
/* 0x004 */ Vec3s * base ;
/* 0x008 */ Vec3s * mod ;
/* 0x00C */ f32 weight ;
} AnimEntryInterp ; // size = 0x10
2020-03-23 01:24:00 +00:00
2020-03-24 17:16:13 +00:00
typedef struct {
2020-12-29 22:46:46 +00:00
/* 0x000 */ u8 queueFlag ;
2020-03-24 16:52:12 +00:00
/* 0x001 */ u8 vecCount ;
/* 0x004 */ Vec3s * dst ;
/* 0x008 */ Vec3s * src ;
2020-12-29 22:46:46 +00:00
/* 0x00C */ u8 * copyFlag ;
} AnimEntryCopyTrue ; // size = 0x10
2020-03-23 01:24:00 +00:00
2020-03-24 17:16:13 +00:00
typedef struct {
2020-12-29 22:46:46 +00:00
/* 0x000 */ u8 queueFlag ;
2020-03-24 16:52:12 +00:00
/* 0x001 */ u8 vecCount ;
/* 0x004 */ Vec3s * dst ;
/* 0x008 */ Vec3s * src ;
2020-12-29 22:46:46 +00:00
/* 0x00C */ u8 * copyFlag ;
} AnimEntryCopyFalse ; // size = 0x10
2020-03-23 01:24:00 +00:00
2020-03-24 17:16:13 +00:00
typedef struct {
2020-03-24 16:52:12 +00:00
/* 0x000 */ struct Actor * actor ;
2020-12-02 03:19:56 +00:00
/* 0x004 */ struct SkelAnime * skelAnime ;
2020-03-24 16:52:12 +00:00
/* 0x008 */ f32 unk_08 ;
2020-12-29 22:46:46 +00:00
} AnimEntryMoveActor ; // size = 0xC
2020-03-23 01:24:00 +00:00
2020-03-24 17:16:13 +00:00
typedef union {
2020-12-29 22:46:46 +00:00
AnimEntryLoadFrame load ;
AnimEntryCopyAll copy ;
AnimEntryInterp interp ;
AnimEntryCopyTrue copy1 ;
AnimEntryCopyFalse copy0 ;
AnimEntryMoveActor move ;
} AnimationEntryData ; // size = 0x3C
2020-03-23 01:24:00 +00:00
2020-03-24 17:16:13 +00:00
typedef struct {
2020-12-02 03:19:56 +00:00
/* 0x00 */ u8 type ;
/* 0x04 */ AnimationEntryData data ;
2020-03-23 01:24:00 +00:00
} AnimationEntry ; // size = 0x40
2020-03-24 17:16:13 +00:00
typedef struct AnimationContext {
2020-03-23 01:24:00 +00:00
s16 animationCount ;
2020-03-25 15:51:25 +00:00
AnimationEntry entries [ ANIMATION_ENTRY_MAX ] ;
2020-12-29 22:46:46 +00:00
} AnimationContext ; // size = 0xC84
2020-03-23 01:24:00 +00:00
2022-05-21 18:23:43 +00:00
typedef void ( * AnimationEntryCallback ) ( struct PlayState * play , AnimationEntryData * data ) ;
2020-03-23 21:31:24 +00:00
2020-12-29 22:46:46 +00:00
typedef s32 ( * AnimUpdateFunc ) ( ) ;
2020-12-02 03:19:56 +00:00
typedef struct SkelAnime {
2020-12-29 22:46:46 +00:00
/* 0x00 */ u8 limbCount ; // Number of limbs in the skeleton
2022-03-16 21:14:56 +00:00
/* 0x01 */ u8 mode ; // See `AnimationMode`
2020-12-29 22:46:46 +00:00
/* 0x02 */ u8 dListCount ; // Number of display lists in a flexible skeleton
/* 0x03 */ s8 taper ; // Tapering to use when morphing between animations. Only used by Door_Warp1.
/* 0x04 */ void * * skeleton ; // An array of pointers to limbs. Can be StandardLimb, LodLimb, or SkinLimb.
/* 0x08 */ void * animation ; // Can be an AnimationHeader or LinkAnimationHeader.
2022-03-16 21:14:56 +00:00
/* 0x0C */ f32 startFrame ; // In mode ANIMMODE_LOOP_PARTIAL*, start of partial loop.
/* 0x10 */ f32 endFrame ; // In mode ANIMMODE_ONCE*, Update returns true when curFrame is equal to this. In mode ANIMMODE_LOOP_PARTIAL*, end of partial loop.
/* 0x14 */ f32 animLength ; // Total number of frames in the current animation.
2020-12-29 22:46:46 +00:00
/* 0x18 */ f32 curFrame ; // Current frame in the animation
/* 0x1C */ f32 playSpeed ; // Multiplied by R_UPDATE_RATE / 3 to get the animation's frame rate.
/* 0x20 */ Vec3s * jointTable ; // Current translation of model and rotations of all limbs
/* 0x24 */ Vec3s * morphTable ; // Table of values used to morph between animations
/* 0x28 */ f32 morphWeight ; // Weight of the current animation morph as a fraction in [0,1]
/* 0x2C */ f32 morphRate ; // Reciprocal of the number of frames in the morph
2022-06-12 23:24:45 +00:00
/* 0x30 */ union {
s32 ( * normal ) ( struct SkelAnime * ) ; // Can be Loop, Partial loop, Play once, Morph, or Tapered morph
s32 ( * link ) ( struct PlayState * , struct SkelAnime * ) ; // Can be Loop, Play once, or Morph
} update ;
2020-12-29 22:46:46 +00:00
/* 0x34 */ s8 initFlags ; // Flags used when initializing Link's skeleton
2021-11-30 23:40:42 +00:00
/* 0x35 */ u8 moveFlags ; // Flags used for animations that move the actor in worldspace.
2020-12-29 22:46:46 +00:00
/* 0x36 */ s16 prevRot ; // Previous rotation in worldspace.
/* 0x38 */ Vec3s prevTransl ; // Previous modelspace translation.
/* 0x3E */ Vec3s baseTransl ; // Base modelspace translation.
2020-12-02 03:19:56 +00:00
} SkelAnime ; // size = 0x44
2020-05-19 20:27:25 +00:00
2020-03-23 21:31:24 +00:00
# endif