goat3d
view libs/anim/anim.h @ 45:8da36540e2e9
fixed memory leak in readxml and reversed error return
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 08 Dec 2013 02:27:32 +0200 |
parents | |
children | 0ecb788a87f7 |
line source
1 #ifndef LIBANIM_H_
2 #define LIBANIM_H_
4 #include "config.h"
6 #include <vmath/vector.h>
7 #include <vmath/quat.h>
8 #include <vmath/matrix.h>
9 #include "track.h"
11 enum {
12 ANM_TRACK_POS_X,
13 ANM_TRACK_POS_Y,
14 ANM_TRACK_POS_Z,
16 ANM_TRACK_ROT_X,
17 ANM_TRACK_ROT_Y,
18 ANM_TRACK_ROT_Z,
19 ANM_TRACK_ROT_W,
21 ANM_TRACK_SCL_X,
22 ANM_TRACK_SCL_Y,
23 ANM_TRACK_SCL_Z,
25 ANM_NUM_TRACKS
26 };
28 struct anm_node {
29 char *name;
31 struct anm_track tracks[ANM_NUM_TRACKS];
32 vec3_t pivot;
34 /* matrix cache */
35 struct mat_cache {
36 mat4_t matrix, inv_matrix;
37 anm_time_t time, inv_time;
38 } cache;
40 struct anm_node *parent;
41 struct anm_node *child;
42 struct anm_node *next;
43 };
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
49 /* node constructor and destructor */
50 int anm_init_node(struct anm_node *node);
51 void anm_destroy_node(struct anm_node *node);
53 /* recursively destroy an animation node tree */
54 void anm_destroy_node_tree(struct anm_node *tree);
56 /* helper functions to allocate/construct and destroy/free with
57 * a single call. They call anm_init_node and anm_destroy_node
58 * internally.
59 */
60 struct anm_node *anm_create_node(void);
61 void anm_free_node(struct anm_node *node);
63 /* recursively destroy and free the nodes of a node tree */
64 void anm_free_node_tree(struct anm_node *tree);
66 int anm_set_node_name(struct anm_node *node, const char *name);
67 const char *anm_get_node_name(struct anm_node *node);
69 void anm_set_interpolator(struct anm_node *node, enum anm_interpolator in);
70 void anm_set_extrapolator(struct anm_node *node, enum anm_extrapolator ex);
72 /* link and unlink nodes with parent/child relations */
73 void anm_link_node(struct anm_node *parent, struct anm_node *child);
74 int anm_unlink_node(struct anm_node *parent, struct anm_node *child);
76 void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm);
77 vec3_t anm_get_node_position(struct anm_node *node, anm_time_t tm);
79 void anm_set_rotation(struct anm_node *node, quat_t rot, anm_time_t tm);
80 quat_t anm_get_node_rotation(struct anm_node *node, anm_time_t tm);
82 void anm_set_scaling(struct anm_node *node, vec3_t scl, anm_time_t tm);
83 vec3_t anm_get_node_scaling(struct anm_node *node, anm_time_t tm);
85 /* these three return the full p/r/s taking hierarchy into account */
86 vec3_t anm_get_position(struct anm_node *node, anm_time_t tm);
87 quat_t anm_get_rotation(struct anm_node *node, anm_time_t tm);
88 vec3_t anm_get_scaling(struct anm_node *node, anm_time_t tm);
90 void anm_set_pivot(struct anm_node *node, vec3_t pivot);
91 vec3_t anm_get_pivot(struct anm_node *node);
93 /* these calculate the matrix and inverse matrix of this node alone */
94 void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
95 void anm_get_node_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
97 /* These calculate the matrix and inverse matrix of this node taking hierarchy
98 * into account. The results are cached in thread-specific storage and returned
99 * if there's no change in time or tracks from the last query...
100 */
101 void anm_get_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
102 void anm_get_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
104 /* those return the start and end times of the whole tree */
105 anm_time_t anm_get_start_time(struct anm_node *node);
106 anm_time_t anm_get_end_time(struct anm_node *node);
108 #ifdef __cplusplus
109 }
110 #endif
112 #endif /* LIBANIM_H_ */