Damn, damn, damn. I took almost 3 hours to solve a problem.
// create a motion state obj->motionState.reset( new btDefaultMotionState( transform ) ); // create a collision shape const btVector3 halfExtents( 0.5f, 0.5f, 0.5f ); obj->collisionShape.reset( new btBoxShape( halfExtents ) ); // create a rigid body const float mass = obj->mass; btVector3 localInertia( 0.0f, 0.0f, 0.0f ); // rigidbody is dynamic if is non zero if( mass != 0.0f ) { obj->collisionShape->calculateLocalInertia( mass, localInertia ); } btRigidBody::btRigidBodyConstructionInfo rbInfo( mass, obj->motionState.get(), obj->collisionShape.get(), localInertia ); shared_ptr< agiRigidBody > rigidBody( new agiRigidBody( rbInfo ) ); rigidBody->Init( obj ); // add to dynamics world imp->dynamicsWorld->addRigidBody( rigidBody.get() ); // set pointer in data object obj->rigidBody = rigidBody; // scale btVector3 bulletScale; bulletScale.setX( obj->scale.x() ); bulletScale.setY( obj->scale.y() ); bulletScale.setZ( obj->scale.z() ); rigidBody->getCollisionShape()->setLocalScaling( bulletScale );
I didn't know I had to initialise localInertia. Most vectors I work with default to 0.0.
I was relying on similar code elsewhere and then when I changed over to this code I had to track that error down. Grr. For three hours I had things falling through my ground for no good reason. Yeah, I need to learn more about physics and the physics library I'm using.
No comments:
Post a Comment