-
Notifications
You must be signed in to change notification settings - Fork 450
/
Copy pathInterpolation.cs
220 lines (173 loc) · 5.27 KB
/
Interpolation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Methods that make LERPs nice
/// </summary>
static public class Interpolation
{
static public float Linear(float t)
{
return t;
}
static public float SmoothStep(float t)
{
return t * t * (3.0f - 2.0f * t);
}
static public float SmootherStep(float t)
{
return t * t * t * (t * (6.0f * t - 15.0f) + 10.0f);
}
static public float SineIn(float t)
{
return Mathf.Sin((t - 1.0f) * Mathf.PI * 0.5f) + 1.0f;
}
static public float SineOut(float t)
{
return Mathf.Sin(t * Mathf.PI * 0.5f);
}
static public float SineInOut(float t)
{
return (1.0f - Mathf.Cos(t * Mathf.PI)) * 0.5f;
}
static public float QuadraticIn(float t)
{
return t * t;
}
static public float QuadraticOut(float t)
{
return -(t * (t - 2.0f));
}
static public float QuadraticInOut(float t)
{
return (t < 0.5f) ? 2.0f * (t * t) : (-2.0f * t * t) + (4 * t) - 1;
}
static public float CubicIn(float t)
{
return Mathf.Pow(t, 3);
}
static public float CubicOut(float t)
{
return 1.0f - Mathf.Pow(1.0f - t, 3);
}
static public float CubicInOut(float t)
{
return (t < 0.5f) ? Mathf.Pow(t * 2.0f, 3) * 0.5f : 1.0f - Mathf.Pow((1.0f - t) * 2.0f, 3) * 0.5f;
}
static public float QuarticIn(float t)
{
return Mathf.Pow(t, 4);
}
static public float QuarticOut(float t)
{
return 1.0f - Mathf.Pow(1.0f - t, 4);
}
static public float QuarticInOut(float t)
{
return (t < 0.5f) ? Mathf.Pow(t * 2.0f, 4) * 0.5f : 1.0f - Mathf.Pow((1.0f - t) * 2.0f, 4) * 0.5f;
}
static public float QuinticIn(float t)
{
return Mathf.Pow(t, 5);
}
static public float QuinticOut(float t)
{
return 1.0f - Mathf.Pow(1.0f - t, 5);
}
static public float QuinticInOut(float t)
{
return (t < 0.5f) ? Mathf.Pow(t * 2.0f, 5) * 0.5f : 1.0f - Mathf.Pow((1.0f - t) * 2.0f, 5) * 0.5f;
}
static public float CircularIn(float t)
{
return 1.0f - Mathf.Sqrt(1.0f - (t * t));
}
static public float CircularOut(float t)
{
return Mathf.Sqrt((2.0f - t) * t);
}
static public float CircularInOut(float t)
{
return (t < 0.5f) ? (1.0f - Mathf.Sqrt(1.0f - 4.0f * (t * t ))) * 0.5f : (Mathf.Sqrt(-((t * 2.0f) - 3.0f) * ((t * 2.0f) - 1.0f)) + 1.0f) * 0.5f;
}
static public float ExpoIn(float t)
{
return (t == 0.0f) ? 0.0f : Mathf.Pow(2, 10.0f * (t - 1.0f));
}
static public float ExpoOut(float t)
{
return (t == 1.0f) ? 1.0f : 1.0f - Mathf.Pow(2, -10.0f * t);
}
static public float ExpoInOut(float t)
{
if (t == 0.0f || t == 1.0f) return t;
t = t * 2.0f;
if (t < 1.0f)
{
return Mathf.Pow(1024.0f, t - 1.0f) * 0.5f;
}
return (-Mathf.Pow(2.0f, -10.0f * (t - 1.0f)) + 2.0f) * 0.5f;
}
static public float BackIn(float t)
{
float s = 1.70158f;
return t * t * ((s + 1.0f) * t - s);
}
static public float BackOut(float t)
{
float s = 1.70158f;
t = (t - 1.0f);
return t * t * ((s + 1.0f) * t + s) + 1.0f;
}
static public float BackInOut(float t)
{
float s = 1.70158f * 1.525f;
t = t * 2.0f;
if (t < 1.0f)
{
return (t * t * ((s + 1.0f) * t - s)) * 0.5f;
}
t = t - 2.0f;
return (t * t * ((s + 1.0f) * t + s) + 2.0f) * 0.5f;
}
static public float BounceIn(float t)
{
return 1.0f - BounceOut(1.0f - t);
}
static public float BounceOut(float t)
{
if (t < (1.0f / 2.75f)) return 7.5625f * t * t;
else if (t < (2.0f / 2.75f)) return 7.5625f * (t -= (1.5f / 2.75f)) * t + 0.75f;
else if (t < (2.5f / 2.75f)) return 7.5625f * (t -= (2.25f / 2.75f)) * t + 0.9375f;
return 7.5625f * (t -= (2.625f / 2.75f)) * t + 0.984375f;
}
static public float BounceInOut(float t)
{
if (t < 0.5f) return BounceIn(t * 2.0f) * 0.5f;
return BounceOut(t * 2.0f - 1.0f) * 0.5f + 0.5f;
}
static public float ElasticIn(float t)
{
if (t == 0.0f || t == 1.0f) return t;
return -Mathf.Pow(2.0f, 10.0f * (t - 1.0f)) * Mathf.Sin((t - 1.1f) * 5.0f * Mathf.PI);
}
static public float ElasticOut(float t)
{
if (t == 0.0f || t == 1.0f) return t;
return Mathf.Pow(2.0f, -10.0f * t) * Mathf.Sin((t - 0.1f) * 5.0f * Mathf.PI) + 1.0f;
}
static public float ElasticInOut(float t)
{
if (t == 0.0f || t == 1.0f) return t;
t = t * 2.0f;
if (t < 1.0f)
{
return Mathf.Pow(2, 10.0f * (t - 1)) * Mathf.Sin((t - 1.1f) * 5.0f * Mathf.PI) * -0.5f;
}
return (Mathf.Pow(2.0f, -10.0f * (t - 1)) * Mathf.Sin((t - 1.1f) * 5.0f * Mathf.PI) * 0.5f) + 1.0f;
}
static public float CatmullRom(float t, float p0, float p1, float p2, float p3)
{
return 0.5f * ((2.0f * p1) + (-p0 + p2) * t + (2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * t * t + (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * t * t * t);
}
}