Simple rotation and translation order question!

Hi,

I’ve made a 3D world, and in order to view that world from the right position and angle, I use the following:

gl.glLoadIdentity();
Matrix lookAt = Matrix.lookAt(direction,up);
gl.glMultMatrixd(lookAt.columnMajor(),0);
gl.glTranslated(-position.x,-position.y,-position.z);

Which works perfectly well.

However, it seems to me that this appears to be the wrong way around, and that I should really be translating the world so that the viewing position is at the origin, and then rotating the world in the correct direction, ie. translation and then rotation, instead of rotation then translation.

I’m sure I’m just missing something really obvious, but can anyone explain what’s going on?

Cheers,
Chris.

Are you wondering why it works or what is your problem ?

Transformation matrix are staked. So the first transformation applied is the lastest matrix added.

—> The stake ;D
V’ = Rot * Trans * V

Ok, I get it now, thanks!

I expect you’re working the MODELVIEW matrix for the camera here.

the MODELVIEW matrix, is a combination of 2 matrices: MODEL and VIEW

In the MODEL matrix you first translate, then rotate (the translate shifts the origin, and you rotate around the new origin)

In the VIEW matrix, you basicly reverse everything, becase as you move forward, you basicly shift the whole MODEL-space backward. Same for rotations and any other transformations.

So: while you’re transforming for the camera, reverse all your operations, and in the modeltransformations, do it in the ‘logical’ order.