public static float CalculateLerpValueClamp01(float lerpValue, Type easingType, bool isZeroToOne)
        {
            switch (easingType)
            {
            case Type.Linear:
                lerpValue = Linear.InOut(lerpValue);
                break;

            case Type.Quadratic:
                lerpValue = Quadratic.InOut(lerpValue);
                break;

            case Type.Cubic:
                lerpValue = Cubic.InOut(lerpValue);
                break;

            case Type.Quartic:
                lerpValue = Quartic.InOut(lerpValue);
                break;

            case Type.Quintic:
                lerpValue = Quintic.InOut(lerpValue);
                break;

            case Type.Sinusoidal:
                lerpValue = Sinusoidal.InOut(lerpValue);
                break;

            case Type.Exponential:
                lerpValue = Exponential.InOut(lerpValue);
                break;

            case Type.Circular:
                lerpValue = Circular.InOut(lerpValue);
                break;

            case Type.Elastic:
                lerpValue = Elastic.InOut(lerpValue);
                break;

            case Type.Back:
                lerpValue = Back.InOut(lerpValue);
                break;

            case Type.Bounce:
                lerpValue = Bounce.InOut(lerpValue);
                break;

            default:
                return(-1f);
            }

            lerpValue = ClampMinMax(0f, 1f, lerpValue);

            return(lerpValue);
        }
