rev |
line source |
nuclear@67
|
1 /* An animation track defines the values of a single scalar over time
|
nuclear@67
|
2 * and supports various interpolation and extrapolation modes.
|
nuclear@67
|
3 */
|
nuclear@67
|
4 #ifndef LIBANIM_TRACK_H_
|
nuclear@67
|
5 #define LIBANIM_TRACK_H_
|
nuclear@67
|
6
|
nuclear@67
|
7 #include <limits.h>
|
nuclear@67
|
8 #include "config.h"
|
nuclear@67
|
9
|
nuclear@67
|
10 enum anm_interpolator {
|
nuclear@67
|
11 ANM_INTERP_STEP,
|
nuclear@67
|
12 ANM_INTERP_LINEAR,
|
nuclear@67
|
13 ANM_INTERP_CUBIC
|
nuclear@67
|
14 };
|
nuclear@67
|
15
|
nuclear@67
|
16 enum anm_extrapolator {
|
nuclear@67
|
17 ANM_EXTRAP_EXTEND, /* extend to infinity */
|
nuclear@67
|
18 ANM_EXTRAP_CLAMP, /* clamp to last value */
|
nuclear@67
|
19 ANM_EXTRAP_REPEAT /* repeat motion */
|
nuclear@67
|
20 };
|
nuclear@67
|
21
|
nuclear@67
|
22 typedef long anm_time_t;
|
nuclear@67
|
23 #define ANM_TIME_INVAL LONG_MIN
|
nuclear@67
|
24
|
nuclear@67
|
25 #define ANM_SEC2TM(x) ((anm_time_t)((x) * 1000))
|
nuclear@67
|
26 #define ANM_MSEC2TM(x) ((anm_time_t)(x))
|
nuclear@67
|
27 #define ANM_TM2SEC(x) ((x) / 1000.0)
|
nuclear@67
|
28 #define ANM_TM2MSEC(x) (x)
|
nuclear@67
|
29
|
nuclear@67
|
30 struct anm_keyframe {
|
nuclear@67
|
31 anm_time_t time;
|
nuclear@67
|
32 float val;
|
nuclear@67
|
33 };
|
nuclear@67
|
34
|
nuclear@67
|
35 struct anm_track {
|
nuclear@67
|
36 char *name;
|
nuclear@67
|
37 int count;
|
nuclear@67
|
38 struct anm_keyframe *keys;
|
nuclear@67
|
39
|
nuclear@67
|
40 float def_val;
|
nuclear@67
|
41
|
nuclear@67
|
42 enum anm_interpolator interp;
|
nuclear@67
|
43 enum anm_extrapolator extrap;
|
nuclear@67
|
44 };
|
nuclear@67
|
45
|
nuclear@67
|
46 /* track constructor and destructor */
|
nuclear@67
|
47 int anm_init_track(struct anm_track *track);
|
nuclear@67
|
48 void anm_destroy_track(struct anm_track *track);
|
nuclear@67
|
49
|
nuclear@67
|
50 /* helper functions that use anm_init_track and anm_destroy_track internally */
|
nuclear@67
|
51 struct anm_track *anm_create_track(void);
|
nuclear@67
|
52 void anm_free_track(struct anm_track *track);
|
nuclear@67
|
53
|
nuclear@67
|
54 int anm_set_track_name(struct anm_track *track, const char *name);
|
nuclear@67
|
55 const char *anm_get_track_name(struct anm_track *track);
|
nuclear@67
|
56
|
nuclear@67
|
57 void anm_set_track_interpolator(struct anm_track *track, enum anm_interpolator in);
|
nuclear@67
|
58 void anm_set_track_extrapolator(struct anm_track *track, enum anm_extrapolator ex);
|
nuclear@67
|
59
|
nuclear@67
|
60 anm_time_t anm_remap_time(struct anm_track *track, anm_time_t tm, anm_time_t start, anm_time_t end);
|
nuclear@67
|
61
|
nuclear@67
|
62 void anm_set_track_default(struct anm_track *track, float def);
|
nuclear@67
|
63
|
nuclear@67
|
64 /* set or update a keyframe */
|
nuclear@67
|
65 int anm_set_keyframe(struct anm_track *track, struct anm_keyframe *key);
|
nuclear@67
|
66
|
nuclear@67
|
67 /* get the idx-th keyframe, returns null if it doesn't exist */
|
nuclear@67
|
68 struct anm_keyframe *anm_get_keyframe(struct anm_track *track, int idx);
|
nuclear@67
|
69
|
nuclear@67
|
70 /* Finds the 0-based index of the intra-keyframe interval which corresponds
|
nuclear@67
|
71 * to the specified time. If the time falls exactly onto the N-th keyframe
|
nuclear@67
|
72 * the function returns N.
|
nuclear@67
|
73 *
|
nuclear@67
|
74 * Special cases:
|
nuclear@67
|
75 * - if the time is before the first keyframe -1 is returned.
|
nuclear@67
|
76 * - if the time is after the last keyframe, the index of the last keyframe
|
nuclear@67
|
77 * is returned.
|
nuclear@67
|
78 */
|
nuclear@67
|
79 int anm_get_key_interval(struct anm_track *track, anm_time_t tm);
|
nuclear@67
|
80
|
nuclear@67
|
81 int anm_set_value(struct anm_track *track, anm_time_t tm, float val);
|
nuclear@67
|
82
|
nuclear@67
|
83 /* evaluates and returns the value of the track for a particular time */
|
nuclear@67
|
84 float anm_get_value(struct anm_track *track, anm_time_t tm);
|
nuclear@67
|
85
|
nuclear@67
|
86
|
nuclear@67
|
87
|
nuclear@67
|
88 #endif /* LIBANIM_TRACK_H_ */
|