Exemplo n.º 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();
  }
Exemplo n.º 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();
    }
  }
Exemplo n.º 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);
  }
Exemplo n.º 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);
    }
  }
Exemplo n.º 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();
          }
        }
      }
    }
  }
Exemplo n.º 6
0
 /** Defines reactions on pressed keys for the arena. */
 public void keyPressed(KeyEvent e) {
   switch (e.getKeyCode()) {
     case KeyEvent.VK_A:
       // switch between antialiased and not antialiased painting.
       setAllArenaPartsAntialiased(!isAllArenaPartsAntialiased);
       break;
     case KeyEvent.VK_V:
       // toggles on and off the visibility of the status frames.
       for (Active active : actives) {
         active.setShowingStatusFrame(!active.isShowingStatusFrame());
       }
       break;
     case KeyEvent.VK_P:
       // Sets the status frames to be binded to their owner.
       for (Active active : actives) {
         active.setStatusFramePinedToPosition(!active.isStatusFramePinedToPosition());
       }
       break;
     case KeyEvent.VK_C:
       // captures an SVG output
       captureToSVG(svgOutputFileName);
       break;
     case KeyEvent.VK_N:
       // start caturing
       capture = true;
       break;
     case KeyEvent.VK_M:
       // stop capturing
       capture = false;
       break;
   }
 }
Exemplo n.º 7
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);
  }
Exemplo n.º 8
0
 public void moveActive(Active a) {
   a.moveComponent();
 }
Exemplo n.º 9
0
 /**
  * Sets up whether the Active objects in the arena are antialiased.
  *
  * @param isAntialiased
  */
 public void setActivesAntialiased(boolean isAntialiased) {
   for (Active active : actives) {
     active.setAntialiased(isAntialiased);
   }
 }