-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathanimation.lua
232 lines (182 loc) · 5.76 KB
/
animation.lua
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
221
222
223
224
225
226
227
228
229
230
231
232
local easing = {}
if makermod then
makermod.easing = easing
end
easing['linear'] = function(n) return n end
easing['swing'] = function(x) return (math.cos(x * math.pi) / -2) + 0.5 end
easing['spring'] = function(x) return 1 - (math.cos(x * 4.5 * math.pi) * math.exp(x * -6)) end
easing['pulse'] = function(x) return (math.cos((x * (5 - 0.5) * 2) * math.pi) / -2) + 0.5 end
easing['wobble'] = function(x) return (math.cos(x * math.pi * 9 * x) / -2) + 0.5 end
easing['ease'] = function(x) return x ^ 2 end
easing['cubic'] = function(x) return x ^ 3 end
easing['quart'] = function(x) return x ^ 4 end
easing['quint'] = function(x) return x ^ 5 end
easing['expo'] = function(x) return 2 ^ (8 * (x-1)) end
easing['circ'] = function(x) return 1 - math.sin(math.acos(x)) end
easing['sine'] = function(x) return 1 - math.cos(x * math.pi / 2) end
easing['back'] = function(x) return (x ^ 2) * (2.618 * x - 1.618) end
easing['bounce'] = function(x)
local a = 0
local b = 1
local value
while true do
if x >= ((7 - 4*a) / 11) then
value = b * b - (((11 - 6*a - 11*x) / 4) ^ 2)
break
end
a = a+b
b = b/2
end
return value
end
easing['elastic'] = function(x)
x = x-1;
return 2 ^ (10 * x) * math.cos(20 * x * math.pi / 3)
end
-- outs & inouts
for k, v in pairs(easing) do
easing[k .. 'Out'] = function(t) return (1 - v(1 - t)) end
easing[k .. 'InOut'] = function(t)
if t <= 0.5 then
return easing[k](2 * t) / 2
else
return (2 - easing[k](2 * (1 - t))) / 2
end
end
end
-- for mmove list
easinglist = 'linear, swing, spring, pulse, wobble, ease, cubic, quart, quint, expo, circ, sine, back, bounce, elastic'
makermod.timerListeners['move'] = function(object)
local now = GetRealTime()
local delta = now - object.start
local t = delta / object.dur
if t > 1 then
t = 1
end
if object.ease ~= 'linear' and easing[object.ease] then
t = easing[object.ease](t)
end
local pos = object.pos + object.coords * t
object.ent.position = pos
if delta > object.dur then
return false
end
end
makermod.timerListeners['rotate'] = function(object)
local now = GetRealTime()
local delta = now - object.start
local t = delta / object.dur
if t > 1 then
t = 1
end
if object.ease ~= 'linear' and easing[object.ease] then
t = easing[object.ease](t)
end
local ang = object.from + object.angle * t
object.ent.angles = ang
if delta > object.dur then
return false
end
end
-- WIP movings
--[[local steps = {}
steps['ellipse_inf'] = function(object)
local now = GetRealTime()
local period = object.period
local delta = (now - object.start) % period
local t = delta / period
local ang = t * 2 * 3.14159265358979
local center = object.center
local pos = Vector3(center.x + object.rx * math.cos(ang), center.y + object.ry * math.sin(ang), center.z)
object.ent.position = pos
end
steps['ellipse'] = function(object)
local now = GetRealTime()
local delta = now - object.start
if delta >= object.dur then
return false
end
local t = delta / object.dur
if object.ease ~= 'linear' and easing[object.ease] then
t = easing[object.ease](t)
end
local angle = object.from + object.to * t
-- converting from degrees to radians
angle = (angle / 180) * 3.14159265358979323
local center = object.center
local pos = Vector3(center.x + object.rx * math.cos(angle), center.y + object.ry * math.sin(angle), center.z)
object.ent.position = pos
end
steps['astroid_inf'] = function(object)
local now = GetRealTime()
local period = object.period
local delta = (now - object.start) % period
local t = delta / period
local ang = t * 2 * 3.14159265358979
local center = object.center
local pos = Vector3(center.x + object.rx * (math.cos(ang) ^ 3), center.y + object.ry * (math.sin(ang) ^ 3), center.z)
object.ent.position = pos
end
steps['astroid'] = function(object)
local now = GetRealTime()
local delta = now - object.start
if delta >= object.dur then
return false
end
local t = delta / object.dur
if object.ease ~= 'linear' and easing[object.ease] then
t = easing[object.ease](t)
end
local angle = object.from + object.to * t
-- converting from degrees to radians
angle = (angle / 180) * 3.14159265358979323
local center = object.center
local pos = Vector3(center.x + object.rx * (math.cos(angle) ^ 3), center.y + object.ry * (math.sin(angle) ^ 3), center.z)
object.ent.position = pos
end
steps['spiral'] = function(object)
local now = GetRealTime()
local delta = now - object.start
if delta >= object.dur then
return false
end
local t = delta / object.dur
if object.ease ~= 'linear' and easing[object.ease] then
t = easing[object.ease](t)
end
local angle = object.from + object.to * t
-- converting from degrees to radians
angle = (angle / 180) * 3.14159265358979323
local center = object.center
local r = angle * object.k
object.ent.position = Vector3(center.x + r * math.cos(angle), center.y + r * math.sin(angle), center.z)
end
steps['rotate'] = function(object)
local now = GetRealTime()
local delta = now - object.start
if delta > object.dur then
return false
end
local t = delta / object.dur
if object.ease ~= 'linear' and easing[object.ease] then
t = easing[object.ease](t)
end
local angles = Vector3(object.from.x + object.angle.x * t, object.from.y + object.angle.y * t, object.from.z + object.angle.z * t)
object.ent.angles = angles
end
function AnimStep(object)
if object.movingType and steps[object.movingType] then
return steps[object.movingType](object)
end
local cur = GetRealTime()
local delta = cur - object.start
if delta > object.dur then
return false
end
local t = delta / object.dur
if object.ease ~= 'linear' and easing[object.ease] then
t = easing[object.ease](t)
end
local pos = Vector3(object.pos.x + object.coords.x * t, object.pos.y + object.coords.y * t, object.pos.z + object.coords.z * t)
object.ent.position = pos
end --]]