Sign in to follow this  

Camera rotation problem

This topic is 3491 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 have a function that rotates the 'lookat' position of my view settings (a 3 vector tuple that holds the eye, lookat & up vectors) to be used with gluLookAt. Effectively, this means that the virtual 'camera' is able to look left and right in the scene, with the actual 'eye' position remaining fixed. The function looks like this: void RotateLocalY(LookAt& viewSettings, float rAmount ) { // Determine rotation matrix about the up vector Matrix44 rotationMatrix; RotationMatrix(rotationMatrix, rAmount, viewSettings.up.rX, viewSettings.up.rY, viewSettings.up.rZ); // Temporary look-at vector holds changes before being applied to actual vector Vertex newVector; // Multiply vector by rotation matrix (w component is ignored) newVector.rX = rotationMatrix[0] * viewSettings.lookAt.rX + rotationMatrix[4] * viewSettings.lookAt.rY + rotationMatrix[8] * viewSettings.lookAt.rZ; newVector.rY = rotationMatrix[1] * viewSettings.lookAt.rX + rotationMatrix[5] * viewSettings.lookAt.rY + rotationMatrix[9] * viewSettings.lookAt.rZ; newVector.rZ = rotationMatrix[2] * viewSettings.lookAt.rX + rotationMatrix[6] * viewSettings.lookAt.rY + rotationMatrix[10] * viewSettings.lookAt.rZ; // Store result memcpy(&viewSettings.lookAt, &newVector, sizeof(Vertex)); } ... with gluLookAt being called like this: // Perform 'camera' transform // Note that the 'lookat' position is being treated as relative to the eye // (camera origin) and so is added to it gluLookAt(viewSettings.eye.rX, viewSettings.eye.rY, viewSettings.eye.rZ, viewSettings.eye.rX + viewSettings.lookAt.rX, viewSettings.eye.rY + viewSettings.lookAt.rY, viewSettings.eye.rZ + viewSettings.lookAt.rZ, viewSettings.up.rX, viewSettings.up.rY, viewSettings.up.rZ); I want to be able to do a very similar thing with another function that moves the 'eye' position instead, giving the impression that the camera is rotating about a point. How could I do this using a similar approach to above? It seems like I should be able to perform the actual rotation calculation in a similar fashion, but update the eye position instead of the lookat position. Please note that I definitely want to update the view settings along with gluLookAt, rather than performing the inverse glRotate and glTranslate functions on the scene instead. Alternatively, I could take a more 'conventional' approach by determining the vector running from the lookat to the eye position, translate this to the origin, perform the rotation, and translate back. So far my attempts have been fruitless. Thanks for any assistance!

Share this post


Link to post
Share on other sites

This topic is 3491 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this