Archived

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

Mr Cucumber

More rotations.

Recommended Posts

Mr Cucumber    122
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?

Share this post


Link to post
Share on other sites
Mezz    571
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

Share this post


Link to post
Share on other sites
X-Man    122
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.



Share this post


Link to post
Share on other sites
Bad Monkey    145
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...

Share this post


Link to post
Share on other sites
X-Man    122
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...

Share this post


Link to post
Share on other sites
X-Man    122
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...

Share this post


Link to post
Share on other sites