Example #2
0
        public void InOut_InputAboveRange_ReturnsDestination()
        {
            Ease  ease = new Cubic();
            float x    = 1.5f;

            float expected = ease.Scale.Y;
            float actual   = ease.InOut(x);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Example #3
0
        public void InOut_InputBelowRange_ReturnsOrigin()
        {
            Ease  ease = new Cubic();
            float x    = -0.5f;

            float expected = 0;
            float actual   = ease.InOut(x);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Example #4
0
        public void InOut_InputInRange2_ReturnsExpectedValue()
        {
            Ease  ease = new Cubic();
            float x    = 0.4f;

            float expected = 0.256f;
            float actual   = ease.InOut(x);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Example #5
0
        public void InOut_ChangedScaleInputAboveRange_ReturnsDestination()
        {
            Vector scale = new Vector(4, 6);
            Ease   ease  = new Cubic(scale);
            float  x     = 11.1f;

            float expected = ease.Scale.Y;
            float actual   = ease.InOut(x);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Example #6
0
        public void InOut_ChangedScaleInputBelowRange_ReturnsOrigin()
        {
            Vector scale = new Vector(4, 6);
            Ease   ease  = new Cubic(scale);
            float  x     = -1.1f;

            float expected = 0;
            float actual   = ease.InOut(x);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Example #7
0
        public void InOut_ChangedScaleInputInRange2_ReturnsExpectedValue()
        {
            Vector scale = new Vector(4, 6);
            Ease   ease  = new Cubic(scale);
            float  x     = 1.5f;

            float expected = 1.266f;
            float actual   = ease.InOut(x);

            Assert.AreEqual(expected, actual, 0.001f);
        }
Example #8
0
    //------------------------------------------------------------------------------------------------------------

    public static float GetEasingFunction(Type easingFunction, float t)
    {
        // Quad
        if (easingFunction == Type.EaseInQuad)
        {
            return(Quadratic.In(t));
        }

        if (easingFunction == Type.EaseOutQuad)
        {
            return(Quadratic.Out(t));
        }

        if (easingFunction == Type.EaseInOutQuad)
        {
            return(Quadratic.InOut(t));
        }

        // Cubic
        if (easingFunction == Type.EaseInCubic)
        {
            return(Cubic.In(t));
        }

        if (easingFunction == Type.EaseOutCubic)
        {
            return(Cubic.Out(t));
        }

        if (easingFunction == Type.EaseInOutCubic)
        {
            return(Cubic.InOut(t));
        }

        // Quart
        if (easingFunction == Type.EaseInQuart)
        {
            return(Quartic.In(t));
        }

        if (easingFunction == Type.EaseOutQuart)
        {
            return(Quartic.Out(t));;
        }

        if (easingFunction == Type.EaseInOutQuart)
        {
            return(Quartic.InOut(t));;
        }

        // Quint
        if (easingFunction == Type.EaseInQuint)
        {
            return(Quintic.In(t));
        }

        if (easingFunction == Type.EaseOutQuint)
        {
            return(Quintic.Out(t));
        }

        if (easingFunction == Type.EaseInOutQuint)
        {
            return(Quintic.InOut(t));
        }

        // Sine
        if (easingFunction == Type.EaseInSine)
        {
            return(Sinusoidal.In(t));
        }

        if (easingFunction == Type.EaseOutSine)
        {
            return(Sinusoidal.Out(t));
        }

        if (easingFunction == Type.EaseInOutSine)
        {
            return(Sinusoidal.InOut(t));
        }

        // Expo
        if (easingFunction == Type.EaseInExpo)
        {
            return(Exponential.In(t));
        }

        if (easingFunction == Type.EaseOutExpo)
        {
            return(Exponential.Out(t));
        }

        if (easingFunction == Type.EaseInOutExpo)
        {
            return(Exponential.InOut(t));
        }

        // CirC
        if (easingFunction == Type.EaseInCirc)
        {
            return(Circular.In(t));
        }

        if (easingFunction == Type.EaseOutCirc)
        {
            return(Circular.Out(t));
        }

        if (easingFunction == Type.EaseInOutCirc)
        {
            return(Circular.InOut(t));
        }

        // Linear
        if (easingFunction == Type.Linear)
        {
            return(Linear(t));
        }

        //  Bounce
        if (easingFunction == Type.EaseInBounce)
        {
            return(Bounce.In(t));
        }

        if (easingFunction == Type.EaseOutBounce)
        {
            return(Bounce.Out(t));
        }

        if (easingFunction == Type.EaseInOutBounce)
        {
            return(Bounce.InOut(t));
        }

        // Back
        if (easingFunction == Type.EaseInBack)
        {
            return(Back.In(t));
        }

        if (easingFunction == Type.EaseOutBack)
        {
            return(Back.Out(t));
        }

        if (easingFunction == Type.EaseInOutBack)
        {
            return(Back.InOut(t));
        }

        // Elastic
        if (easingFunction == Type.EaseInElastic)
        {
            return(Elastic.In(t));
        }

        if (easingFunction == Type.EaseOutElastic)
        {
            return(Elastic.Out(t));
        }

        if (easingFunction == Type.EaseInOutElastic)
        {
            return(Elastic.InOut(t));
        }

        return(0);
    }
Example #9
0
        public static float GetTerpedPosition(float time, float totalTime, Function function, Direction direction)
        {
            switch (function)
            {
            case Function.Quadratic:
                switch (direction)
                {
                case Direction.In:
                    return(Quadratic.In(time / totalTime));

                case Direction.Out:
                    return(Quadratic.Out(time / totalTime));

                default:
                    return(Quadratic.InOut(time / totalTime));
                }

            case Function.Cubic:
                switch (direction)
                {
                case Direction.In:
                    return(Cubic.In(time / totalTime));

                case Direction.Out:
                    return(Cubic.Out(time / totalTime));

                default:
                    return(Cubic.InOut(time / totalTime));
                }

            case Function.Quartic:
                switch (direction)
                {
                case Direction.In:
                    return(Quartic.In(time / totalTime));

                case Direction.Out:
                    return(Quartic.Out(time / totalTime));

                default:
                    return(Quartic.InOut(time / totalTime));
                }

            case Function.Quintic:
                switch (direction)
                {
                case Direction.In:
                    return(Quintic.In(time / totalTime));

                case Direction.Out:
                    return(Quintic.Out(time / totalTime));

                default:
                    return(Quintic.InOut(time / totalTime));
                }

            case Function.Sinusoidal:
                switch (direction)
                {
                case Direction.In:
                    return(Sinusoidal.In(time / totalTime));

                case Direction.Out:
                    return(Sinusoidal.Out(time / totalTime));

                default:
                    return(Sinusoidal.InOut(time / totalTime));
                }

            case Function.Exponential:
                switch (direction)
                {
                case Direction.In:
                    return(Exponential.In(time / totalTime));

                case Direction.Out:
                    return(Exponential.Out(time / totalTime));

                default:
                    return(Exponential.InOut(time / totalTime));
                }

            case Function.Circular:
                switch (direction)
                {
                case Direction.In:
                    return(Circular.In(time / totalTime));

                case Direction.Out:
                    return(Circular.Out(time / totalTime));

                default:
                    return(Circular.InOut(time / totalTime));
                }

            case Function.Elastic:
                switch (direction)
                {
                case Direction.In:
                    return(Elastic.In(time / totalTime));

                case Direction.Out:
                    return(Elastic.Out(time / totalTime));

                default:
                    return(Elastic.InOut(time / totalTime));
                }

            case Function.Back:
                switch (direction)
                {
                case Direction.In:
                    return(Back.In(time / totalTime));

                case Direction.Out:
                    return(Back.Out(time / totalTime));

                default:
                    return(Back.InOut(time / totalTime));
                }

            default:    //Function.Bounce:
                switch (direction)
                {
                case Direction.In:
                    return(Bounce.In(time / totalTime));

                case Direction.Out:
                    return(Bounce.Out(time / totalTime));

                default:
                    return(Bounce.InOut(time / totalTime));
                }
            }
        }
Example #10
0
        public static float Ease(EasingType easingFunction, float k)
        {
            switch (easingFunction)
            {
            case EasingType.Linear:
                return(Linear(k));

            case EasingType.QuadraticIn:
                return(Quadratic.In(k));

            case EasingType.QuadraticOut:
                return(Quadratic.Out(k));

            case EasingType.QuadraticInOut:
                return(Quadratic.InOut(k));

            case EasingType.CubicIn:
                return(Cubic.In(k));

            case EasingType.CubicOut:
                return(Cubic.Out(k));

            case EasingType.CubicInOut:
                return(Cubic.InOut(k));

            case EasingType.QuarticIn:
                return(Quartic.In(k));

            case EasingType.QuarticOut:
                return(Quartic.Out(k));

            case EasingType.QuarticInOut:
                return(Quartic.InOut(k));

            case EasingType.QuinticIn:
                return(Quintic.In(k));

            case EasingType.QuinticOut:
                return(Quintic.Out(k));

            case EasingType.QuinticInOut:
                return(Quintic.InOut(k));

            case EasingType.SinusoidalIn:
                return(Sinusoidal.In(k));

            case EasingType.SinusoidalOut:
                return(Sinusoidal.Out(k));

            case EasingType.SinusoidalInOut:
                return(Sinusoidal.InOut(k));

            case EasingType.ExponentialIn:
                return(Exponential.In(k));

            case EasingType.ExponentialOut:
                return(Exponential.Out(k));

            case EasingType.ExponentialInOut:
                return(Exponential.InOut(k));

            case EasingType.CircularIn:
                return(Circular.In(k));

            case EasingType.CircularOut:
                return(Circular.Out(k));

            case EasingType.CircularInOut:
                return(Circular.InOut(k));

            case EasingType.ElasticIn:
                return(Elastic.In(k));

            case EasingType.ElasticOut:
                return(Elastic.Out(k));

            case EasingType.ElasticInOut:
                return(Elastic.InOut(k));

            case EasingType.BackIn:
                return(Back.In(k));

            case EasingType.BackOut:
                return(Back.Out(k));

            case EasingType.BackInOut:
                return(Back.InOut(k));

            case EasingType.BounceIn:
                return(Bounce.In(k));

            case EasingType.BounceOut:
                return(Bounce.Out(k));

            case EasingType.BounceInOut:
                return(Bounce.InOut(k));

            default:
                return(Linear(k));
            }
        }
Example #11
0
        public static double Specify(EaseType easeType, EaseOption easeOption, double k)
        {
            switch (easeType)
            {
            case EaseType.Quadratic:
                switch (easeOption)
                {
                case EaseOption.In:
                    return(Quadratic.In(k));

                case EaseOption.Out:
                    return(Quadratic.Out(k));

                case EaseOption.InOut:
                    return(Quadratic.InOut(k));
                }

                break;

            case EaseType.Cubic:
                switch (easeOption)
                {
                case EaseOption.In:
                    return(Cubic.In(k));

                case EaseOption.Out:
                    return(Cubic.Out(k));

                case EaseOption.InOut:
                    return(Cubic.InOut(k));
                }

                break;

            case EaseType.Quartic:
                switch (easeOption)
                {
                case EaseOption.In:
                    return(Quartic.In(k));

                case EaseOption.Out:
                    return(Quartic.Out(k));

                case EaseOption.InOut:
                    return(Quartic.InOut(k));
                }

                break;

            case EaseType.Quintic:
                switch (easeOption)
                {
                case EaseOption.In:
                    return(Quintic.In(k));

                case EaseOption.Out:
                    return(Quintic.Out(k));

                case EaseOption.InOut:
                    return(Quintic.InOut(k));
                }

                break;

            case EaseType.Sinusoidal:
                switch (easeOption)
                {
                case EaseOption.In:
                    return(Sinusoidal.In(k));

                case EaseOption.Out:
                    return(Sinusoidal.Out(k));

                case EaseOption.InOut:
                    return(Sinusoidal.InOut(k));
                }

                break;
            }

            return(Linear(k));
        }