private static Single CalculateRotation(Single rotation, Single gamePadLeftX, Single gamePadLeftY, Boolean turnLeft, Boolean turnRight) { if (gamePadLeftX >= TURN_AXIS_DEADBAND || gamePadLeftX <= -TURN_AXIS_DEADBAND || gamePadLeftY >= TURN_AXIS_DEADBAND || gamePadLeftY <= -TURN_AXIS_DEADBAND) { Single desiredRotation = FloatMathHelper.Atan2(gamePadLeftY, gamePadLeftX); if (Math.Abs(rotation - desiredRotation) < TOP_TURN_SPEED) { rotation = desiredRotation; } else { if (FloatMathHelper.CounterClockwiseAngularDistance(rotation, desiredRotation) < FloatMathHelper.ClockwiseAngularDistance(rotation, desiredRotation)) { rotation -= TOP_TURN_SPEED; } else { rotation += TOP_TURN_SPEED; } } } else { if (turnLeft) { rotation -= TOP_TURN_SPEED * 0.5f; } else if (turnRight) { rotation += TOP_TURN_SPEED * 0.5f; } } return(MathHelper.WrapAngle(rotation)); }
private static Single CalculateRotation(Single currentRotation, Vector2 rotationVector, Single topTurningSpeed) { rotationVector.Normalize(); Single desiredRotation = FloatMathHelper.Atan2(rotationVector.Y, rotationVector.X); if (Math.Abs(currentRotation - desiredRotation) < topTurningSpeed) { currentRotation = desiredRotation; } else { if (FloatMathHelper.CounterClockwiseAngularDistance(currentRotation, desiredRotation) < FloatMathHelper.ClockwiseAngularDistance(currentRotation, desiredRotation)) { currentRotation -= topTurningSpeed; } else { currentRotation += topTurningSpeed; } } return(MathHelper.WrapAngle(currentRotation)); }