I\'m working on a simple rotate routine which normalizes an objects rotation between 0 and 360 degrees. My C# code seems to be working but I\'m not entirely happy with it. Can a
I'd recommend making separate function for normalizing angle - it's a cleaner solution.
public static float NormalizeEulerAngle(float angle){
var normalized = angle % 360;
if(normalized < 0)
normalized += 360;
return normalized;
}
Fiddle proving that such function works as intended: https://dotnetfiddle.net/Vh4CUa
And then you can use it like here:
public void Rotate(int degrees){
orientation = NormalizeEulerAngle(orientation + degrees);
}