gpuray_glsl
diff anim/track.h @ 0:f234630e38ff
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 09 Nov 2014 13:03:36 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/anim/track.h Sun Nov 09 13:03:36 2014 +0200 1.3 @@ -0,0 +1,101 @@ 1.4 +/* An animation track defines the values of a single scalar over time 1.5 + * and supports various interpolation and extrapolation modes. 1.6 + */ 1.7 +#ifndef LIBANIM_TRACK_H_ 1.8 +#define LIBANIM_TRACK_H_ 1.9 + 1.10 +#include <limits.h> 1.11 +#include "config.h" 1.12 + 1.13 +enum anm_interpolator { 1.14 + ANM_INTERP_STEP, 1.15 + ANM_INTERP_LINEAR, 1.16 + ANM_INTERP_CUBIC 1.17 +}; 1.18 + 1.19 +enum anm_extrapolator { 1.20 + ANM_EXTRAP_EXTEND, /* extend to infinity */ 1.21 + ANM_EXTRAP_CLAMP, /* clamp to last value */ 1.22 + ANM_EXTRAP_REPEAT, /* repeat motion */ 1.23 + ANM_EXTRAP_PINGPONG /* repeat with mirroring */ 1.24 +}; 1.25 + 1.26 +typedef long anm_time_t; 1.27 +#define ANM_TIME_INVAL LONG_MIN 1.28 + 1.29 +#define ANM_SEC2TM(x) ((anm_time_t)((x) * 1000)) 1.30 +#define ANM_MSEC2TM(x) ((anm_time_t)(x)) 1.31 +#define ANM_TM2SEC(x) ((x) / 1000.0) 1.32 +#define ANM_TM2MSEC(x) (x) 1.33 + 1.34 +struct anm_keyframe { 1.35 + anm_time_t time; 1.36 + float val; 1.37 +}; 1.38 + 1.39 +struct anm_track { 1.40 + char *name; 1.41 + int count; 1.42 + struct anm_keyframe *keys; 1.43 + 1.44 + float def_val; 1.45 + 1.46 + enum anm_interpolator interp; 1.47 + enum anm_extrapolator extrap; 1.48 +}; 1.49 + 1.50 +#ifdef __cplusplus 1.51 +extern "C" { 1.52 +#endif 1.53 + 1.54 +/* track constructor and destructor */ 1.55 +int anm_init_track(struct anm_track *track); 1.56 +void anm_destroy_track(struct anm_track *track); 1.57 + 1.58 +/* helper functions that use anm_init_track and anm_destroy_track internally */ 1.59 +struct anm_track *anm_create_track(void); 1.60 +void anm_free_track(struct anm_track *track); 1.61 + 1.62 +/* copies track src to dest 1.63 + * XXX: dest must have been initialized first 1.64 + */ 1.65 +void anm_copy_track(struct anm_track *dest, struct anm_track *src); 1.66 + 1.67 +int anm_set_track_name(struct anm_track *track, const char *name); 1.68 +const char *anm_get_track_name(struct anm_track *track); 1.69 + 1.70 +void anm_set_track_interpolator(struct anm_track *track, enum anm_interpolator in); 1.71 +void anm_set_track_extrapolator(struct anm_track *track, enum anm_extrapolator ex); 1.72 + 1.73 +anm_time_t anm_remap_time(struct anm_track *track, anm_time_t tm, anm_time_t start, anm_time_t end); 1.74 + 1.75 +void anm_set_track_default(struct anm_track *track, float def); 1.76 + 1.77 +/* set or update a keyframe */ 1.78 +int anm_set_keyframe(struct anm_track *track, struct anm_keyframe *key); 1.79 + 1.80 +/* get the idx-th keyframe, returns null if it doesn't exist */ 1.81 +struct anm_keyframe *anm_get_keyframe(struct anm_track *track, int idx); 1.82 + 1.83 +/* Finds the 0-based index of the intra-keyframe interval which corresponds 1.84 + * to the specified time. If the time falls exactly onto the N-th keyframe 1.85 + * the function returns N. 1.86 + * 1.87 + * Special cases: 1.88 + * - if the time is before the first keyframe -1 is returned. 1.89 + * - if the time is after the last keyframe, the index of the last keyframe 1.90 + * is returned. 1.91 + */ 1.92 +int anm_get_key_interval(struct anm_track *track, anm_time_t tm); 1.93 + 1.94 +int anm_set_value(struct anm_track *track, anm_time_t tm, float val); 1.95 + 1.96 +/* evaluates and returns the value of the track for a particular time */ 1.97 +float anm_get_value(struct anm_track *track, anm_time_t tm); 1.98 + 1.99 +#ifdef __cplusplus 1.100 +} 1.101 +#endif 1.102 + 1.103 + 1.104 +#endif /* LIBANIM_TRACK_H_ */