Jump to content
  • Advertisement
Sign in to follow this  
HopHopTraLaLaGdaltiBshAna

How can I rotate object around any point

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I had understood the rotaion transformation , but this transformation rotate the object around (0,0), I would like to choose this point and rotate object in any position around his middle that I alrady have , so how can I rotate any object in any position around any point I would like

Share this post


Link to post
Share on other sites
Advertisement

Translate that point to the origin and do your rotation there instead, then translate back to the original position.

 

it is not a only point , it is a triangle, segment, polygon, and I cant place it that (0,0) will be the middle of that objects , so move it every time isnt good soloution .

Share this post


Link to post
Share on other sites

I don't understand your issue with translating. If you want to rotate around a triangle's or object's center, then translate that center to the origin and rotate the triangle or object there. That is: subtract the point or rotation from all vertices, rotate, and finally add the point of rotation back to the rotated vertices. That can easily be achieved with matrices, for example, by multiplying a translation matrix, a rotation matrix and an inverse translation matrix (the inverse translation of the first matrix). Then multiply your vertices by that final matrix product.

Share this post


Link to post
Share on other sites

start with your mesh specified in local coordinates - IE the origin is in the middle of your object (or where ever you want it in relation to your object). this origin will be the point around which the object rotates. now, build your transform matrix to rotate it, then translate it to its world position. IE for 2 degrees of rotational freedom,  create an x rotation matrix, concatenate on a y rotation matrix, then concatenate on a translation matrix that moves the object's origin to its proper location in the world. the result is your world transform matrix for that object for that frame (and any subsequent frames until the object moves or rotates). when the object moves or rotates, you calculate a new world transform matrix for it.

 

there are 2 general approaches:

 

1. simply calculate the world transform matrix for each object each time you draw, as you draw. ok, unless you have LOTS of objects.

 

2. calculate and store the world transform matrix, and flag it as "dirty" when the object moves or rotates. when its time to draw, if its flagged as "dirty", recalculate the world transform matrix (and store it) before drawing, else use the stored world transform matrix. this recalculates the world matrix only when needed. an optimization for dealing with LOTS of objects.

Share this post


Link to post
Share on other sites

I don't understand your issue with translating. If you want to rotate around a triangle's or object's center, then translate that center to the origin and rotate the triangle or object there. That is: subtract the point or rotation from all vertices, rotate, and finally add the point of rotation back to the rotated vertices. That can easily be achieved with matrices, for example, by multiplying a translation matrix, a rotation matrix and an inverse translation matrix (the inverse translation of the first matrix). Then multiply your vertices by that final matrix product.

 

Thanks you very much its works :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!