goat3d

diff libs/anim/anim.h @ 27:4deb0b12fe14

wtf... corrupted heap?
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 29 Sep 2013 08:20:19 +0300
parents
children 0ecb788a87f7
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/anim/anim.h	Sun Sep 29 08:20:19 2013 +0300
     1.3 @@ -0,0 +1,112 @@
     1.4 +#ifndef LIBANIM_H_
     1.5 +#define LIBANIM_H_
     1.6 +
     1.7 +#include "config.h"
     1.8 +
     1.9 +#include <vmath/vector.h>
    1.10 +#include <vmath/quat.h>
    1.11 +#include <vmath/matrix.h>
    1.12 +#include "track.h"
    1.13 +
    1.14 +enum {
    1.15 +	ANM_TRACK_POS_X,
    1.16 +	ANM_TRACK_POS_Y,
    1.17 +	ANM_TRACK_POS_Z,
    1.18 +
    1.19 +	ANM_TRACK_ROT_X,
    1.20 +	ANM_TRACK_ROT_Y,
    1.21 +	ANM_TRACK_ROT_Z,
    1.22 +	ANM_TRACK_ROT_W,
    1.23 +
    1.24 +	ANM_TRACK_SCL_X,
    1.25 +	ANM_TRACK_SCL_Y,
    1.26 +	ANM_TRACK_SCL_Z,
    1.27 +
    1.28 +	ANM_NUM_TRACKS
    1.29 +};
    1.30 +
    1.31 +struct anm_node {
    1.32 +	char *name;
    1.33 +
    1.34 +	struct anm_track tracks[ANM_NUM_TRACKS];
    1.35 +	vec3_t pivot;
    1.36 +
    1.37 +	/* matrix cache */
    1.38 +	struct mat_cache {
    1.39 +		mat4_t matrix, inv_matrix;
    1.40 +		anm_time_t time, inv_time;
    1.41 +	} cache;
    1.42 +
    1.43 +	struct anm_node *parent;
    1.44 +	struct anm_node *child;
    1.45 +	struct anm_node *next;
    1.46 +};
    1.47 +
    1.48 +#ifdef __cplusplus
    1.49 +extern "C" {
    1.50 +#endif
    1.51 +
    1.52 +/* node constructor and destructor */
    1.53 +int anm_init_node(struct anm_node *node);
    1.54 +void anm_destroy_node(struct anm_node *node);
    1.55 +
    1.56 +/* recursively destroy an animation node tree */
    1.57 +void anm_destroy_node_tree(struct anm_node *tree);
    1.58 +
    1.59 +/* helper functions to allocate/construct and destroy/free with
    1.60 + * a single call. They call anm_init_node and anm_destroy_node
    1.61 + * internally.
    1.62 + */
    1.63 +struct anm_node *anm_create_node(void);
    1.64 +void anm_free_node(struct anm_node *node);
    1.65 +
    1.66 +/* recursively destroy and free the nodes of a node tree */
    1.67 +void anm_free_node_tree(struct anm_node *tree);
    1.68 +
    1.69 +int anm_set_node_name(struct anm_node *node, const char *name);
    1.70 +const char *anm_get_node_name(struct anm_node *node);
    1.71 +
    1.72 +void anm_set_interpolator(struct anm_node *node, enum anm_interpolator in);
    1.73 +void anm_set_extrapolator(struct anm_node *node, enum anm_extrapolator ex);
    1.74 +
    1.75 +/* link and unlink nodes with parent/child relations */
    1.76 +void anm_link_node(struct anm_node *parent, struct anm_node *child);
    1.77 +int anm_unlink_node(struct anm_node *parent, struct anm_node *child);
    1.78 +
    1.79 +void anm_set_position(struct anm_node *node, vec3_t pos, anm_time_t tm);
    1.80 +vec3_t anm_get_node_position(struct anm_node *node, anm_time_t tm);
    1.81 +
    1.82 +void anm_set_rotation(struct anm_node *node, quat_t rot, anm_time_t tm);
    1.83 +quat_t anm_get_node_rotation(struct anm_node *node, anm_time_t tm);
    1.84 +
    1.85 +void anm_set_scaling(struct anm_node *node, vec3_t scl, anm_time_t tm);
    1.86 +vec3_t anm_get_node_scaling(struct anm_node *node, anm_time_t tm);
    1.87 +
    1.88 +/* these three return the full p/r/s taking hierarchy into account */
    1.89 +vec3_t anm_get_position(struct anm_node *node, anm_time_t tm);
    1.90 +quat_t anm_get_rotation(struct anm_node *node, anm_time_t tm);
    1.91 +vec3_t anm_get_scaling(struct anm_node *node, anm_time_t tm);
    1.92 +
    1.93 +void anm_set_pivot(struct anm_node *node, vec3_t pivot);
    1.94 +vec3_t anm_get_pivot(struct anm_node *node);
    1.95 +
    1.96 +/* these calculate the matrix and inverse matrix of this node alone */
    1.97 +void anm_get_node_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
    1.98 +void anm_get_node_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
    1.99 +
   1.100 +/* These calculate the matrix and inverse matrix of this node taking hierarchy
   1.101 + * into account. The results are cached in thread-specific storage and returned
   1.102 + * if there's no change in time or tracks from the last query...
   1.103 + */
   1.104 +void anm_get_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
   1.105 +void anm_get_inv_matrix(struct anm_node *node, mat4_t mat, anm_time_t tm);
   1.106 +
   1.107 +/* those return the start and end times of the whole tree */
   1.108 +anm_time_t anm_get_start_time(struct anm_node *node);
   1.109 +anm_time_t anm_get_end_time(struct anm_node *node);
   1.110 +
   1.111 +#ifdef __cplusplus
   1.112 +}
   1.113 +#endif
   1.114 +
   1.115 +#endif	/* LIBANIM_H_ */