Beispiel #1
0
  public void step() {
    for (int i = 0; i < worldStepsPerLoop; i++) {
      world.step();
      //                if (stepsDone % 100 == 0) {
      //                    System.out.println("println = "+stepsDone);

      //                }
      if (capture) {
        if (stepsDone % 5 == 0) {
          String s = String.format("%06d", stepsDone);
          this.captureToSVG("step" + s + ".svg");
        }
      }
      stepsDone++;
    }

    for (Active active : getActives()) {
      active.setDamping(getFrictionOfSurface(active)); // speedup
      //            active.setDamping((float) frictionBuffer.getFriction((int) active.getX(), (int)
      // active.getY()));
    }
    for (Passive passive : getPassives()) {
      passive.setDamping(getFrictionOfSurface(passive)); // speedup
      //            passive.setDamping((float) frictionBuffer.getFriction((int) passive.getX(),
      // (int) passive.getY()));

    }
    moveVivaes();

    repaint();
  }
Beispiel #2
0
 /** Sets up new coordinates and rotation of all VivaeObjects according to their movement. */
 public void moveVivaes() {
   //        for (Active active : actives) {
   //            active.moveComponent();
   //        }
   for (Passive passive : passives) {
     passive.moveComponent();
   }
   for (VivaeController controller : controllers) {
     controller.moveControlledObject();
   }
 }
Beispiel #3
0
  /**
   * Initializates the World and adds all the actives and passives and physical boundaries inside.
   */
  public void initWorld() {
    encloseWithWalls(50);

    for (Passive passive : getPassives()) {
      world.add(passive.getBody());
    }

    for (Active active : actives) {
      world.add(active.getBody());
    }
    world.setGravity(0, 0);
    setAllArenaPartsAntialiased(isAllArenaPartsAntialiased);
  }
Beispiel #4
0
  /**
   * Paints up the arena and all the surfaces and objects inside without DoubleBuffering.
   *
   * @param svgGraphics
   */
  public void paintUnbuffered(Graphics svgGraphics) {

    svgGraphics.setColor(Color.WHITE);
    svgGraphics.fillRect(this.getX(), this.getY(), screenWidth, screenHeight);

    for (Surface vivaeObject : surfaces) {
      vivaeObject.paintComponent(svgGraphics);
    }
    for (Passive vivaeObject : getPassives()) {
      vivaeObject.paintComponent(svgGraphics, false);
    }
    for (Active active : actives) {
      active.paintComponent(svgGraphics, false);
    }
  }
Beispiel #5
0
  /**
   * Runs the main loop. Several number of world steps (according to worldStepsPerLoop property) is
   * taken, a friction coefficient is set up to all Actives and Passives, the VivaeObjects are
   * moved, if the visible output is turned on, the painting method is called and the thread sleeps
   * for a several (according to loopSleepTime property) milisecs.
   */
  @Override
  public void run() {
    //        while (true) {
    while (isRunning) {
      for (int i = 0; i < worldStepsPerLoop; i++) {
        world.step();
        //                if (stepsDone % 100 == 0) {
        //                    System.out.println("println = "+stepsDone);

        //                }
        if (capture) {
          if (stepsDone % 5 == 0) {
            String s = new PrintfFormat("%06d").sprintf(stepsDone);
            this.captureToSVG("step" + s + ".svg");
          }
        }
        stepsDone++;
      }
      if (stepsDone > totalStepsPerSimulation) isRunning = false;
      for (Active active : getActives()) {
        // active.setDamping(getFrictionOfSurface(active));  //speedup
        active.setDamping(
            (float) frictionBuffer.getFriction((int) active.getX(), (int) active.getY()));
      }
      for (Passive passive : getPassives()) {
        // passive.setDamping(getFrictionOfSurface(passive));  //speedup
        passive.setDamping(
            (float) frictionBuffer.getFriction((int) passive.getX(), (int) passive.getY()));
      }
      moveVivaes();

      if (isVisible && loopSleepTime > 0) {
        repaint();
        if (loopSleepTime > 0) {
          try {
            Thread.sleep(loopSleepTime);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }
    }
  }
Beispiel #6
0
  @Override
  /** Paints up the arena and all the surfaces and objects inside using DoubleBuffering. */
  public void paint(Graphics g) {
    if (offscreen == null) {
      return;
    }
    bufferGraphics.setColor(Color.WHITE);
    bufferGraphics.fillRect(this.getX(), this.getY(), screenWidth, screenHeight);

    for (Surface vivaeObject : surfaces) {
      vivaeObject.paintComponent(bufferGraphics);
    }
    for (Passive vivaeObject : getPassives()) {
      vivaeObject.paintComponent(bufferGraphics, isObjectsOnSightBlinking);
    }
    for (Active active : actives) {
      active.paintComponent(bufferGraphics, isObjectsOnSightBlinking);
    }
    // bufferGraphics.draw(new Rectangle(10,10,100,100));
    // frictionBuffer.paintSensorBuffer(bufferGraphics);
    g.drawImage(offscreen, 0, 0, this);
  }
Beispiel #7
0
 /**
  * Sets up whether the Passive objects in the arena are antialiased.
  *
  * @param isAntialiased
  */
 public void setPassivesAntialiased(boolean isAntialiased) {
   for (Passive passive : passives) {
     passive.setAntialiased(isAntialiased);
   }
 }