Ejemplo n.º 1
0
    public void Update(float desireDistance, float delatTime)
    {
        float diff = desireDistance - _currentDistance;

        if (diff == 0.0f)
        {
        }
        else if (diff > 0.0f)
        {
            float newSpd = _currentSpeed + _accelerate * delatTime;
            float maxSpd = ViMathDefine.Sqrt(diff * _accelerate * 2.0f);
            _currentSpeed = ViMathDefine.Min(ViMathDefine.Min(newSpd, maxSpd), _maxSpeed);
            float delatDist = _currentSpeed * delatTime;
            _currentDistance += delatDist;
            if (_currentDistance >= desireDistance)
            {
                _currentDistance = desireDistance;
                _currentSpeed    = 0.0f;
            }
        }
        else
        {
            float newSpd = _currentSpeed - _accelerate * delatTime;
            float maxSpd = -ViMathDefine.Sqrt(-diff * _accelerate * 2.0f);
            _currentSpeed = ViMathDefine.Max(ViMathDefine.Max(newSpd, maxSpd), -_maxSpeed);
            float delatDist = _currentSpeed * delatTime;
            _currentDistance += delatDist;
            if (_currentDistance <= desireDistance)
            {
                _currentDistance = desireDistance;
                _currentSpeed    = 0.0f;
            }
        }
    }
Ejemplo n.º 2
0
    public static float GetHorizontalDistance(ViVector3 pos1, ViVector3 pos2)
    {
        float deltaX = pos1.x - pos2.x;
        float deltaY = pos1.y - pos2.y;

        return(ViMathDefine.Sqrt((deltaX * deltaX) + (deltaY * deltaY)));
    }
Ejemplo n.º 3
0
    public static float Distance(ViVector3 a, ViVector3 b)
    {
        float deltaX = a.x - b.x;
        float deltaY = a.y - b.y;
        float deltaZ = a.z - b.z;

        return(ViMathDefine.Sqrt((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ)));
    }
Ejemplo n.º 4
0
    public bool Update(float deltaTime, float newDir)
    {
        float deltaAngle = newDir - _curDiretion;

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

        if (deltaAngle > 0.0f)
        {
            _currentSpeed = Math.Abs(_currentSpeed);
            float newSpd = _currentSpeed + _accelerate * deltaTime;
            float maxSpd = ViMathDefine.Sqrt(deltaAngle * _accelerate * 2.0f);
            _currentSpeed = ViMathDefine.Min(ViMathDefine.Min(newSpd, maxSpd), _maxSpeed);
            maxRot        = _currentSpeed * deltaTime;
        }
        else
        {
            _currentSpeed = -Math.Abs(_currentSpeed);
            float newSpd = _currentSpeed - _accelerate * deltaTime;
            float maxSpd = -ViMathDefine.Sqrt(-deltaAngle * _accelerate * 2.0f);
            _currentSpeed = ViMathDefine.Max(ViMathDefine.Max(newSpd, maxSpd), -_maxSpeed);
            maxRot        = _currentSpeed * deltaTime;
        }
        if (Math.Abs(deltaAngle) < Math.Abs(maxRot))
        {
            _curDiretion  = newDir;
            _currentSpeed = 0.0f;
        }
        else
        {
            _curDiretion += maxRot;
        }
        ViAngle.Normalize(ref _curDiretion);
        return(true);
    }
Ejemplo n.º 5
0
 public static float Magnitude(ViVector3 a)
 {
     return(ViMathDefine.Sqrt(((a.x * a.x) + (a.y * a.y)) + (a.z * a.z)));
 }