This project has moved. For the latest updates, please go here.

setting Settings.MaxRotation

Dec 6, 2011 at 7:47 PM
Edited Dec 7, 2011 at 10:41 PM

I'm having a problem with Body.Rotation.  I'm doing math with angles, and it's troublesome when Body.Rotation is not constrained between (-PI and PI).

Solution 1:

Set Settings.MaxRotation=Math.PI.

Unfortunately, it cannot be set, and doesn't make any mention of what happens on MinRotation.

Why is not constrained in the first place?


Solution 2:

To try to solve this, I use MathHelper.WrapAngle(Body.Rotation). For reason, it doesn't actually WrapAngle until it's already made like, 4 incorrect calculations.


To test the code I'm thinking of:


float Rotation1=MathHelper.WrapAngle(Body.Rotation);
float Rotation2=(float)Math.Atan2(Mouse.Y - Body.Y, Mouse.X - Body.X);
//Rotation2 is the direction from Body to Mouse.

float CalcRotation=MathHelper.Lerp(Rotation1,Rotation2,.6);
//weight can be any number, (0,1) noninclusive.

From here, you can draw a line from
(0,0) to (100,CalcRotation) //polar coordinates

Create a second body, whose Rotation is CalcRotation

Draw text of CalcRotation

Either way, you'll see that there is a lapse when the incorrect Body.Rotation is used when it jumps from -PI to PI.



Thanks for the help