goat3d

view libs/anim/track.h @ 55:af1310ed212b

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