tags:

views:

83

answers:

3

I have this float which is a rotation angle.

Camera.roty += (float) diffx * 0.2;

where diff is the change in mouse position.

In OpenGL it will wrap it if it exceeds 360 or is below 0, but how could I do this if I want to verify if the angle is between 0 and 180?

Thanks

A: 

According to comment by @bta:

why not use:

angle % 180

and save that number as an angle?

Tomasz Kowalczyk
Mod doesnt work when its negetive
Milo
you could save information about the sign, abs() it, and then mod, at the end multiplying by sign.
Tomasz Kowalczyk
+2  A: 

To deal with floating-point values, you could do:

angle = angle - floor(angle / 360) * 360;

This should deal with negative values properly too (-1 would be converted to 359).

jamesdlin
Yay yours worked
Milo
+2  A: 

If I understand your question correctly you're basically looking for something like this?:

float Wrap( const float Number, const float Max, const float Min ) {
 if( Number > 0.0f ) {
  return fmod( Number, Max ) + Min;
 }
 else {
  return Max - fmod( abs( Number ), Max ) + Min;
 }
}
Jacob
only works clockwise, if the number is < 0, its not working
Milo