Rotation Interpolation
I know this is 2 years old, but I've recently been looking around for the same problem and I don't see an elegant solution without ifs posted in here, so here it goes:
shortest_angle=((((end - start) % 360) + 540) % 360) - 180;
return shortest_angle * amount;
that's it
ps: of course, % is meaning modulo and shortest_angle is the variable that holds the whole interpolation angle
Sorry, that was a bit convoluted, here's a more concise version:
public static float LerpDegrees(float start, float end, float amount)
{
float difference = Math.Abs(end - start);
if (difference > 180)
{
// We need to add on to one of the values.
if (end > start)
{
// We'll add it on to start...
start += 360;
}
else
{
// Add it on to end.
end += 360;
}
}
// Interpolate it.
float value = (start + ((end - start) * amount));
// Wrap it..
float rangeZero = 360;
if (value >= 0 && value <= 360)
return value;
return (value % rangeZero);
}
Anyone got a more optimised version?