From f8b92ce3aa08b1445c9f956d8166830946562d12 Mon Sep 17 00:00:00 2001 From: navewindre Date: Wed, 3 Sep 2025 20:10:09 +0200 Subject: a --- src/util/anim.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/util/anim.h (limited to 'src/util/anim.h') 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 + +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; +} -- cgit v1.2.3