Page 1 of 1

btPersistentManifold::getNumContacts always returns zero

Posted: Sat Jun 15, 2019 4:36 pm
by s_kohan
I want to get access to the contact point details for a collision. The problem is, whenever I try to get the number of contacts from a manifold, via btPersistentManifold::getNumContacts, the result is always zero. Here's how I'm getting the contacts:

Code: Select all

  
        // these methods are part of a C wrapper so I can use bullet using the C FFI

	int btDynamicsWorldGetCollisionCount(btDynamicsWorldRef* world) {
		return ((btDynamicsWorld*)world)->getDispatcher()->getNumManifolds();
	}
	
	btContact btDynamicsWorldGetCollision(btDynamicsWorldRef* world, int index) {
	
		btPersistentManifold* contactManifold = ((btDynamicsWorld*)world)->getDispatcher()->getManifoldByIndexInternal(index);
		
		btContact contact; // this is a struct defined to expose contact info to this C wrapper
		contact.objectA = contactManifold->getBody0()->getUserPointer();
		contact.objectB = contactManifold->getBody1()->getUserPointer();
		contact.manifoldRef = (btContactManifoldRef*)contactManifold;
		return contact;
		
	}
	
     int btContactManifordGetContactCount(btContactManifoldRef* manifold) {
        btPersistentManifold* contactManifold = (btPersistentManifold*) manifold;
        int count = contactManifold->getNumContacts();
        return count;
    }

The strange thing is, when I debug, I can see that there are 4 btManifoldPoint records inside contactManifold->m_pointCache. What am I missing here?

Re: btPersistentManifold::getNumContacts always returns zero

Posted: Mon Jun 17, 2019 3:06 pm
by drleviathan
I would like to help, however I don't have any good hypothesises. I looked at some working code that harvests contacts details from the contact manifolds and AFAICT your code should work. Perhaps you could supply enough source to actually build and reproduce your problem?

Re: btPersistentManifold::getNumContacts always returns zero

Posted: Wed Jul 03, 2019 6:10 pm
by s_kohan
Thank you, I actually ended up solving the problem myself. It turns out the problem was a false assumption I had about the contact manifolds: I thought they would only be created when there were already points of contact, but it turns out those "collisions" are already registered when the bodies are just close (broad-phase detection I think?) - so I just had to make my collision handling logic a bit smarter and wait until the collision manifolds already had contacts before handling it.

Re: btPersistentManifold::getNumContacts always returns zero

Posted: Thu Mar 25, 2021 3:57 am
by acu192
Yep, I'm seeing the same behavior as @s_kohan. Even if there is a btPersistentManifold, you still have to check getNumContacts() > 0 to actually know if the collision is for-realz.