# Camera rotation problem

This topic is 3833 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 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!

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633410
• Total Posts
3011726
• ### Who's Online (See full list)

There are no registered users currently online

×