• Create Account

We need 7 developers from Canada and 18 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a \$50 Amazon gift card. Click here to get started!

# Turn Object around Point

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Johannes1991  Members   -  Reputation: 433

Like
0Likes
Like

Posted 26 October 2011 - 07:06 AM

I've been trying to rotate a box around a certain point (for the purpose of angular velocity). I Know how to rotate the mesh around a point by changing the origo in mesh space, but the problem is that the i don't know how to rotate the Position variable too. Because if i change the rotation point(and the mesh origor) then the box "jumps" so the new origo in mesh space.

Here's a pic for further explanation:

The Plus is the Box Mesh Origo and the red circle is the Rotation Point.

EnJOJ Gaming

### #2clb  Members   -  Reputation: 2064

Like
0Likes
Like

Posted 26 October 2011 - 11:25 AM

To rotate an object around the origin, generate the primitive rotation matrix M e.g. by axis and angle, from one of the conventions for Euler angles, from a quaternion, etc. To adjust M to rotate about an axis that contains the given point P on the rotation axis, translate the vector space origin to the point P, then perform the rotation, and finally translate back, i.e. M' = T(P) * M * T(-P), where the matrix T(x) translates by x.

Use the resulting matrix M' to transform the coordinate frame of the box. If your box is represented by a center point and three direction vectors, e.g. like OBB here, then remember to use the transformation matrix M' to transform the pivot point of the OBB as a point vector, and the axes of the box as direction vectors. See here.

If you have any questions of the code implementation, I'll try to clarify.

Me+PC=clb.demon.fi | C++ Math and Geometry library: MathGeoLib, test it live! | C++ Game Networking: kNet | 2D Bin Packing: RectangleBinPack | Use gcc/clang/emcc from VS: vs-tool | Resume+Portfolio | gfxapi, test it live!

### #3Juliean  GDNet+   -  Reputation: 4226

Like
0Likes
Like

Posted 26 October 2011 - 11:55 AM

Translate your mesh in the point you want the mesh to rotate around to origin -> rotate -> translate back. You will need multiple translation matrices to rotate around certain points. Looks like this:

MatrixTransform(mTrans1; -Point);
MatrixRotate(mRotate; angel);
MatrixTransform(mTrans2; Point);

mWorld = mTrans1 * mRotate * mTrans2;

### #4҉W ҉I ҉R ҉E ҉D ҉ ҉C ҉A ҉T  Members   -  Reputation: 696

Like
0Likes
Like

Posted 27 October 2011 - 03:02 PM

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS