libanim

annotate src/track.h @ 64:73a26dc37e43

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