//--------------------------------------------------------------------- public bool IsBetween(EbAngle kLeft, EbAngle kRight) { if (kLeft.Value <= kRight.Value) { return(kLeft.Value <= Value && Value <= kRight.Value); } else { return(kLeft.Value <= Value || Value <= kRight.Value); } }
//--------------------------------------------------------------------- public static float SameSignAngle(EbAngle angle, EbAngle record) { if (angle.Value > record.Value + EbMath.PI) { return angle.Value - EbMath.PI_X2; } else if (angle.Value < record.Value - EbMath.PI) { return angle.Value + EbMath.PI_X2; } else { return angle.Value; } }
//--------------------------------------------------------------------- public static float SameSignAngle(EbAngle angle, EbAngle record) { if (angle.Value > record.Value + EbMath.PI) { return(angle.Value - EbMath.PI_X2); } else if (angle.Value < record.Value - EbMath.PI) { return(angle.Value + EbMath.PI_X2); } else { return(angle.Value); } }
//--------------------------------------------------------------------- public static float Diff(EbAngle from, EbAngle to) { float fDiff = from.Value - to.Value; if (fDiff < -EbMath.PI) { return fDiff + EbMath.PI_X2; } else if (fDiff >= EbMath.PI) { return fDiff - EbMath.PI_X2; } else { return fDiff; } }
//--------------------------------------------------------------------- public static float Diff(EbAngle from, EbAngle to) { float fDiff = from.Value - to.Value; if (fDiff < -EbMath.PI) { return(fDiff + EbMath.PI_X2); } else if (fDiff >= EbMath.PI) { return(fDiff - EbMath.PI_X2); } else { return(fDiff); } }
//--------------------------------------------------------------------- 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); }
//--------------------------------------------------------------------- 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); }
//--------------------------------------------------------------------- public EbAngle(EbAngle rAngle) { _value = rAngle.Value; }
//--------------------------------------------------------------------- public void Lerp(EbAngle a, EbAngle b, float t) { _value = a.Value * t + SameSignAngle(a, b) * (1 - t); Normalize(); }
//--------------------------------------------------------------------- public bool IsBetween(EbAngle kLeft, EbAngle kRight) { if (kLeft.Value <= kRight.Value) { return (kLeft.Value <= Value && Value <= kRight.Value); } else { return (kLeft.Value <= Value || Value <= kRight.Value); } }