Code: Select all
{
btTransform trans;
trans.setIdentity();
trans.setOrigin(btVector3(25, 0, 0));
btSphereShape* shape = new btSphereShape(10.0f);
mTriggerObj = new btPairCachingGhostObject();
mTriggerObj->setWorldTransform(trans);
mTriggerObj->setCollisionShape(shape);
mTriggerObj->setCollisionFlags(btCollisionObject::CF_NO_CONTACT_RESPONSE);
mScene->addCollisionObject(mTriggerObj, btBroadphaseProxy::SensorTrigger, btBroadphaseProxy::AllFilter & ~btBroadphaseProxy::StaticFilter & ~btBroadphaseProxy::SensorTrigger);
}
Code: Select all
mGhostObj = new btPairCachingGhostObject();
mGhostObj->setWorldTransform(startTransform);
btScalar characterHeight=1.75;
btScalar characterWidth = mSceneMgr->getEntity("Char")->getBoundingRadius();
btConvexShape* capsule = new btCapsuleShape(characterWidth,characterHeight);
mGhostObj->setCollisionShape (capsule);
mGhostObj->setCollisionFlags (btCollisionObject::CF_CHARACTER_OBJECT);
mScene->addCollisionObject(mGhostObj, btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter | btBroadphaseProxy::SensorTrigger | btBroadphaseProxy::DefaultFilter);
Basically I want the character and rigid bodies to not collide, but I want to still be able to get the bodies inside the ghost object.
Here's how I'm trying to get the bodies inside: (adapted from the wiki)
Code: Select all
btManifoldArray manifoldArray;
btBroadphasePairArray& pairArray = mTriggerObj->getOverlappingPairCache()->getOverlappingPairArray();
int numPairs = pairArray.size();
for (int i=0;i<numPairs;i++)
{
manifoldArray.clear();
const btBroadphasePair& pair = pairArray[i];
//unless we manually perform collision detection on this pair, the contacts are in the dynamics world paircache:
btBroadphasePair* collisionPair = mScene->getPairCache()->findPair(pair.m_pProxy0,pair.m_pProxy1);
if (!collisionPair)
continue;
if (collisionPair->m_algorithm)
collisionPair->m_algorithm->getAllContactManifolds(manifoldArray);
for (int j=0;j<manifoldArray.size();j++)
{
btPersistentManifold* manifold = manifoldArray[j];
btScalar directionSign = manifold->getBody0() == mTriggerObj ? btScalar(-1.0) : btScalar(1.0);
for (int p=0;p<manifold->getNumContacts();p++)
{
const btManifoldPoint&pt = manifold->getContactPoint(p);
if (pt.getDistance()<0.f)
{
const btVector3& ptA = pt.getPositionWorldOnA();
const btVector3& ptB = pt.getPositionWorldOnB();
const btVector3& normalOnB = pt.m_normalWorldOnB;
/// work here
Ogre::Vector3 pos = BtOgre::Convert::toOgre(ptB);
printf("Hit at %s\n", Ogre::StringConverter::toString(pos).c_str());
}
}
}
}