libanim

diff src/anim.h @ 24:09e267e7ed4a

implemented high-level animation blending interface
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 30 Dec 2013 15:20:31 +0200
parents 203c11299586
children 60a46a122b0f
line diff
     1.1 --- a/src/anim.h	Fri Dec 27 11:29:42 2013 +0200
     1.2 +++ b/src/anim.h	Mon Dec 30 15:20:31 2013 +0200
     1.3 @@ -36,8 +36,12 @@
     1.4  	char *name;
     1.5  
     1.6  	int cur_anim[2];
     1.7 +	anm_time_t cur_anim_offset[2];
     1.8  	float cur_mix;
     1.9  
    1.10 +	/* high-level animation blending transition duration */
    1.11 +	anm_time_t blend_dur;
    1.12 +
    1.13  	struct anm_animation *animations;
    1.14  	vec3_t pivot;
    1.15  
    1.16 @@ -68,6 +72,8 @@
    1.17  void anm_set_animation_name(struct anm_animation *anim, const char *name);
    1.18  
    1.19  
    1.20 +/* ---- node/hierarchy management ---- */
    1.21 +
    1.22  /* node constructor and destructor */
    1.23  int anm_init_node(struct anm_node *node);
    1.24  void anm_destroy_node(struct anm_node *node);
    1.25 @@ -95,6 +101,8 @@
    1.26  void anm_set_pivot(struct anm_node *node, vec3_t pivot);
    1.27  vec3_t anm_get_pivot(struct anm_node *node);
    1.28  
    1.29 +/* ---- multiple animations and animation blending ---- */
    1.30 +
    1.31  /* set active animation(s) */
    1.32  int anm_use_node_animation(struct anm_node *node, int aidx);
    1.33  int anm_use_node_animations(struct anm_node *node, int aidx, int bidx, float t);
    1.34 @@ -102,13 +110,19 @@
    1.35  int anm_use_animation(struct anm_node *node, int aidx);
    1.36  int anm_use_animations(struct anm_node *node, int aidx, int bidx, float t);
    1.37  
    1.38 +/* set/get current animation offset(s) */
    1.39 +void anm_set_node_animation_offset(struct anm_node *node, anm_time_t offs, int which);
    1.40 +anm_time_t anm_get_animation_offset(const struct anm_node *node, int which);
    1.41 +/* recursive variant */
    1.42 +void anm_set_animation_offset(struct anm_node *node, anm_time_t offs, int which);
    1.43 +
    1.44  /* returns the requested current animation index, which can be 0 or 1 */
    1.45 -int anm_get_active_animation_index(struct anm_node *node, int which);
    1.46 +int anm_get_active_animation_index(const struct anm_node *node, int which);
    1.47  /* returns the requested current animation, which can be 0 or 1 */
    1.48 -struct anm_animation *anm_get_active_animation(struct anm_node *node, int which);
    1.49 -float anm_get_active_animation_mix(struct anm_node *node);
    1.50 +struct anm_animation *anm_get_active_animation(const struct anm_node *node, int which);
    1.51 +float anm_get_active_animation_mix(const struct anm_node *node);
    1.52  
    1.53 -int anm_get_animation_count(struct anm_node *node);
    1.54 +int anm_get_animation_count(const struct anm_node *node);
    1.55  
    1.56  /* add/remove an animation to the specified node */
    1.57  int anm_add_node_animation(struct anm_node *node);
    1.58 @@ -136,6 +150,26 @@
    1.59  /* get the name of the currently active animation of this node */
    1.60  const char *anm_get_active_animation_name(struct anm_node *node);
    1.61  
    1.62 +
    1.63 +/* ---- high level animation blending interface ---- */
    1.64 +/* XXX this convenience interface assumes monotonically increasing time values
    1.65 + *     in all subsequent calls to anm_get_* and anm_eval_* functions.
    1.66 + *
    1.67 + * anmidx: index of the animation to transition to
    1.68 + * start: when to start the transition
    1.69 + * dur: transition duration
    1.70 + *
    1.71 + * sets up a transition from the current animation (cur_anim[0]) to another animation.
    1.72 + * at time start + dur, the transition will be completed, cur_anim[0] will be the new
    1.73 + * animation and cur_anim_offset[0] will be equal to start.
    1.74 + */
    1.75 +void anm_transition(struct anm_node *node, int anmidx, anm_time_t start, anm_time_t dur);
    1.76 +/* non-recursive variant, acts on a single node (you probably DON'T want to use this) */
    1.77 +void anm_node_transition(struct anm_node *node, int anmidx, anm_time_t start, anm_time_t dur);
    1.78 +
    1.79 +
    1.80 +/* ---- keyframes / PRS interpolation ---- */
    1.81 +
    1.82  void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm);
    1.83  vec3_t anm_get_node_position(struct anm_node *node, anm_time_t tm);
    1.84  
    1.85 @@ -154,6 +188,9 @@
    1.86  anm_time_t anm_get_start_time(struct anm_node *node);
    1.87  anm_time_t anm_get_end_time(struct anm_node *node);
    1.88  
    1.89 +
    1.90 +/* ---- transformation matrices ---- */
    1.91 +
    1.92  /* these calculate the matrix and inverse matrix of this node alone */
    1.93  void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
    1.94  void anm_get_node_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);