libanim

diff src/anim.h @ 37:c97151c60302

libanim mercurial repo
author John Tsiombikas <nuclear@mutantstargoat.com>
date Sun, 08 Jan 2012 05:13:13 +0200
parents
children 69654793abc3
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/anim.h	Sun Jan 08 05:13:13 2012 +0200
     1.3 @@ -0,0 +1,107 @@
     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/vmath.h>
    1.12 +#include "track.h"
    1.13 +
    1.14 +enum {
    1.15 +	ANM_TRACK_POS_X,
    1.16 +	ANM_TRACK_POS_Y,
    1.17 +	ANM_TRACK_POS_Z,
    1.18 +
    1.19 +	ANM_TRACK_ROT_X,
    1.20 +	ANM_TRACK_ROT_Y,
    1.21 +	ANM_TRACK_ROT_Z,
    1.22 +	ANM_TRACK_ROT_W,
    1.23 +
    1.24 +	ANM_TRACK_SCL_X,
    1.25 +	ANM_TRACK_SCL_Y,
    1.26 +	ANM_TRACK_SCL_Z,
    1.27 +
    1.28 +	ANM_NUM_TRACKS
    1.29 +};
    1.30 +
    1.31 +struct anm_node {
    1.32 +	char *name;
    1.33 +
    1.34 +	struct anm_track tracks[ANM_NUM_TRACKS];
    1.35 +	vec3_t pivot;
    1.36 +
    1.37 +	/* matrix cache */
    1.38 +	struct mat_cache {
    1.39 +		mat4_t matrix, inv_matrix;
    1.40 +		anm_time_t time, inv_time;
    1.41 +		struct mat_cache *next;
    1.42 +	} *cache_list;
    1.43 +	pthread_key_t cache_key;
    1.44 +	pthread_mutex_t cache_list_lock;
    1.45 +
    1.46 +	struct anm_node *parent;
    1.47 +	struct anm_node *child;
    1.48 +	struct anm_node *next;
    1.49 +};
    1.50 +
    1.51 +#ifdef __cplusplus
    1.52 +extern "C" {
    1.53 +#endif
    1.54 +
    1.55 +/* node constructor and destructor */
    1.56 +int anm_init_node(struct anm_node *node);
    1.57 +void anm_destroy_node(struct anm_node *node);
    1.58 +
    1.59 +/* recursively destroy an animation node tree */
    1.60 +void anm_destroy_node_tree(struct anm_node *tree);
    1.61 +
    1.62 +/* helper functions to allocate/construct and destroy/free with
    1.63 + * a single call. They call anm_init_node and anm_destroy_node
    1.64 + * internally.
    1.65 + */
    1.66 +struct anm_node *anm_create_node(void);
    1.67 +void anm_free_node(struct anm_node *node);
    1.68 +
    1.69 +/* recursively destroy and free the nodes of a node tree */
    1.70 +void anm_free_node_tree(struct anm_node *tree);
    1.71 +
    1.72 +int anm_set_node_name(struct anm_node *node, const char *name);
    1.73 +const char *anm_get_node_name(struct anm_node *node);
    1.74 +
    1.75 +void anm_set_interpolator(struct anm_node *node, enum anm_interpolator in);
    1.76 +void anm_set_extrapolator(struct anm_node *node, enum anm_extrapolator ex);
    1.77 +
    1.78 +/* link and unlink nodes with parent/child relations */
    1.79 +void anm_link_node(struct anm_node *parent, struct anm_node *child);
    1.80 +int anm_unlink_node(struct anm_node *parent, struct anm_node *child);
    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 +void anm_set_rotation(struct anm_node *node, quat_t rot, anm_time_t tm);
    1.86 +quat_t anm_get_node_rotation(struct anm_node *node, anm_time_t tm);
    1.87 +
    1.88 +void anm_set_scaling(struct anm_node *node, vec3_t scl, anm_time_t tm);
    1.89 +vec3_t anm_get_node_scaling(struct anm_node *node, anm_time_t tm);
    1.90 +
    1.91 +/* these three return the full p/r/s taking hierarchy into account */
    1.92 +vec3_t anm_get_position(struct anm_node *node, anm_time_t tm);
    1.93 +quat_t anm_get_rotation(struct anm_node *node, anm_time_t tm);
    1.94 +vec3_t anm_get_scaling(struct anm_node *node, anm_time_t tm);
    1.95 +
    1.96 +void anm_set_pivot(struct anm_node *node, vec3_t pivot);
    1.97 +vec3_t anm_get_pivot(struct anm_node *node);
    1.98 +
    1.99 +void anm_get_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
   1.100 +void anm_get_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
   1.101 +
   1.102 +/* those return the start and end times of the whole tree */
   1.103 +anm_time_t anm_get_start_time(struct anm_node *node);
   1.104 +anm_time_t anm_get_end_time(struct anm_node *node);
   1.105 +
   1.106 +#ifdef __cplusplus
   1.107 +}
   1.108 +#endif
   1.109 +
   1.110 +#endif	/* LIBANIM_H_ */