// bodypair = new Pair<Body>(b2,b1);
// geometrypair = new Pair<Geometry>(inputpair.getSecond(), inputpair.getFirst());
// }
ContactConstraint contactConstraint = null;
//a contact constraint already exists
if (contactConstraints.containsKey(bodypair)) {
contactConstraint = contactConstraints.get(bodypair);
// order the geometry pair to match the order of the contact constraint.
// this is necessary to keep normals pointing in the right direction when
// contact constraints have more than one contact generator
Pair<Body> orderedpair = contactConstraint.getBodies();
if (orderedpair.getFirst() == bodypair.getFirst()) {
// same order
geometrypair = inputpair;
} else {
// swap
geometrypair = new Pair<Geometry>(inputpair.getSecond(),inputpair.getFirst());
}
//add a new contact generator to this contact constraint
ContactGenerator generator = getContactGenerator(geometrypair);
contactGenerators.put(geometrypair, generator);
contactConstraint.addGenerator(generator);
//no contact constraint is present
} else {
//do not act if some other constraint(joint) is already present
//in the contact graph
if (constraintGraph.getEdge(bodypair) == null) {
//create a new contact generator
ContactGenerator generator = getContactGenerator(inputpair);
// try custom contact constraint generators
for ( ContactConstraintCreator c : contactConstraintCreators) {
contactConstraint = c.createContactConstraint(bodypair.getFirst(), bodypair.getSecond(), generator);
if (contactConstraint != null)
break;
}
// if no contact constraint was obtained, use the default creator
if ( contactConstraint == null) {
contactConstraint = defaultcreator.createContactConstraint(bodypair.getFirst(), bodypair.getSecond(), generator);
}
//insert into data structures
contactConstraints.put(bodypair, contactConstraint);
contactGenerators.put(inputpair, generator);
constraintGraph.addEdge( bodypair, contactConstraint);
// signal handlers
for (Handler h: handlers) {
h.contactConstraintCreated(bodypair, contactConstraint);
}
}
}
}
@Override
public final void separation(Pair<Geometry> geometrypair) {
//retrieve the bodies associated with overlapping geometries
Body a = geometrypair.getFirst().getBody();
Body b = geometrypair.getSecond().getBody();
Pair<Body> bodypair = new Pair<Body>(a,b);
//ignore overlaps stemming from the same body
if ( a == b) return;
//ignore overlaps for non-body geometries
if ( a == null || b == null) return;
//ignore overlaps of fixed bodies
if ( a.isFixed() && b.isFixed() ) return;
//if this geometry pair has an acting contact constraint,
//we must remove the contact generator
if (contactConstraints.containsKey(bodypair)) {
//check that we have the generator (if not, something is very wrong)
if (contactGenerators.containsKey(geometrypair)) {
//remove the generator from the contact constraint
ContactConstraint constraint = contactConstraints.get(bodypair);
ContactGenerator cg = contactGenerators.get(geometrypair);
//notify contact generator (for possible clean-up)
cg.remove();
// remove from contact constraint
constraint.removeGenerator(cg);
//remove the generator from our list
contactGenerators.remove(geometrypair);
//if the contact constraint has no more generators, also
//remove the contact constraint
if (constraint.getNumberOfGenerators() < 1 ) {
contactConstraints.remove(bodypair);
constraintGraph.removeEdge(bodypair);
// signal event handlers
for (Handler h: handlers) {