How can I rotate object around any point

Started by
4 comments, last by HopHopTraLaLaGdaltiBshAna 9 years, 6 months ago

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

Advertisement

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

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 .

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.

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.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

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

This topic is closed to new replies.

Advertisement