Quote:
float normalize_angle( float a )
{
while( a < 0 ) a += deg2rad( 360 );
while( a >= 360 ) a -= deg2rad( 360 );
return a;
}
{
while( a < 0 ) a += deg2rad( 360 );
while( a >= 360 ) a -= deg2rad( 360 );
return a;
}
Isn't this code wrong? shouldn't the 360 in "a >= 360" be deg2rad(360)?
EDIT: As always, my knowledge of 2d math is a standstill for this. I'm not good with theories, since I don't know trig or anything offhand.
Code:
inline void DoBulletAngling (BulletBody *B)
{
float dest_angle = atan2( B->PhysicsBody->GetLinearVelocity().y, B->PhysicsBody->GetLinearVelocity().x );
// Find the shortest variation
float var1 = (abs(dest_angle - B->PhysicsBody->GetAngle()));
float var2 = (abs((dest_angle + DEG2RAD(360)) - B->PhysicsBody->GetAngle()));
float var3 = (abs((dest_angle - DEG2RAD(360)) - B->PhysicsBody->GetAngle()));
if (var1 < var2 && var1 < var3)
B->PhysicsBody->SetAngularVelocity (( var1 - B->PhysicsBody->GetAngle() ) * 4);
else if (var2 < var1 && var2 < var3)
B->PhysicsBody->SetAngularVelocity (( var2 - B->PhysicsBody->GetAngle() ) * 4);
else if (var3 < var1 && var3 < var2)
B->PhysicsBody->SetAngularVelocity (( var3 - B->PhysicsBody->GetAngle() ) * 4);
}
{
float dest_angle = atan2( B->PhysicsBody->GetLinearVelocity().y, B->PhysicsBody->GetLinearVelocity().x );
// Find the shortest variation
float var1 = (abs(dest_angle - B->PhysicsBody->GetAngle()));
float var2 = (abs((dest_angle + DEG2RAD(360)) - B->PhysicsBody->GetAngle()));
float var3 = (abs((dest_angle - DEG2RAD(360)) - B->PhysicsBody->GetAngle()));
if (var1 < var2 && var1 < var3)
B->PhysicsBody->SetAngularVelocity (( var1 - B->PhysicsBody->GetAngle() ) * 4);
else if (var2 < var1 && var2 < var3)
B->PhysicsBody->SetAngularVelocity (( var2 - B->PhysicsBody->GetAngle() ) * 4);
else if (var3 < var1 && var3 < var2)
B->PhysicsBody->SetAngularVelocity (( var3 - B->PhysicsBody->GetAngle() ) * 4);
}
I'm missing something. I can't see in your previous example where you get the derivative from or what -> is implying
-P