gpuray_glsl
diff anim/anim.h @ 0:f234630e38ff
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 09 Nov 2014 13:03:36 +0200 |
parents | |
children | 92695e89164b |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/anim/anim.h Sun Nov 09 13:03:36 2014 +0200 1.3 @@ -0,0 +1,117 @@ 1.4 +#ifndef LIBANIM_H_ 1.5 +#define LIBANIM_H_ 1.6 + 1.7 +#include "config.h" 1.8 + 1.9 +#include <pthread.h> 1.10 + 1.11 +#include <vmath/vector.h> 1.12 +#include <vmath/quat.h> 1.13 +#include <vmath/matrix.h> 1.14 +#include "track.h" 1.15 + 1.16 +enum { 1.17 + ANM_TRACK_POS_X, 1.18 + ANM_TRACK_POS_Y, 1.19 + ANM_TRACK_POS_Z, 1.20 + 1.21 + ANM_TRACK_ROT_X, 1.22 + ANM_TRACK_ROT_Y, 1.23 + ANM_TRACK_ROT_Z, 1.24 + ANM_TRACK_ROT_W, 1.25 + 1.26 + ANM_TRACK_SCL_X, 1.27 + ANM_TRACK_SCL_Y, 1.28 + ANM_TRACK_SCL_Z, 1.29 + 1.30 + ANM_NUM_TRACKS 1.31 +}; 1.32 + 1.33 +struct anm_node { 1.34 + char *name; 1.35 + 1.36 + struct anm_track tracks[ANM_NUM_TRACKS]; 1.37 + vec3_t pivot; 1.38 + 1.39 + /* matrix cache */ 1.40 + struct mat_cache { 1.41 + mat4_t matrix, inv_matrix; 1.42 + anm_time_t time, inv_time; 1.43 + struct mat_cache *next; 1.44 + } *cache_list; 1.45 + pthread_key_t cache_key; 1.46 + pthread_mutex_t cache_list_lock; 1.47 + 1.48 + struct anm_node *parent; 1.49 + struct anm_node *child; 1.50 + struct anm_node *next; 1.51 +}; 1.52 + 1.53 +#ifdef __cplusplus 1.54 +extern "C" { 1.55 +#endif 1.56 + 1.57 +/* node constructor and destructor */ 1.58 +int anm_init_node(struct anm_node *node); 1.59 +void anm_destroy_node(struct anm_node *node); 1.60 + 1.61 +/* recursively destroy an animation node tree */ 1.62 +void anm_destroy_node_tree(struct anm_node *tree); 1.63 + 1.64 +/* helper functions to allocate/construct and destroy/free with 1.65 + * a single call. They call anm_init_node and anm_destroy_node 1.66 + * internally. 1.67 + */ 1.68 +struct anm_node *anm_create_node(void); 1.69 +void anm_free_node(struct anm_node *node); 1.70 + 1.71 +/* recursively destroy and free the nodes of a node tree */ 1.72 +void anm_free_node_tree(struct anm_node *tree); 1.73 + 1.74 +int anm_set_node_name(struct anm_node *node, const char *name); 1.75 +const char *anm_get_node_name(struct anm_node *node); 1.76 + 1.77 +void anm_set_interpolator(struct anm_node *node, enum anm_interpolator in); 1.78 +void anm_set_extrapolator(struct anm_node *node, enum anm_extrapolator ex); 1.79 + 1.80 +/* link and unlink nodes with parent/child relations */ 1.81 +void anm_link_node(struct anm_node *parent, struct anm_node *child); 1.82 +int anm_unlink_node(struct anm_node *parent, struct anm_node *child); 1.83 + 1.84 +void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm); 1.85 +vec3_t anm_get_node_position(struct anm_node *node, anm_time_t tm); 1.86 + 1.87 +void anm_set_rotation(struct anm_node *node, quat_t rot, anm_time_t tm); 1.88 +quat_t anm_get_node_rotation(struct anm_node *node, anm_time_t tm); 1.89 + 1.90 +void anm_set_scaling(struct anm_node *node, vec3_t scl, anm_time_t tm); 1.91 +vec3_t anm_get_node_scaling(struct anm_node *node, anm_time_t tm); 1.92 + 1.93 +/* these three return the full p/r/s taking hierarchy into account */ 1.94 +vec3_t anm_get_position(struct anm_node *node, anm_time_t tm); 1.95 +quat_t anm_get_rotation(struct anm_node *node, anm_time_t tm); 1.96 +vec3_t anm_get_scaling(struct anm_node *node, anm_time_t tm); 1.97 + 1.98 +void anm_set_pivot(struct anm_node *node, vec3_t pivot); 1.99 +vec3_t anm_get_pivot(struct anm_node *node); 1.100 + 1.101 +/* these calculate the matrix and inverse matrix of this node alone */ 1.102 +void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm); 1.103 +void anm_get_node_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm); 1.104 + 1.105 +/* These calculate the matrix and inverse matrix of this node taking hierarchy 1.106 + * into account. The results are cached in thread-specific storage and returned 1.107 + * if there's no change in time or tracks from the last query... 1.108 + */ 1.109 +void anm_get_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm); 1.110 +void anm_get_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm); 1.111 + 1.112 +/* those return the start and end times of the whole tree */ 1.113 +anm_time_t anm_get_start_time(struct anm_node *node); 1.114 +anm_time_t anm_get_end_time(struct anm_node *node); 1.115 + 1.116 +#ifdef __cplusplus 1.117 +} 1.118 +#endif 1.119 + 1.120 +#endif /* LIBANIM_H_ */