Skip to content

Instantly share code, notes, and snippets.

@Dragorn421
Created April 5, 2020 21:28
Show Gist options
  • Save Dragorn421/0c041edc51d3885891adb0aaa337b6ac to your computer and use it in GitHub Desktop.
Save Dragorn421/0c041edc51d3885891adb0aaa337b6ac to your computer and use it in GitHub Desktop.
Custom actor for OoT64 for animation showcase purposes
#include <z64ovl/oot/debug.h>
#include <z64ovl/z64ovl_helpers.h>
#define OBJ_ID 0x4
#define ACT_ID 0x1
#define PAD 0x0
#define MODEL 0x0600CDE0
#define ANIM_DAMAGE 0x060072CC
#define ANIM_KICK 0x06009264
#define ANIM_DEATH 0x0600B074
#define ANIM_RUN 0x0600BAE4
#define ANIM_DEFENSE 0x0600CB78
#define N_ANIMATIONS 5
#define ANIMATIONS {ANIM_DAMAGE, ANIM_KICK, ANIM_DEATH, ANIM_RUN, ANIM_DEFENSE}
#define ANIMATIONS_NAMES {"damage", "kick", "death", "run", "defense"}
#ifdef __IDE_VS__
// copied from z64ovl/h/mips.h
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
typedef float f32;
typedef double f64;
#endif
typedef struct {
z64_actor_t actor;
z64_skelanime_t anim;
u32 animId;
u32 t;
u32 lastAnimChange;
} entity_t;
static void init(entity_t* en, z64_global_t* global) {
//actor_set_scale(&en->actor, 1);
_z_skelanime_mtx_init(global, &en->anim, MODEL, ANIM_RUN, 0, 0, 0);
z_skelanime_change_anim(&en->anim, ANIM_RUN, 1, 0, 0, 1);
en->animId = 3;
en->t = 0;
en->lastAnimChange = 0;
}
static void update(entity_t* en, z64_global_t* global) {
en->t++;
actor_anime_frame_update_mtx(&en->anim);
z64_input_t* in = &global->common.input[0];
u32 i = en->animId;
if (en->t - en->lastAnimChange > 5)
{
if (in->raw.dl)
i--;
if (in->raw.dr)
i++;
}
if (i != en->animId)
{
u32 animations[] = ANIMATIONS;
if (i < 0 || i >= N_ANIMATIONS)
i = 0;
z_skelanime_change_anim(&en->anim, animations[i], 1, 0, 0, 1);
en->animId = i;
en->lastAnimChange = en->t;
}
}
static void dest(entity_t* en, z64_global_t* global) {
}
static void draw(entity_t* en, z64_global_t* global) {
// seems that drawing model directly crashes the game
// z_cheap_proc_draw_opa(global, MODEL);
_z_skelanime_draw_mtx(global, (u32)en->anim.limb_index, (u32)en->anim.draw_table_rot, en->anim.dlist_count, 0, 0, (void*)&en->actor);
char* names[] = ANIMATIONS_NAMES;
zh_draw_debug_text(global, 0xFFFFFFFF, 1, 1, "anim #%d %s", en->animId, names[en->animId]);
}
z64_actor_init_t init_vars = {
.number = ACT_ID,
.type = 0x01,
.room = 0x00,
.flags = 0x00000010,
.object = OBJ_ID,
.padding = PAD,
.instance_size = sizeof(entity_t),
.init = init,
.dest = dest,
.main = update,
.draw = draw
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment