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