How can I rotate object around any point

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

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 on other sites

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

Share on other sites

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 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 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 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 :)

1. 1
2. 2
3. 3
Rutin
14
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• Forum Statistics

• Total Topics
633672
• Total Posts
3013272
×