123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958 |
- //
- // The graphics engine GLXEngine
- //
- unit Stage.AnimationUtils;
- (* Main purpose is to give an easy way to create a linear interpolation *)
- interface
- {$I Stage.Defines.inc}
- uses
- System.SysUtils,
- System.Classes,
- System.Math,
- Stage.VectorTypes,
- Stage.VectorGeometry;
- type
- TEaseType=
- (
- etLinear,
- etQuadIn,
- etQuadOut,
- etQuadInOut,
- etQuadOutIn,
- etCubicIn,
- etCubicOut,
- etCubicInOut,
- etCubicOutIn,
- etQuintIn,
- etQuintOut,
- etQuintInOut,
- etQuintOutIn,
- etSineIn,
- etSineOut,
- etSineInOut,
- etSineOutIn,
- etCircIn,
- etCircOut,
- etCircInOut,
- etCircOutIn,
- etExpoIn,
- etExpoOut,
- etExpoInOut,
- etExpoOutIn,
- etElasticIn,
- etElasticOut,
- etElasticInOut,
- etElasticOutIn,
- etBackIn,
- etBackOut,
- etBackInOut,
- etBackOutIn,
- etBounceIn,
- etBounceOut,
- etBounceInOut,
- etBounceOutIn
- );
- function Tweener(Current, Target: TAffineVector; Time, Duration: Single;
- EaseType: TEaseType): TAffineVector; overload;
- function Tweener(Current, Target: TGLVector; Time, Duration: Single;
- EaseType: TEaseType): TGLVector; overload;
- function Tweener(Current, Target: TVector2f; Time, Duration: Single;
- EaseType: TEaseType): TVector2f; overload;
- function Tweener(Current, Target: Single; Time, Duration: Single;
- EaseType: TEaseType): Single; overload;
- implementation //-------------------------------------------------------------
- type
- TEaseFunction = function(t:Single; b:Single; c:Single; d:Single):Single;
- (*
- Easing equation function for a simple linear tweening, with no easing.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeNone (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- Result := c*t/d + b;
- end;
- (*
- Easing equation function for a quadratic (t^2) easing in: accelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeInQuad (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- t := t/d;
- Result := c*t*t + b;
- end;
- (*
- Easing equation function for a quadratic (t^2) easing out: decelerating to zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeOutQuad (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- t := t/d;
- Result := -c *t*(t-2) + b;
- end;
- (*
- Easing equation function for a quadratic (t^2) easing in/out: acceleration until halfway, then deceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeInOutQuad (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- t := t/(d/2);
- if (t < 1) then
- Result := c/2*t*t + b
- else
- begin
- t := t-1;
- Result := -c/2 * (t*(t-2) - 1) + b;
- end;
- end;
- (*
- Easing equation function for a quadratic (t^2) easing out/in: deceleration until halfway, then acceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeOutInQuad (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- if (t < d/2) then
- Result := easeOutQuad (t*2, b, c/2, d)
- else
- Result := easeInQuad((t*2)-d, b+c/2, c/2, d);
- end;
- (*
- Easing equation function for a cubic (t^3) easing in: accelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeInCubic (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- t := t/d;
- Result := c*t*t*t + b;
- end;
- (*
- Easing equation function for a cubic (t^3) easing out: decelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeOutCubic (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- t := t/d-1;
- Result := c*(t*t*t + 1) + b;
- end;
- (*
- Easing equation function for a cubic (t^3) easing in/out: acceleration until halfway, then deceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeInOutCubic (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- t := t/(d/2);
- if (t < 1) then
- Result := c/2*t*t*t + b
- else
- begin
- t := t-2;
- Result := c/2*(t*t*t + 2) + b;
- end;
- end;
- (*
- Easing equation function for a cubic (t^3) easing out/in: deceleration until halfway, then acceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeOutInCubic (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- if (t < d/2) then
- Result := easeOutCubic (t*2, b, c/2, d)
- else
- Result := easeInCubic((t*2)-d, b+c/2, c/2, d);
- end;
- (*
- Easing equation function for a quartic (t^4) easing in: accelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeInQuart (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- t := t/d;
- Result := c*t*t*t*t + b;
- end;
- (*
- Easing equation function for a quartic (t^4) easing out: decelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeOutQuart (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- t := t/d-1;
- Result := -c * (t*t*t*t - 1) + b;
- end;
- (*
- Easing equation function for a quartic (t^4) easing in/out: acceleration until halfway, then deceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeInOutQuart (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- t := t/(d/2);
- if (t < 1) then
- Result := c/2*t*t*t*t + b
- else
- begin
- t := t-2;
- Result := -c/2 * (t*t*t*t - 2) + b;
- end;
- end;
- (*
- Easing equation function for a quartic (t^4) easing out/in: deceleration until halfway, then acceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeOutInQuart (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- if (t < d/2) then
- Result := easeOutQuart (t*2, b, c/2, d)
- else
- Result := easeInQuart((t*2)-d, b+c/2, c/2, d);
- end;
- (*
- Easing equation function for a quintic (t^5) easing in: accelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeInQuint (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- t := t/d;
- Result := c*t*t*t*t*t + b;
- end;
- (*
- Easing equation function for a quintic (t^5) easing out: decelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeOutQuint (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- t := t/d-1;
- Result := c*(t*t*t*t*t + 1) + b;
- end;
- (*
- Easing equation function for a quintic (t^5) easing in/out: acceleration until halfway, then deceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeInOutQuint (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- t := t/(d/2);
- if (t < 1) then
- Result := c/2*t*t*t*t*t + b
- else
- begin
- t := t-2;
- Result := c/2*(t*t*t*t*t + 2) + b;
- end;
- end;
- (*
- Easing equation function for a quintic (t^5) easing out/in: deceleration until halfway, then acceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeOutInQuint (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- if (t < d/2) then
- Result := easeOutQuint (t*2, b, c/2, d)
- else
- Result := easeInQuint((t*2)-d, b+c/2, c/2, d);
- end;
- (*
- Easing equation function for a sinusoidal (sin(t)) easing in: accelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeInSine (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- Result := -c * cos(t/d * (PI/2)) + c + b;
- end;
- (*
- Easing equation function for a sinusoidal (sin(t)) easing out: decelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeOutSine (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- Result := c * sin(t/d * (PI/2)) + b;
- end;
- (*
- Easing equation function for a sinusoidal (sin(t)) easing in/out: acceleration until halfway, then deceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeInOutSine (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- Result := -c/2 * (cos(PI*t/d) - 1) + b;
- end;
- (*
- Easing equation function for a sinusoidal (sin(t)) easing out/in: deceleration until halfway, then acceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeOutInSine (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- if (t < d/2) then
- Result := easeOutSine (t*2, b, c/2, d)
- else
- Result := easeInSine((t*2)-d, b+c/2, c/2, d);
- end;
- (*
- Easing equation function for an exponential (2^t) easing in: accelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeInExpo (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- if t=0 then
- Result := b
- else
- Result := c * Power(2, 10 * (t/d - 1)) + b - c * 0.001;
- end;
- (*
- Easing equation function for an exponential (2^t) easing out: decelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeOutExpo (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- if t=d then
- Result := b+c
- else
- Result := c * 1.001 * (-Power(2, -10 * t/d) + 1) + b;
- end;
- (*
- Easing equation function for an exponential (2^t) easing in/out: acceleration until halfway, then deceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeInOutExpo (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- if (t=0) then
- Result := b
- else
- if (t=d) then
- Result := b+c
- else
- begin
- t := t/(d/2);
- if (t < 1) then
- Result := c/2 * Power(2, 10 * (t - 1)) + b - c * 0.0005
- else
- begin
- t := t-1;
- Result := c/2 * 1.0005 * (-Power(2, -10 * t) + 2) + b;
- end;
- end;
- end;
- (*
- Easing equation function for an exponential (2^t) easing out/in: deceleration until halfway, then acceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeOutInExpo (t:Single; b:Single; c:Single; d:Single):Single; begin
- if (t < d/2) then
- Result := easeOutExpo (t*2, b, c/2, d)
- else
- Result := easeInExpo((t*2)-d, b+c/2, c/2, d);
- end;
- (*
- Easing equation function for a circular (sqrt(1-t^2)) easing in: accelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeInCirc (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- t := t/d;
- Result := -c * (Sqrt(1 - t*t) - 1) + b;
- end;
- (*
- Easing equation function for a circular (sqrt(1-t^2)) easing out: decelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeOutCirc (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- t := t/d-1;
- Result := c * Sqrt(1 - t*t) + b;
- end;
- (*
- Easing equation function for a circular (sqrt(1-t^2)) easing in/out: acceleration until halfway, then deceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeInOutCirc (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- t := t/(d/2);
- if (t < 1) then
- Result := -c/2 * (Sqrt(1 - t*t) - 1) + b
- else
- begin
- t := t-2;
- Result := c/2 * (Sqrt(1 - t*t) + 1) + b;
- end;
- end;
- (*
- Easing equation function for a circular (sqrt(1-t^2)) easing out/in: deceleration until halfway, then acceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeOutInCirc (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- if (t < d/2) then
- Result := easeOutCirc (t*2, b, c/2, d)
- else
- Result := easeInCirc((t*2)-d, b+c/2, c/2, d);
- end;
- (*
- Easing equation function for an elastic (exponentially decaying sine wave) easing in: accelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- a Amplitude.
- p Period.
- Result The correct value.
- *)
- function easeInElastic (t:Single; b:Single; c:Single; d:Single):Single;
- var
- p, a, s: Single;
- begin
- if t=0 then
- Result := b
- else
- begin
- t := t/d;
- if t=1 then
- Result := b+c
- else
- begin
- p := d*0.3;
- a := c;
- s := p/4;
- t := t-1;
- Result := -((a * Power(2, 10*t)) * sin((t*d-s)*(2*PI)/p )) + b;
- end;
- end;
- end;
- (*
- Easing equation function for an elastic (exponentially decaying sine wave) easing out: decelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- a Amplitude.
- p Period.
- Result The correct value.
- *)
- function easeOutElastic (t:Single; b:Single; c:Single; d:Single):Single;
- var
- p, a, s: Single;
- begin
- if t=0 then
- Result := b
- else
- begin
- t := t/d;
- if t=1 then
- Result := b+c
- else
- begin
- p := d*0.3;
- a := c;
- s := p/4;
- Result := (a* Power(2,-10*t) * sin( (t*d-s)*(2*PI)/p ) + c + b);
- end;
- end;
- end;
- (*
- Easing equation function for an elastic (exponentially decaying sine wave) easing in/out: acceleration until halfway, then deceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- a Amplitude.
- p Period.
- Result The correct value.
- *)
- function easeInOutElastic (t:Single; b:Single; c:Single; d:Single):Single;
- var
- p, a, s: Single;
- begin
- if t=0 then
- Result := b
- else
- begin
- t := t/(d/2);
- if t=2 then
- Result := b+c
- else
- begin
- p := d*0.3*1.5;
- a := c;
- s := p/4;
- t := t-1;
- if t<1 then
- Result := -0.5* ((a* Power(2,10*t)) * sin( (t*d-s)*(2*PI)/p)) + b
- else
- Result := (a* Power(2,-10*t)) * sin( (t*d-s)*(2*PI)/p )*0.5 + c + b;
- end;
- end;
- end;
- (*
- Easing equation function for an elastic (exponentially decaying sine wave) easing out/in: deceleration until halfway, then acceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- a Amplitude.
- p Period.
- Result The correct value.
- *)
- function easeOutInElastic (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- if (t < d/2) then
- Result := easeOutElastic (t*2, b, c/2, d)
- else
- Result := easeInElastic((t*2)-d, b+c/2, c/2, d)
- end;
- (*
- Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
- Result The correct value.
- *)
- function easeInBack (t:Single; b:Single; c:Single; d:Single):Single;
- var
- s: Single;
- begin
- s := 1.70158;
- t := t/d;
- Result := c*t*t*((s+1)*t - s) + b;
- end;
- (*
- Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out: decelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
- Result The correct value.
- *)
- function easeOutBack (t:Single; b:Single; c:Single; d:Single):Single;
- var
- s: Single;
- begin
- s := 1.70158;
- t := t/d-1;
- Result := c*(t*t*((s+1)*t + s) + 1) + b;
- end;
- (*
- Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
- Result The correct value.
- *)
- function easeInOutBack (t:Single; b:Single; c:Single; d:Single):Single;
- var
- s: Single;
- begin
- s := 1.70158;
- t := t/(d/2);
- s := s*1.525;
- if (t < 1) then
- Result := c/2*(t*t*((s+1)*t - s)) + b
- else
- begin
- t := t-2;
- Result := c/2*(t*t*((s+1)*t + s) + 2) + b;
- end;
- end;
- (*
- Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- s Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
- Result The correct value.
- *)
- function easeOutInBack (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- if (t < d/2) then
- Result := easeOutBack (t*2, b, c/2, d)
- else
- Result := easeInBack((t*2)-d, b+c/2, c/2, d);
- end;
- (*
- Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out: decelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeOutBounce (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- t := t/d;
- if t < (1/2.75) then
- Result := c*(7.5625*t*t) + b
- else
- if t < (2/2.75) then
- begin
- t := t-(1.5/2.75);
- Result := c*(7.5625*t*t + 0.75) + b;
- end
- else
- if (t < (2.5/2.75)) then
- begin
- t := t-(2.25/2.75);
- Result := c*(7.5625*t*t + 0.9375) + b;
- end
- else
- begin
- t := t-(2.625/2.75);
- Result := c*(7.5625*t*t + 0.984375) + b;
- end;
- end;
- (*
- Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in: accelerating from zero velocity.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- * Result The correct value.
- *)
- function easeInBounce (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- Result := c - easeOutBounce (d-t, 0, c, d) + b;
- end;
- (*
- Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out: acceleration until halfway, then deceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- * Result The correct value.
- *)
- function easeInOutBounce (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- if (t < d/2) then
- Result := easeInBounce(t*2, 0, c, d) * 0.5 + b
- else
- Result := easeOutBounce(t*2-d, 0, c, d) * 0.5 + c*0.5 + b;
- end;
- (*
- Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out/in: deceleration until halfway, then acceleration.
- t Current time (in frames or seconds).
- b Starting value.
- c Change needed in value.
- d Expected easing duration (in frames or seconds).
- Result The correct value.
- *)
- function easeOutInBounce (t:Single; b:Single; c:Single; d:Single):Single;
- begin
- if (t < d/2) then
- Result := easeOutBounce(t*2, b, c/2, d)
- else
- Result := easeInBounce((t*2)-d, b+c/2, c/2, d);
- end;
- function GetEaseFunctionFromType(const EaseType: TEaseType): TEaseFunction;
- begin
- case EaseType of
- etLinear : Result := easeNone;
- etQuadIn : Result := easeInQuad;
- etQuadOut : Result := easeOutQuad;
- etQuadInOut : Result := easeInOutQuad;
- etQuadOutIn : Result := easeOutInQuad;
- etCubicIn : Result := easeInCubic;
- etCubicOut : Result := easeOutCubic;
- etCubicInOut : Result := easeInOutCubic;
- etCubicOutIn : Result := easeOutInCubic;
- etQuintIn : Result := easeInQuint;
- etQuintOut : Result := easeOutQuint;
- etQuintInOut : Result := easeInOutQuint;
- etQuintOutIn : Result := easeOutInQuint;
- etSineIn : Result := easeInSine;
- etSineOut : Result := easeOutSine;
- etSineInOut : Result := easeInOutSine;
- etSineOutIn : Result := easeOutInSine;
- etCircIn : Result := easeInCirc;
- etCircOut : Result := easeOutCirc;
- etCircInOut : Result := easeInOutCirc;
- etCircOutIn : Result := easeOutInCirc;
- etExpoIn : Result := easeInExpo;
- etExpoOut : Result := easeOutExpo;
- etExpoInOut : Result := easeInOutExpo;
- etExpoOutIn : Result := easeOutInExpo;
- etElasticIn : Result := easeInElastic;
- etElasticOut : Result := easeOutElastic;
- etElasticInOut : Result := easeInOutElastic;
- etElasticOutIn : Result := easeOutInElastic;
- etBackIn : Result := easeInBack;
- etBackOut : Result := easeOutBack;
- etBackInOut : Result := easeInOutBack;
- etBackOutIn : Result := easeOutBack;
- etBounceIn : Result := easeInBounce;
- etBounceOut : Result := easeOutBounce;
- etBounceInOut : Result := easeInOutBounce;
- etBounceOutIn : Result := easeOutInBounce
- else
- Result := nil;
- end;
- end;
- function Tweener(Current, Target: TAffineVector; Time, Duration: Single; EaseType: TEaseType): TAffineVector;
- var
- i: integer;
- EaseFunction : TEaseFunction;
- begin
- if Time > Duration then
- Time := Duration;
- EaseFunction := GetEaseFunctionFromType(EaseType);
- for i := 0 to 2 do
- begin
- Target.V[i] := Target.V[i]-Current.V[i];
- Result.V[i] := EaseFunction(Time, Current.V[i], Target.V[i], Duration);
- end;
- end;
- function Tweener(Current, Target: TGLVector; Time, Duration: Single; EaseType: TEaseType): TGLVector;
- var
- i: integer;
- EaseFunction : TEaseFunction;
- begin
- if Time > Duration then
- Time := Duration;
- EaseFunction := GetEaseFunctionFromType(EaseType);
- for i := 0 to 3 do
- begin
- Target.V[i] := Target.V[i]-Current.V[i];
- Result.V[i] := EaseFunction(Time, Current.V[i], Target.V[i], Duration);
- end;
- end;
- function Tweener(Current, Target: TVector2f; Time, Duration: Single; EaseType: TEaseType): TVector2f;
- var
- i: integer;
- EaseFunction : TEaseFunction;
- begin
- if Time > Duration then
- Time := Duration;
- EaseFunction := GetEaseFunctionFromType(EaseType);
- for i := 0 to 1 do
- begin
- Target.V[i] := Target.V[i]-Current.V[i];
- Result.V[i] := EaseFunction(Time, Current.V[i], Target.V[i], Duration);
- end;
- end;
- function Tweener(Current, Target: Single; Time, Duration: Single; EaseType: TEaseType): Single;
- var
- EaseFunction : TEaseFunction;
- begin
- if Time > Duration then
- Time := Duration;
- EaseFunction := GetEaseFunctionFromType(EaseType);
- Result := EaseFunction(Time, Current, Target-Current, Duration);
- end;
- //----------------------------------------------------------------------------
- end.
|