Exemplo n.º 1
0
  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();
  }
Exemplo n.º 2
0
  private void simLoop(boolean pause) {
    int i;
    if (!pause) {
      // apply forces to all bodies
      for (i = 0; i < N1; i++) {
        for (int j = 0; j < N2; j++) {
          body[i][j].addForce(FORCE * (i + 1), 0, 0);
        }
      }

      OdeHelper.spaceCollide(space, 0, nearCallback);
      world.step(0.05);

      // remove all contact joints
      contactgroup.empty();
    }

    dsSetColor(1, 0, 1);
    DVector3 sides = new DVector3(LENGTH, LENGTH, HEIGHT);
    for (i = 0; i < N1; i++) {
      for (int j = 0; j < N2; j++) {
        dsDrawBox(box[i][j].getPosition(), box[i][j].getRotation(), sides);
      }
    }
  }