goat3d

annotate libs/anim/track.h @ 38:60f2037680ee

split the exporter into two files to make it more readable (and maybe make an importer too at some point?)
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 07 Oct 2013 20:02:57 +0300
parents
children 0ecb788a87f7
rev   line source
nuclear@27 1 /* An animation track defines the values of a single scalar over time
nuclear@27 2 * and supports various interpolation and extrapolation modes.
nuclear@27 3 */
nuclear@27 4 #ifndef LIBANIM_TRACK_H_
nuclear@27 5 #define LIBANIM_TRACK_H_
nuclear@27 6
nuclear@27 7 #include <limits.h>
nuclear@27 8 #include "config.h"
nuclear@27 9
nuclear@27 10 enum anm_interpolator {
nuclear@27 11 ANM_INTERP_STEP,
nuclear@27 12 ANM_INTERP_LINEAR,
nuclear@27 13 ANM_INTERP_CUBIC
nuclear@27 14 };
nuclear@27 15
nuclear@27 16 enum anm_extrapolator {
nuclear@27 17 ANM_EXTRAP_EXTEND, /* extend to infinity */
nuclear@27 18 ANM_EXTRAP_CLAMP, /* clamp to last value */
nuclear@27 19 ANM_EXTRAP_REPEAT, /* repeat motion */
nuclear@27 20 ANM_EXTRAP_PINGPONG /* repeat with mirroring */
nuclear@27 21 };
nuclear@27 22
nuclear@27 23 typedef long anm_time_t;
nuclear@27 24 #define ANM_TIME_INVAL LONG_MIN
nuclear@27 25
nuclear@27 26 #define ANM_SEC2TM(x) ((anm_time_t)((x) * 1000))
nuclear@27 27 #define ANM_MSEC2TM(x) ((anm_time_t)(x))
nuclear@27 28 #define ANM_TM2SEC(x) ((x) / 1000.0)
nuclear@27 29 #define ANM_TM2MSEC(x) (x)
nuclear@27 30
nuclear@27 31 struct anm_keyframe {
nuclear@27 32 anm_time_t time;
nuclear@27 33 float val;
nuclear@27 34 };
nuclear@27 35
nuclear@27 36 struct anm_track {
nuclear@27 37 char *name;
nuclear@27 38 int count;
nuclear@27 39 struct anm_keyframe *keys;
nuclear@27 40
nuclear@27 41 float def_val;
nuclear@27 42
nuclear@27 43 enum anm_interpolator interp;
nuclear@27 44 enum anm_extrapolator extrap;
nuclear@27 45 };
nuclear@27 46
nuclear@27 47 #ifdef __cplusplus
nuclear@27 48 extern "C" {
nuclear@27 49 #endif
nuclear@27 50
nuclear@27 51 /* track constructor and destructor */
nuclear@27 52 int anm_init_track(struct anm_track *track);
nuclear@27 53 void anm_destroy_track(struct anm_track *track);
nuclear@27 54
nuclear@27 55 /* helper functions that use anm_init_track and anm_destroy_track internally */
nuclear@27 56 struct anm_track *anm_create_track(void);
nuclear@27 57 void anm_free_track(struct anm_track *track);
nuclear@27 58
nuclear@27 59 /* copies track src to dest
nuclear@27 60 * XXX: dest must have been initialized first
nuclear@27 61 */
nuclear@27 62 void anm_copy_track(struct anm_track *dest, struct anm_track *src);
nuclear@27 63
nuclear@27 64 int anm_set_track_name(struct anm_track *track, const char *name);
nuclear@27 65 const char *anm_get_track_name(struct anm_track *track);
nuclear@27 66
nuclear@27 67 void anm_set_track_interpolator(struct anm_track *track, enum anm_interpolator in);
nuclear@27 68 void anm_set_track_extrapolator(struct anm_track *track, enum anm_extrapolator ex);
nuclear@27 69
nuclear@27 70 anm_time_t anm_remap_time(struct anm_track *track, anm_time_t tm, anm_time_t start, anm_time_t end);
nuclear@27 71
nuclear@27 72 void anm_set_track_default(struct anm_track *track, float def);
nuclear@27 73
nuclear@27 74 /* set or update a keyframe */
nuclear@27 75 int anm_set_keyframe(struct anm_track *track, struct anm_keyframe *key);
nuclear@27 76
nuclear@27 77 /* get the idx-th keyframe, returns null if it doesn't exist */
nuclear@27 78 struct anm_keyframe *anm_get_keyframe(struct anm_track *track, int idx);
nuclear@27 79
nuclear@27 80 /* Finds the 0-based index of the intra-keyframe interval which corresponds
nuclear@27 81 * to the specified time. If the time falls exactly onto the N-th keyframe
nuclear@27 82 * the function returns N.
nuclear@27 83 *
nuclear@27 84 * Special cases:
nuclear@27 85 * - if the time is before the first keyframe -1 is returned.
nuclear@27 86 * - if the time is after the last keyframe, the index of the last keyframe
nuclear@27 87 * is returned.
nuclear@27 88 */
nuclear@27 89 int anm_get_key_interval(struct anm_track *track, anm_time_t tm);
nuclear@27 90
nuclear@27 91 int anm_set_value(struct anm_track *track, anm_time_t tm, float val);
nuclear@27 92
nuclear@27 93 /* evaluates and returns the value of the track for a particular time */
nuclear@27 94 float anm_get_value(struct anm_track *track, anm_time_t tm);
nuclear@27 95
nuclear@27 96 #ifdef __cplusplus
nuclear@27 97 }
nuclear@27 98 #endif
nuclear@27 99
nuclear@27 100
nuclear@27 101 #endif /* LIBANIM_TRACK_H_ */