vrshoot

view libs/anim/track.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
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 void anm_clear_track(struct anm_track *track);
66 int anm_set_track_name(struct anm_track *track, const char *name);
67 const char *anm_get_track_name(struct anm_track *track);
69 void anm_set_track_interpolator(struct anm_track *track, enum anm_interpolator in);
70 void anm_set_track_extrapolator(struct anm_track *track, enum anm_extrapolator ex);
72 anm_time_t anm_remap_time(struct anm_track *track, anm_time_t tm, anm_time_t start, anm_time_t end);
74 void anm_set_track_default(struct anm_track *track, float def);
76 /* set or update a keyframe */
77 int anm_set_keyframe(struct anm_track *track, struct anm_keyframe *key);
79 /* get the idx-th keyframe, returns null if it doesn't exist */
80 struct anm_keyframe *anm_get_keyframe(struct anm_track *track, int idx);
82 /* Finds the 0-based index of the intra-keyframe interval which corresponds
83 * to the specified time. If the time falls exactly onto the N-th keyframe
84 * the function returns N.
85 *
86 * Special cases:
87 * - if the time is before the first keyframe -1 is returned.
88 * - if the time is after the last keyframe, the index of the last keyframe
89 * is returned.
90 */
91 int anm_get_key_interval(struct anm_track *track, anm_time_t tm);
93 int anm_set_value(struct anm_track *track, anm_time_t tm, float val);
95 /* evaluates and returns the value of the track for a particular time */
96 float anm_get_value(struct anm_track *track, anm_time_t tm);
98 #ifdef __cplusplus
99 }
100 #endif
103 #endif /* LIBANIM_TRACK_H_ */