[Ode4j-users] hello world
Brought to you by:
tzaeschke
|
From: M@ <mat...@gm...> - 2012-08-22 18:20:49
|
Hello everyone. I'm trying to get a simple bouncing ball going and but the
ball keeps falling through the floor (despite me adding a contact with the
OdeConstants.dContactBounce flag set). One thing that may be complicating
matters is that I'm not using DrawStuff (instead I have the values passing
into a jReality scene graph, which seems to work, I see the ball falling).
Overall my code is this:
public void tick() {
checkForCollisions(null);
physicsWorld.quickStep(dt); // 1/60s
contactsGroup.empty();
}
public void checkForCollisions(Object cause) {
collisionSpace.collide(cause, nearCallback); // TODO: consider using
collide2
}
DGeom.DNearCallback nearCallback = new DGeom.DNearCallback() {
@Override
public void call(Object o, DGeom dgeom, DGeom dgeom1) {
final int contactsCount = 4;
DContactBuffer contacts = new DContactBuffer(contactsCount);
int n = OdeHelper.collide(dgeom1, dgeom, contactsCount,
contacts.getGeomBuffer());
for (int i = 0; i < n; i++) {
DContact contact = contacts.get(i);
contact.surface.mode = OdeConstants.dContactSoftCFM |
OdeConstants.dContactBounce;
if (dgeom instanceof DSphere || dgeom1 instanceof DSphere) {
contact.surface.mu = 20;
} else {
contact.surface.mu = 0.5;
}
contact.surface.bounce = 0.7;
contact.surface.slip1 = 0.0;
contact.surface.slip2 = 0.0;
contact.surface.soft_erp = 0.8;
contact.surface.soft_cfm = 0.01;
DJoint c = OdeHelper.createContactJoint(physicsWorld, contactsGroup,
contact);
c.attach(dgeom.getBody(), dgeom1.getBody());
}
}
};
Tick is called every .1s or so, which is fine for my purposes.
Any idea what I'm doing wrong?
--M@
|