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@0
|
68 /* node constructor and destructor */
|
nuclear@0
|
69 int anm_init_node(struct anm_node *node);
|
nuclear@0
|
70 void anm_destroy_node(struct anm_node *node);
|
nuclear@0
|
71
|
nuclear@0
|
72 /* recursively destroy an animation node tree */
|
nuclear@0
|
73 void anm_destroy_node_tree(struct anm_node *tree);
|
nuclear@0
|
74
|
nuclear@0
|
75 /* helper functions to allocate/construct and destroy/free with
|
nuclear@0
|
76 * a single call. They call anm_init_node and anm_destroy_node
|
nuclear@0
|
77 * internally.
|
nuclear@0
|
78 */
|
nuclear@0
|
79 struct anm_node *anm_create_node(void);
|
nuclear@0
|
80 void anm_free_node(struct anm_node *node);
|
nuclear@0
|
81
|
nuclear@0
|
82 /* recursively destroy and free the nodes of a node tree */
|
nuclear@0
|
83 void anm_free_node_tree(struct anm_node *tree);
|
nuclear@0
|
84
|
nuclear@0
|
85 int anm_set_node_name(struct anm_node *node, const char *name);
|
nuclear@0
|
86 const char *anm_get_node_name(struct anm_node *node);
|
nuclear@0
|
87
|
nuclear@0
|
88 /* link and unlink nodes with parent/child relations */
|
nuclear@0
|
89 void anm_link_node(struct anm_node *parent, struct anm_node *child);
|
nuclear@0
|
90 int anm_unlink_node(struct anm_node *parent, struct anm_node *child);
|
nuclear@0
|
91
|
nuclear@21
|
92 void anm_set_pivot(struct anm_node *node, vec3_t pivot);
|
nuclear@21
|
93 vec3_t anm_get_pivot(struct anm_node *node);
|
nuclear@21
|
94
|
nuclear@21
|
95 /* set active animation(s) */
|
nuclear@21
|
96 int anm_use_node_animation(struct anm_node *node, int aidx);
|
nuclear@21
|
97 int anm_use_node_animations(struct anm_node *node, int aidx, int bidx, float t);
|
nuclear@21
|
98 /* recursive variants */
|
nuclear@21
|
99 int anm_use_animation(struct anm_node *node, int aidx);
|
nuclear@21
|
100 int anm_use_animations(struct anm_node *node, int aidx, int bidx, float t);
|
nuclear@21
|
101
|
nuclear@21
|
102 /* returns the requested current animation index, which can be 0 or 1 */
|
nuclear@21
|
103 int anm_get_active_animation_index(struct anm_node *node, int which);
|
nuclear@21
|
104 /* returns the requested current animation, which can be 0 or 1 */
|
nuclear@21
|
105 struct anm_animation *anm_get_active_animation(struct anm_node *node, int which);
|
nuclear@21
|
106 float anm_get_active_animation_mix(struct anm_node *node);
|
nuclear@21
|
107
|
nuclear@21
|
108 int anm_get_animation_count(struct anm_node *node);
|
nuclear@21
|
109
|
nuclear@21
|
110 /* add/remove an animation to the specified node */
|
nuclear@21
|
111 int anm_add_node_animation(struct anm_node *node);
|
nuclear@21
|
112 int anm_remove_node_animation(struct anm_node *node, int idx);
|
nuclear@21
|
113
|
nuclear@21
|
114 /* add/remove an animation to the specified node and all it's descendants */
|
nuclear@21
|
115 int anm_add_animation(struct anm_node *node);
|
nuclear@21
|
116 int anm_remove_animation(struct anm_node *node, int idx);
|
nuclear@21
|
117
|
nuclear@21
|
118 struct anm_animation *anm_get_animation(struct anm_node *node, int idx);
|
nuclear@21
|
119 struct anm_animation *anm_get_animation_by_name(struct anm_node *node, const char *name);
|
nuclear@21
|
120
|
nuclear@21
|
121 int anm_find_animation(struct anm_node *node, const char *name);
|
nuclear@21
|
122
|
nuclear@21
|
123 /* set the interpolator for the (first) currently active animation */
|
nuclear@21
|
124 void anm_set_interpolator(struct anm_node *node, enum anm_interpolator in);
|
nuclear@21
|
125 /* set the extrapolator for the (first) currently active animation */
|
nuclear@21
|
126 void anm_set_extrapolator(struct anm_node *node, enum anm_extrapolator ex);
|
nuclear@21
|
127
|
nuclear@0
|
128 void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm);
|
nuclear@0
|
129 vec3_t anm_get_node_position(struct anm_node *node, anm_time_t tm);
|
nuclear@0
|
130
|
nuclear@0
|
131 void anm_set_rotation(struct anm_node *node, quat_t rot, anm_time_t tm);
|
nuclear@0
|
132 quat_t anm_get_node_rotation(struct anm_node *node, anm_time_t tm);
|
nuclear@0
|
133
|
nuclear@0
|
134 void anm_set_scaling(struct anm_node *node, vec3_t scl, anm_time_t tm);
|
nuclear@0
|
135 vec3_t anm_get_node_scaling(struct anm_node *node, anm_time_t tm);
|
nuclear@0
|
136
|
nuclear@0
|
137 /* these three return the full p/r/s taking hierarchy into account */
|
nuclear@0
|
138 vec3_t anm_get_position(struct anm_node *node, anm_time_t tm);
|
nuclear@0
|
139 quat_t anm_get_rotation(struct anm_node *node, anm_time_t tm);
|
nuclear@0
|
140 vec3_t anm_get_scaling(struct anm_node *node, anm_time_t tm);
|
nuclear@0
|
141
|
nuclear@20
|
142 /* those return the start and end times of the whole tree */
|
nuclear@20
|
143 anm_time_t anm_get_start_time(struct anm_node *node);
|
nuclear@20
|
144 anm_time_t anm_get_end_time(struct anm_node *node);
|
nuclear@20
|
145
|
nuclear@5
|
146 /* these calculate the matrix and inverse matrix of this node alone */
|
nuclear@5
|
147 void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
|
nuclear@5
|
148 void anm_get_node_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
|
nuclear@5
|
149
|
nuclear@20
|
150 /* ---- top-down matrix calculation interface ---- */
|
nuclear@20
|
151
|
nuclear@20
|
152 /* calculate and set the matrix of this node */
|
nuclear@20
|
153 void anm_eval_node(struct anm_node *node, anm_time_t tm);
|
nuclear@20
|
154 /* calculate and set the matrix of this node and all its children recursively */
|
nuclear@20
|
155 void anm_eval(struct anm_node *node, anm_time_t tm);
|
nuclear@20
|
156
|
nuclear@20
|
157
|
nuclear@20
|
158 /* ---- bottom-up lazy matrix calculation interface ---- */
|
nuclear@20
|
159
|
nuclear@5
|
160 /* These calculate the matrix and inverse matrix of this node taking hierarchy
|
nuclear@5
|
161 * into account. The results are cached in thread-specific storage and returned
|
nuclear@5
|
162 * if there's no change in time or tracks from the last query...
|
nuclear@5
|
163 */
|
nuclear@0
|
164 void anm_get_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
|
nuclear@0
|
165 void anm_get_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
|
nuclear@0
|
166
|
nuclear@0
|
167 #ifdef __cplusplus
|
nuclear@0
|
168 }
|
nuclear@0
|
169 #endif
|
nuclear@0
|
170
|
nuclear@0
|
171 #endif /* LIBANIM_H_ */
|