FMath.DegToRad(): use look-up table.

GitOrigin-RevId: 2dab2e175cf99448595304eeb7593bf499485273
This commit is contained in:
Colin McMillen 2020-02-15 15:14:44 -05:00
parent 24078d6c62
commit a21802e9f2

View File

@ -19,8 +19,24 @@ namespace SemiColinGames {
public static class FMath { public static class FMath {
public const float PI = (float) Math.PI; public const float PI = (float) Math.PI;
public static float DegToRad(float degrees) { private static float[] degToRad = new float[360];
return PI / 180 * degrees;
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) { public static float Sin(double degrees) {