More rotations.

Started by
7 comments, last by Mr Cucumber 23 years, 9 months ago
I know how to rotate an object around the world origin and how to rotate an object around it self. What I don''t know is how to rotate an object around a certain point in world space. Could anyone help me with that?
Advertisement
Come on. Someone must know this.
I can explain one way to do it, I''m not sure it''s the only way, but here we go.
I''m assuming your familiar with matrices.

You essentially have to move the arbitrary point back to the origin and then apply your rotation matrix (or the other way round, depending on your chosen form of matrix) so you multiply these together and then transform your object with this matrix.

It''s hefty work, and there is probably a better way. Infact there is, because thatonly works for coaxial planar rotations. Shit. Hopefully it will be some help in getting the full answer.

-Mezz
I think this is right...

The object(vertices thereof) and the center-of-rotation need to be transformed so that the center is at 0,0,0. Rotation is applied, which causes rotation about the origin and the object is transformed back using the opposite (-dx,-dy,-dz) of the original transform.



Hi Mr Cucumber,

Sorry if this is totally redundant (I only skimmed the other answers and decided to post anyway).
Put very simply, to rotate around any given point, translate to that point (so this effectively becomes the origin), apply your rotations, and then reverse the translation to go back to your original start point (or just pop the matrix stack... sorry, I''m an OpenGL man )

You''ve been doing it all along (when you make an object ''rotate around itself'', you''re just doing rotation around an arbitary point (the centre of the object) )

-------------
squirrels are a remarkable source of protein...
The rotations are made in model space so the rotation is around the models coordinate origin which happens to be in the wrong position.
Find the x,y,z difference between the model origin and the desired center-of-rotation and add(subtract?) it to all the model vertices...
That''s what I thought I could do but that would be pretty slow especially if I wan''t to change the model every frame.
Is there no other solution?
If you can''t pre-translate the vertices at load time, I guess the only option is to do it with every frame. Incorporating it as part of the geometry pipeline might be quicker than vertex accessing, cause you can combine multiple matrices (translate, rotate-X, resize, etc) into one.

BTW, Witchlord''s "Building a World" tutorial is pretty good if you''re unsure of matrices. Also checkout the SDK docs on Geometry Pipeline:Setting up a World matrix; - Then view \mssdk\samples\multimedia\d3dim\src\d3dframe\d3dutil.cpp to see how it''s done. Good luck...

This topic is closed to new replies.

Advertisement