]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/anim/easing.qc
Header police
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / anim / easing.qc
1 #include "easing.qh"
2 #ifndef ANIM_EASING_H
3         #define ANIM_EASING_H
4         #include "animation.qc"
5         entity makeHostedEasing(entity, void(entity, float), float(float, float, float, float), float, float, float);
6         entity makeEasing(entity, void(entity, float), float(float, float, float, float), float, float, float, float);
7         float easingLinear(float, float, float, float);
8         float easingQuadIn(float, float, float, float);
9         float easingQuadOut(float, float, float, float);
10         float easingQuadInOut(float, float, float, float);
11         CLASS(Easing, Animation)
12                 METHOD(Easing, calcValue, float(entity, float, float, float, float));
13                 METHOD(Easing, setMath, void(entity, float(float, float, float, float)));
14                 ATTRIB(Easing, math, float(float, float, float, float), easingLinear)
15         ENDCLASS(Easing)
16 #endif
17
18 #ifdef IMPLEMENTATION
19         entity makeHostedEasing(entity obj, void(entity, float) objSetter, float(float, float, float, float) func, float animDuration, float animStartValue, float animEnd)
20         {
21                 entity this = makeEasing(obj, objSetter, func, time, animDuration, animStartValue, animEnd);
22                 anim.addAnim(anim, this);
23                 return this;
24         }
25
26         entity makeEasing(entity obj, void(entity, float) objSetter, float(float, float, float, float) func, float animStartTime, float animDuration, float animStartValue, float animEnd)
27         {
28                 entity this = NEW(Easing);
29                 this.configureAnimation(this, obj, objSetter, animStartTime, animDuration, animStartValue, animEnd);
30                 this.setMath(this, func);
31                 return this;
32         }
33
34         METHOD(Easing, calcValue, float(entity this, float tickTime, float animDuration, float animStart, float animDelta))
35         {
36                 return this.math(tickTime, animDuration, animStart, animDelta);
37         }
38
39         METHOD(Easing, setMath, void(entity this, float(float, float, float, float) func))
40         {
41                 this.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)) return easingQuadIn(tickTime, (animDuration / 2), animStart, (animDelta / 2));
64                 else return easingQuadOut((tickTime - (animDuration / 2)), (animDuration / 2), (animStart + (animDelta / 2)), (animDelta / 2));
65         }
66
67 #endif