So I've got Bullet 3D controlling the motion of objects rendered with DirectX. In the clipping below I've got 2 identical rectangles & 5 balls. The lowest rectangle has a mass of 0 and doesn't move (as expected). All other objects have a mass of 1 and fall as expected.
There are two issues that I'm seeing: 1. When the balls land on an angled surface (not shown) they don't rotate, but they do move 'down hill'. 2. Pictured below you see that the top rectangle is perched on the bottom rectangle when it should've rotated a bit and kept falling.
What do I need to do in Bullet to enable object rotations? I'm not a physicist so I suspect my google-fu is lacking, also the Bullet docs are painfully inadequate.
This code here is how I initialize my rigid bodies:
RESULT_CODE ubAddRigidBody(HANDLE collisionShape, float mass, ubVector3 position, ubVector4 orientation, HANDLE* rigidBodyHandle)
{
if (rigidBodyHandle == nullptr)
{
return INVALID_PARAM;
}
if (_world->isValidCollisionShapeHandle(collisionShape) != SUCCESS)
{
return INVALID_HANDLE;
}
auto transform = btTransform(btQuaternion(orientation.x, orientation.y, orientation.z, orientation.w), btVector3(position.x, position.y, position.z));
auto collisionShapeObject = _world->m_collisionShapes[collisionShape].get();
auto motionStateObject = new btDefaultMotionState();
motionStateObject->setWorldTransform(transform);
auto rigidBodyInfo = btRigidBody::btRigidBodyConstructionInfo(btScalar(mass), motionStateObject, collisionShapeObject);
// Enable rotations for the object
collisionShapeObject->calculateLocalInertia(mass, rigidBodyInfo.m_localInertia);
rigidBodyInfo.m_linearDamping = .2f;
rigidBodyInfo.m_angularDamping = .2f;
auto rigidBody = new btRigidBody(rigidBodyInfo);
auto uniqueHandle = _world->getUniqueHandle();
rigidBody->setFriction(.5f);
rigidBody->setRollingFriction(.5f);
_world->m_world->addRigidBody(rigidBody);
_world->m_rigidBodies[uniqueHandle] = unique_ptr<ubRigidBody>(new ubRigidBody(rigidBody, collisionShapeObject, motionStateObject));
*rigidBodyHandle = uniqueHandle;
return SUCCESS;
}