#### Archived

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

# More rotations.

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

## Recommended Posts

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 on other sites
Come on. Someone must know this.

##### Share on other sites
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 on other sites
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 on other sites
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 on other sites
The rotations are made in model space so the rotation is around the models coordinate origin which happens to be in the wrong position.

##### Share on other sites
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 on other sites
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?

##### Share on other sites
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...

• 10
• 16
• 14
• 18
• 15