Jump to content
  • Advertisement
Sign in to follow this  
MattCa

gluLookAt and it's target vector

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

If you intended to correct an error in the post then please contact us.

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.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!