I hope you will be able to help as I'm a bit lost at the moment. I've been trying to follow the KinematicCharacterController and the ConcaveDemo without much luck.
Currently I'm trying to get collision detection and response working for:
I have a rigid Body that acts as my level geometry with mass=0.0 that's just polygon soup that uses a btBvhTriangleMeshShape created by:
/
Code: Select all
/ create the collision mesh
bool useQuantizedAabbCompression = true;
collisionShape = new btBvhTriangleMeshShape(triangleMesh, useQuantizedAabbCompression);
Code: Select all
// create the collision capsule
collisionShape = new btCapsuleShape( btScalar(radius), btScalar(height) );
Cheers and thanks for any help you can give,
John.
Code: Select all
// bullet collision deletection
int numManifolds = dynamicsWorld->getDispatcher()->getNumManifolds();
for ( int i=0; i<numManifolds; i++)
{
// get the contact manifold
btPersistentManifold *contactManifold = dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
// collision ?
if( contactManifold->getNumContacts() > 0 )
{
bool penetration = false;
// get the collision objects
btCollisionObject *objA = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject *objB = static_cast<btCollisionObject*>(contactManifold->getBody1());
btVector3 normal;
btVector3 translation(0.0,0.0,0.0);
// separate
btScalar maxPen = btScalar(0.0);
for (int p=0;p<contactManifold->getNumContacts();p++)
{
if( contactManifold->getNumContacts() > 1 )
{
int i=0;
i++;
}
const btManifoldPoint&pt = contactManifold->getContactPoint(p);
if (pt.getDistance() < 0.0)
{
if (pt.getDistance() < maxPen)
{
maxPen = pt.getDistance();
normal = pt.m_normalWorldOnB;
printf("col_point:%d : normal:%4.2f,%4.2f,%4.2f\n", p, normal.getX(), normal.getY(), normal.getZ() );
// Pause();
}
translation += pt.m_normalWorldOnB * pt.getDistance() * btScalar(-0.2);
penetration = true;
}
else
{
//printf("touching %f\n", pt.getDistance());
}
}
if( penetration )
{
// get the entities
Entity *entityA = static_cast<Entity*>(objA->getUserPointer());
Entity *entityB = static_cast<Entity*>(objB->getUserPointer());
// get the current pos of Entity A
btVector3 currentPos = ToBulletVector( entityA->GetPosition() );
// move entity A away
entityA->SetPosition( ToIrrVector(currentPos + translation) );
// btTransform start, end;
// m_targetPosition = currentPos + walkMove;
// start.setIdentity ();
// end.setIdentity ();
// call the collision callbacks
entityA->OnCollision( *entityB );
entityB->OnCollision( *entityA );
}
}
//you can un-comment out this line, and then all points are removed
//contactManifold->clearManifold();
}