libanim
view src/track.h @ 29:70ad14ba4df2
merged
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 17 Apr 2014 07:58:35 +0300 |
parents | 821411647b40 |
children |
line source
1 /*
2 libanim - hierarchical keyframe animation library
3 Copyright (C) 2012-2014 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
19 /* An animation track defines the values of a single scalar over time
20 * and supports various interpolation and extrapolation modes.
21 */
22 #ifndef LIBANIM_TRACK_H_
23 #define LIBANIM_TRACK_H_
25 #include <limits.h>
26 #include "config.h"
28 enum anm_interpolator {
29 ANM_INTERP_STEP,
30 ANM_INTERP_LINEAR,
31 ANM_INTERP_CUBIC
32 };
34 enum anm_extrapolator {
35 ANM_EXTRAP_EXTEND, /* extend to infinity */
36 ANM_EXTRAP_CLAMP, /* clamp to last value */
37 ANM_EXTRAP_REPEAT, /* repeat motion */
38 ANM_EXTRAP_PINGPONG /* repeat with mirroring */
39 };
41 typedef long anm_time_t;
42 #define ANM_TIME_INVAL LONG_MIN
44 #define ANM_SEC2TM(x) ((anm_time_t)((x) * 1000))
45 #define ANM_MSEC2TM(x) ((anm_time_t)(x))
46 #define ANM_TM2SEC(x) ((x) / 1000.0)
47 #define ANM_TM2MSEC(x) (x)
49 struct anm_keyframe {
50 anm_time_t time;
51 float val;
52 };
54 struct anm_track {
55 char *name;
56 int count;
57 struct anm_keyframe *keys;
59 float def_val;
61 enum anm_interpolator interp;
62 enum anm_extrapolator extrap;
63 };
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
69 /* track constructor and destructor */
70 int anm_init_track(struct anm_track *track);
71 void anm_destroy_track(struct anm_track *track);
73 /* helper functions that use anm_init_track and anm_destroy_track internally */
74 struct anm_track *anm_create_track(void);
75 void anm_free_track(struct anm_track *track);
77 /* copies track src to dest
78 * XXX: dest must have been initialized first
79 */
80 void anm_copy_track(struct anm_track *dest, const struct anm_track *src);
82 int anm_set_track_name(struct anm_track *track, const char *name);
83 const char *anm_get_track_name(struct anm_track *track);
85 void anm_set_track_interpolator(struct anm_track *track, enum anm_interpolator in);
86 void anm_set_track_extrapolator(struct anm_track *track, enum anm_extrapolator ex);
88 anm_time_t anm_remap_time(struct anm_track *track, anm_time_t tm, anm_time_t start, anm_time_t end);
90 void anm_set_track_default(struct anm_track *track, float def);
92 /* set or update a keyframe */
93 int anm_set_keyframe(struct anm_track *track, struct anm_keyframe *key);
95 /* get the idx-th keyframe, returns null if it doesn't exist */
96 struct anm_keyframe *anm_get_keyframe(struct anm_track *track, int idx);
98 /* Finds the 0-based index of the intra-keyframe interval which corresponds
99 * to the specified time. If the time falls exactly onto the N-th keyframe
100 * the function returns N.
101 *
102 * Special cases:
103 * - if the time is before the first keyframe -1 is returned.
104 * - if the time is after the last keyframe, the index of the last keyframe
105 * is returned.
106 */
107 int anm_get_key_interval(struct anm_track *track, anm_time_t tm);
109 int anm_set_value(struct anm_track *track, anm_time_t tm, float val);
111 /* evaluates and returns the value of the track for a particular time */
112 float anm_get_value(struct anm_track *track, anm_time_t tm);
114 #ifdef __cplusplus
115 }
116 #endif
119 #endif /* LIBANIM_TRACK_H_ */