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@0
|
8 #include <vmath/vector.h>
|
nuclear@0
|
9 #include <vmath/quat.h>
|
nuclear@0
|
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@0
|
30 struct anm_node {
|
nuclear@0
|
31 char *name;
|
nuclear@0
|
32
|
nuclear@0
|
33 struct anm_track tracks[ANM_NUM_TRACKS];
|
nuclear@0
|
34 vec3_t pivot;
|
nuclear@0
|
35
|
nuclear@0
|
36 /* matrix cache */
|
nuclear@0
|
37 struct mat_cache {
|
nuclear@0
|
38 mat4_t matrix, inv_matrix;
|
nuclear@0
|
39 anm_time_t time, inv_time;
|
nuclear@0
|
40 struct mat_cache *next;
|
nuclear@0
|
41 } *cache_list;
|
nuclear@1
|
42 #ifdef ANIM_THREAD_SAFE
|
nuclear@0
|
43 pthread_key_t cache_key;
|
nuclear@0
|
44 pthread_mutex_t cache_list_lock;
|
nuclear@1
|
45 #endif
|
nuclear@0
|
46
|
nuclear@0
|
47 struct anm_node *parent;
|
nuclear@0
|
48 struct anm_node *child;
|
nuclear@0
|
49 struct anm_node *next;
|
nuclear@0
|
50 };
|
nuclear@0
|
51
|
nuclear@0
|
52 #ifdef __cplusplus
|
nuclear@0
|
53 extern "C" {
|
nuclear@0
|
54 #endif
|
nuclear@0
|
55
|
nuclear@0
|
56 /* node constructor and destructor */
|
nuclear@0
|
57 int anm_init_node(struct anm_node *node);
|
nuclear@0
|
58 void anm_destroy_node(struct anm_node *node);
|
nuclear@0
|
59
|
nuclear@0
|
60 /* recursively destroy an animation node tree */
|
nuclear@0
|
61 void anm_destroy_node_tree(struct anm_node *tree);
|
nuclear@0
|
62
|
nuclear@0
|
63 /* helper functions to allocate/construct and destroy/free with
|
nuclear@0
|
64 * a single call. They call anm_init_node and anm_destroy_node
|
nuclear@0
|
65 * internally.
|
nuclear@0
|
66 */
|
nuclear@0
|
67 struct anm_node *anm_create_node(void);
|
nuclear@0
|
68 void anm_free_node(struct anm_node *node);
|
nuclear@0
|
69
|
nuclear@0
|
70 /* recursively destroy and free the nodes of a node tree */
|
nuclear@0
|
71 void anm_free_node_tree(struct anm_node *tree);
|
nuclear@0
|
72
|
nuclear@0
|
73 int anm_set_node_name(struct anm_node *node, const char *name);
|
nuclear@0
|
74 const char *anm_get_node_name(struct anm_node *node);
|
nuclear@0
|
75
|
nuclear@0
|
76 void anm_set_interpolator(struct anm_node *node, enum anm_interpolator in);
|
nuclear@0
|
77 void anm_set_extrapolator(struct anm_node *node, enum anm_extrapolator ex);
|
nuclear@0
|
78
|
nuclear@0
|
79 /* link and unlink nodes with parent/child relations */
|
nuclear@0
|
80 void anm_link_node(struct anm_node *parent, struct anm_node *child);
|
nuclear@0
|
81 int anm_unlink_node(struct anm_node *parent, struct anm_node *child);
|
nuclear@0
|
82
|
nuclear@0
|
83 void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm);
|
nuclear@0
|
84 vec3_t anm_get_node_position(struct anm_node *node, anm_time_t tm);
|
nuclear@0
|
85
|
nuclear@0
|
86 void anm_set_rotation(struct anm_node *node, quat_t rot, anm_time_t tm);
|
nuclear@0
|
87 quat_t anm_get_node_rotation(struct anm_node *node, anm_time_t tm);
|
nuclear@0
|
88
|
nuclear@0
|
89 void anm_set_scaling(struct anm_node *node, vec3_t scl, anm_time_t tm);
|
nuclear@0
|
90 vec3_t anm_get_node_scaling(struct anm_node *node, anm_time_t tm);
|
nuclear@0
|
91
|
nuclear@0
|
92 /* these three return the full p/r/s taking hierarchy into account */
|
nuclear@0
|
93 vec3_t anm_get_position(struct anm_node *node, anm_time_t tm);
|
nuclear@0
|
94 quat_t anm_get_rotation(struct anm_node *node, anm_time_t tm);
|
nuclear@0
|
95 vec3_t anm_get_scaling(struct anm_node *node, anm_time_t tm);
|
nuclear@0
|
96
|
nuclear@0
|
97 void anm_set_pivot(struct anm_node *node, vec3_t pivot);
|
nuclear@0
|
98 vec3_t anm_get_pivot(struct anm_node *node);
|
nuclear@0
|
99
|
nuclear@0
|
100 /* these calculate the matrix and inverse matrix of this node alone */
|
nuclear@0
|
101 void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
|
nuclear@0
|
102 void anm_get_node_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
|
nuclear@0
|
103
|
nuclear@0
|
104 /* These calculate the matrix and inverse matrix of this node taking hierarchy
|
nuclear@0
|
105 * into account. The results are cached in thread-specific storage and returned
|
nuclear@0
|
106 * if there's no change in time or tracks from the last query...
|
nuclear@0
|
107 */
|
nuclear@0
|
108 void anm_get_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
|
nuclear@0
|
109 void anm_get_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
|
nuclear@0
|
110
|
nuclear@0
|
111 /* those return the start and end times of the whole tree */
|
nuclear@0
|
112 anm_time_t anm_get_start_time(struct anm_node *node);
|
nuclear@0
|
113 anm_time_t anm_get_end_time(struct anm_node *node);
|
nuclear@0
|
114
|
nuclear@0
|
115 #ifdef __cplusplus
|
nuclear@0
|
116 }
|
nuclear@0
|
117 #endif
|
nuclear@0
|
118
|
nuclear@0
|
119 #endif /* LIBANIM_H_ */
|