# gluLookAt and it's target vector

This topic is 2451 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey guys! I'm sure this will have been answered before, but I've not found a solution to my specific problem (either that or my searching skills aren't that good).

I'm using the following code to create a lookAt (target) vector:

 // Create a matrix to calculate the cameras new rotation. Matrix4f cameraTransformMatrix = new Matrix4f(); Matrix4f.rotate((float)Math.toRadians(xRotation), new Vector3f(1, 0, 0), cameraTransformMatrix, cameraTransformMatrix); Matrix4f.rotate((float)Math.toRadians(yRotation), new Vector3f(0, 1, 0), cameraTransformMatrix, cameraTransformMatrix); Matrix4f.rotate((float)Math.toRadians(zRotation), new Vector3f(0, 0, 1), cameraTransformMatrix, cameraTransformMatrix); // Multiply forward vector with a Matrix4x4 Vector4f rotatedForwardVector = Matrix4f.transform(cameraTransformMatrix, new Vector4f(0.0f, 0.0f, 1.0f, 1.0f), null); Vector3f finalTarget = new Vector3f(rotatedForwardVector.x, rotatedForwardVector.y, rotatedForwardVector.z); Vector3f.add(playerPosition, finalTarget, cameraLookAt);

This works when I'm facing forwards, but when I'm looking from behind, the up/down is swapped, and when looking from the side, the up/down causes the camera to rotate in a circle.

This code worked perfectly fine in XNA, but I'm wondering whether or not I'm producing the same output. Do I need to apply any changes to the 'Up' vector?

Thanks,
Matt.

Edit: Forgot to mention, I'm using LWJGL.

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 11
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013708
×