EaseFunctions.hh 3.84 KB
Newer Older
1 2 3 4 5
/***********************************************************************
 * Copyright 2011-2012 Computer Graphics Group RWTH Aachen University. *
 * All rights reserved.                                                *
 * Distributed under the terms of the MIT License (see LICENSE.TXT).   *
 **********************************************************************/
6

7 8 9 10
// See http://www.graphics.rwth-aachen.de/redmine/projects/acgl/wiki/ACGL_compile_time_settings
// for a comment what unsupported means.
#ifdef ACGL_INCLUDE_UNSUPPORTED

Ole Untzelmann's avatar
Ole Untzelmann committed
11 12
#ifndef ACGL_ANIMATIONS_EASEFUNCTIONS_HH
#define ACGL_ANIMATIONS_EASEFUNCTIONS_HH
13

14 15
#include <ACGL/ACGL.hh>

Ole Untzelmann's avatar
Ole Untzelmann committed
16 17
#include <ACGL/Math/Math.hh>
#include <ACGL/Base/Macros.hh>
18 19 20 21 22 23 24 25 26 27 28 29 30 31

namespace ACGL
{
namespace Animations
{

class EaseFunction
{
public:
    virtual ~EaseFunction(){}

    virtual float value(const float _progress) = 0;
};

Robert Menzel's avatar
Robert Menzel committed
32
ACGL_SMARTPOINTER_TYPEDEFS(EaseFunction)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

/*
float Linear(float progress, ease_function_parameter& parameter);
float InQuad(float progress, ease_function_parameter& parameter);
float OutQuad(float progress, ease_function_parameter& parameter);
float InOutQuad(float progress, ease_function_parameter& parameter);

float BlendLinear(float progress, ease_function_parameter& parameter);
float BlendSin(float progress, ease_function_parameter& parameter);
float BlendCos(float progress, ease_function_parameter& parameter);
float BlendSinDamped(float progress, ease_function_parameter& parameter);
float BlendCosDamped(float progress, ease_function_parameter& parameter);
*/


namespace EaseFunctions{

class Linear : public EaseFunction
{
public:
    Linear(){ }
    virtual ~Linear(){}

    virtual float value(const float _progress)
    {
        return _progress;
    }
};
class InQuad : public EaseFunction
{
public:
    InQuad(){ }
    virtual ~InQuad(){}

    virtual float value(const float _progress)
    {
        return _progress*_progress;
    }
};
class OutQuad : public EaseFunction
{
public:
    OutQuad(){ }
    virtual ~OutQuad(){}

    virtual float value(const float _progress)
    {
        return 1.0f-_progress*_progress;
    }
};
class InOutQuad : public EaseFunction
{
public:
    InOutQuad(){ }
    virtual ~InOutQuad(){}

    virtual float value(const float _progress)
    {
        if(_progress < 0.5)
            return 2.0f*_progress*_progress;
        else
Robert Menzel's avatar
Robert Menzel committed
94
            return 1.0f-2.0f*pow(_progress-1.0f,2.0f);
95 96 97
    }
};

98 99 100 101 102 103 104 105 106
class Sin : public EaseFunction
{
public:
    Sin(float _frequency = 1.0f) :
        mFrequency(_frequency) { }
    virtual ~Sin(){}

    virtual float value(const float _progress)
    {
Robert Menzel's avatar
Robert Menzel committed
107
        return sin(0.5f*(float)M_PI*mFrequency*_progress);
108 109 110 111 112
    }

    float mFrequency;
};

113 114 115 116 117 118 119 120
class BlendLinear : public EaseFunction
{
public:
    BlendLinear(){ }
    virtual ~BlendLinear(){}

    virtual float value(const float _progress)
    {
Robert Menzel's avatar
Robert Menzel committed
121
		return 2.0f*Math::Functions::min(_progress, 1.0f-_progress);
122 123 124 125 126 127 128 129 130 131
    }
};
class BlendSin : public EaseFunction
{
public:
    BlendSin(){ }
    virtual ~BlendSin(){}

    virtual float value(const float _progress)
    {
Robert Menzel's avatar
Robert Menzel committed
132
        return sin(20*(float)M_PI*_progress);
133 134 135 136 137 138 139 140 141 142
    }
};
class BlendCos : public EaseFunction
{
public:
    BlendCos(){ }
    virtual ~BlendCos(){}

    virtual float value(const float _progress)
    {
Robert Menzel's avatar
Robert Menzel committed
143
        return cos(6*(float)M_PI*_progress)-1.0f;
144 145 146 147 148 149 150 151 152 153
    }
};
class BlendSinDamped : public EaseFunction
{
public:
    BlendSinDamped(){ }
    virtual ~BlendSinDamped(){}

    virtual float value(const float _progress)
    {
Robert Menzel's avatar
Robert Menzel committed
154
        return 2.0f*Math::Functions::min(_progress, 1.0f-_progress)*sin(10.0f*(float)M_PI*_progress);
155 156 157 158 159 160 161 162 163 164
    }
};
class BlendCosDamped : public EaseFunction
{
public:
    BlendCosDamped(){ }
    virtual ~BlendCosDamped(){}

    virtual float value(const float _progress)
    {
Robert Menzel's avatar
Robert Menzel committed
165
        return 2.0f*Math::Functions::min(_progress, 1.0f-_progress)*cos(10.0f*(float)M_PI*_progress);
166 167 168 169 170 171 172 173
    }
};

}

}
}

Ole Untzelmann's avatar
Ole Untzelmann committed
174
#endif // ACGL_ANIMATIONS_EASEFUNCTIONS_HH
175 176

#endif