Esempio n. 1
0
        //---------------------------------------------------------------------
        public bool Update(float deltaTime, float newDir)
        {
            if (newDir == _curDiretion)
            {
                return(false);
            }
            float maxRot     = deltaTime * _rotSpd;
            float deltaAngle = newDir - _curDiretion;

            EbAngle.Normalize(ref deltaAngle);
            if (Math.Abs(deltaAngle) < maxRot)
            {
                _curDiretion = newDir;
            }
            else
            {
                _curDiretion += maxRot * EbMath.Sign(deltaAngle);
            }
            EbAngle.Normalize(ref _curDiretion);
            return(true);
        }
Esempio n. 2
0
        //---------------------------------------------------------------------
        public bool Update(float deltaTime, float newDir)
        {
            float deltaAngle = newDir - _curDiretion;

            if (deltaAngle == 0.0f)
            {
                return(false);
            }
            EbAngle.Normalize(ref deltaAngle);
            float maxRot = 0.0f;

            if (deltaAngle > 0.0f)
            {
                _currentSpeed = Math.Abs(_currentSpeed);
                float newSpd = _currentSpeed + _accelerate * deltaTime;
                float maxSpd = EbMath.Sqrt(deltaAngle * _accelerate * 2.0f);
                _currentSpeed = EbMath.Min(EbMath.Min(newSpd, maxSpd), _maxSpeed);
                maxRot        = _currentSpeed * deltaTime;
            }
            else
            {
                _currentSpeed = -Math.Abs(_currentSpeed);
                float newSpd = _currentSpeed - _accelerate * deltaTime;
                float maxSpd = -EbMath.Sqrt(-deltaAngle * _accelerate * 2.0f);
                _currentSpeed = EbMath.Max(EbMath.Max(newSpd, maxSpd), -_maxSpeed);
                maxRot        = _currentSpeed * deltaTime;
            }
            if (Math.Abs(deltaAngle) < Math.Abs(maxRot))
            {
                _curDiretion  = newDir;
                _currentSpeed = 0.0f;
            }
            else
            {
                _curDiretion += maxRot;
            }
            EbAngle.Normalize(ref _curDiretion);
            return(true);
        }