Here is what is happening
Here are the relevant parts of my code:
Creating the world:
Code: Select all
m_pBroadphase = new btDbvtBroadphase();
m_pCollisionConfig = new btDefaultCollisionConfiguration();
m_pCollisionDispatcher = new btCollisionDispatcher( m_pCollisionConfig );
m_pPhysicsSolver = new btSequentialImpulseConstraintSolver();
// Create the world
m_pPhysWorld = new btDiscreteDynamicsWorld( m_pCollisionDispatcher, m_pBroadphase, m_pPhysicsSolver, m_pCollisionConfig );
m_pPhysWorld->setGravity( btVector3( 0, -9.8f, 0 ) );
Code: Select all
// Create the collision shape
m_pBoxCollision = new btBoxShape( btVector3( 0.5f, 0.5f, 0.5f ) );
boxMass = 1.0f;
boxInertia = btVector3( 0.0f, 0.0f, 0.0f );
m_pBoxCollision->calculateLocalInertia( boxMass, boxInertia );
// Create the motion state
boxTrans.setIdentity();
boxTrans.setOrigin( ConversionUtil::vec3_to_btVector3( this->getPosition() ) );
m_pBoxMotion = new btDefaultMotionState( boxTrans );
// Create rigid body
btRigidBody::btRigidBodyConstructionInfo boxRigidBodyInfo( boxMass, m_pBoxMotion, m_pBoxCollision, boxInertia );
//boxRigidBodyInfo.m_friction = 25.0f;
m_pBoxBody = new btRigidBody( boxRigidBodyInfo );
// Add box physics to world
GetGame()->getRenderer()->getWorld()->addRigidBody( m_pBoxBody );
Code: Select all
m_pPhysWorld->stepSimulation( (btScalar)GetGame()->getFrameTimeS(), 10 );
Code: Select all
btTransform trans;
btScalar matrixRaw[16];
glm::mat4 matrix;
m_pBoxBody->getMotionState( )->getWorldTransform( trans );
trans.getOpenGLMatrix( matrixRaw );
matrix = ConversionUtil::btScalar_to_mat4( &matrixRaw[0] );
If I had to guess the problem would be in the stepping part, to be honest I'm still not too sure as to how that works. My game is running at about 1200 FPS currently, although when I locked it to around 60 FPS and adjusted the step function, the boxes behaved the same. Also most of this code is just copied from the tutorials, I've looked it over countless times to find differences but maybe someone else's eyes can find something I missed.