Rotating objetcs around their center
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?
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.
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.
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.
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.
Glad I could help.
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
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
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
Marijn
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]
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement