vrshoot

diff libs/anim/anim.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/anim/anim.h	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,132 @@
     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 +	/* matrix calculated by anm_eval functions (no locking, meant as a pre-pass) */
    1.49 +	mat4_t matrix;
    1.50 +
    1.51 +	struct anm_node *parent;
    1.52 +	struct anm_node *child;
    1.53 +	struct anm_node *next;
    1.54 +};
    1.55 +
    1.56 +#ifdef __cplusplus
    1.57 +extern "C" {
    1.58 +#endif
    1.59 +
    1.60 +/* node constructor and destructor */
    1.61 +int anm_init_node(struct anm_node *node);
    1.62 +void anm_destroy_node(struct anm_node *node);
    1.63 +
    1.64 +/* recursively destroy an animation node tree */
    1.65 +void anm_destroy_node_tree(struct anm_node *tree);
    1.66 +
    1.67 +/* helper functions to allocate/construct and destroy/free with
    1.68 + * a single call. They call anm_init_node and anm_destroy_node
    1.69 + * internally.
    1.70 + */
    1.71 +struct anm_node *anm_create_node(void);
    1.72 +void anm_free_node(struct anm_node *node);
    1.73 +
    1.74 +/* recursively destroy and free the nodes of a node tree */
    1.75 +void anm_free_node_tree(struct anm_node *tree);
    1.76 +
    1.77 +int anm_set_node_name(struct anm_node *node, const char *name);
    1.78 +const char *anm_get_node_name(struct anm_node *node);
    1.79 +
    1.80 +void anm_set_interpolator(struct anm_node *node, enum anm_interpolator in);
    1.81 +void anm_set_extrapolator(struct anm_node *node, enum anm_extrapolator ex);
    1.82 +
    1.83 +/* link and unlink nodes with parent/child relations */
    1.84 +void anm_link_node(struct anm_node *parent, struct anm_node *child);
    1.85 +int anm_unlink_node(struct anm_node *parent, struct anm_node *child);
    1.86 +
    1.87 +void anm_clear(struct anm_node *node);
    1.88 +
    1.89 +void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm);
    1.90 +vec3_t anm_get_node_position(struct anm_node *node, anm_time_t tm);
    1.91 +
    1.92 +void anm_set_rotation(struct anm_node *node, quat_t rot, anm_time_t tm);
    1.93 +quat_t anm_get_node_rotation(struct anm_node *node, anm_time_t tm);
    1.94 +
    1.95 +void anm_set_scaling(struct anm_node *node, vec3_t scl, anm_time_t tm);
    1.96 +vec3_t anm_get_node_scaling(struct anm_node *node, anm_time_t tm);
    1.97 +
    1.98 +/* these three return the full p/r/s taking hierarchy into account */
    1.99 +vec3_t anm_get_position(struct anm_node *node, anm_time_t tm);
   1.100 +quat_t anm_get_rotation(struct anm_node *node, anm_time_t tm);
   1.101 +vec3_t anm_get_scaling(struct anm_node *node, anm_time_t tm);
   1.102 +
   1.103 +void anm_set_pivot(struct anm_node *node, vec3_t pivot);
   1.104 +vec3_t anm_get_pivot(struct anm_node *node);
   1.105 +
   1.106 +/* those return the start and end times of the whole tree */
   1.107 +anm_time_t anm_get_start_time(struct anm_node *node);
   1.108 +anm_time_t anm_get_end_time(struct anm_node *node);
   1.109 +
   1.110 +/* these calculate the matrix and inverse matrix of this node alone */
   1.111 +void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
   1.112 +void anm_get_node_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
   1.113 +
   1.114 +/* ---- top-down matrix calculation interface ---- */
   1.115 +
   1.116 +/* calculate and set the matrix of this node */
   1.117 +void anm_eval_node(struct anm_node *node, anm_time_t tm);
   1.118 +/* calculate and set the matrix of this node and all its children recursively */
   1.119 +void anm_eval(struct anm_node *node, anm_time_t tm);
   1.120 +
   1.121 +
   1.122 +/* ---- bottom-up lazy matrix calculation interface ---- */
   1.123 +
   1.124 +/* These calculate the matrix and inverse matrix of this node taking hierarchy
   1.125 + * into account. The results are cached in thread-specific storage and returned
   1.126 + * if there's no change in time or tracks from the last query...
   1.127 + */
   1.128 +void anm_get_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
   1.129 +void anm_get_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
   1.130 +
   1.131 +#ifdef __cplusplus
   1.132 +}
   1.133 +#endif
   1.134 +
   1.135 +#endif	/* LIBANIM_H_ */