No, you only have to normalize the angles.
The easiest approach for that would be like this:
Code:
//deg2rad - angle unit conversion from degrees to radians
float normalize_angle( float a )
{
while( a < 0 ) a += deg2rad( 360 );
while( a >= 360 ) a -= deg2rad( 360 );
return a;
}
A bit more advanced code would be like this (I'm not sure that it works but it should
😀)
Code:
float normalize_angle( float a )
{
a = fmodf( a, deg2rad( 360 ) );
if( a < 0 ) a += deg2rad( 360 );
}
And for the fastest way to destination angle you'll have to look at three cases
1. src_angle -> dest_angle
2. src_angle -> dest_angle + 360 degrees
3. src_angle -> dest_angle - 360 degrees
find the shortest way of those -- abs( dest_angle_variation - src_angle )
and then use this code:
angular_velocity = ( dest_angle_variation - src_angle ) * turn_speed;
Now it should work..
😀