Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
easing.c
Go to the documentation of this file.
1
2class Easing
3{
4 static float EaseInSine( float t )
5 {
6 return -1 * Math.Cos( t * ( Math.PI / 2 ) ) + 1;
7 }
8
9 static float EaseOutSine( float t )
10 {
11 return Math.Sin( t * ( Math.PI / 2 ) );
12 }
13
14 static float EaseInOutSine( float t )
15 {
16 return -0.5 * ( Math.Cos( Math.PI * t ) - 1 );
17 }
18
19 static float EaseInQuad( float t )
20 {
21 return t * t;
22 }
23
24 static float EaseOutQuad( float t )
25 {
26 return t * ( 2 - t );
27 }
28
29 static float EaseInOutQuad( float t )
30 {
31 if(t < 0.5)
32 return 2 * t * t;
33 else
34 return -1 + ( 4 - 2 * t ) * t;
35 }
36
37 static float EaseInCubic( float t )
38 {
39 return t * t * t;
40 }
41
42 static float EaseOutCubic( float t )
43 {
44 float t1 = t - 1;
45 return t1 * t1 * t1 + 1;
46 }
47
48 static float EaseInOutCubic( float t )
49 {
50 if( t < 0.5 )
51 return 4 * t * t * t;
52 else
53 return ( t - 1 ) * ( 2 * t - 2 ) * ( 2 * t - 2 ) + 1;
54 }
55
56 static float EaseInQuart( float t )
57 {
58 return t * t * t * t;
59 }
60
61 static float EaseOutQuart( float t )
62 {
63 float t1 = t - 1;
64 return 1 - t1 * t1 * t1 * t1;
65 }
66
67
68 static float EaseInOutQuart( float t )
69 {
70 float t1 = t - 1;
71
72 if(t < 0.5)
73 return 8 * t * t * t * t;
74 else
75 return 1 - 8 * t1 * t1 * t1 * t1;
76 }
77
78 static float EaseInQuint( float t )
79 {
80 return t * t * t * t * t;
81 }
82
83 static float EaseOutQuint( float t )
84 {
85 float t1 = t - 1;
86 return 1 + t1 * t1 * t1 * t1 * t1;
87 }
88
89 static float EaseInOutQuint( float t )
90 {
91 float t1 = t - 1;
92
93 if( t < 0.5 )
94 {
95 return 16 * t * t * t * t * t;
96 }
97 else
98 {
99 return 1 + 16 * t1 * t1 * t1 * t1 * t1;
100 }
101 }
102
103 static float EaseInExpo( float t )
104 {
105 if( t == 0 )
106 {
107 return 0;
108 }
109
110 return Math.Pow( 2, 10 * ( t - 1 ) );
111 }
112
113 static float EaseOutExpo( float t )
114 {
115 if( t == 1 ) {
116 return 1;
117 }
118
119 return ( -Math.Pow( 2, -10 * t ) + 1 );
120 }
121
122 static float EaseInOutExpo( float t )
123 {
124
125 if( t == 0 || t == 1 )
126 {
127 return t;
128 }
129
130 float scaledTime = t * 2;
131 float scaledTime1 = scaledTime - 1;
132
133 if( scaledTime < 1 )
134 {
135 return 0.5 * Math.Pow( 2, 10 * scaledTime1 );
136 }
137
138 return 0.5 * ( -Math.Pow( 2, -10 * scaledTime1 ) + 2 );
139
140 }
141
142 static float EaseInCirc( float t )
143 {
144 float scaledTime = t / 1;
145 return -1 * ( Math.Sqrt( 1 - scaledTime * t ) - 1 );
146 }
147
148 static float EaseOutCirc( float t )
149 {
150 float t1 = t - 1;
151 return Math.Sqrt( 1 - t1 * t1 );
152 }
153
154 static float EaseInOutCirc( float t )
155 {
156
157 float scaledTime = t * 2;
158 float scaledTime1 = scaledTime - 2;
159
160 if( scaledTime < 1 )
161 {
162 return -0.5 * ( Math.Sqrt( 1 - scaledTime * scaledTime ) - 1 );
163 }
164
165 return 0.5 * ( Math.Sqrt( 1 - scaledTime1 * scaledTime1 ) + 1 );
166 }
167
168 static float EaseInBack( float t, float magnitude = 1.70158 )
169 {
170 return t * t * ( ( magnitude + 1 ) * t - magnitude );
171 }
172
173 static float EaseOutBack( float t, float magnitude = 1.70158 )
174 {
175 float scaledTime = ( t / 1 ) - 1;
176 return (scaledTime * scaledTime * ( ( magnitude + 1 ) * scaledTime + magnitude )) + 1;
177 }
178
179 static float EaseInOutBack( float t, float magnitude = 1.70158 )
180 {
181
182 float scaledTime = t * 2;
183 float scaledTime2 = scaledTime - 2;
184
185 float s = magnitude * 1.525;
186
187 if( scaledTime < 1)
188 {
189 return 0.5 * scaledTime * scaledTime * (( ( s + 1 ) * scaledTime ) - s);
190 }
191
192 return 0.5 * (scaledTime2 * scaledTime2 * ( ( s + 1 ) * scaledTime2 + s ) + 2);
193 }
194
195 static float EaseInElastic( float t, float magnitude = 0.7 )
196 {
197 if( t == 0 || t == 1 )
198 return t;
199
200 float scaledTime = t / 1;
201 float scaledTime1 = scaledTime - 1;
202
203 float p = 1 - magnitude;
204 float s = p / ( 2 * Math.PI ) * Math.Asin( 1 );
205
206 return -(Math.Pow( 2, 10 * scaledTime1 ) * Math.Sin( ( scaledTime1 - s ) * ( 2 * Math.PI ) / p ));
207 }
208
209 static float EaseOutElastic( float t, float magnitude = 0.7 )
210 {
211 float p = 1 - magnitude;
212 float scaledTime = t * 2;
213
214 if( t == 0 || t == 1 ) {
215 return t;
216 }
217
218 float s = p / ( 2 * Math.PI ) * Math.Asin( 1 );
219 return (Math.Pow( 2, -10 * scaledTime ) * Math.Sin( ( scaledTime - s ) * ( 2 * Math.PI ) / p )) + 1;
220 }
221
222 static float EaseInOutElastic( float t, float magnitude = 0.65 )
223 {
224 float p = 1 - magnitude;
225
226 if( t == 0 || t == 1 )
227 {
228 return t;
229 }
230
231 float scaledTime = t * 2;
232 float scaledTime1 = scaledTime - 1;
233
234 float s = p / ( 2 * Math.PI ) * Math.Asin( 1 );
235
236 if( scaledTime < 1 )
237 {
238 return -0.5 * (Math.Pow( 2, 10 * scaledTime1 ) * Math.Sin( ( scaledTime1 - s ) * ( 2 * Math.PI ) / p ));
239 }
240
241 return (Math.Pow( 2, -10 * scaledTime1 ) * Math.Sin( ( scaledTime1 - s ) * ( 2 * Math.PI ) / p ) * 0.5) + 1;
242 }
243
244 static float EaseOutBounce( float t )
245 {
246
247 float scaledTime = t / 1;
248
249 if( scaledTime < ( 1 / 2.75 ) ) {
250
251 return 7.5625 * scaledTime * scaledTime;
252
253 } else if( scaledTime < ( 2 / 2.75 ) ) {
254
255 float scaledTime2 = scaledTime - ( 1.5 / 2.75 );
256 return ( 7.5625 * scaledTime2 * scaledTime2 ) + 0.75;
257
258 } else if( scaledTime < ( 2.5 / 2.75 ) ) {
259
260 scaledTime2 = scaledTime - ( 2.25 / 2.75 );
261 return ( 7.5625 * scaledTime2 * scaledTime2 ) + 0.9375;
262
263 } else {
264
265 scaledTime2 = scaledTime - ( 2.625 / 2.75 );
266 return ( 7.5625 * scaledTime2 * scaledTime2 ) + 0.984375;
267
268 }
269 }
270
271 static float EaseInBounce( float t )
272 {
273 return 1 - EaseOutBounce( 1 - t );
274 }
275
276 static float EaseInOutBounce( float t )
277 {
278 if( t < 0.5 )
279 {
280 return EaseInBounce( t * 2 ) * 0.5;
281 }
282 return ( EaseOutBounce( ( t * 2 ) - 1 ) * 0.5 ) + 0.5;
283 }
284}
Input value between 0 and 1, returns value adjusted by easing, no automatic clamping of input(do your...
Definition easing.c:3
Definition enmath.c:7