# Thread: rotation point

1. ## 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?

2. ## Re: rotation point

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

3. ## Re: rotation point

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

4. ## Re: rotation point

Oops, the sequence should be

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

5. ## Re: rotation point

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

6. ## Re: rotation point

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???

7. ## Re: rotation point

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.

8. ## Re: rotation point

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!

9. ## Re: 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!

10. ## Re: 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??

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•