I have been trying to provide some way of using a callback to register when a ball in my game bounces on the floor so that I can do some game specific logic. Currently I have tried using the ContactPairTest Function with my own callback to try and accomplish this. The two object I was using were a btStaticPlaneShape and a btSphereShape. For some reason the AddSingleResult was continually being called when the ball was nowhere near the floor.
I did think that this may have something to do with the fact that the floor was a btStaticPlaneShape so I tried changing it to the btBoxShape but now he collisions don't work at all i.e.the ball doesn't even bounce now.
I am just wondering whether I am going about this the completely wrong way or whether I am doing something terribly wrong, I have tried looking at the demos but they don't show much for the ContactPairTest and I can't seem to find much on here for it.
Here is some of my initialisation code:
Code: Select all
PhysicsObject* PhysicsManager::AddPlane( vec3 halfExtents, CMatrix* transform )
{
btTransform trans;
float mat[16];
trans.setFromOpenGLMatrix( mat );
btCollisionShape* planeShape = new btBoxShape( btVector3( halfExtents.x, halfExtents.y, halfExtents.z ) );
btDefaultMotionState* planeMotionState = new btDefaultMotionState( trans );
btRigidBody::btRigidBodyConstructionInfo planeRigidBodyCI(0, planeMotionState, planeShape, btVector3( 0, 0, 0 ) );
planeRigidBodyCI.m_restitution = 1.0f;
btRigidBody* planeRigidBody = new btRigidBody( planeRigidBodyCI );
mDynamicsWorld->addRigidBody( planeRigidBody );
planeRigidBody->activate();
PhysicsObject* physObj = new PhysicsObject( planeRigidBody, planeShape, transform );
mPhysicsObjects.push_back( physObj );
return physObj;
}
Code: Select all
PhysicsObject* PhysicsManager::AddSphere( float radius, CMatrix* transform )
{
btCollisionShape* sphereShape = new btSphereShape( 0.2 );
btTransform trans;
float mat[16] ;
btDefaultMotionState* sphereMotionState = new btDefaultMotionState( trans );
btScalar mass = 500;
btVector3 sphereInertia( 0, 0, 0 );
sphereShape->calculateLocalInertia( mass, sphereInertia );
btRigidBody::btRigidBodyConstructionInfo sphereRigidBodyCI( mass, sphereMotionState, sphereShape, sphereInertia );
sphereRigidBodyCI.m_restitution = 1.0f;
sphereRigidBodyCI.m_linearDamping = btScalar(0.9);
btRigidBody* sphereRigidBody = new btRigidBody( sphereRigidBodyCI );
mDynamicsWorld->addRigidBody( sphereRigidBody );
sphereRigidBody->activate();
PhysicsObject* physObj = new PhysicsObject( sphereRigidBody, sphereShape, transform );
mPhysicsObjects.push_back( physObj );
return physObj;
}
and my Update function:
Code: Select all
void PhysicsManager::Update( float updateTime )
{
//Do the physics simulations
mDynamicsWorld->stepSimulation( updateTime, 10 );
//Test all the Contact Callbacks
for( unsigned int i = 0; i < mContactCallbacks.size(); i++ )
{
mDynamicsWorld->contactPairTest( mContactCallbacks[i]->GetCollisionObject1()->GetRigidBody(),mContactCallbacks[i]->GetCollisionObject1()->GetRigidBody(), *mContactCallbacks[i]->GetCallback() ) ;
}
}
Cheers