dungeon_crawler

view prototype/anim/track.h @ 67:2560a7ab0243

internalized libanim, libimago2, and libpsys
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 07 Oct 2012 02:04:00 +0300
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 };
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 /* track constructor and destructor */
47 int anm_init_track(struct anm_track *track);
48 void anm_destroy_track(struct anm_track *track);
50 /* helper functions that use anm_init_track and anm_destroy_track internally */
51 struct anm_track *anm_create_track(void);
52 void anm_free_track(struct anm_track *track);
54 int anm_set_track_name(struct anm_track *track, const char *name);
55 const char *anm_get_track_name(struct anm_track *track);
57 void anm_set_track_interpolator(struct anm_track *track, enum anm_interpolator in);
58 void anm_set_track_extrapolator(struct anm_track *track, enum anm_extrapolator ex);
60 anm_time_t anm_remap_time(struct anm_track *track, anm_time_t tm, anm_time_t start, anm_time_t end);
62 void anm_set_track_default(struct anm_track *track, float def);
64 /* set or update a keyframe */
65 int anm_set_keyframe(struct anm_track *track, struct anm_keyframe *key);
67 /* get the idx-th keyframe, returns null if it doesn't exist */
68 struct anm_keyframe *anm_get_keyframe(struct anm_track *track, int idx);
70 /* Finds the 0-based index of the intra-keyframe interval which corresponds
71 * to the specified time. If the time falls exactly onto the N-th keyframe
72 * the function returns N.
73 *
74 * Special cases:
75 * - if the time is before the first keyframe -1 is returned.
76 * - if the time is after the last keyframe, the index of the last keyframe
77 * is returned.
78 */
79 int anm_get_key_interval(struct anm_track *track, anm_time_t tm);
81 int anm_set_value(struct anm_track *track, anm_time_t tm, float val);
83 /* evaluates and returns the value of the track for a particular time */
84 float anm_get_value(struct anm_track *track, anm_time_t tm);
88 #endif /* LIBANIM_TRACK_H_ */