From 80f59dd749ae3986d659a8c5b3c69942a2f90a8f Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Mon, 23 Apr 2018 03:24:13 +0200 Subject: [PATCH] tween: add function to just interpolate the value, without using Tween object --- src/tween.c | 16 ++++++++++++---- src/tween.h | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/tween.c b/src/tween.c index d1abfd7..c9a3d59 100644 --- a/src/tween.c +++ b/src/tween.c @@ -264,9 +264,14 @@ double GetTweenPosition(struct Tween* tween) { return tween->pos / tween->duration; } -double GetTweenInterpolation(struct Tween* tween) { - double pos = GetTweenPosition(tween); - switch (tween->style) { +double Interpolate(double pos, TWEEN_STYLE style) { + if (pos < 0.0) { + pos = 0.0; + } + if (pos > 1.0) { + pos = 1.0; + } + switch (style) { case TWEEN_STYLE_LINEAR: return LinearInterpolation(pos); case TWEEN_STYLE_QUADRATIC_IN: @@ -330,7 +335,10 @@ double GetTweenInterpolation(struct Tween* tween) { case TWEEN_STYLE_BOUNCE_IN_OUT: return BounceEaseInOut(pos); } - return pos; +} + +double GetTweenInterpolation(struct Tween* tween) { + return Interpolate(GetTweenPosition(tween), tween->style); } double GetTweenValue(struct Tween* tween) { diff --git a/src/tween.h b/src/tween.h index 7387a9c..6cdb5b7 100644 --- a/src/tween.h +++ b/src/tween.h @@ -84,5 +84,6 @@ double GetTweenPosition(struct Tween* tween); double GetTweenInterpolation(struct Tween* tween); double GetTweenValue(struct Tween* tween); void UpdateTween(struct Tween* tween, double delta); +double Interpolate(double pos, TWEEN_STYLE style); #endif