From 4738d8ea245b2b1bffc00d76fbbac7fade39b457 Mon Sep 17 00:00:00 2001 From: Cedric Pinson Date: Tue, 7 Apr 2009 08:40:49 +0000 Subject: [PATCH] From Serge Lages, Elastic added to EaseMotion --- include/osgAnimation/EaseMotion | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/include/osgAnimation/EaseMotion b/include/osgAnimation/EaseMotion index df3ae8d7f..3eb6d9478 100644 --- a/include/osgAnimation/EaseMotion +++ b/include/osgAnimation/EaseMotion @@ -160,6 +160,41 @@ namespace osgAnimation { } }; + /// Elastic function + struct OutElasticFunction + { + inline static void getValueAt(float t, float& result) + { + result = pow(2.0f, -10.0f * t) * sinf((t - 0.3f / 4.0f) * (2.0f * osg::PI) / 0.3f) + 1.0f; + } + }; + + struct InElasticFunction + { + inline static void getValueAt(float t, float& result) + { + OutElasticFunction::getValueAt(1.0f - t, result); + result = 1.0f - result; + } + }; + + struct InOutElasticFunction + { + inline static void getValueAt(float t, float& result) + { + t *= 2.0f; + if (t < 1.0f) + { + t -= 1.0f; + result = -0.5 * (1.0f * pow(2.0f, 10.0f * t) * sinf((t - 0.45f / 4.0f) * (2.0f * osg::PI) / 0.45f)); + } + else + { + t -= 1.0f; + result = pow(2.0f, -10.0f * t) * sinf((t - 0.45f / 4.0f) * (2.0f * osg::PI) / 0.45f) * 0.5f + 1.0f; + } + } + }; class Motion : public osg::Referenced @@ -320,6 +355,10 @@ namespace osgAnimation { typedef MathMotionTemplate InBounceMotion; typedef MathMotionTemplate InOutBounceMotion; + // elastic + typedef MathMotionTemplate OutElasticMotion; + typedef MathMotionTemplate InElasticMotion; + typedef MathMotionTemplate InOutElasticMotion; }