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)
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.collide(space);
collision.collide2(box.getNativeAddr(), sphere.getNativeAddr());
// Note that i tried both versions of colliding written above
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();
}
}