btCompoundCollisionAlgorithm and refreshing the manifolds

bradclancy
Posts: 7
Joined: Thu Jun 25, 2009 4:32 am

btCompoundCollisionAlgorithm and refreshing the manifolds

Post by bradclancy »

Hey All,

I'm trying to understand why btCompoundCollisionAlgorithm needs to refresh all the contact manifolds before processing the collision (btCompoundCollisionAlgorithm.cpp Ln:212-233.

Just as a test I commented out the lines mentioned above and the simulation is observable the same. But I'd really like to know why this collision algorithm has to refresh the contact points?

Is the code just using a simple means to cover off refreshing contact points for collision algorithms that don't get touched turing the call to process collision? Could it possibly be better to keep track of which manifolds are used during the actual collision processing and then only refresh the manifolds that are not used?

The reasons for all this is that I'm trying to keep track of manifolds and send events out to my game when objects come into contact and when they come out of contact. And I'd like for these 'start'/'end' events to match up 1 for 1 (I'm on PS3 with the SPU code, so I can't use the callback functions and must iterate over the persistent manifolds each substep). Processing all the manifolds before doing the collision is removing points from a manifold setting its count to 0 but the subsequent collision processing is adding a new contact so I now have a manifold that has created two start events but no end events.

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

Re: btCompoundCollisionAlgorithm and refreshing the manifolds

Post by Erwin Coumans »

All contact manifolds need to be refreshed each frame, to make sure they are up-to-date.
(I'm on PS3 with the SPU code, so I can't use the callback functions and must iterate over the persistent manifolds each substep)
Bullet collision detection has already been ported to PS3 SPU, including the refresh of contact manifolds.

Are you licensed PS3 developer? If so, you can download spubullet from PS3 Devnet (spubullet-2.75 is available soon).

Hope this helps,
Erwin
bradclancy
Posts: 7
Joined: Thu Jun 25, 2009 4:32 am

Re: btCompoundCollisionAlgorithm and refreshing the manifolds

Post by bradclancy »

Erwin Coumans wrote:All contact manifolds need to be refreshed each frame, to make sure they are up-to-date.
Yes I understand that they need to be updated, but is the btCompoundCollisionAlgorithm refreshing some manifolds more than once if they get into NarrowPhase functions? (All the narrow phase functions call refreshManifold...)
Erwin Coumans wrote: Bullet collision detection has already been ported to PS3 SPU, including the refresh of contact manifolds.
Yes I have the spubullet code.

I think you've missed the specifics of my question. Should the btCompoundCollisionAlgorithm be refeshing ALL the manifolds before processing the more detailed collision? Or could it just keep track of all the manifolds that are not updated during the detailed collision testing and then update those manifolds only?

It appears to me that for some manifolds the contacts are getting refreshed twice? So a contact in a manifold might go through these steps:

* Compound Object Process Collision
* Contact Detected and added to Mandifold (Contact X life Time initialised to 0)
* Manifold Refeshed (in lower level Collision Algorithm) (Contact X life Time incremented to 1)
--End Sub Step
* Refresh All Manifolds (including the contact added last sub-step) (Contact X life Time incremented to 2)
* Compound Object Process Collision
* Manifold Refeshed (in lower level Collision Algorithm) (Contact X life Time incremented to 3)

So, the life time of a contact has incremented unnessesarily.

The bigger problem I get is this:

* Compound Object Process Collision
* New Contact Detected and added to Mandifold (contact added to manifold and m_cachedPoints incremented to 1, Contact X life Time initialised to 0)
* Manifold Refeshed (in lower level Collision Algorithm) (Contact X life Time incremented to 1)
--End Sub Step Callback, process manifold, find a manifold with new contacts with life time = 1
* Refresh All Manifolds (including the contact added last sub-step) (Contact X has moved too far away and contact is removed and m_cachedPoints is set to 0)
* Compound Object Process Collision
* New Contact Detected and added to Mandifold (contact added to manifold and m_cachedPoints incremented to 1, Contact X life Time initialised to 0)
* Manifold Refeshed (in lower level Collision Algorithm) (Contact X life Time incremented to 1)
-- End Sup Step Callback, process manifold, find a manifold with new contacts with life time = 1

So, in the second sub-step the manifold appears as if it was a brand new manifold and my game sends out a OnStartContact event... but we've completely missed the OnEndContact because a manifold was updated twice... the only way I've figured to detect two objects comming out of contact is to use manifolds that have m_cachedPoints = 0 (and some other internal flags I've added to the btPersistentManifold that get set when a point is added to the manifold.).

Taking the events I'm trying to generate out of it though, I suppose I'm just very interest to know if refreshing the manifolds multiple time is the intention here, or just ease of implementation. Does anything rely on the manifolds of the btCompoundCollisionAlgorithm getting updated multiple times?


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

Re: btCompoundCollisionAlgorithm and refreshing the manifolds

Post by Erwin Coumans »

All contact manifolds should be refreshed each frame, but the current implementation might refresh some manifolds multiple times indeed.

If we can figure out a way to only refresh manifolds once, with minor changes to the implementation, we can try that.
Do you have any suggestion?
Thanks,
Erwin
bradclancy
Posts: 7
Joined: Thu Jun 25, 2009 4:32 am

Re: btCompoundCollisionAlgorithm and refreshing the manifolds

Post by bradclancy »

Erwin Coumans wrote:All contact manifolds should be refreshed each frame, but the current implementation might refresh some manifolds multiple times indeed.

If we can figure out a way to only refresh manifolds once, with minor changes to the implementation, we can try that.
Do you have any suggestion?
Thanks,
Erwin

Thanks Erwin, Yes, I've just added an array of bools to the btCompoundCollisionAlgorithm which is passed through everywhere the algorithm array is. If the algorithm is touched I set its array indexes bool to true. then just loop through the array after processing the collisions to find the algorithms that were not touched and then refresh their manifolds. (Updated files attached).

It works for my purposes but I've got no idea if its going to break something else.

Cheers,
Brad
You do not have the required permissions to view the files attached to this post.
bradclancy
Posts: 7
Joined: Thu Jun 25, 2009 4:32 am

Re: btCompoundCollisionAlgorithm and refreshing the manifolds

Post by bradclancy »

Hey Erwin,

Just one more addition to this, I've found the bulletspu implementation is also refreshing manifolds multiple times. I've got a change to make it work how I want, but again I don't know if it will affect other features. Would this be better posted on PS3 DevNet?

Cheers,
Brad