Skip to content

Instantly share code, notes, and snippets.

@eriksk
Created June 10, 2015 18:32
Show Gist options
  • Save eriksk/e5e588f4c043aeaacf4c to your computer and use it in GitHub Desktop.
Save eriksk/e5e588f4c043aeaacf4c to your computer and use it in GitHub Desktop.
public const float PiOverTwo = (float)Math.PI * 2f;
public static float SLerp(float x, float y, float amount)
{
float diff = (float)Math.Abs(y - x);
if (diff > Math.PI)
{
if (y > x)
x += PiOverTwo;
else
y += PiOverTwo;
}
float value = (x + ((y - x)*amount));
if (value >= 0f && value <= PiOverTwo)
return value;
return (value % PiOverTwo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment