My contacts seem to have stoped working
Here is my code if anyone spots I have missed something stupid.
The contacts that come always have id’s of 0. Body id’s or geom id’s. The collisions work fine though in the actual simulator.
I am using the new BulkContact but it still does not work with the old one
package odeAbstraction;
import org.odejava.Space;
import org.odejava.Geom;
import org.odejava.ode.Ode;
import org.odejava.collision.BulkContact;
import org.odejava.collision.JavaCollision;
import org.odejava.collision.Contact;
import java.util.Observable;
import odeAbstraction.events.ObjectManagerEvents.SimObjectEventListener;
import odeAbstraction.events.ObjectManagerEvents.DynamicObjectEvent;
import odeAbstraction.events.ObjectManagerEvents.StaticObjectEvent;
import odeAbstraction.collision.CollisionRuleManager;
import model.geometry.RelativePrimative;
/**
* User: ttl0
* Date: 02-Aug-2004
* Time: 15:37:07
*/
public class CollisionManager implements SimObjectEventListener {
private final SimWorld world;
private CollisionRuleManager ruleManager = new CollisionRuleManager();
Space space = new Space();
JavaCollision collision = new JavaCollision();
BulkContact contact = new BulkContact(collision.getContactIntBuffer(),
collision.getContactFloatBuffer());
public CollisionManager(SimWorld world) {
setupDefaultCollision();
this.world = world;
}
private void setupDefaultCollision() {
// Setup some surface parameters
collision.setSurfaceMu(1000f);
collision.setSurfaceBounce(0.14f);
collision.setSurfaceBounceVel(0.1f);
collision.setSurfaceMode(Ode.dContactBounce | Ode.dContactApprox1);
}
public void handleCollisions() {
//collision.emptyContactGroup(); allready done in collide
// Collide objects in given space
collision.collide(space);
// Read & modify contact information
iterateContacts();
//update all the contact buffers in one call
contact.commit();
// Add all contacts to contact jointGroup
collision.applyContacts();
}
private void iterateContacts() {
for (Object o : space.getGeoms()) {
Geom geom = (Geom) o;
System.out.println("geom.getNativeAddr() = " + geom.getNativeAddr());
}
for (int i = 0; i < collision.getContactCount(); i++) {
contact.setIndex(i);
System.out.println("contact.getGeomID1() = " + contact.getGeomID1());
System.out.println("contact.getGeomID2() = " + contact.getGeomID2());
System.out.println("contact.getBodyID1() = " + contact.getBodyID1());
System.out.println("contact.getBodyID2() = " + contact.getBodyID2());
ruleManager.process(contact, world);
}
}
public void dynamicObjectListChange(DynamicObjectEvent evt) {
for (RelativePrimative primative : evt.getSimObject().getInfo().getPrimatives()) {
if (evt.getType() == (DynamicObjectEvent.ADDED)) {
space.add(primative.getGeom());
} else if (evt.getType() == (DynamicObjectEvent.REMOVED)) {
space.remove(primative.getGeom());
}
}
}
public void staticObjectListChange(StaticObjectEvent evt) {
//System.out.println("static added to collision");
if (evt.getType() == (StaticObjectEvent.ADDED)){
space.add(evt.getSimObject().getPrimative().getGeom());
}
else if (evt.getType() == (StaticObjectEvent.REMOVED)) {
space.remove(evt.getSimObject().getPrimative().getGeom());
}
}
public CollisionRuleManager getRuleManager() {
return ruleManager;
}
}