diff options
Diffstat (limited to 'src/util/anim.h')
| -rw-r--r-- | src/util/anim.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/util/anim.h b/src/util/anim.h new file mode 100644 index 0000000..dbc2c11 --- /dev/null +++ b/src/util/anim.h @@ -0,0 +1,27 @@ +#include "typedef.h" + +#include <SDL.h> + +template < typename T > +inline T lerp( T a, T b, F32 t ) { + return a + ( b - a ) * t; +} + +template < typename t > +inline t clamp( t a, t min, t max ) { + if ( a < min ) return min; + if ( a > max ) return max; + return a; +} + +inline F32 ease_in( F32 t, F32 pow = 2.f ) { + return powf( t, pow ); +} + +inline F32 ease_out( F32 t, F32 pow = 2.f ) { + return 1.f - powf( 1.f - t, pow ); +} + +inline F32 ease_in_out( F32 t, F32 pow = 2.f ) { + return t < 0.5f ? ease_in( t * 2.f, pow ) / 2.f : ease_out( t * 2.f - 1.f, pow ) / 2.f + 0.5f; +} |
