Wouldn't it make more sense to do something in the lines of:
```
rotate = fmod(rotate, 360.0f);
if (rotate < 0) {
    rotate += 360.0f 
}
```
here? The while loop looks a bit like a waste.