예제 #1
0
  // Walls are simply added to environment since they do not need updating
  private void createWalls() {
    int environmentWidth = config.getEnvironmentWidth();
    int environmentHeight = config.getEnvironmentHeight();
    // Left
    Double2D pos = new Double2D(0, environmentHeight / 2.0);
    Double2D v1 = new Double2D(0, -pos.y);
    Double2D v2 = new Double2D(0, pos.y);
    WallObject wall = new WallObject(physicsWorld, pos, v1, v2);
    drawProxy.registerDrawable(wall.getPortrayal());

    // Right
    pos = new Double2D(environmentWidth, environmentHeight / 2.0);
    wall = new WallObject(physicsWorld, pos, v1, v2);
    drawProxy.registerDrawable(wall.getPortrayal());

    // Top
    pos = new Double2D(environmentWidth / 2.0, 0);
    v1 = new Double2D(-pos.x, 0);
    v2 = new Double2D(pos.x, 0);
    wall = new WallObject(physicsWorld, pos, v1, v2);
    drawProxy.registerDrawable(wall.getPortrayal());

    // Bottom
    pos = new Double2D(environmentWidth / 2.0, environmentHeight);
    wall = new WallObject(physicsWorld, pos, v1, v2);
    drawProxy.registerDrawable(wall.getPortrayal());
  }
예제 #2
0
  @Override
  public void start() {
    super.start();

    environment =
        new Continuous2D(1.0, config.getEnvironmentWidth(), config.getEnvironmentHeight());
    drawProxy = new DrawProxy(environment.getWidth(), environment.getHeight());
    environment.setObjectLocation(drawProxy, new Double2D());

    physicsWorld = new World(new Vec2());
    placementArea =
        new PlacementArea((float) environment.getWidth(), (float) environment.getHeight());
    placementArea.setSeed(config.getSimulationSeed());
    schedule.reset();
    System.gc();

    physicsWorld.setContactListener(contactListener);

    // Create ALL the objects
    createWalls();
    createTargetArea();
    robotFactory.placeInstances(
        placementArea.new ForType<>(), physicsWorld, config.getTargetAreaPlacement());
    config.getResourceFactory().placeInstances(placementArea.new ForType<>(), physicsWorld);

    // Now actually add the objects that have been placed to the world and schedule
    for (PhysicalObject object : placementArea.getPlacedObjects()) {
      drawProxy.registerDrawable(object.getPortrayal());
      schedule.scheduleRepeating(object);
    }

    schedule.scheduleRepeating(
        simState -> physicsWorld.step(TIME_STEP, VELOCITY_ITERATIONS, POSITION_ITERATIONS));
  }