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@0
|
19 ANM_EXTRAP_REPEAT /* repeat motion */
|
nuclear@0
|
20 };
|
nuclear@0
|
21
|
nuclear@0
|
22 typedef long anm_time_t;
|
nuclear@0
|
23 #define ANM_TIME_INVAL LONG_MIN
|
nuclear@0
|
24
|
nuclear@0
|
25 #define ANM_SEC2TM(x) ((anm_time_t)((x) * 1000))
|
nuclear@0
|
26 #define ANM_MSEC2TM(x) ((anm_time_t)(x))
|
nuclear@0
|
27 #define ANM_TM2SEC(x) ((x) / 1000.0)
|
nuclear@0
|
28 #define ANM_TM2MSEC(x) (x)
|
nuclear@0
|
29
|
nuclear@0
|
30 struct anm_keyframe {
|
nuclear@0
|
31 anm_time_t time;
|
nuclear@0
|
32 float val;
|
nuclear@0
|
33 };
|
nuclear@0
|
34
|
nuclear@0
|
35 struct anm_track {
|
nuclear@0
|
36 char *name;
|
nuclear@0
|
37 int count;
|
nuclear@0
|
38 struct anm_keyframe *keys;
|
nuclear@0
|
39
|
nuclear@0
|
40 float def_val;
|
nuclear@0
|
41
|
nuclear@0
|
42 enum anm_interpolator interp;
|
nuclear@0
|
43 enum anm_extrapolator extrap;
|
nuclear@0
|
44 };
|
nuclear@0
|
45
|
nuclear@0
|
46 #ifdef __cplusplus
|
nuclear@0
|
47 extern "C" {
|
nuclear@0
|
48 #endif
|
nuclear@0
|
49
|
nuclear@0
|
50 /* track constructor and destructor */
|
nuclear@0
|
51 int anm_init_track(struct anm_track *track);
|
nuclear@0
|
52 void anm_destroy_track(struct anm_track *track);
|
nuclear@0
|
53
|
nuclear@0
|
54 /* helper functions that use anm_init_track and anm_destroy_track internally */
|
nuclear@0
|
55 struct anm_track *anm_create_track(void);
|
nuclear@0
|
56 void anm_free_track(struct anm_track *track);
|
nuclear@0
|
57
|
nuclear@0
|
58 int anm_set_track_name(struct anm_track *track, const char *name);
|
nuclear@0
|
59 const char *anm_get_track_name(struct anm_track *track);
|
nuclear@0
|
60
|
nuclear@0
|
61 void anm_set_track_interpolator(struct anm_track *track, enum anm_interpolator in);
|
nuclear@0
|
62 void anm_set_track_extrapolator(struct anm_track *track, enum anm_extrapolator ex);
|
nuclear@0
|
63
|
nuclear@0
|
64 anm_time_t anm_remap_time(struct anm_track *track, anm_time_t tm, anm_time_t start, anm_time_t end);
|
nuclear@0
|
65
|
nuclear@0
|
66 void anm_set_track_default(struct anm_track *track, float def);
|
nuclear@0
|
67
|
nuclear@0
|
68 /* set or update a keyframe */
|
nuclear@0
|
69 int anm_set_keyframe(struct anm_track *track, struct anm_keyframe *key);
|
nuclear@0
|
70
|
nuclear@0
|
71 /* get the idx-th keyframe, returns null if it doesn't exist */
|
nuclear@0
|
72 struct anm_keyframe *anm_get_keyframe(struct anm_track *track, int idx);
|
nuclear@0
|
73
|
nuclear@0
|
74 /* Finds the 0-based index of the intra-keyframe interval which corresponds
|
nuclear@0
|
75 * to the specified time. If the time falls exactly onto the N-th keyframe
|
nuclear@0
|
76 * the function returns N.
|
nuclear@0
|
77 *
|
nuclear@0
|
78 * Special cases:
|
nuclear@0
|
79 * - if the time is before the first keyframe -1 is returned.
|
nuclear@0
|
80 * - if the time is after the last keyframe, the index of the last keyframe
|
nuclear@0
|
81 * is returned.
|
nuclear@0
|
82 */
|
nuclear@0
|
83 int anm_get_key_interval(struct anm_track *track, anm_time_t tm);
|
nuclear@0
|
84
|
nuclear@0
|
85 int anm_set_value(struct anm_track *track, anm_time_t tm, float val);
|
nuclear@0
|
86
|
nuclear@0
|
87 /* evaluates and returns the value of the track for a particular time */
|
nuclear@0
|
88 float anm_get_value(struct anm_track *track, anm_time_t tm);
|
nuclear@0
|
89
|
nuclear@0
|
90 #ifdef __cplusplus
|
nuclear@0
|
91 }
|
nuclear@0
|
92 #endif
|
nuclear@0
|
93
|
nuclear@0
|
94
|
nuclear@0
|
95 #endif /* LIBANIM_TRACK_H_ */
|