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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| 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;
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() { collision.setSurfaceMu(1000f); collision.setSurfaceBounce(0.14f); collision.setSurfaceBounceVel(0.1f); collision.setSurfaceMode(Ode.dContactBounce | Ode.dContactApprox1); }
public void handleCollisions() { collision.collide(space); iterateContacts();
contact.commit(); 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) { 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; } } |