diff --git a/include/osgAnimation/EaseMotion b/include/osgAnimation/EaseMotion index 7a41e3a50..3c55851e6 100644 --- a/include/osgAnimation/EaseMotion +++ b/include/osgAnimation/EaseMotion @@ -1,5 +1,5 @@ /* -*-c++-*- - * Copyright (C) 2008 Cedric Pinson + * Copyright (C) 2008 Cedric Pinson * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or @@ -10,10 +10,10 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. -*/ + */ -#ifndef OSGANIMATION_EASE_MOTION_H -#define OSGANIMATION_EASE_MOTION_H +#ifndef OSGANIMATION_EASE_MOTION +#define OSGANIMATION_EASE_MOTION 1 #include #include @@ -21,9 +21,8 @@ #include #include -namespace osgAnimation { - - +namespace osgAnimation +{ struct OutBounceFunction { inline static void getValueAt(float t, float& result) @@ -76,14 +75,12 @@ namespace osgAnimation { } }; - /// Linear function struct LinearFunction { inline static void getValueAt(float t, float& result) { result = t;} }; - /// Quad function struct OutQuadFunction { @@ -94,46 +91,47 @@ namespace osgAnimation { { inline static void getValueAt(float t, float& result) { result = t*t;} }; + struct InOutQuadFunction { inline static void getValueAt(float t, float& result) - { - t = t * 2.0; - if (t < 1.0) + { + t *= 2.0; + if (t < 1.0) result = 0.5 * t * t; else { - t = t - 1.0; - result = - 0.5 * t * ( t - 2) - 1; + t -= 1.0; + result = - 0.5 * (t * ( t - 2) - 1); } } }; - /// Cubic function struct OutCubicFunction { inline static void getValueAt(float t, float& result) { t = t-1.0; result = t*t*t + 1;} }; + struct InCubicFunction { inline static void getValueAt(float t, float& result) { result = t*t*t;} }; + struct InOutCubicFunction { inline static void getValueAt(float t, float& result) { - t = t * 2; - if (t < 1.0) - result = 0.5 * t * t * t; + t *= 2.0f; + if (t < 1.0f) + result = 0.5f * t * t * t; else { - t = t - 2; - result = 0.5 * t * t * t + 2; + t -= 2.0f; + result = 0.5 * (t * t * t + 2.0f); } } }; - /// Quart function struct InQuartFunction { @@ -196,6 +194,155 @@ namespace osgAnimation { } }; + // Sine function + struct OutSineFunction + { + inline static void getValueAt(float t, float& result) + { + result = sinf(t * (osg::PI / 2.0f)); + } + }; + + struct InSineFunction + { + inline static void getValueAt(float t, float& result) + { + result = -cosf(t * (osg::PI / 2.0f)) + 1.0f; + } + }; + + struct InOutSineFunction + { + inline static void getValueAt(float t, float& result) + { + result = -0.5f * (cosf((osg::PI * t)) - 1.0f); + } + }; + + // Back function + struct OutBackFunction + { + inline static void getValueAt(float t, float& result) + { + t -= 1.0f; + result = t * t * ((1.70158 + 1.0f) * t + 1.70158) + 1.0f; + } + }; + + struct InBackFunction + { + inline static void getValueAt(float t, float& result) + { + result = t * t * ((1.70158 + 1.0f) * t - 1.70158); + } + }; + + struct InOutBackFunction + { + inline static void getValueAt(float t, float& result) + { + float s = 1.70158 * 1.525f; + t *= 2.0f; + if (t < 1.0f) + { + result = 0.5f * (t * t * ((s + 1.0f) * t - s)); + } + else + { + float p = t -= 2.0f; + result = 0.5f * ((p) * t * ((s + 1.0f) * t + s) + 2.0f); + } + } + }; + + // Circ function + struct OutCircFunction + { + inline static void getValueAt(float t, float& result) + { + t -= 1.0f; + result = sqrt(1.0f - t * t); + } + }; + + struct InCircFunction + { + inline static void getValueAt(float t, float& result) + { + result = -(sqrt(1.0f - (t * t)) - 1.0f); + } + }; + + struct InOutCircFunction + { + inline static void getValueAt(float t, float& result) + { + t *= 2.0f; + if (t < 1.0f) + { + result = -0.5f * (sqrt(1.0f - t * t) - 1.0f); + } + else + { + t -= 2.0f; + result = 0.5f * (sqrt(1 - t * t) + 1.0f); + } + } + }; + + // Expo function + struct OutExpoFunction + { + inline static void getValueAt(float t, float& result) + { + if(t == 1.0f) + { + result = 0.0f; + } + else + { + result = -powf(2.0f, -10.0f * t) + 1.0f; + } + } + }; + + struct InExpoFunction + { + inline static void getValueAt(float t, float& result) + { + if(t == 0.0f) + { + result = 0.0f; + } + else + { + result = powf(2.0f, 10.0f * (t - 1.0f)); + } + } + }; + + struct InOutExpoFunction + { + inline static void getValueAt(float t, float& result) + { + if(t == 0.0f || t == 1.0f) + { + result = 0.0f; + } + else + { + t *= 2.0f; + if(t < 1.0f) + { + result = 0.5f * powf(2.0f, 10.0f * (t - 1.0f)); + } + else + { + result = 0.5f * (-powf(2.0f, -10.0f * (t - 1.0f)) + 2.0f); + } + } + } + }; class Motion : public osg::Referenced { @@ -349,7 +496,6 @@ namespace osgAnimation { typedef MathMotionTemplate InQuartMotion; typedef MathMotionTemplate InOutQuartMotion; - // bounce typedef MathMotionTemplate OutBounceMotion; typedef MathMotionTemplate InBounceMotion; @@ -360,6 +506,25 @@ namespace osgAnimation { typedef MathMotionTemplate InElasticMotion; typedef MathMotionTemplate InOutElasticMotion; + // sine + typedef MathMotionTemplate OutSineMotion; + typedef MathMotionTemplate InSineMotion; + typedef MathMotionTemplate InOutSineMotion; + + // back + typedef MathMotionTemplate OutBackMotion; + typedef MathMotionTemplate InBackMotion; + typedef MathMotionTemplate InOutBackMotion; + + // circ + typedef MathMotionTemplate OutCircMotion; + typedef MathMotionTemplate InCircMotion; + typedef MathMotionTemplate InOutCircMotion; + + // expo + typedef MathMotionTemplate OutExpoMotion; + typedef MathMotionTemplate InExpoMotion; + typedef MathMotionTemplate InOutExpoMotion; } #endif