Ghost object in persistent manifold

Post Reply
space_roach
Posts: 2
Joined: Wed Nov 12, 2014 6:32 pm

Ghost object in persistent manifold

Post by space_roach »

Hi folks,
There is a player ship, some enemy ships, player-fired bullets and a bounding wall ( which is a ghost object, destroys the bullets that come in contact with it )

This function checks and destroys the bullets colliding with the wall

Code: Select all

void GameState::boundChecks() {
	btAlignedObjectArray<btCollisionObject*>& boundCollisionList = m_pGhostPlane->getOverlappingPairs();
	int size = boundCollisionList.size();
	for(int i = 0 ; i < size ; i++ ) {
		btCollisionObject* obj = boundCollisionList[i];
		m_DeadWeights.insert(obj);
	}
}
On it's own, it works as expected. However I need to call the following function right after it to check for bullet-enemy collisions :-

Code: Select all

void GameState::processPhysics() {
	int i,
		numManifolds = m_pCollisionWorld->getDispatcher()->getNumManifolds();
	for(i = 0 ; i < numManifolds ; i++ ) {
		btPersistentManifold* contactManifold = m_pCollisionWorld->getDispatcher()->getManifoldByIndexInternal(i);
		btCollisionObject* objA = const_cast<btCollisionObject*>(contactManifold->getBody0());
		btCollisionObject* objB = const_cast<btCollisionObject*>(contactManifold->getBody1());

		m_DeadWeights.insert(objA);
		m_DeadWeights.insert(objB);
	}
}
And this is where I'm stuck. The persistent manifold contains the ghost object, which is then passed onto the dead weight list and to the clearing function from there.

How do you manage collisions when there are both ghost and non-ghost objects and the non-ghost objects need to interact with each other as well?

Thank you
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: Ghost object in persistent manifold

Post by xexuxjy »

I don't think theres any nice bullet standard way of doing this, but one slightly ugly option would be to store a user pointer on your 'permanent' ghosts and change use that extra logic to avoid adding them to your deadWeights list.....
space_roach
Posts: 2
Joined: Wed Nov 12, 2014 6:32 pm

Re: Ghost object in persistent manifold

Post by space_roach »

xexuxjy wrote:I don't think theres any nice bullet standard way of doing this, but one slightly ugly option would be to store a user pointer on your 'permanent' ghosts and change use that extra logic to avoid adding them to your deadWeights list.....
Thank you for the response, I'll try your suggestion once I get home.

However, I'm afraid this'll defeat the purpose of ghost objects(even though I can't see any other solution right now). Even If I discard ghosts in the loop, I would have to iterate over them in the manifold. I wanted to avoid this
:(

EDIT: I tried your suggestion (albeit a bit differently) and yes it works.
Thanks!

Code: Select all

void GameState::processPhysics() {
	int i,
		numManifolds = m_pCollisionWorld->getDispatcher()->getNumManifolds();
	for(i = 0 ; i < numManifolds ; i++ ) {
		btPersistentManifold* contactManifold = m_pCollisionWorld->getDispatcher()->getManifoldByIndexInternal(i);
		btCollisionObject* objA = const_cast<btCollisionObject*>(contactManifold->getBody0());
		btCollisionObject* objB = const_cast<btCollisionObject*>(contactManifold->getBody1());
                
                /*Added this check*/
		if(objA == m_pGhostPlane ||
			objB == m_pGhostPlane )
			continue;

		m_DeadWeights.insert(objA);
		m_DeadWeights.insert(objB);
	}
}
Post Reply