# how to rotate rigidbody along a arbitrary point

## how to rotate rigidbody along a arbitrary point

hi,

if i call  rigidBody->setRotation( quaternion )  the rigid body will rotate around his center point.

but how can i make this same rigidBody rotate around an arbitrary point outside his shape?

my use case is that i need to rotate N diferent objects around their center point.

can someone help?

thanks

- Luis

5 posts / novo 0
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

Hi Luis,

A body rotates around its centre of mass, not necessarily its center point. So changing the COM might get the effect you want but the object will no longer behave correctly on its own. There are a couple of ways you could possibly do this but each will have some other effects on the object's behavior. Could you give us some more details about exactly what you are trying to do so we can try find one to suit your use case?

Amy Developer Support Engineer Havok www.havok.com

Hi Amy,

Thanks for the replaying.

Let i try to explain more accuratly them.

I will have N objects (let's say 2 for now). Suppose each object is a (1,1,1) Box.

Now, box1 will be located in the coords (-1,0,0)  and box2 will be at (+1,0,0)

What i need is to find the center of those objects togheter as like they are grouped (in this case the center would be (0,0,0) ) and them rotate BOTH objects around this center point, an amount of angle defined by a quaternion. They sould *not* rotate around their *own* center individually but around the center of all objects together (the coord (0,0,0).

In this example, supossing the quaternion defined would be axis (0,0,1) and angle 90 degrees clockwise, the final coordinates of the boxes would be box1 (0,+1,0)  and box2 (0,-1,0)

there is just one catch: i will actually *not* move the objects in the middle of the calculations, but phantons. After all phantons proved that they could move that amount of angle requested by the user (without collide with anyone in their final position), them i discard the phantons and move the boxes rigidBodies to the coordinates the phantons proved to be valid.

The code is already implemented for N objects moving around their own center points individually (when they are not grouped togheter). I can easily calculate the center point of the boxes in the case they are grouped but i just don't know how to rotate them around a diferent point that is not their own center points.

Once again, thanks for the help!  I'm lost on this one  :(

Hi Luis,

Sorry, I should have been more specific about the details I was looking for. I was looking for details about how the boxes should behave when these rotations are applied. I'll give you some ways you might achieve these rotations and hopefully one of their behaviours is what you're looking for.

- The approach that's most guaranteed to get the effect you want is to key-frame the objects using hkpKeyFrameUtility. However you'd have to calculate the positions you want yourself. The basic algorithm for rotating a point around another arbitrary point is a common one and there's a bullet point version here, and the hkVector4 class has functions that'll do each of these steps.
- You could also set the COM of each of the boxes yourself to be the center point, but the boxes won't appear to behave physically like boxes anymore.
- If the boxes stay in the same position relative to each other then you might use a hkpListShape with the COM at the centre of all the boxes and apply the rotation to the body holding the list shape .
- A hkpTransformShape will rotate about its own center so using one with a transform equal to the box's transform from the rotation point could simulate having the centre of rotation outside the object. However you will have to set/update this offset yourself and it could be tricky doing this without moving the object in world space.
- Lastly you could use a ball and socket or hinge constraint, but I don't think these will allow you to use a quaternion like you intend to.

I hope some of this helps, or at least helps you define what behaviour you want from these boxes during and after these rotations are applied.

Amy Developer Support Engineer Havok www.havok.com

Hi Amy!

Thank you very much for the tips! It helped a lot! I tried a mix of two of them and *worked*!  Phew.

In the end i created a phantom object with an hkpListShape made of the shapes (enveloped with hkpTransformShape) of the boxes.

them i rotated the phantom, checked for colisions and translated it to a place where the colisions is no more.

them i iterate the shapes, getting their actual position and moved the boxes to that places.

the trick was doing some math to get this transforms.. because the math is not comutative.. but in the end, the struggle (with your help), work!!

thanks!  :)