DayZ 1.24
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 return 16 * t * t * t * t * t;
95 else
96 return 1 + 16 * t1 * t1 * t1 * t1 * t1;
97 }
98
99 static float EaseInExpo(float t)
100 {
101 if (t == 0)
102 return 0;
103
104 return Math.Pow(2, 10 * (t - 1));
105 }
106
107 static float EaseOutExpo(float t)
108 {
109 if (t == 1)
110 return 1;
111
112 return (-Math.Pow(2, -10 * t) + 1);
113 }
114
115 static float EaseInOutExpo(float t)
116 {
117
118 if (t == 0 || t == 1)
119 return t;
120
121 float scaledTime = t * 2;
122 float scaledTime1 = scaledTime - 1;
123
124 if (scaledTime < 1)
125 return 0.5 * Math.Pow(2, 10 * scaledTime1);
126
127 return 0.5 * (-Math.Pow(2, -10 * scaledTime1) + 2);
128
129 }
130
131 static float EaseInCirc(float t)
132 {
133 float scaledTime = t / 1;
134 return -1 * (Math.Sqrt(1 - scaledTime * t) - 1);
135 }
136
137 static float EaseOutCirc(float t)
138 {
139 float t1 = t - 1;
140 return Math.Sqrt(1 - t1 * t1);
141 }
142
143 static float EaseInOutCirc(float t)
144 {
145
146 float scaledTime = t * 2;
147 float scaledTime1 = scaledTime - 2;
148
149 if (scaledTime < 1)
150 return -0.5 * (Math.Sqrt(1 - scaledTime * scaledTime) - 1);
151
152 return 0.5 * (Math.Sqrt(1 - scaledTime1 * scaledTime1) + 1);
153 }
154
155 static float EaseInBack(float t, float magnitude = 1.70158)
156 {
157 return t * t * ((magnitude + 1) * t - magnitude);
158 }
159
160 static float EaseOutBack(float t, float magnitude = 1.70158)
161 {
162 float scaledTime = (t / 1) - 1;
163 return (scaledTime * scaledTime * ((magnitude + 1) * scaledTime + magnitude)) + 1;
164 }
165
166 static float EaseInOutBack(float t, float magnitude = 1.70158)
167 {
168
169 float scaledTime = t * 2;
170 float scaledTime2 = scaledTime - 2;
171
172 float s = magnitude * 1.525;
173
174 if (scaledTime < 1)
175 return 0.5 * scaledTime * scaledTime * (((s + 1) * scaledTime) - s);
176
177 return 0.5 * (scaledTime2 * scaledTime2 * ((s + 1) * scaledTime2 + s) + 2);
178 }
179
180 static float EaseInElastic(float t, float magnitude = 0.7)
181 {
182 if (t == 0 || t == 1)
183 return t;
184
185 float scaledTime = t / 1;
186 float scaledTime1 = scaledTime - 1;
187
188 float p = 1 - magnitude;
189 float s = p / (2 * Math.PI) * Math.Asin(1);
190
191 return -(Math.Pow(2, 10 * scaledTime1) * Math.Sin((scaledTime1 - s) * (2 * Math.PI) / p));
192 }
193
194 static float EaseOutElastic(float t, float magnitude = 0.7)
195 {
196 float p = 1 - magnitude;
197 float scaledTime = t * 2;
198
199 if (t == 0 || t == 1)
200 return t;
201
202 float s = p / (2 * Math.PI) * Math.Asin(1);
203 return (Math.Pow(2, -10 * scaledTime) * Math.Sin((scaledTime - s) * (2 * Math.PI) / p)) + 1;
204 }
205
206 static float EaseInOutElastic(float t, float magnitude = 0.65)
207 {
208 float p = 1 - magnitude;
209
210 if (t == 0 || t == 1)
211 return t;
212
213 float scaledTime = t * 2;
214 float scaledTime1 = scaledTime - 1;
215
216 float s = p / (2 * Math.PI) * Math.Asin(1);
217
218 if (scaledTime < 1)
219 return -0.5 * (Math.Pow(2, 10 * scaledTime1) * Math.Sin((scaledTime1 - s) * (2 * Math.PI) / p));
220
221 return (Math.Pow(2, -10 * scaledTime1) * Math.Sin((scaledTime1 - s) * (2 * Math.PI) / p) * 0.5) + 1;
222 }
223
224 static float EaseOutBounce(float t)
225 {
226
227 float scaledTime = t / 1;
228
229 if (scaledTime < (1 / 2.75))
230
231 return 7.5625 * scaledTime * scaledTime;
232
233 else if (scaledTime < (2 / 2.75))
234 {
235
236 float scaledTime2 = scaledTime - (1.5 / 2.75);
237 return (7.5625 * scaledTime2 * scaledTime2) + 0.75;
238
239 }
240 else if (scaledTime < (2.5 / 2.75))
241 {
242
243 scaledTime2 = scaledTime - (2.25 / 2.75);
244 return (7.5625 * scaledTime2 * scaledTime2) + 0.9375;
245
246 }
247 else
248 {
249
250 scaledTime2 = scaledTime - (2.625 / 2.75);
251 return (7.5625 * scaledTime2 * scaledTime2) + 0.984375;
252
253 }
254 }
255
256 static float EaseInBounce(float t)
257 {
258 return 1 - EaseOutBounce(1 - t);
259 }
260
261 static float EaseInOutBounce(float t)
262 {
263 if (t < 0.5)
264 return EaseInBounce(t * 2) * 0.5;
265 return (EaseOutBounce((t * 2) - 1) * 0.5) + 0.5;
266 }
267}
Input value between 0 and 1, returns value adjusted by easing, no automatic clamping of input(do your...
Definition Easing.c:3
static float EaseInQuint(float t)
Definition Easing.c:78
static float EaseInBack(float t, float magnitude=1.70158)
Definition Easing.c:155
static float EaseInOutBounce(float t)
Definition Easing.c:261
static float EaseInOutQuint(float t)
Definition Easing.c:89
static float EaseOutBack(float t, float magnitude=1.70158)
Definition Easing.c:160
static float EaseOutSine(float t)
Definition Easing.c:9
static float EaseInSine(float t)
Definition Easing.c:4
static float EaseInOutCirc(float t)
Definition Easing.c:143
static float EaseInOutElastic(float t, float magnitude=0.65)
Definition Easing.c:206
static float EaseInOutSine(float t)
Definition Easing.c:14
static float EaseOutQuart(float t)
Definition Easing.c:61
static float EaseInQuart(float t)
Definition Easing.c:56
static float EaseInOutCubic(float t)
Definition Easing.c:48
static float EaseInBounce(float t)
Definition Easing.c:256
static float EaseOutElastic(float t, float magnitude=0.7)
Definition Easing.c:194
static float EaseInCubic(float t)
Definition Easing.c:37
static float EaseInOutBack(float t, float magnitude=1.70158)
Definition Easing.c:166
static float EaseOutQuad(float t)
Definition Easing.c:24
static float EaseOutExpo(float t)
Definition Easing.c:107
static float EaseOutCubic(float t)
Definition Easing.c:42
static float EaseOutQuint(float t)
Definition Easing.c:83
static float EaseInOutQuad(float t)
Definition Easing.c:29
static float EaseInOutQuart(float t)
Definition Easing.c:68
static float EaseInOutExpo(float t)
Definition Easing.c:115
static float EaseOutBounce(float t)
Definition Easing.c:224
static float EaseInExpo(float t)
Definition Easing.c:99
static float EaseInElastic(float t, float magnitude=0.7)
Definition Easing.c:180
static float EaseInQuad(float t)
Definition Easing.c:19
static float EaseOutCirc(float t)
Definition Easing.c:137
static float EaseInCirc(float t)
Definition Easing.c:131
Definition EnMath.c:7
static proto float Asin(float s)
Returns angle in radians from sinus.
static proto float Sqrt(float val)
Returns square root.
static proto float Cos(float angle)
Returns cosinus of angle in radians.
static proto float Sin(float angle)
Returns sinus of angle in radians.
static proto float Pow(float v, float power)
Return power of v ^ power.
static const float PI
Definition EnMath.c:12