Reputation: 54133
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
Upvotes: 0
Views: 1621
Reputation: 3686
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;
}
}
Upvotes: 2
Reputation: 90085
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).
Upvotes: 1
Reputation: 10467
According to comment by @bta:
why not use:
angle % 180
and save that number as an angle?
Upvotes: 0