libanim

annotate src/anim.h @ 22:9758004136f8

added anm_set_animation_name
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 27 Dec 2013 10:58:23 +0200
parents 5993f405a1cb
children 203c11299586
rev   line source
nuclear@0 1 #ifndef LIBANIM_H_
nuclear@0 2 #define LIBANIM_H_
nuclear@0 3
nuclear@0 4 #include "config.h"
nuclear@0 5
nuclear@0 6 #include <pthread.h>
nuclear@0 7
nuclear@1 8 #include <vmath/vector.h>
nuclear@1 9 #include <vmath/quat.h>
nuclear@1 10 #include <vmath/matrix.h>
nuclear@0 11 #include "track.h"
nuclear@0 12
nuclear@0 13 enum {
nuclear@0 14 ANM_TRACK_POS_X,
nuclear@0 15 ANM_TRACK_POS_Y,
nuclear@0 16 ANM_TRACK_POS_Z,
nuclear@0 17
nuclear@0 18 ANM_TRACK_ROT_X,
nuclear@0 19 ANM_TRACK_ROT_Y,
nuclear@0 20 ANM_TRACK_ROT_Z,
nuclear@0 21 ANM_TRACK_ROT_W,
nuclear@0 22
nuclear@0 23 ANM_TRACK_SCL_X,
nuclear@0 24 ANM_TRACK_SCL_Y,
nuclear@0 25 ANM_TRACK_SCL_Z,
nuclear@0 26
nuclear@0 27 ANM_NUM_TRACKS
nuclear@0 28 };
nuclear@0 29
nuclear@21 30 struct anm_animation {
nuclear@21 31 char *name;
nuclear@21 32 struct anm_track tracks[ANM_NUM_TRACKS];
nuclear@21 33 };
nuclear@21 34
nuclear@0 35 struct anm_node {
nuclear@0 36 char *name;
nuclear@0 37
nuclear@21 38 int cur_anim[2];
nuclear@21 39 float cur_mix;
nuclear@21 40
nuclear@21 41 struct anm_animation *animations;
nuclear@0 42 vec3_t pivot;
nuclear@0 43
nuclear@0 44 /* matrix cache */
nuclear@0 45 struct mat_cache {
nuclear@0 46 mat4_t matrix, inv_matrix;
nuclear@0 47 anm_time_t time, inv_time;
nuclear@0 48 struct mat_cache *next;
nuclear@0 49 } *cache_list;
nuclear@0 50 pthread_key_t cache_key;
nuclear@0 51 pthread_mutex_t cache_list_lock;
nuclear@0 52
nuclear@20 53 /* matrix calculated by anm_eval functions (no locking, meant as a pre-pass) */
nuclear@20 54 mat4_t matrix;
nuclear@20 55
nuclear@0 56 struct anm_node *parent;
nuclear@0 57 struct anm_node *child;
nuclear@0 58 struct anm_node *next;
nuclear@0 59 };
nuclear@0 60
nuclear@0 61 #ifdef __cplusplus
nuclear@0 62 extern "C" {
nuclear@0 63 #endif
nuclear@0 64
nuclear@21 65 int anm_init_animation(struct anm_animation *anim);
nuclear@21 66 void anm_destroy_animation(struct anm_animation *anim);
nuclear@21 67
nuclear@22 68 void anm_set_animation_name(struct anm_animation *anim, const char *name);
nuclear@22 69
nuclear@22 70
nuclear@0 71 /* node constructor and destructor */
nuclear@0 72 int anm_init_node(struct anm_node *node);
nuclear@0 73 void anm_destroy_node(struct anm_node *node);
nuclear@0 74
nuclear@0 75 /* recursively destroy an animation node tree */
nuclear@0 76 void anm_destroy_node_tree(struct anm_node *tree);
nuclear@0 77
nuclear@0 78 /* helper functions to allocate/construct and destroy/free with
nuclear@0 79 * a single call. They call anm_init_node and anm_destroy_node
nuclear@0 80 * internally.
nuclear@0 81 */
nuclear@0 82 struct anm_node *anm_create_node(void);
nuclear@0 83 void anm_free_node(struct anm_node *node);
nuclear@0 84
nuclear@0 85 /* recursively destroy and free the nodes of a node tree */
nuclear@0 86 void anm_free_node_tree(struct anm_node *tree);
nuclear@0 87
nuclear@0 88 int anm_set_node_name(struct anm_node *node, const char *name);
nuclear@0 89 const char *anm_get_node_name(struct anm_node *node);
nuclear@0 90
nuclear@0 91 /* link and unlink nodes with parent/child relations */
nuclear@0 92 void anm_link_node(struct anm_node *parent, struct anm_node *child);
nuclear@0 93 int anm_unlink_node(struct anm_node *parent, struct anm_node *child);
nuclear@0 94
nuclear@21 95 void anm_set_pivot(struct anm_node *node, vec3_t pivot);
nuclear@21 96 vec3_t anm_get_pivot(struct anm_node *node);
nuclear@21 97
nuclear@21 98 /* set active animation(s) */
nuclear@21 99 int anm_use_node_animation(struct anm_node *node, int aidx);
nuclear@21 100 int anm_use_node_animations(struct anm_node *node, int aidx, int bidx, float t);
nuclear@21 101 /* recursive variants */
nuclear@21 102 int anm_use_animation(struct anm_node *node, int aidx);
nuclear@21 103 int anm_use_animations(struct anm_node *node, int aidx, int bidx, float t);
nuclear@21 104
nuclear@21 105 /* returns the requested current animation index, which can be 0 or 1 */
nuclear@21 106 int anm_get_active_animation_index(struct anm_node *node, int which);
nuclear@21 107 /* returns the requested current animation, which can be 0 or 1 */
nuclear@21 108 struct anm_animation *anm_get_active_animation(struct anm_node *node, int which);
nuclear@21 109 float anm_get_active_animation_mix(struct anm_node *node);
nuclear@21 110
nuclear@21 111 int anm_get_animation_count(struct anm_node *node);
nuclear@21 112
nuclear@21 113 /* add/remove an animation to the specified node */
nuclear@21 114 int anm_add_node_animation(struct anm_node *node);
nuclear@21 115 int anm_remove_node_animation(struct anm_node *node, int idx);
nuclear@21 116
nuclear@21 117 /* add/remove an animation to the specified node and all it's descendants */
nuclear@21 118 int anm_add_animation(struct anm_node *node);
nuclear@21 119 int anm_remove_animation(struct anm_node *node, int idx);
nuclear@21 120
nuclear@21 121 struct anm_animation *anm_get_animation(struct anm_node *node, int idx);
nuclear@21 122 struct anm_animation *anm_get_animation_by_name(struct anm_node *node, const char *name);
nuclear@21 123
nuclear@21 124 int anm_find_animation(struct anm_node *node, const char *name);
nuclear@21 125
nuclear@21 126 /* set the interpolator for the (first) currently active animation */
nuclear@21 127 void anm_set_interpolator(struct anm_node *node, enum anm_interpolator in);
nuclear@21 128 /* set the extrapolator for the (first) currently active animation */
nuclear@21 129 void anm_set_extrapolator(struct anm_node *node, enum anm_extrapolator ex);
nuclear@21 130
nuclear@0 131 void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm);
nuclear@0 132 vec3_t anm_get_node_position(struct anm_node *node, anm_time_t tm);
nuclear@0 133
nuclear@0 134 void anm_set_rotation(struct anm_node *node, quat_t rot, anm_time_t tm);
nuclear@0 135 quat_t anm_get_node_rotation(struct anm_node *node, anm_time_t tm);
nuclear@0 136
nuclear@0 137 void anm_set_scaling(struct anm_node *node, vec3_t scl, anm_time_t tm);
nuclear@0 138 vec3_t anm_get_node_scaling(struct anm_node *node, anm_time_t tm);
nuclear@0 139
nuclear@0 140 /* these three return the full p/r/s taking hierarchy into account */
nuclear@0 141 vec3_t anm_get_position(struct anm_node *node, anm_time_t tm);
nuclear@0 142 quat_t anm_get_rotation(struct anm_node *node, anm_time_t tm);
nuclear@0 143 vec3_t anm_get_scaling(struct anm_node *node, anm_time_t tm);
nuclear@0 144
nuclear@20 145 /* those return the start and end times of the whole tree */
nuclear@20 146 anm_time_t anm_get_start_time(struct anm_node *node);
nuclear@20 147 anm_time_t anm_get_end_time(struct anm_node *node);
nuclear@20 148
nuclear@5 149 /* these calculate the matrix and inverse matrix of this node alone */
nuclear@5 150 void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
nuclear@5 151 void anm_get_node_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
nuclear@5 152
nuclear@20 153 /* ---- top-down matrix calculation interface ---- */
nuclear@20 154
nuclear@20 155 /* calculate and set the matrix of this node */
nuclear@20 156 void anm_eval_node(struct anm_node *node, anm_time_t tm);
nuclear@20 157 /* calculate and set the matrix of this node and all its children recursively */
nuclear@20 158 void anm_eval(struct anm_node *node, anm_time_t tm);
nuclear@20 159
nuclear@20 160
nuclear@20 161 /* ---- bottom-up lazy matrix calculation interface ---- */
nuclear@20 162
nuclear@5 163 /* These calculate the matrix and inverse matrix of this node taking hierarchy
nuclear@5 164 * into account. The results are cached in thread-specific storage and returned
nuclear@5 165 * if there's no change in time or tracks from the last query...
nuclear@5 166 */
nuclear@0 167 void anm_get_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
nuclear@0 168 void anm_get_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
nuclear@0 169
nuclear@0 170 #ifdef __cplusplus
nuclear@0 171 }
nuclear@0 172 #endif
nuclear@0 173
nuclear@0 174 #endif /* LIBANIM_H_ */