manipulations inside collisionCallback

almatea
Posts: 29
Joined: Mon Nov 02, 2009 10:15 am

manipulations inside collisionCallback

Post by almatea »

Several question relative to issue 90. In example from Erwin breaking is _after_ simulation step (Erwin using tickCallback - this calling after ever step), but to correct breaking with correct impulse logic I need to process impacts _before_ simulation step. So:

1) Is it possible to correctful change a collision shapes inside gContactAddedCallback or gContactProcessedCallback? I want to break a compound shape if impulse of collision is some big.

2) Is it possible to delete manifold inside gContactAddedCallback or gContactProcessedCallback? If so - how to?

3) I have a zero impulses inside gContactAddedCallback or gContactProcessedCallback - btManifoldPoint's m_appliedImpulse return a 0. I calculate impulse manually - ((v0*mass0)-(v1*mass1))/2, but it is would be great to have working out box.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: manipulations inside collisionCallback

Post by Erwin Coumans »

You cannot make changes during the collision callback.

You should be able to make the changes after the simulation step. The applied impulses etc. are available in the contact points.

We can make a change in a future Bullet version to disable constraints during the constraint solving. Hopefully this helps a fracturing implementation.

Thanks,
Erwin
almatea
Posts: 29
Joined: Mon Nov 02, 2009 10:15 am

Re: manipulations inside collisionCallback

Post by almatea »

Erwin Coumans wrote:You cannot make changes during the collision callback.

You should be able to make the changes after the simulation step.
Let's think about how to correct process a impact after simulation step.

If my impact > some value then I make breaking. But if my virtual connections between parts of body not so strength then impact must be influence only collided piece, impact not influence othep parts (for example: glass vase vs a set of wood boxes).
In other words I want to break my body to two parts and eliminate impulse for second part.

May be it would be helpful a second simulation world? Second world only for testing collisions - a copy of first world in each step.

The applied impulses etc. are available in the contact points.
Unfortunately, no:

Code: Select all

bool my_gContactAddedCallback (    btManifoldPoint& cp,    const btCollisionObject* colObj0,    int partId0,    int index0,    const btCollisionObject* colObj1,    int partId1,    int index1   )
{
...
cout cp.m_appliedImpulse << endl;
...
}
print only 0 - everytime. In tick callback print correct.

thanks!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: manipulations inside collisionCallback

Post by Erwin Coumans »

The applied impulse should be available during the tick callback, not during the gContactAddedCallback. The gContactAddedCallback happens during the collision detection, but before the contact constraint solving, so there are no impulses yet. So it is best to use the tick callback.

We are planning to improve the glue/fracture demo, and hopefully that will give us a better idea what is needed.
Likely the option to disable constraints during the constraint solving will help.
Thanks,
Erwin
almatea
Posts: 29
Joined: Mon Nov 02, 2009 10:15 am

Re: manipulations inside collisionCallback

Post by almatea »

Still trying to catch and void collision before simulation step.

I use custom NearCallback. How to get a index of btCompound child before process collision? if i get a btManifoldResult::getPersistentManifold() before collisionPair.m_algorithm->processCollision(...) then my persistent manifold is broken. For example, if I try to manifold->getContactPoint then i get a segmentation fault. Okay - it is normal.

But i can to use contactPairTest inside my NearCallback function. So:

Code: Select all

void MyNearCallback( btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo) 
{
	cout << "MyNearCallback!!!" << endl;
                btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
		btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;
		if (dispatcher.needsCollision(colObj0,colObj1))
		{
			if (!collisionPair.m_algorithm)
			{
				collisionPair.m_algorithm = dispatcher.findAlgorithm(colObj0,colObj1);
			}
			if (collisionPair.m_algorithm)
			{
				btManifoldResult cp(colObj0,colObj1);
					struct   MyContactResultCallback : public btCollisionWorld::ContactResultCallback
					{
						int index0_m;
						int index1_m;
						MyContactResultCallback()
						{
						}
						virtual   btScalar   addSingleResult(btManifoldPoint& cp,   const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1)
						{
							index0_m = index0;
							index1_m = index1;
							return 1.f;
						}
					};
					MyContactResultCallback result;
result.index0_m and result.index0_m now - COLLIDING child numbers of colObj0 and colObj1!

Now i can to filter collision inside NearCallback by child number (I just do not process collision between pair if one of members is bsCompound). I store this numbers and use in tick callbact for break my btCompounds. So I void a impulse to second breaking part of compound.

Is it correct way?
almatea
Posts: 29
Joined: Mon Nov 02, 2009 10:15 am

Re: manipulations inside collisionCallback

Post by almatea »