diff --git a/Shared/Geometry.cs b/Shared/Geometry.cs index b5a22e5..58e1eff 100644 --- a/Shared/Geometry.cs +++ b/Shared/Geometry.cs @@ -19,8 +19,24 @@ namespace SemiColinGames { public static class FMath { public const float PI = (float) Math.PI; - public static float DegToRad(float degrees) { - return PI / 180 * degrees; + private static float[] degToRad = new float[360]; + + static FMath() { + for (int i = 0; i < degToRad.Length; i++) { + degToRad[i] = PI / 180 * i; + } + } + + // Converts degrees to radians using a look-up table. Expects the input to be near [0, 360) + // and will loop for potentially a long while if that's not the case. + public static float DegToRad(int degrees) { + while (degrees < 0) { + degrees += 360; + } + while (degrees >= 360) { + degrees -= 360; + } + return degToRad[degrees]; } public static float Sin(double degrees) {