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