private void demo(String[] args) { int i, j; DMass m = OdeHelper.createMass(); // create world OdeHelper.initODE2(0); world = OdeHelper.createWorld(); space = OdeHelper.createHashSpace(null); contactgroup = OdeHelper.createJointGroup(); world.setGravity(0, 0, -GRAVITY); ground = OdeHelper.createPlane(space, 0, 0, 1, 0); // bodies for (i = 0; i < N1; i++) { for (j = 0; j < N2; j++) { body[i][j] = OdeHelper.createBody(world); m.setBox(1, LENGTH, LENGTH, HEIGHT); m.adjust(MASS * (j + 1)); body[i][j].setMass(m); body[i][j].setPosition(i * 2 * LENGTH, j * 2 * LENGTH, HEIGHT * 0.5); box[i][j] = OdeHelper.createBox(space, LENGTH, LENGTH, HEIGHT); box[i][j].setBody(body[i][j]); } } // run simulation dsSimulationLoop(args, 352, 288, this); contactgroup.destroy(); space.destroy(); world.destroy(); OdeHelper.closeODE(); }
/** The call to ragdoll.destroy() used to cause an NPE. */ @Test public void testIssue31() { DWorld world = OdeHelper.createWorld(); world.setGravity(0, 0, -9.8); world.setDamping(1e-4, 1e-5); // dWorldSetERP(world, 1); DSpace space = OdeHelper.createSimpleSpace(); OdeHelper.createPlane(space, 0, 0, 1, 0); DxRagdoll ragdoll = new DxRagdoll(world, space, new DxDefaultHumanRagdollConfig()); ragdoll.setAngularDamping(0.1); DQuaternion q = new DQuaternion(1, 0, 0, 0); Rotation.dQFromAxisAndAngle(q, new DVector3(1, 0, 0), -0.5 * Math.PI); for (int i = 0; i < ragdoll.getBones().size(); i++) { DxRagdollBody bone = ragdoll.getBones().get(i); DGeom g = OdeHelper.createCapsule(space, bone.getRadius(), bone.getLength()); DBody body = bone.getBody(); DQuaternion qq = new DQuaternion(); OdeMath.dQMultiply1(qq, q, body.getQuaternion()); body.setQuaternion(qq); DMatrix3 R = new DMatrix3(); OdeMath.dRfromQ(R, q); DVector3 v = new DVector3(); OdeMath.dMultiply0_133(v, body.getPosition(), R); body.setPosition(v.get0(), v.get1(), v.get2()); g.setBody(body); } ragdoll.destroy(); }