#### Archived

This topic is now archived and is closed to further replies.

# Rotating objetcs around their center

This topic is 5582 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have tried to rotate a mesh using glrotatef(), but using gltranslate also. So the mesh is rotating aroung the center of the world, 0,0,0, but I need to make it rotate around his own center how do I do that?

##### Share on other sites
Be sure to have your transformations in the roght order.
First translating then rotating won''t give you the same result as first rotating and then translating.

Indeed, if you recall from Linear Algebra, A * B != B * A where A and B are 2 matrices.

##### Share on other sites
Actually that worked pretty well!
I was going to try but tought that it wouldn''t solve anything... guess what I was wrong. Next time I''ll try everything even if it sounds stupid in my head.

##### Share on other sites
If you''re not that familiar with Linear Algebra (i.e. Matrices, Vectors, Transformations etc...) I''d recommend getting a book about it. because you''re gonna use it a lot when doing 3D stuff.
Or you can search the web for references about it. I''m sure you can find lots of stuff around. Believe me, it''s damn usefull

##### Share on other sites
The way to think of it is that the matrix operations take place in the opposite order from the order you called them, so you''ll generally want to translate first and rotate last (if the rotation is meant to be around the objects own origin).

Marijn

##### Share on other sites
--- Is dumbfounded by the idea that A*B != B*A ---

##### Share on other sites
quote:

Original post by zackriggle
--- Is dumbfounded by the idea that A*B != B*A ---

Instead of trying to explain it, here''s an example...

let A = [1 2] &        [3 4]let B = [5 6]        [7 8]             A * B != B * A     [1 2] * [5 6] != [5 6] * [1 2]     [3 4]   [7 8]    [7 8]   [3 4] [1*5+2*7 1*6+2*8] != [5*1+6*3 5*2+6*4] [3*5+4*7 3*6+4*8]    [7*1+8*3 7*2+8*4]           [19 22] != [23 34]           [43 50]    [31 46]

##### Share on other sites
Easy!!!!

Let''s say that your mesh is in coordinate [1,2,3], so:

glTranslatef(-1,-2,-3);// put our mesh on the center of the world
glRotate...; // rotate the mesh
glTranslatef(1,2,3);// back to the right position

• 41
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631371
• Total Posts
2999614
×