/-----------------------------------/
/ Start core code
/-----------------------------------/
Snippet should be like this:
Code: Select all
// Try angles
void DOIT( float from, float to )
{
// Normalize
NormalizeAngle( from );
NormalizeAngle( to );
// Equal, do nothing
if( from == to ) return;
// max and min
float max = MAX(from, to);
float min = MIN(from, to);
// Differences
float difN = max - min;
float difI = (360 - max) + min;
// If normal is lower than inverse
if( difN <= difI )
if( from > to )
RotateLeft( from, to );
else
RotateRight( from, to );
else
if( from > to )
RotateRight( from, to );
else
RotateLeft ( from, to );
}
/ End core code
/-----------------------------------/
Where normalize could be like:
Code: Select all
// Normalize to interval 0 - 360
void NormalizeAngle( float& ang )
{
while( ang >= 360 ) ang -= 360;
while( ang < 0 ) ang += 360;
}
Code: Select all
// Rotates angle to the right (adding)
void RotateRight( float from, float to )
{
// Vars
float oFrom = from;
int stepsDone = 0;
// Step vars
float step = 1.0f;
bool stop = fabsf(from - to) < step;
// GO!
while( !stop ) {
// Add step
from += step;
// Normalize or maybe we wont get there
NormalizeAngle( from );
// Step done
++stepsDone;
// Continue?
stop = fabsf(from - to) < step;
}
}
// Rotates angle to the left (substracting)
void RotateLeft(float from, float to)
{
// Vars
float oFrom = from;
int stepsDone = 0;
// Step vars
float step = 1.0f;
bool stop = fabsf(from - to) < step;
// GO!
while( !stop ) {
// Substract step
from -= step;
// Normalize or maybe we wont get there
NormalizeAngle( from );
// Step done
++stepsDone;
// Continue?
stop = fabsf(from - to) < step;
}
}
