inline const Vector2& PhysicsMotion2D::UpdateVelocity(const Vector2& accelUnitsPerSecondSquared, double deltaSeconds) { m_velocityUnitsPerSecond += accelUnitsPerSecondSquared * (float)deltaSeconds; //update velocity direction with angular velocity if (m_lockMotionToOrientation) { m_velocityUnitsPerSecond.SetLengthAndHeadingDegrees(ClampVelocity(m_velocityUnitsPerSecond.CalcLength()), m_orientationDegrees); } else { ClampVelocity(m_velocityUnitsPerSecond.CalcLength()); } return m_velocityUnitsPerSecond; }
inline const Vector2& PhysicsMotion2D::UpdateAcceleration(double deltaSeconds) { UNUSED(deltaSeconds); if (m_lockMotionToOrientation) { m_accelerationUnitsPerSecondSquared.SetLengthAndHeadingDegrees(m_accelerationUnitsPerSecondSquared.CalcLength(), m_orientationDegrees); } return m_accelerationUnitsPerSecondSquared; }
//----------------------------------------------------------------------------------------------- void Scenario::ForceActorOutsideOfArea( Actor& actor, Area& area ) { Vector2 closestPointInAreaToActorCenter = FindClosestPointInBoundsToTarget( area.m_bounds, actor.m_position, false ); Vector2 displacementToClosestPoint = closestPointInAreaToActorCenter - actor.m_position; float distanceToClosestPoint = displacementToClosestPoint.CalcLength(); if( distanceToClosestPoint < actor.CalcRadius() ) { Vector2 desiredDisplacementFromClosestPoint = -displacementToClosestPoint; desiredDisplacementFromClosestPoint.SetLength( actor.CalcRadius() ); actor.m_position = closestPointInAreaToActorCenter + desiredDisplacementFromClosestPoint; } }
//----------------------------------------------------------------------------------------------- bool Scenario::IsActorAtAllInsideArea( Actor& actor, Area& area ) { Vector2 closestPointInAreaToActorCenter = FindClosestPointInBoundsToTarget( area.m_bounds, actor.m_position, true ); Vector2 displacementToClosestPoint = closestPointInAreaToActorCenter - actor.m_position; float distanceToClosestPoint = displacementToClosestPoint.CalcLength(); if( distanceToClosestPoint < actor.CalcRadius() ) { return true; } else { return false; } }