PDA

View Full Version : Rotate camera around point-of-interest in opengl



anopheles
01-14-2013, 04:20 AM
I want to rotate my "camera" around a point of interest. Currently the camera only rotates around the origin.

The standard way:



translate(-P)
rotate
translate(P)

Unfortunately, this doesn't work. My application uses a translation vector (QVector3D) as well as a quaternion (QQuaternion) to save translation and rotation of the camera.


Currently, it is done like this, which always rotates around the origin:




glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(translation.x(),translation.y(), translation.z());
multMatrix(accumulatedQuaternionRotation);


where mulMatrix uses the Quaternion to build a 4x4 matrix which is passed to glMultMatrixf();


Using something like this:




glTranslatef(-translation.x(),-translation.y(), -translation.z());
multMatrix(accumulatedQuaternionRotation);
glTranslatef(translation.x(),translation.y(), translation.z());


results in very weird controls which I'm unable to describe further. In my application translation.z() means: move the camera forward. Changing x() and y() issues a pan like operation.

Help is greatly appreciated. :)

tonyo_au
01-14-2013, 04:48 AM
You have to think about what is happening to you lookat point as well as the camera. Your lookat will also rotate

anopheles
01-14-2013, 08:57 AM
How do I prevent the lookAt from also rotating? I really don't even know where to start to look where my problem is.

tonyo_au
01-16-2013, 01:12 AM
You don't want to prevent it you want to ensure it happens - I would try calculating a new eye and lookat target for your rotation and call gluLookAt