Game Development Reference
In-Depth Information
class Contact
// Holds the doubly linked list pointers for the ordered list.
Contact * nextInOrder;
Contact * previousInOrder;
// Holds pointers to the next contact that involves each rigid body.
Contact * nextObject[2];
// ... Other data as before ...
class RigidBody.
// Holds the list of contacts that involve this body.
Contact * contacts;
// ... Other data as before ...
At this point we have a set of contacts whose penetration values have changed.
One contact has changed because it has been resolved, and possibly a whole set of
other contacts have been changed as a consequence of that resolution. All of these
may now be in the wrong position in the ordered list. The final stage of this algorithm
is to adjust their positions.
The easiest way to do this is to extract them from the main ordered list. Sort them
as a new sublist, and then walk through the main list, inserting them in order at the
correct point. In abbreviated code, this looks like:
Contact *adjustedList;
Contact *orderedList;
orderedList = sort(contacts);
for (unsigned i = 0; i < positionIterations; i++)
// Make sure the worst contact is bad.
if (orderedList->penetration < 0) break;
// Adjust its position.
Search Nedrilad ::

Custom Search