Collisions: Calculate applied impulse without applying it

Post Reply
Ondrej.Petrzilka
Posts: 2
Joined: Fri May 03, 2013 1:50 pm

Collisions: Calculate applied impulse without applying it

Post by Ondrej.Petrzilka »

I'm doing some kind of destruction. On contact whole block is supposed to be destroyed...when impulse is sufficient.

I have material callback (ContactAdded).
In callback, geometry block is found (contact world position), removed and collision shape is updated.
No collision occurs in solver, that ok for now.

But how do I detect that contact force/impulse is large enough?
I cant use getAppliesImpulse, because it's always zero. I've read it's zero in material callbacks.

I've tried to handle it in tickCallback, but contact impulse is already applied here (and I applying reversed impulse does quite nasty things...weird rotations...).

Whole idea is:
You fly with ship, you hit something, part of ship is destroyed, ship is slowed down (some additional damping applied is sufficient for this)
kijoshua2
Posts: 7
Joined: Wed Mar 06, 2013 9:12 pm

Re: Collisions: Calculate applied impulse without applying i

Post by kijoshua2 »

I don't have a full solution to this problem yet, but I can tell you what steps I've taken towards solving this problem.

I use the gContactAddedCallback callback to create a collision tracking object for every contact. I save its pointer to the btManifoldPoint point's m_userPersistentData (like the user pointer for other objects throughout the Bullet system). I delete this object eventually when it shows up again in the gContactDestroyedCallback callback.

The tracking object is needed because impulses can be split up into multiple parts. If I see a tracking object already in place during the gContactAddedCallback , I simply update the stored impulse (in my object) (btManifoldPoint has a getAppliedImpulse method).

Currently, I set up my own dynamics world class that derives from btDiscreteDynamicsWorld. I then redefined the solveConstraints method to first call the original solveConstraints method and then do my collision stuff. This involves looping through all the contact manifolds, looking for the collision tracking objects created earlier. When I find one, that is when I actually make use of it.

You can counteract the automatically applied impulse on the surviving body by applying your own impulses manually. But for this to work reliably, you'll need to store the initial velocity information and such, so you can restore it after the collision. You'll also need to remove the body and re-add it later, otherwise Bullet will sometimes do strange things with information it has cached. You can re-add the bodies after the simulation step.

Unfortunately, I still don't have the system working as well as I want, and I left the code in quite a mess before moving onto other tasks. If I ever get something working, I'll post back again with it.

The main issues IIRC were that sometimes the breakthrough velocities were a bit off in either direction or magnitude. Most of the time, the surviving object would blast through the destroyed object quite nicely. For more complex tests, sometimes Bullet would crash, though I could never tell if this was directly due to my breakthrough code or if it was something else that was interacting poorly with it.

Somewhere on the forums you can find information about a fracturing demo. If you need the fracturing part, that'll probably be better for you. I did it my own way because I didn't need the fracturing and I wanted the breakthrough velocities to be more reliable (my way is working better for that part, but still not 100%). I also needed more control over determining which objects broke, when, and what amount of energy is left over after the collision.
STTrife
Posts: 109
Joined: Tue May 01, 2012 10:42 am

Re: Collisions: Calculate applied impulse without applying i

Post by STTrife »

thanks for posting this, I also want to see if I can do something like this later on. If find a good final solution please let me know!
Post Reply