1 #ifndef TWEEN_H
2 #define TWEEN_H
3
4 #include <SFML/Graphics/Color.hpp>
5 /**
6 Tweening functions. Allows for none-linear effects and stuff.
7 */
8
9 template<typename T> class Tween
10 {
11 protected:
12 static T tweenApply(float f, const T& value0, const T& value1);
13 public:
linear(float time_now,float time_start,float time_end,const T & value0,const T & value1)14 static inline T linear(float time_now, float time_start, float time_end, const T& value0, const T& value1)
15 {
16 float t = (time_now - time_start) / (time_end - time_start);
17 return tweenApply(t, value0, value1);
18 }
19
easeInQuad(float time_now,float time_start,float time_end,const T & value0,const T & value1)20 static inline T easeInQuad(float time_now, float time_start, float time_end, const T& value0, const T& value1)
21 {
22 float t = (time_now - time_start) / (time_end - time_start);
23 return tweenApply(t * t, value0, value1);
24 }
easeOutQuad(float time_now,float time_start,float time_end,const T & value0,const T & value1)25 static inline T easeOutQuad(float time_now, float time_start, float time_end, const T& value0, const T& value1)
26 {
27 float t = (time_now - time_start) / (time_end - time_start);
28 return tweenApply(-t * (t - 2.0f), value0, value1);
29 }
easeInCubic(float time_now,float time_start,float time_end,const T & value0,const T & value1)30 static inline T easeInCubic(float time_now, float time_start, float time_end, const T& value0, const T& value1)
31 {
32 float t = (time_now - time_start) / (time_end - time_start);
33 return tweenApply(t * t * t, value0, value1);
34 }
easeOutCubic(float time_now,float time_start,float time_end,const T & value0,const T & value1)35 static inline T easeOutCubic(float time_now, float time_start, float time_end, const T& value0, const T& value1)
36 {//BUGGED!
37 float t = (time_now - time_start) / (time_end - time_start);
38 t -= 1.0;
39 return tweenApply(-(t * t * t + 1), value0, value1);
40 }
41 };
42
43 template<typename T>
tweenApply(float f,const T & value0,const T & value1)44 T Tween<T>::tweenApply(float f, const T& value0, const T& value1)
45 {
46 return value0 + (value1 - value0) * f;
47 }
48
49 template<> sf::Color Tween<sf::Color>::tweenApply(float f, const sf::Color& value0, const sf::Color& value1);
50
51 #endif//TWEEN_H
52