package gl_engine; import gl_engine.vec.Vec2d; import gl_engine.vec.Vec3d; public class MathHelpers { public static final double FallSpeed = 0.00098; private static double[] TRIG_SIN_VALUES = null; private static double[] TRIG_ASIN_VALUES = null; public static final double PI = 3.1415926535897932384626; public static final double TWO_PI = PI * 2; public static final double HALF_PI = PI / 2; public static void init() { // Initialize by default with 8 MB of trig values init(1048576); } public static void init(int size) { TRIG_SIN_VALUES = new double[size]; TRIG_ASIN_VALUES = new double[size]; for(int i=0;i 1) return Double.NaN; return TRIG_ASIN_VALUES[(int)((a + 1) / (2 * TRIG_ASIN_VALUES.length))]; } public static double acos(double a) { return HALF_PI - asin(a); } public static double atan(double a) { return Math.atan(a); } public static double atan2(double y, double x) { if(x > 0) return tan(y / x); if(x < 0) { if(y >= 0) return tan(y / x) + PI; if(y < 0) return tan(y / x) - PI; }; if(x == 0) { if(y > 0) return HALF_PI; if(y < 0) return -HALF_PI; } return Double.NaN; } public static double sqrt(double a) { return Math.sqrt(a); } public static double nextPowerOf(double x, double n) { double i = 1; while(i < x) { i *= n; } return i; } public static int nextPowerOf(double x, int n) { int i = 1; while(i < x) { i *= n; } return i; } public static double squared(double x) { return x*x; } public static double pow(int c, double x) { double res = 1; for(int i=0;i b) return a; else return b; } public static double smallest(double a, double b) { if(a < b) return a; else return b; } }