Getting collision array from bullet

Physics APIs, Physics file formats, Maya, Max, XSI, Cinema 4D, Lightwave, Blender, thinkingParticles™ and other simulation tools, exporters and importers
biaggi
Posts: 2
Joined: Wed Apr 21, 2010 5:52 pm

Getting collision array from bullet

Post by biaggi »

Hi, im new in bullet, I'm trying to use it on android using jni calls, the proyect is public, so you can check it out at http://code.google.com/p/android-2d-engine/

The question seems to be simple, but it causes me a lot of headheaches, I'm trying to just detect who rigidbody is colliding with another one, and return an array with all collisions to android to be managed there, a simple callback, but i cant manage to get that info from the engine.

The last approach was this code from the bullets wiki:
LOGV("collisions detected");
int numManifolds = pDynamicsWorld->getDispatcher()->getNumManifolds();
logdi(numManifolds);
for (int i=0;i<numManifolds;i++)
{
btPersistentManifold* contactManifold = pDynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
logdi((int)btRigidBody::upcast(obA));
logdi((int)btRigidBody::upcast(obB));

jclass bullet_clazz = env->GetObjectClass(thiz);
jmethodID bullet_resultSimulation_mid = env->GetMethodID(bullet_clazz, "collisionDetected", "(II)V");
env->CallVoidMethod(thiz, bullet_resultSimulation_mid, (int)btRigidBody::upcast(obA), (int)btRigidBody::upcast(obB));
}
But I keep getting "false collisions", obviously this is not what i prettend to do, I'be been reading a lot about bullet physics, but now i'm pretty stalled with this algorithm.

I just want an array like collisions[] = (objA => rigidBody, objB => rigidBody).

Any help or pointer to document please?
biaggi
Posts: 2
Joined: Wed Apr 21, 2010 5:52 pm

Re: Getting collision array from bullet

Post by biaggi »

Sorry, this is a situation for RTFM :)

I missunderstood the wiki page http://bulletphysics.org/mediawiki-1.5. ... d_Triggers
LOGV("collisions detected");
int numManifolds = pDynamicsWorld->getDispatcher()->getNumManifolds();
logdi(numManifolds);
for (int i=0;i<numManifolds;i++)
{
btPersistentManifold* contactManifold = pDynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());

int numContacts = contactManifold->getNumContacts();
for (int j=0;j<numContacts;j++)
{
btManifoldPoint& pt = contactManifold->getContactPoint(j);
if (pt.getDistance()<0.f)
{
jclass bullet_clazz = env->GetObjectClass(thiz);
jmethodID bullet_resultSimulation_mid = env->GetMethodID(bullet_clazz, "collisionDetected", "(II)V");
env->CallVoidMethod(thiz, bullet_resultSimulation_mid, (int)btRigidBody::upcast(obA), (int)btRigidBody::upcast(obB));
}
}

}