Hi all, I've been trying to make a 3D camera using Euler angles and I've been getting some unexpected results. I'm using LWJGL and I've plotted out a very basic flat scene to test whether the camera's working properly. I used the algorithm at the end of the FAQ question below to create and multiply the 3 rotation matrices X, Y and Z.

http://www.cs.princeton.edu/~gewang/projects/darth/stuff/quat_faq.html#Q36To transform to the perspective of the rotated viewport I have the method below:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public void transform(Player player) { float xcos = (float) Math.cos(Math.toRadians(xrot)); float xsin = (float) Math.sin(Math.toRadians(xrot)); float ycos = (float) Math.cos(Math.toRadians(yrot)); float ysin = (float) Math.sin(Math.toRadians(yrot)); float zcos = (float) Math.cos(Math.toRadians(zrot)); float zsin = (float) Math.sin(Math.toRadians(zrot)); float[] mat = new float[16]; mat[0] = ycos * zcos; mat[1] = -ycos * zsin; mat[2] = ysin; mat[4] = xsin * ysin * zcos + xcos * zsin; mat[5] = -xsin * ysin * zsin + xcos * zcos; mat[6] = -xsin * ycos; mat[8] = -xcos * ysin * zcos + xsin * zsin; mat[9] = xcos * ysin * zsin + xsin * zcos; mat[10] = xcos * ycos; mat[3] = mat[7] = mat[11] = mat[12] = mat[13] = mat[14] = 0.0f; mat[15] = 1.0f; GL11.glMultMatrix((FloatBuffer) BufferUtils.createFloatBuffer(16).put(mat).flip()); } |

With xrot, yrot and zrot being the rotation angles in degrees. I have some other methods that just add to these values to add/subtract from the angles.

The results are fairly hard to describe. When I only change one rotation angle the scene seems to rotate correctly, but when I add a second the scene seems to spiral out of control. Can anyone spot any errors that I've made?

Thanks