X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fanim%2Feasing.qc;fp=qcsrc%2Fmenu%2Fanim%2Feasing.qc;h=94ea9cf0872da839e836be94e28cda460f029bab;hb=e3507f4fdbc2b3e15b663365e57e0aa60f3cf1a6;hp=0000000000000000000000000000000000000000;hpb=02013c593abe7ccb7c6502148df33b34390d8216;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/anim/easing.qc b/qcsrc/menu/anim/easing.qc new file mode 100644 index 000000000..94ea9cf08 --- /dev/null +++ b/qcsrc/menu/anim/easing.qc @@ -0,0 +1,72 @@ +#ifdef INTERFACE +CLASS(Easing) EXTENDS(Animation) + METHOD(Easing, calcValue, float(entity, float, float, float, float)) + METHOD(Easing, setMath, void(entity, float(float, float, float, float))) + ATTRIB(Easing, math, float(float, float, float, float), easingLinear) +ENDCLASS(Easing) +entity makeHostedEasing(entity, void(entity, float), float(float, float, float, float), float, float, float); +entity makeEasing(entity, void(entity, float), float(float, float, float, float), float, float, float, float); +float easingLinear(float, float, float, float); +float easingQuadIn(float, float, float, float); +float easingQuadOut(float, float, float, float); +float easingQuadInOut(float, float, float, float); +#endif + +#ifdef IMPLEMENTATION +entity makeHostedEasing(entity obj, void(entity, float) objSetter, float(float, float, float, float) func, float animDuration, float animStartValue, float animEnd) +{ + entity me; + me = makeEasing(obj, objSetter, func, time, animDuration, animStartValue, animEnd); + anim.addAnim(anim, me); + return me; +} + +entity makeEasing(entity obj, void(entity, float) objSetter, float(float, float, float, float) func, float animStartTime, float animDuration, float animStartValue, float animEnd) +{ + entity me; + me = spawnEasing(); + me.configureAnimation(me, obj, objSetter, animStartTime, animDuration, animStartValue, animEnd); + me.setMath(me, func); + return me; +} + +float Easing_calcValue(entity me, float tickTime, float animDuration, float animStart, float animDelta) +{ + return me.math(tickTime, animDuration, animStart, animDelta); +} + +void Easing_setMath(entity me, float(float, float, float, float) func) +{ + me.math = func; +} + +float easingLinear(float tickTime, float animDuration, float animStart, float animDelta) +{ + return (animDelta * (tickTime / animDuration)) + animStart; +} + +float easingQuadIn(float tickTime, float animDuration, float animStart, float animDelta) +{ + float frac = tickTime / animDuration; + return (animDelta * frac * frac) + animStart; +} + +float easingQuadOut(float tickTime, float animDuration, float animStart, float animDelta) +{ + float frac = tickTime / animDuration; + return (-animDelta * frac * (frac - 2)) + animStart; +} + +float easingQuadInOut(float tickTime, float animDuration, float animStart, float animDelta) +{ + if (tickTime < (animDuration / 2)) + { + return easingQuadIn(tickTime, (animDuration / 2), animStart, (animDelta / 2)); + } + else + { + return easingQuadOut((tickTime - (animDuration / 2)), (animDuration / 2), (animStart + (animDelta / 2)), (animDelta / 2)); + } +} + +#endif