Hey Lost,

You need to understand how the OpenGL pipeline works.

Your object coordinates get post-multiplied by the current model view matrix. Meaning:

(X’, Y’, Z’, W’) = [current_model_view_matrix] * (X, Y, Z,W)

where X,Y, Z and W are the coordinates of your object and X’, Y’, Z’ and W’ are the actual coordinates that get drawn on the screen (this is not entirely true as they get post-multiplied by the projection matrix and etc, but for now we can just ignore that.

So in order to rotate/translate/scale an object, all you have to do is modify the [current_model_view_matrix]. A call to glRotate*, glTranslate* or glScale* will positmultiply the [current_model_view_matrix] by the appropiate transformation matrix. For example,

[current_model_view_matrix] = [current_model_view_matrix] * [rotation_matrix]

or

[current_model_view_matrix] = [current_model_view_matrix] * [translation_matrix]

or

[current_model_view_matrix] = [current_model_view_matrix] * [scaling_matrix]

so what happens when you call glRoate*() and then glTranslate*()?

[current_model_view_matrix] = [current_model_view_matrix] * [rotation_matrix]

then

[current_model_view_matrix] = [current_model_view_matrix] * [translation_matrix]

the end result is

[current_model_view_matrix] = [current_model_view_matrix] * [rotation_matrix] * [translation_matrix]

the net effect is that you 1st translate (move) the object to some location and the rotate it. Now rotation in either direction is a rotation about that axis. If you call glRoate(current_angle,1.0,0.0,0.0) you are rotating the object about the x axis. Now if you have translated your object say for 5 units, this will cause your object to move in a circular path with centre (0.0,0.0,0.0) and radius 5.0.

But what you want is:

[current_model_view_matrix] = [current_model_view_matrix] * [translation_matrix] * [rotation_matrix]

In this case you 1st rotate the object and then translate it. Always remember this, matrices always work from right to left.

How do you avoid this? there are to solutions:

If you want to premultiply rotation and then translation

- Translate your object back to (0.0,0.0,0.0)
- Rotate it
- Translate it back to the previous location.

Use post multiply, but reconstruct your [current_view_matrix] everytime you do a transformation. In this case you do ALL the rotations 1st, then ALL the translations and finally all the scales.

Hope this helps,

Rizo

[This message has been edited by Rizo (edited 02-15-2001).]