I'm using the Bullet Physics engine. I currently have a platform (btRigidBody
) that can move and rotate. On this platform I want to place 4 cubes (on at each corner. Now as the platform translates or rotates, I want the cubes to stay in these corners. Basically, I want their position/orientation with respect to the platform to stay the same.
Here's what I've tried:
btTransform transform;
m_platform->getMotionState()->getWorldTransform(transform);
btQuaternion platformRotation = transform.getRotation();
btVector3 platformOrigin = transform.getOrigin();
btMatrix3x3 platformBasis = transform.getBasis();
for (int i = 0; i < CubeEnvironment::OBJECT_COUNT; ++i)
{
btTransform objTransform;
m_bodies[i]->getMotionState()->getWorldTransform(objTransform);
objTransform.setRotation(platformRotation);
m_bodies[i]->getMotionState()->setWorldTransform(objTransform);
}
Here, m_platform
is the platform and m_bodies
consists of the 4 cubes. With this code, the cubes do rotate along with the platform, but only in their local frame, meaning their origin stays in the same place.
I've also experimented a bit with get/setOrigin
and get/setBasis
, but it didn't help.
Any ideas what I should do?
I would suggest using some form of a constraint between the cube(s) and the platform, depending on your needs, you can fix the cube wrt the platform (btfixedconstraint), or you can move it about an axis (bthingeconstraint) or others.
you can find the complete list on: http://bulletphysics.org/mediawiki-1.5.8/index.php/Constraints