1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| public void updateCamera() { Quat4f rotation = new Quat4f(); AxisAngle4f axisAngleX = new AxisAngle4f(cameraX.x, cameraX.y, cameraX.z, (float)Math.toRadians(angleX)); AxisAngle4f axisAngleY = new AxisAngle4f(cameraY.x, cameraY.y, cameraY.z, (float)Math.toRadians(angleY)); Quat4f quatXRotation = new Quat4f(); Quat4f quatYRotation = new Quat4f(); quatXRotation.set(axisAngleX); quatYRotation.set(axisAngleY); rotation.mul(quatYRotation, quatXRotation); rotation.normalize(); Matrix4f newViewMatrix = new Matrix4f(); newViewMatrix.set(rotation); newViewMatrix.transpose(); float[] rotationMatrixArray = new float[] { newViewMatrix.m00, newViewMatrix.m01, newViewMatrix.m02, 0, newViewMatrix.m10, newViewMatrix.m11, newViewMatrix.m12, 0, newViewMatrix.m20, newViewMatrix.m21, newViewMatrix.m22, 0, 0, 0, 0, 1 };
gl.glLoadIdentity(); glu.gluPerspective(60.0, 800/600, 2.0, 500.0f); gl.glTranslatef(cameraPosition.x, cameraPosition.y, cameraPosition.z); gl.glMultMatrixf(rotationMatrixArray); } |