Angles arithmetics that drive me crazy!
Page 1 of 1
LeoNatan
Banned



Posts: 73193
Location: Ramat Gan, Israel 🇮🇱
PostPosted: Mon, 22nd Sep 2008 02:56    Post subject: Angles arithmetics that drive me crazy!
OK, so I'm sure this is something small and stupid I'm somehow missing, but this things just drives me crazy, and I'm too tired to figure it out... Sad

This is the problematic part (I think):
Code:
if(Angle != NewAngle)
   Rotate(0, DirRotate * min(dist / 10, fabs(NewAngle - Angle)) , 0);


Angle and NewAngle are members of a class, Angle holds the current angle of the shape, while NewAngle is the angle I want the shape to be in. DirRotate is the direction the rotation should occur in (this one is calculated correctly). Dist is the distance I want the shape to move in {X,Z} according to the angle the shape is in. Before it moves, it rotates toward NewAngle. Obviously, the rotation will be around the Y axis.

The Rotate method:
Code:
void ComplexShape::Rotate(double x, double y, double z)
{
   Angle = MathHelper::MakeAngle(Angle + y);

   Shape::Rotate(x, y, z);
}

MakeAngle just fixes the angle to be between 0 and 360 degrees.

Well, the problem is that when NewAngle is 0, the shape just rotates and rotates and rotates. I use min(dist / 10, fabs(NewAngle - Angle)) to determine how much to rotate the shape each iteration (something like animation), but I think fabs(NewAngle - Angle) is the problem.

Any sort of help will be very appreciated!
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Programmers Corner
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group