]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/anim/easing.qc
Merge branch 'master' into Mario/qc_updates
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / anim / easing.qc
1 #ifdef INTERFACE
2 CLASS(Easing) EXTENDS(Animation)
3         METHOD(Easing, calcValue, float(entity, float, float, float, float))
4         METHOD(Easing, setMath, void(entity, float(float, float, float, float)))
5         ATTRIB(Easing, math, float(float, float, float, float), easingLinear)
6 ENDCLASS(Easing)
7 entity makeHostedEasing(entity, void(entity, float), float(float, float, float, float), float, float, float);
8 entity makeEasing(entity, void(entity, float), float(float, float, float, float), float, float, float, float);
9 float easingLinear(float, float, float, float);
10 float easingQuadIn(float, float, float, float);
11 float easingQuadOut(float, float, float, float);
12 float easingQuadInOut(float, float, float, float);
13 #endif
14
15 #ifdef IMPLEMENTATION
16 entity makeHostedEasing(entity obj, void(entity, float) objSetter, float(float, float, float, float) func, float animDuration, float animStartValue, float animEnd)
17 {
18         entity me;
19         me = makeEasing(obj, objSetter, func, time, animDuration, animStartValue, animEnd);
20         anim.addAnim(anim, me);
21         return me;
22 }
23
24 entity makeEasing(entity obj, void(entity, float) objSetter, float(float, float, float, float) func, float animStartTime, float animDuration, float animStartValue, float animEnd)
25 {
26         entity me;
27         me = spawnEasing();
28         me.configureAnimation(me, obj, objSetter, animStartTime, animDuration, animStartValue, animEnd);
29         me.setMath(me, func);
30         return me;
31 }
32
33 float Easing_calcValue(entity me, float tickTime, float animDuration, float animStart, float animDelta)
34 {
35         return me.math(tickTime, animDuration, animStart, animDelta);
36 }
37
38 void Easing_setMath(entity me, float(float, float, float, float) func)
39 {
40         me.math = func;
41 }
42
43 float easingLinear(float tickTime, float animDuration, float animStart, float animDelta)
44 {
45         return (animDelta * (tickTime / animDuration)) + animStart;
46 }
47
48 float easingQuadIn(float tickTime, float animDuration, float animStart, float animDelta)
49 {
50         float frac = tickTime / animDuration;
51         return (animDelta * frac * frac) + animStart;
52 }
53
54 float easingQuadOut(float tickTime, float animDuration, float animStart, float animDelta)
55 {
56         float frac = tickTime / animDuration;
57         return (-animDelta * frac * (frac - 2)) + animStart;
58 }
59
60 float easingQuadInOut(float tickTime, float animDuration, float animStart, float animDelta)
61 {
62         if (tickTime < (animDuration / 2))
63         {
64                 return easingQuadIn(tickTime, (animDuration / 2), animStart, (animDelta / 2));
65         }
66         else
67         {
68                 return easingQuadOut((tickTime - (animDuration / 2)), (animDuration / 2), (animStart + (animDelta / 2)), (animDelta / 2));
69         }
70 }
71
72 #endif