libanim
view src/track.h @ 9:710658962108
simplified the matrix calculation and removed two quaternion normalizations that were probably not needed
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 08 Mar 2013 04:54:05 +0200 |
parents | fad4701f484e |
children | 9691b3521fa3 |
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 };
22 typedef long anm_time_t;
23 #define ANM_TIME_INVAL LONG_MIN
25 #define ANM_SEC2TM(x) ((anm_time_t)((x) * 1000))
26 #define ANM_MSEC2TM(x) ((anm_time_t)(x))
27 #define ANM_TM2SEC(x) ((x) / 1000.0)
28 #define ANM_TM2MSEC(x) (x)
30 struct anm_keyframe {
31 anm_time_t time;
32 float val;
33 };
35 struct anm_track {
36 char *name;
37 int count;
38 struct anm_keyframe *keys;
40 float def_val;
42 enum anm_interpolator interp;
43 enum anm_extrapolator extrap;
44 };
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
50 /* track constructor and destructor */
51 int anm_init_track(struct anm_track *track);
52 void anm_destroy_track(struct anm_track *track);
54 /* helper functions that use anm_init_track and anm_destroy_track internally */
55 struct anm_track *anm_create_track(void);
56 void anm_free_track(struct anm_track *track);
58 /* copies track src to dest
59 * XXX: dest must have been initialized first
60 */
61 void anm_copy_track(struct anm_track *dest, struct anm_track *src);
63 int anm_set_track_name(struct anm_track *track, const char *name);
64 const char *anm_get_track_name(struct anm_track *track);
66 void anm_set_track_interpolator(struct anm_track *track, enum anm_interpolator in);
67 void anm_set_track_extrapolator(struct anm_track *track, enum anm_extrapolator ex);
69 anm_time_t anm_remap_time(struct anm_track *track, anm_time_t tm, anm_time_t start, anm_time_t end);
71 void anm_set_track_default(struct anm_track *track, float def);
73 /* set or update a keyframe */
74 int anm_set_keyframe(struct anm_track *track, struct anm_keyframe *key);
76 /* get the idx-th keyframe, returns null if it doesn't exist */
77 struct anm_keyframe *anm_get_keyframe(struct anm_track *track, int idx);
79 /* Finds the 0-based index of the intra-keyframe interval which corresponds
80 * to the specified time. If the time falls exactly onto the N-th keyframe
81 * the function returns N.
82 *
83 * Special cases:
84 * - if the time is before the first keyframe -1 is returned.
85 * - if the time is after the last keyframe, the index of the last keyframe
86 * is returned.
87 */
88 int anm_get_key_interval(struct anm_track *track, anm_time_t tm);
90 int anm_set_value(struct anm_track *track, anm_time_t tm, float val);
92 /* evaluates and returns the value of the track for a particular time */
93 float anm_get_value(struct anm_track *track, anm_time_t tm);
95 #ifdef __cplusplus
96 }
97 #endif
100 #endif /* LIBANIM_TRACK_H_ */