public void Update(SAMTime gameTime) { // ReSharper disable once CompareOfFloatsByEqualityOperator if (ActualValue != TargetValue) { var radSpeed = deltaSpeed * gameTime.ElapsedSeconds; var diff = FloatMath.DiffModulo(ActualValue, TargetValue, modulo); ActualValue = FloatMath.Abs(diff) <= radSpeed ? TargetValue : FloatMath.AddRads(ActualValue, -FloatMath.Sign(diff) * radSpeed); } }
/// acceleration until halfway, then deceleration /// http://robertpenner.com/easing/ public static float FunctionEaseInOutExpo(float t, float p = 10) { var s = FloatMath.Pow(2, -2 * p) / 2; var e = 1 - FloatMath.Pow(2, -p) / 2; if (t < 0.5) { return((FloatMath.Pow(2, p * (2 * t - 1)) / 2 - s) / (e - s)); } return((1 - FloatMath.Pow(2, -p * (2 * t - 1)) / 2 - s) / (e - s)); }
private void RealUpdate() { LastValue = NextValue; var delta = 1 / CalculationUPS; var force = (TargetValue - NextValue) * _forcePerUnit; Speed += force * delta; Speed *= _dragFactor; if (FloatMath.Abs(Speed) < _minSpeed && Speed > 0) { Speed = _minSpeed * FloatMath.Sign(Speed); } var nv = NextValue + Speed * delta; if (nv < ValueMin) { var nnv = FloatMath.Max(NextValue, ValueMin); NextValue = nnv; if (Speed < 0) { Speed = 0; } } else if (nv > ValueMax) { var nnv = FloatMath.Min(NextValue, ValueMax); NextValue = nnv; if (Speed > 0) { Speed = 0; } } else if (FloatMath.Sign(nv - TargetValue) != FloatMath.Sign(NextValue - TargetValue) && FloatMath.Abs(FloatMath.Abs(Speed) - _minSpeed) < FloatMath.EPSILON) { NextValue = TargetValue; Speed = 0; } else { NextValue = nv; } }
/// decelerating to zero velocity /// http://robertpenner.com/easing/ public static float FunctionEaseOutExpo(float t, float p = 10) { return((1 - FloatMath.Pow(2, -p * t)) / (1 - FloatMath.Pow(2, -p))); }
/// accelerating from zero velocity /// http://robertpenner.com/easing/ public static float FunctionEaseInExpo(float t, float p = 10f) { var s = FloatMath.Pow(2, -p); return((FloatMath.Pow(2, p * (t - 1)) - s) / (1 - s)); }
/// acceleration until halfway, then deceleration /// http://robertpenner.com/easing/ public static float FunctionEaseInOutSine(float t) => (1 - FloatMath.Cos(FloatMath.PI * t)) / 2;
/// decelerating to zero velocity /// http://robertpenner.com/easing/ public static float FunctionEaseOutSine(float t) => 1 + FloatMath.Sin((t - 1) * FloatMath.PI / 2);
/// accelerating from zero velocity /// http://robertpenner.com/easing/ public static float FunctionEaseInSine(float t) => FloatMath.Sin(t * FloatMath.PI / 2);