I want to rotate my "camera" around a point of interest. Currently the camera only rotates around the origin.

A lot of tutorials suggest to use following scheme:

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.

I suspect that I'm using the translation vector wrong, resulting in the above sequence of operations to fail.

Is there any thing I can else check?

Edit: This is how the quaternion rotation works:

// calculate rotation axis QVector3D rotationAxis = QVector3D(diff.y(), diff.x(), 0.0).normalized(); // update rotation see http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation accumulatedQuaternionRotation = QQuaternion::fromAxisAndAngle(rotationAxis, diff.length()/4.0f) * accumulatedQuaternionRotation;

diff is simply the difference of two mouse move event points.