Ejemplo n.º 1
0
  public void createPolygons() {
    Graphics2D g = screen.getGraphics();
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, screen.getWidth(), screen.getHeight());
    g.setColor(Color.WHITE);
    g.drawString("Loading...", 5, screen.getHeight() - 5);
    screen.update();

    float ambientLightIntensity = .2f;
    List lights = new LinkedList();
    lights.add(new PointLight3D(-100, 100, 100, .3f, -1));
    lights.add(new PointLight3D(100, 100, 0, .3f, -1));

    MapLoader loader = new MapLoader(new BSPTreeBuilderWithPortals());
    loader.setObjectLights(lights, ambientLightIntensity);

    try {
      bspTree = loader.loadMap(mapFile);
    } catch (IOException ex) {
      ex.printStackTrace();
    }

    collisionDetection = new CollisionDetectionWithSliding(bspTree);
    gameObjectManager = new GridGameObjectManager(bspTree.calcBounds(), collisionDetection);
    gameObjectManager.addPlayer(new Player());

    ((BSPRenderer) polygonRenderer).setGameObjectManager(gameObjectManager);

    createGameObjects(loader.getObjectsInMap());
    Transform3D start = loader.getPlayerStartLocation();
    gameObjectManager.getPlayer().getTransform().setTo(start);
  }
Ejemplo n.º 2
0
  public void drawPolygons(Graphics2D g) {

    polygonRenderer.startFrame(g);

    // draw polygons in bsp tree (set z buffer)
    ((BSPRenderer) polygonRenderer).draw(g, bspTree);

    // draw game object polygons (check and set z buffer)
    gameObjectManager.draw(g, (GameObjectRenderer) polygonRenderer);

    polygonRenderer.endFrame(g);
  }