vrshoot

view libs/anim/anim.h @ 3:c179c72369be

rename candy->vr
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 03 Feb 2014 08:52:13 +0200
parents
children
line source
1 #ifndef LIBANIM_H_
2 #define LIBANIM_H_
4 #include "config.h"
6 #include <pthread.h>
8 #include <vmath/vector.h>
9 #include <vmath/quat.h>
10 #include <vmath/matrix.h>
11 #include "track.h"
13 enum {
14 ANM_TRACK_POS_X,
15 ANM_TRACK_POS_Y,
16 ANM_TRACK_POS_Z,
18 ANM_TRACK_ROT_X,
19 ANM_TRACK_ROT_Y,
20 ANM_TRACK_ROT_Z,
21 ANM_TRACK_ROT_W,
23 ANM_TRACK_SCL_X,
24 ANM_TRACK_SCL_Y,
25 ANM_TRACK_SCL_Z,
27 ANM_NUM_TRACKS
28 };
30 struct anm_node {
31 char *name;
33 struct anm_track tracks[ANM_NUM_TRACKS];
34 vec3_t pivot;
36 /* matrix cache */
37 struct mat_cache {
38 mat4_t matrix, inv_matrix;
39 anm_time_t time, inv_time;
40 struct mat_cache *next;
41 } *cache_list;
42 pthread_key_t cache_key;
43 pthread_mutex_t cache_list_lock;
45 /* matrix calculated by anm_eval functions (no locking, meant as a pre-pass) */
46 mat4_t matrix;
48 struct anm_node *parent;
49 struct anm_node *child;
50 struct anm_node *next;
51 };
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
57 /* node constructor and destructor */
58 int anm_init_node(struct anm_node *node);
59 void anm_destroy_node(struct anm_node *node);
61 /* recursively destroy an animation node tree */
62 void anm_destroy_node_tree(struct anm_node *tree);
64 /* helper functions to allocate/construct and destroy/free with
65 * a single call. They call anm_init_node and anm_destroy_node
66 * internally.
67 */
68 struct anm_node *anm_create_node(void);
69 void anm_free_node(struct anm_node *node);
71 /* recursively destroy and free the nodes of a node tree */
72 void anm_free_node_tree(struct anm_node *tree);
74 int anm_set_node_name(struct anm_node *node, const char *name);
75 const char *anm_get_node_name(struct anm_node *node);
77 void anm_set_interpolator(struct anm_node *node, enum anm_interpolator in);
78 void anm_set_extrapolator(struct anm_node *node, enum anm_extrapolator ex);
80 /* link and unlink nodes with parent/child relations */
81 void anm_link_node(struct anm_node *parent, struct anm_node *child);
82 int anm_unlink_node(struct anm_node *parent, struct anm_node *child);
84 void anm_clear(struct anm_node *node);
86 void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm);
87 vec3_t anm_get_node_position(struct anm_node *node, anm_time_t tm);
89 void anm_set_rotation(struct anm_node *node, quat_t rot, anm_time_t tm);
90 quat_t anm_get_node_rotation(struct anm_node *node, anm_time_t tm);
92 void anm_set_scaling(struct anm_node *node, vec3_t scl, anm_time_t tm);
93 vec3_t anm_get_node_scaling(struct anm_node *node, anm_time_t tm);
95 /* these three return the full p/r/s taking hierarchy into account */
96 vec3_t anm_get_position(struct anm_node *node, anm_time_t tm);
97 quat_t anm_get_rotation(struct anm_node *node, anm_time_t tm);
98 vec3_t anm_get_scaling(struct anm_node *node, anm_time_t tm);
100 void anm_set_pivot(struct anm_node *node, vec3_t pivot);
101 vec3_t anm_get_pivot(struct anm_node *node);
103 /* those return the start and end times of the whole tree */
104 anm_time_t anm_get_start_time(struct anm_node *node);
105 anm_time_t anm_get_end_time(struct anm_node *node);
107 /* these calculate the matrix and inverse matrix of this node alone */
108 void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
109 void anm_get_node_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
111 /* ---- top-down matrix calculation interface ---- */
113 /* calculate and set the matrix of this node */
114 void anm_eval_node(struct anm_node *node, anm_time_t tm);
115 /* calculate and set the matrix of this node and all its children recursively */
116 void anm_eval(struct anm_node *node, anm_time_t tm);
119 /* ---- bottom-up lazy matrix calculation interface ---- */
121 /* These calculate the matrix and inverse matrix of this node taking hierarchy
122 * into account. The results are cached in thread-specific storage and returned
123 * if there's no change in time or tracks from the last query...
124 */
125 void anm_get_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
126 void anm_get_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
128 #ifdef __cplusplus
129 }
130 #endif
132 #endif /* LIBANIM_H_ */