-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCTween.h
130 lines (115 loc) · 2.62 KB
/
CTween.h
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
#ifndef CTWEEN_H
#define CTWEEN_H
#define funcsmoothstart 0
#define funcsmoothstop 1
#define funcsmoothstartflip 3
#define funcsmoothstopflip 4
#define funcsmoothstep 5
#define funcarchstep 6
struct CTweenInfo
{
float val;
float ticks;
float maxticks;
float inc;
bool active;
int func;
int id;
float funcval;
float multiplier;
};
void initialize_CTweenInfo(CTweenInfo *TweenInfo)
{
TweenInfo->val = 0.0;
TweenInfo->ticks = 0.0;
TweenInfo->maxticks = 0.0;
TweenInfo->inc = 0.0;
TweenInfo->active = false;
TweenInfo->func = funcsmoothstart;
TweenInfo->id = -1;
TweenInfo->funcval = 0.0;
TweenInfo->multiplier = 0.0;
}
float smoothstart2(float val)
{
return val*val;
}
float smoothstop2(float val)
{
return 1-((1-val)*(1-val));
}
float smoothstartflip2(float val)
{
return 1 - smoothstart2(val);
}
float smoothstopflip2(float val)
{
return 1 - smoothstop2(val);
}
float mix(float val1, float val2, float blendval)
{
return (1-blendval)*val1 + blendval*val2;
}
float smoothstep3(float val)
{
return mix(smoothstart2(val), smoothstop2(val), val);
}
float arch(float val)
{
return 4*(val)*(1-val);
}
float tweencalcstepinc(float seconds, float FPS)
{
return 1/ (FPS * seconds);
}
float tweencalcmaxticks(float seconds, float FPS)
{
return seconds * FPS;
}
void setTweenInfo(CTweenInfo* tween, int id, float duration, int tweenfunc, float multiplier, bool active, float FPS)
{
tween->maxticks = tweencalcmaxticks(duration, FPS);
tween->ticks = 0;
tween->inc = tweencalcstepinc(duration, FPS);
tween->multiplier = multiplier;
tween->val = 0;
tween->func = tweenfunc;
tween->funcval = 0;
tween->active = active;
tween->id = id;
}
void updateTween(CTweenInfo* tween)
{
if (tween->active)
{
if (tween->ticks < tween->maxticks)
{
tween->ticks += 1;
tween->val += tween->inc;
switch(tween->func)
{
case funcsmoothstart:
tween->funcval = smoothstart2(tween->val) * tween->multiplier;
break;
case funcsmoothstop:
tween->funcval = smoothstop2(tween->val) * tween->multiplier;
break;
case funcsmoothstartflip:
tween->funcval = smoothstartflip2(tween->val) * tween->multiplier;
break;
case funcsmoothstopflip:
tween->funcval = smoothstopflip2(tween->val) * tween->multiplier;
break;
case funcsmoothstep:
tween->funcval = smoothstep3(tween->val) * tween->multiplier;
break;
case funcarchstep:
tween->funcval = arch(smoothstep3(tween->val)) * tween->multiplier;
break;
}
}
else
tween->active = false;
}
}
#endif