This project has moved and is read-only. For the latest updates, please go here.

Question about Arbiter.Collide()

Feb 27, 2009 at 9:11 AM
Edited Feb 27, 2009 at 9:20 AM
In this method,I have a little question about follow line:

    int index = _contactList.IndexOfSafe(_newContactList[i]);
    I don't understand why to search a new 'Contact 'object  in the '_contactList', maybe their 'ContactId' are equals,but the 'Contact 'object in the '_newContactList' is created in another loop, and I have found that 'Contact._geometryAIndex' always equals 2 ,'Contact._geometryBIndex' always equals 1, the 'Contact._geometryAVertex' means the index of found order.
is there some relationships between the two objects that I didn't found?
Feb 27, 2009 at 5:12 PM
That code is before my time. I will take a look later and answer your question to the best of my knowledge.
Feb 27, 2009 at 10:16 PM
I'm not sure, but it might be part of the sequential impulse solver.

The code you refer to is needed because the last collision update might have had some collisions and the new collision update will calculate the impulse to apply to those contacts.
Basically the engine checks if there is a collision by using the narrow phase collision detector (distance grid for now). If there is a collision, it will detect all the places where those geometries touch (it uses the polygons defined on the surface of the geometry to place the contacts - point of impact) and save them for later. Then it resolves the deepest (the most penetrating) contacts first and save those for later too. (clearing the first contactlist).

Then it arrives to the line you wrote. It has a list of contacts contained inside _newContactList and it then checks _contactList (that contains contacts from the last update) to see if any contacts from the last update equals the one from the current update.
The contacts from the current update then gets cleared and only the new ones are saved for the next update.

As for the geometryBIndex and geometryAIndex, I'm not quite sure why they are even in there. They get defined as 1 and 2 each time and thus is an unused constant. My guess is that it's some code left behind from an earlier version, but I'm not sure and will ask Jeff why they are in there.

Hope this answers your question. I like that you took the time to look into our code and try to figure out how it works. You are more than welcome to post if you find anything you think looks unusual.
Mar 2, 2009 at 3:48 AM
Edited Mar 2, 2009 at 4:11 AM
Thank you for your detailed answer,it makes me know better about how this engine works.

For now, I have know that why to find these contacts from the last update,but to be frank,I'm doubtful of the contacts from the last update and current update witch have the same "ContactId" are really "equal" ? Because the "ContactId" is only depend on the index of found order,when the two collide body moved to another position in the new loop,maybe some contacts are lost (separated),and some new contacts are add in.In this case,the "same" contact maybe has two different "ContactId" in the two update loops,and some old contact's info("NormalImpulse" and  "TangentImpulse") will deliver to another contact.

Otherwise, in the normal situation(I means no contact lost and no new contact add in ),the contacts which have the same "ContactId" maybe just means these two contact's (in the two update loops) position are very close ,so the old contact's impulses will affect to the new one?

I'm not sure this situation is possible to happening,maybe it could be ignore,I just bring out what I thought.

Thanks again for your assistance!

Mar 2, 2009 at 9:08 AM
Edited Mar 2, 2009 at 9:10 AM
It seems to be a bug. The contactId is not unique for different geometries. Contacts created for geom1 can be equal to contacts created for geom2, this should not be possible.
I will take a look at it later. Thanks for notifying me.
Mar 7, 2009 at 12:01 AM
I've confirmed it is a bug and fixed it in the latest source code checkin.
Mar 7, 2009 at 3:20 PM
Nice going! I respect your work.