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