libanim
changeset 49:fb9659ca5cf2
added ping-pong extrapolator
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 13 Apr 2013 07:27:32 +0300 |
parents | 9915b036863d |
children | b92a21c31008 |
files | src/track.c src/track.h |
diffstat | 2 files changed, 12 insertions(+), 1 deletions(-) [+] |
line diff
1.1 --- a/src/track.c Sun Mar 10 18:52:57 2013 +0200 1.2 +++ b/src/track.c Sat Apr 13 07:27:32 2013 +0300 1.3 @@ -14,6 +14,7 @@ 1.4 static anm_time_t remap_extend(anm_time_t tm, anm_time_t start, anm_time_t end); 1.5 static anm_time_t remap_clamp(anm_time_t tm, anm_time_t start, anm_time_t end); 1.6 static anm_time_t remap_repeat(anm_time_t tm, anm_time_t start, anm_time_t end); 1.7 +static anm_time_t remap_pingpong(anm_time_t tm, anm_time_t start, anm_time_t end); 1.8 1.9 /* XXX keep this in sync with enum anm_interpolator at track.h */ 1.10 static float (*interp[])(float, float, float, float, float) = { 1.11 @@ -28,6 +29,7 @@ 1.12 remap_extend, 1.13 remap_clamp, 1.14 remap_repeat, 1.15 + remap_pingpong, 1.16 0 1.17 }; 1.18 1.19 @@ -304,3 +306,11 @@ 1.20 } 1.21 return (tm - start) % interv + start;*/ 1.22 } 1.23 + 1.24 +static anm_time_t remap_pingpong(anm_time_t tm, anm_time_t start, anm_time_t end) 1.25 +{ 1.26 + anm_time_t interv = end - start; 1.27 + anm_time_t x = remap_repeat(tm, start, end + interv); 1.28 + 1.29 + return x > end ? end + interv - x : x; 1.30 +}
2.1 --- a/src/track.h Sun Mar 10 18:52:57 2013 +0200 2.2 +++ b/src/track.h Sat Apr 13 07:27:32 2013 +0300 2.3 @@ -16,7 +16,8 @@ 2.4 enum anm_extrapolator { 2.5 ANM_EXTRAP_EXTEND, /* extend to infinity */ 2.6 ANM_EXTRAP_CLAMP, /* clamp to last value */ 2.7 - ANM_EXTRAP_REPEAT /* repeat motion */ 2.8 + ANM_EXTRAP_REPEAT, /* repeat motion */ 2.9 + ANM_EXTRAP_PINGPONG /* repeat with mirroring */ 2.10 }; 2.11 2.12 typedef long anm_time_t;