# rotation point

How can I move my rotation point?
Normaly I rotate around point(0,0,0)
That’s correct. When I want to change the
rotation point I first do glrotate and then gltranstate to the rotation point but then my object jumps to the rotation point.
I hope I explain this understandable.
Can anybody help me?

I would suggest you flip the order of your command bearing in mind that opengl works in reverse. So if you want to achieve a rotation about a non zero point then the sequence of commands need to be

glrotate …
gltranslate …
rendering commands etc.

At the moment I am assuming that you have the command sequence the other way round

to rotate around a point, using glTranslate and glRotate function, you have to:

C is the camera/object position
P is the point

compute the vector CP in local coordinates (camera/object)
translate using this vector
apply rotation
translate using -CP

Oops, the sequence should be

gltranslate back to where it was
glrotate
gltranslate rotation point to zero

I supposed with the following code it would work,
Z = the Z-value of the rotation

When I change the Z-value with my object in a certain angle
the rotation point is correct but my object jumps on the screen in Z-direction to the rotation point!

glTranslatef 0, 0, -Z
glRotatef xAngle, 0.5, 0, 0
glRotatef yAngle, 0, 0.5, 0
glRotatef zAngle, 0, 0, 0.5
glTranslatef 0, 0, Z
glScalef schaal, schaal, schaal

If you do a translation, a rotation and then a new Translation without drawing anything between, isn’t that the same as do the sum of the two translations in one translation and then rotate???

No. The sum of the two translations would be zero, anyway. You are moving away from the origin so that you can simulate a rotation about an arbitrary point, then moving the object back to its original location.

OK, but what’s the real solution to my problem?? I want to transfer, rotate and then change the rotation point, rotate again and so on without my object jumps when I change the rotation point!

Here is something that confuses people about rotation/translation, in openGL the last rotation/translation is acted on first.

example:

#1
glRotate
glTranslate

is not the same as

#2
glTranslate
glRotate

The first example we translate then rotate, which means the object is translated first from it’s origin then rotated. Note we always rotate around the worlds origin, but now the objects origin is no longer 0,0.
Example would be if you placed a string on the object with one end of the string tied to 0,0,0 and the other to the object moved out some distance from the origin. Then move the object along the path created by the string in a circular motion.

The second example we rotate first then translate the object. So now we have rotated the ball around it’s origin(0,0,0) and then moved it out to some point.

Let say we have a Cude and it’s origin is at one corner, we need to have it at the cubes center.

Our cude is 4 unit’s in size, so the center will be at 2 units. We difine our cube as one near lower corner is 0,0,0 and the far upper corner is 4,4,4.

glRotate( 15, 0, 1, 0);
glTranslate(-2,-2,-2); Move cude so origin is now at center
DrawCube( 4 );

What we have done is moved the cude so that is center is now located 0,0,0 of our world coords. Since all rotations are done around the worlds origin, the cube is now rotated around its center.

Now if you are doing this and it does not look correct them maybe you should post some of your code so we can see what you are doing.

Hope this helps.

Originally posted by fobru:
OK, but what’s the real solution to my problem?? I want to transfer, rotate and then change the rotation point, rotate again and so on without my object jumps when I change the rotation point!

A last, maybe stupid question, then I gone sleep over it!
Are the values of gltranslate and glrotate always absolute to the world center(0,0,0)
or relative to the last position of the object in the world??

World center. That’s why people translate the object, rotate it, and translate it back: It simulates rotation about its local (or any other arbitrary) axes.

Yes and NO, it can get a little tricky since the rotate and Translate calls are additive in the matrix.

example:

glTranslate( 5, 0, 0);
DrawObject(); // The object will be drawn at x = 5.

glTranslate( 6, 0, 0);
DrawObject(); //The object will be drawn at x = 11, not 6

Yes, everything is drawn relative to the origin of 0,0,0, but what happens are the objects get their origins change. An object after being tranlated or rotated is no longer at 0,0,0.

That is why when drawing with call things like glLoadIdentity and glPush/PopMatrix.

Look at the example again:

glTranslate( 5, 0, 0);
DrawObject(); // The object will be drawn at x = 5.

glTranslate( 6, 0, 0);
DrawObject(); //The object will be drawn this time at x = 6, not 11 becuase we cleared the matrix back to 0,0,0!!

Now this example has limitations in that camera function will not work well.
So we replace glLoadIdentity with glPush/PopMatix

glPushMatrix(); Save matrix
glTranslate( 5, 0, 0);
DrawObject(); // The object will be drawn at x = 5.
glPopMatrix(); Restore matrix to state before the glTranslate was called

glPushMatrix();
glTranslate( 6, 0, 0);
DrawObject(); //The object will be drawn at x = 6
glPopMatrix();

Hope this helps.

A last, maybe stupid question, then I gone sleep over it!
Are the values of gltranslate and glrotate always absolute to the world center(0,0,0)
or relative to the last position of the object in the world??
[/QUOTE]

If you want to rotate about a point with coordinates z then you should change the
-z in the first line to z
and z in the 5th line to -z

glTranslatef 0, 0, -Z
glRotatef xAngle, 0.5, 0, 0
glRotatef yAngle, 0, 0.5, 0
glRotatef zAngle, 0, 0, 0.5
glTranslatef 0, 0, Z
glScalef schaal, schaal, schaal