-
Notifications
You must be signed in to change notification settings - Fork 0
/
Animator.s3d
89 lines (77 loc) · 1.75 KB
/
Animator.s3d
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
#ifndef _ANIMATOR
#define _ANIMATOR
class Animator
{
var size;
var objs;
var head;
var tail;
Add(obj, delay, startPos, endPos, hMax);
Update();
CalcParabola(xBegin, xEnd, zBegin, zEnd, yStart, yApex, t);
CalcY(startingHeight, apexHeight, t);
CalcX(start, end, t);
CalcZ(start, end, t);
};
function Animator::Animator()
{
size = 6;
objs = Array(size);
head = 0;
tail = 0;
}
function Animator::Add(obj, delay, startPos, endPos, hMax)
{
objs[tail] = {obj, delay, startPos, endPos, hMax};
tail = (tail + 1) % size;
}
function Animator::Update()
{
var i = head;
while(i != tail)
{
var o = objs[i];
var t = o[1];
if(t < 1.0)
{
t = t + 0.01;
o[1] = t;
if(t > 0.0)
{
var newPos = CalcParabola(o[2][0], o[3][0], o[2][2], o[3][2], o[2][1], o[4], t);
o[0].obj.SetPosition(newPos);
}
if(t > 0.8)
{
o[0].Promote();
//OutputLN("Promoting!!!");
}
}
else if(i == head)
head = (head + 1) % size;
i = (i+1) % size;
}
}
function Animator::CalcParabola(xBegin, xEnd, zBegin, zEnd, yStart, yApex, t){
return [CalcX(xBegin,xEnd,t), CalcY(yStart,yApex,t), CalcZ(zBegin,zEnd,t)];
}
function Animator::CalcY(startingHeight, apexHeight, t)
{
var B = (apexHeight - startingHeight) / 4;
var A = -B;
var C = startingHeight;
return A*t*t + B*t + C;
}
function Animator::CalcX(start, end, t)
{
var A = (end - start);
var B = start;
return A*t + B;
}
function Animator::CalcZ(start, end, t)
{
var A = (end - start);
var B = start;
return A*t + B;
}
#endif