Fillwave  10.0.0
Easing.h
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2018 Filip Wasil and Fillwave community members
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20  */
21 
22 //
23 // easing.h
24 //
25 // Copyright (c) 2011, Auerhaus Development, LLC
26 //
27 // This program is free software. It comes without any warranty, to
28 // the extent permitted by applicable law. You can redistribute it
29 // and/or modify it under the terms of the Do What The Fuck You Want
30 // To Public License, Version 2, as published by Sam Hocevar. See
31 // http://sam.zoy.org/wtfpl/COPYING for more details.
32 //
33 
34 #ifndef EASING_H_
35 #define EASING_H_
36 
37 #include <flw/OpenGL.h>
38 #include <functional>
39 
40 #if defined(__LP64__) && !defined(AH_EASING_USE_DBL_PRECIS)
41 #define AH_EASING_USE_DBL_PRECIS
42 #endif
43 
44 /* We need the same float everywhere */
45 typedef GLfloat AHFloat;
46 
47 /*
48  #ifdef AH_EASING_USE_DBL_PRECIS
49  #define AHFloat double
50  #else
51  #define AHFloat float
52  #endif
53  */
54 
55 //typedef AHFloat (*AHEasingFunction)(AHFloat);
56 typedef std::function<AHFloat(AHFloat)> EasingFunction;
57 
58 // Linear interpolation (no easing)
59 AHFloat LinearInterpolation(AHFloat p);
60 
61 // Quadratic easing; p^2
62 AHFloat QuadraticEaseIn(AHFloat p);
63 
64 AHFloat QuadraticEaseOut(AHFloat p);
65 
66 AHFloat QuadraticEaseInOut(AHFloat p);
67 
68 // Cubic easing; p^3
69 AHFloat CubicEaseIn(AHFloat p);
70 
71 AHFloat CubicEaseOut(AHFloat p);
72 
73 AHFloat CubicEaseInOut(AHFloat p);
74 
75 // Quartic easing; p^4
76 AHFloat QuarticEaseIn(AHFloat p);
77 
78 AHFloat QuarticEaseOut(AHFloat p);
79 
80 AHFloat QuarticEaseInOut(AHFloat p);
81 
82 // Quintic easing; p^5
83 AHFloat QuinticEaseIn(AHFloat p);
84 
85 AHFloat QuinticEaseOut(AHFloat p);
86 
87 AHFloat QuinticEaseInOut(AHFloat p);
88 
89 // Sine wave easing; sin(p * PI/2)
90 AHFloat SineEaseIn(AHFloat p);
91 
92 AHFloat SineEaseOut(AHFloat p);
93 
94 AHFloat SineEaseInOut(AHFloat p);
95 
96 // Circular easing; sqrt(1 - p^2)
97 AHFloat CircularEaseIn(AHFloat p);
98 
99 AHFloat CircularEaseOut(AHFloat p);
100 
101 AHFloat CircularEaseInOut(AHFloat p);
102 
103 // Exponential easing, base 2
104 AHFloat ExponentialEaseIn(AHFloat p);
105 
106 AHFloat ExponentialEaseOut(AHFloat p);
107 
108 AHFloat ExponentialEaseInOut(AHFloat p);
109 
110 // Exponentially-damped sine wave easing
111 AHFloat ElasticEaseIn(AHFloat p);
112 
113 AHFloat ElasticEaseOut(AHFloat p);
114 
115 AHFloat ElasticEaseInOut(AHFloat p);
116 
117 // Overshooting cubic easing;
118 AHFloat BackEaseIn(AHFloat p);
119 
120 AHFloat BackEaseOut(AHFloat p);
121 
122 AHFloat BackEaseInOut(AHFloat p);
123 
124 // Exponentially-decaying bounce easing
125 AHFloat BounceEaseIn(AHFloat p);
126 
127 AHFloat BounceEaseOut(AHFloat p);
128 
129 AHFloat BounceEaseInOut(AHFloat p);
130 
131 #endif /* EASING_H_ */