Пример #1
0
        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;
            }
        }
Пример #2
0
        public bool CUpdate(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);

                return(true);
            }

            return(false);
        }