nuclear@0: /* An animation track defines the values of a single scalar over time nuclear@0: * and supports various interpolation and extrapolation modes. nuclear@0: */ nuclear@0: #ifndef LIBANIM_TRACK_H_ nuclear@0: #define LIBANIM_TRACK_H_ nuclear@0: nuclear@0: #include nuclear@0: #include "config.h" nuclear@0: nuclear@0: enum anm_interpolator { nuclear@0: ANM_INTERP_STEP, nuclear@0: ANM_INTERP_LINEAR, nuclear@0: ANM_INTERP_CUBIC nuclear@0: }; nuclear@0: nuclear@0: enum anm_extrapolator { nuclear@0: ANM_EXTRAP_EXTEND, /* extend to infinity */ nuclear@0: ANM_EXTRAP_CLAMP, /* clamp to last value */ nuclear@12: ANM_EXTRAP_REPEAT, /* repeat motion */ nuclear@12: ANM_EXTRAP_PINGPONG /* repeat with mirroring */ nuclear@0: }; nuclear@0: nuclear@0: typedef long anm_time_t; nuclear@0: #define ANM_TIME_INVAL LONG_MIN nuclear@0: nuclear@0: #define ANM_SEC2TM(x) ((anm_time_t)((x) * 1000)) nuclear@0: #define ANM_MSEC2TM(x) ((anm_time_t)(x)) nuclear@0: #define ANM_TM2SEC(x) ((x) / 1000.0) nuclear@0: #define ANM_TM2MSEC(x) (x) nuclear@0: nuclear@0: struct anm_keyframe { nuclear@0: anm_time_t time; nuclear@0: float val; nuclear@0: }; nuclear@0: nuclear@0: struct anm_track { nuclear@0: char *name; nuclear@0: int count; nuclear@0: struct anm_keyframe *keys; nuclear@0: nuclear@0: float def_val; nuclear@0: nuclear@0: enum anm_interpolator interp; nuclear@0: enum anm_extrapolator extrap; nuclear@0: }; nuclear@0: nuclear@0: #ifdef __cplusplus nuclear@0: extern "C" { nuclear@0: #endif nuclear@0: nuclear@0: /* track constructor and destructor */ nuclear@0: int anm_init_track(struct anm_track *track); nuclear@0: void anm_destroy_track(struct anm_track *track); nuclear@0: nuclear@0: /* helper functions that use anm_init_track and anm_destroy_track internally */ nuclear@0: struct anm_track *anm_create_track(void); nuclear@0: void anm_free_track(struct anm_track *track); nuclear@0: nuclear@2: /* copies track src to dest nuclear@2: * XXX: dest must have been initialized first nuclear@2: */ nuclear@17: void anm_copy_track(struct anm_track *dest, const struct anm_track *src); nuclear@2: nuclear@0: int anm_set_track_name(struct anm_track *track, const char *name); nuclear@0: const char *anm_get_track_name(struct anm_track *track); nuclear@0: nuclear@0: void anm_set_track_interpolator(struct anm_track *track, enum anm_interpolator in); nuclear@0: void anm_set_track_extrapolator(struct anm_track *track, enum anm_extrapolator ex); nuclear@0: nuclear@0: anm_time_t anm_remap_time(struct anm_track *track, anm_time_t tm, anm_time_t start, anm_time_t end); nuclear@0: nuclear@0: void anm_set_track_default(struct anm_track *track, float def); nuclear@0: nuclear@0: /* set or update a keyframe */ nuclear@0: int anm_set_keyframe(struct anm_track *track, struct anm_keyframe *key); nuclear@0: nuclear@0: /* get the idx-th keyframe, returns null if it doesn't exist */ nuclear@0: struct anm_keyframe *anm_get_keyframe(struct anm_track *track, int idx); nuclear@0: nuclear@0: /* Finds the 0-based index of the intra-keyframe interval which corresponds nuclear@0: * to the specified time. If the time falls exactly onto the N-th keyframe nuclear@0: * the function returns N. nuclear@0: * nuclear@0: * Special cases: nuclear@0: * - if the time is before the first keyframe -1 is returned. nuclear@0: * - if the time is after the last keyframe, the index of the last keyframe nuclear@0: * is returned. nuclear@0: */ nuclear@0: int anm_get_key_interval(struct anm_track *track, anm_time_t tm); nuclear@0: nuclear@0: int anm_set_value(struct anm_track *track, anm_time_t tm, float val); nuclear@0: nuclear@0: /* evaluates and returns the value of the track for a particular time */ nuclear@0: float anm_get_value(struct anm_track *track, anm_time_t tm); nuclear@0: nuclear@0: #ifdef __cplusplus nuclear@0: } nuclear@0: #endif nuclear@0: nuclear@0: nuclear@0: #endif /* LIBANIM_TRACK_H_ */