Browse Source

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

GitOrigin-RevId: 2dab2e175c
master
Colin McMillen 4 years ago
parent
commit
a21802e9f2
  1. 20
      Shared/Geometry.cs

20
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) {

Loading…
Cancel
Save