public static void setCamera(Camera cam) { setPerspective(cam.aspect, cam.fov, cam.znear, cam.zfar); view = Matrix.scale(0.1f, -0.1f, 0.1f); view = Matrix.mul(view, Matrix.rotate(cam.getAngles().x, 1, 0, 0)); view = Matrix.mul(view, Matrix.rotate(cam.getAngles().y, 0, 1, 0)); view = Matrix.mul(view, Matrix.rotate(cam.getAngles().z, 0, 0, 1)); view = Matrix.mul(view, Matrix.translate(cam.getWorldX(), cam.getWorldY(), cam.getWorldZ())); glLoadMatrixf(view.get()); }
public static void setOrtho() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); float l = -Runtime.screen_width / 2f; float r = -l; float b = -Runtime.screen_height / 2f; float t = -b; float zn = -1; float zf = 1; float[] m = new float[16]; m[0] = 2f / (r - l); m[1] = 0; m[2] = 0; m[3] = 0; m[4] = 0; m[5] = 2f / (b - t); m[6] = 0; m[7] = 0; m[8] = 0; m[9] = 0; m[10] = 2f / (zf - zn); m[11] = 0; m[12] = (l + r) / (l - r) + (l * m[0]); m[13] = (t + b) / (b - t) + (b * m[5]); m[14] = (zf + zn) / (zn - zf); m[15] = 1; projection.set(m); glLoadMatrixf(projection.get()); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
public static void setPerspective(float aspect, float fov, float znear, float zfar) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); float f = 1f / (float) Math.tan(Math.toRadians(fov) / 2f); float zrange = znear - zfar; float[] m = new float[16]; m[0] = f / aspect; m[1] = 0; m[2] = 0; m[3] = 0; m[4] = 0; m[5] = f; m[6] = 0; m[7] = 0; m[8] = 0; m[9] = 0; m[10] = (zfar + znear) / zrange; m[11] = (zfar * znear) / zrange; m[12] = 0; m[13] = 0; m[14] = -1f; m[15] = 1; projection.set(m); glLoadMatrixf(projection.get()); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
public static void refreshView() { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadMatrixf(view.get()); }