LoneWolf
24-06-2011 12:05:18
Hello,
I've managed to make two collision boxes with ogrebullet, they're properly shown by the debugDrawer and everything works so far, but now I need to do something when the collision occurs between them, how can I make it? Thanks in advance
Caith
25-06-2011 11:42:07
This should work.
OgreBulletDynamics::RigidBody *box1;
OgreBulletDynamics::RigidBody *box2;
OgreBulletDynamics::DynamicsWorld *mWorld;
...
// Simulate.
mWorld->stepSimulation(elapsedTime);
// Number of manifolds.
const unsigned int numManifolds =
mWorld->getBulletCollisionWorld()->getDispatcher()->getNumManifolds();
// Go through every manifold.
for (unsigned int i=0; i < numManifolds; i++)
{
// Get current manifold.
btPersistentManifold* contactManifold =
mWorld->getBulletCollisionWorld()->
getDispatcher()->getManifoldByIndexInternal(i);
// Get collisionpair.
btCollisionObject* obA =
static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB =
static_cast<btCollisionObject*>(contactManifold->getBody1());
// Check if the two colliding objects are the boxes.
if ( (box1->getBulletObject() == obA && box2->getBulletObject() == obB)
|| (box2->getBulletObject() == obA && box1->getBulletObject() == obB) )
{
// Your code here.
}
// Refresh contact points.
contactManifold->refreshContactPoints(obA->getWorldTransform(),obB->getWorldTransform());
// Get number of contact points of these two objects.
const unsigned int numContacts = contactManifold->getNumContacts();
// Go through every contact point.
for (unsigned int j = 0;j < numContacts; j++)
{
// Get current manifold point.
btManifoldPoint& pt = contactManifold->getContactPoint(j);
// Get positions.
btVector3 ptA = pt.getPositionWorldOnA();
btVector3 ptB = pt.getPositionWorldOnB();
// Transform to ogre.
Vector3 aPoint = Vector3(ptA.x(), ptA.y(), ptA.z());
Vector3 bPoint = Vector3(ptB.x(), ptB.y(), ptB.z());
// Your code here if need to check the collision by contact points.
} // End for each point.
} // End for each contact manifold.
I also need help on this problem.
I find the similiar code in OgreBulletDynamics::CollisionsWorld::discreteCollide() and OgreBulletDynamics::DynamicsWorld::stepSimulation(...).
But, Is there any callback function avaiable to let the developer make custom actions after collision occured?
If not, I have to put Caith's code in MyLisener::frameEnded() or MyLisener::frameEnded() , right?
Any suggestion is appreciated.
dermont
28-06-2011 12:03:00
I also need help on this problem.
I find the similiar code in OgreBulletDynamics::CollisionsWorld::discreteCollide() and OgreBulletDynamics::DynamicsWorld::stepSimulation(...).
But, Is there any callback function avaiable to let the developer make custom actions after collision occured?
If not, I have to put Caith's code in MyLisener::frameEnded() or MyLisener::frameEnded() , right?
Any suggestion is appreciated.
Check the bullet wiki and bullet demos, there is an example in the 2nd link that you should be able to cut and paste.
http://www.bulletphysics.org/mediawiki- ... d_Triggers
http://bullet.googlecode.com/svn-histor ... csDemo.cpp