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; } } }
public float GetDistance(ViGeographicObject obj) { if (obj == null) { return(1.0f); } float diff = GetHorizontalDistance(Position, obj.Position); return(ViMathDefine.Max(0.0f, diff - BodyRadius - obj.BodyRadius)); }
public override void Start(float duration) { ViDebuger.AssertWarning(Target); if (Target == null) { Target = new ViSimpleProvider <ViVector3>(); } _velocity = ViVector3.ZERO; _duration = ViMathDefine.Max(0.01f, duration); ViVector3 targetPos = Target.Value; float distanceH = ViMath2D.Length(targetPos.x, targetPos.y, Translate.x, Translate.y); float distanceV = targetPos.z - Translate.z; float time = distanceV / m_GravityAcc / _duration; float preDeltaTime = _duration * 0.5f + time; float aftDeltaTime = _duration * 0.5f - time; _velocity.z = preDeltaTime * m_GravityAcc; }
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); }
public float GetDistance(ViVector3 pos) { float diff = GetHorizontalDistance(pos, Position); return(ViMathDefine.Max(0.0f, diff - BodyRadius)); }
public static ViVector3 Max(ViVector3 lhs, ViVector3 rhs) { return(new ViVector3(ViMathDefine.Max(lhs.x, rhs.x), ViMathDefine.Max(lhs.y, rhs.y), ViMathDefine.Max(lhs.z, rhs.z))); }