Hello,
I want to create an application which tests the collision of geoms (not bodies). When i run the following program, i get contact counts as zero. Do you have any idea about what the problem is?
(In fact i want to test collision of trimeshes but this simple example just test collision of a sphere and a box)
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
| public class TestBoxSphereGeomCollision {
World world; HashSpace space; JavaCollision collision; Contact contact;
GeomBox box; GeomSphere sphere;
public TestBoxSphereGeomCollision() { Odejava.getInstance(); initWorld(); initObjects(); for (int i=0; i<100; i++) { step(); } cleanup(); }
private void initWorld() { world = new World(); world.setGravity(0f, 0f, 0f); world.setStepInteractions(10); world.setStepSize(0.05f); collision = new JavaCollision(world);
contact = new Contact( collision.getContactIntBuffer(), collision.getContactFloatBuffer()); space = new HashSpace(); collision.setSurfaceMode(0); collision.setSurfaceMu(Float.MAX_VALUE); }
private void initObjects() {
box = new GeomBox("box1", 15, 15, 15); box.setPosition(0f , 0f, 0f); space.addGeom(box); sphere = new GeomSphere("sphere1", 20); sphere.setPosition(0f , 0f, 1f); space.addGeom(sphere); }
public void step() { collision.collide2(box.getNativeAddr(), sphere.getNativeAddr()); iterateContacts(); collision.applyContacts(); world.stepFast(); }
private void iterateContacts() { System.out.println("ContactCount: "+collision.getContactCount());
}
public void cleanup() { space.delete(); collision.delete(); world.delete(); Ode.dCloseODE(); } } |