Esempio n. 1
0
/*! For elastic objects, if we have two contacts close to each other 
	we assume they are actually part of the same contact. This function 
	checks for overlapping neighborhoods and merges them.
*/
void
mergeSoftNeighborhoods(Body *body1, Body *body2, ContactReport &contactSet)
{
	bool mergePerformed = true;

	ContactReport::iterator refContact, otherContact;

	while (mergePerformed) {
		mergePerformed = false;
		//check each contact agains each other contact
		for (refContact=contactSet.begin(); refContact!=contactSet.end(); refContact++) {
			for (otherContact = contactSet.begin(); otherContact != contactSet.end(); otherContact++) {
				if (otherContact == refContact)	continue;

				//this arbitrarily checks only the neighborhoods on body1
				if ( neighborhoodsOverlap(refContact->nghbd1, otherContact->nghbd1) ) {
					DBGP("Overlap found");
					// this should be improved; it keeps the closest contact but merges neighborhoods
					// ideally it should keep the closest contact and RECALCULATE the neighborhoods
					if ( contactDistance(body1, body2, *refContact) < contactDistance(body1, body2, *otherContact) ) {
						mergeNeighborhoods( refContact->nghbd1, otherContact->nghbd1 );
						mergeNeighborhoods( refContact->nghbd2, otherContact->nghbd2 );
						contactSet.erase( otherContact );
					} else {
						mergeNeighborhoods( otherContact->nghbd1, refContact->nghbd1 );
						mergeNeighborhoods( otherContact->nghbd2, refContact->nghbd2 );
						contactSet.erase( refContact );
					}
					mergePerformed = true;
					break;
				} else {
					DBGP("Overlap not found");
				}
			}
			//if we have a merge, restart operation
			if (mergePerformed)
				break;
		}
	}
}