Can someone tell me why my camera class isn't working correctly? I set the position vector to (0,0,-10) and the look at vector to (0,0,0) but when I draw something on (0,0,0) it isn't there. I'm very new to vector math and matrix stuff, so I'm betting it's LookThrough() where the problem is.
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| import org.lwjgl.opengl.GL11; import org.lwjgl.util.vector.Matrix3f; import org.lwjgl.util.vector.Vector3f; public class Camera { Vector3f position = null; Vector3f lookAt = null; float yaw = 0; float pitch = 0; float roll = 0; public Camera(float x, float y, float z) { position = new Vector3f(x, y, z); lookAt = new Vector3f(); } public void lookThrough() { Matrix3f m = new Matrix3f(); Vector3f out = new Vector3f(); Vector3f.sub(position, lookAt, out); out.normalise(); m.m00 = out.x; m.m01 = out.y; m.m02 = out.z; m.m10 = 1; m.m11 = 0; m.m12 = 0; m.m20 = 0; m.m21 = 1; m.m22 = 0; yaw = (float) -(Math.tan(m.m10/m.m00)); pitch = (float) -(Math.tan((-m.m20)/(Math.sqrt(Math.pow(m.m21, 2) + Math.pow(m.m22, 2))))); roll = (float) -(Math.tan(m.m21/m.m22)); GL11.glRotatef(pitch, 1.0f, 0.0f, 0.0f); GL11.glRotatef(yaw, 0.0f, 1.0f, 0.0f); GL11.glRotatef(roll, 0.0f, 0.0f, 1.0f); GL11.glTranslatef(position.x, position.y, position.z); } } |