Esempio n. 1
0
  public void init(Controller c) {
    super.init(c);
    // Make the Display3D.  We'll have it display stuff later.
    display = new Display3D(600, 600, this);

    // attach the portrayals to the displayer, from bottom to top
    display.attach(heatPortrayal, "Heat");
    display.attach(bugPortrayal, "Bugs");
    heatPortrayal.setValueName("Heat");

    HeatBugs hbState = (HeatBugs) state;

    // center the bug graph.  Right now it's located at the (0,0) position.  For
    // example, if it's a 5x5 graph, and the origin is at (0,0), we want to move it
    // to (2,2).  So we want it to be at (  (5-1)/2 = 2,  (5-1/2) = 2  ).  Similarly,
    // if it's a 6x6 graph we want the origin to be at (2.5, 2.5), dead center between
    // the (2,2) and (3,3) grid positions.  To center
    // the origin there, we need to move the graph in the opposite direction.
    // so the general equation for each dimension: (numGridPoints - 1) / -2.0.
    display.translate((hbState.gridWidth - 1) / -2.0, (hbState.gridHeight - 1) / -2.0, 0);

    // now let's scale it so it fits inside a 1x1x1 cube centered at the origin.  We don't
    // have to, but it'll look nicer.
    display.scale(1.0 / Math.max(hbState.gridWidth, hbState.gridHeight));

    displayFrame = display.createFrame();
    c.registerFrame(displayFrame); // register the frame so it appears in the "Display" list
    displayFrame.setVisible(true);
  }
Esempio n. 2
0
  public void setupPortrayals() {
    // display.destroySceneGraph();

    // determine
    SimpleColorMap cm = new SimpleColorMap();
    cm.setLevels(0.0, HeatBugs.MAX_HEAT, Color.blue, Color.red);

    // specify that the "bugs" are going to be cones pointing straight up.
    TransformedPortrayal3D p = new TransformedPortrayal3D(new ConePortrayal3D());
    p.rotateX(90.0);
    bugPortrayal.setPortrayalForAll(p);

    // the heat can be tiles, meshes, or tiles with no change in height (NOZ).
    // Specify which one here.
    switch (heatmode) {
      case TILE:
        quadP = new TilePortrayal(cm, 1f / 2000);
        break;
      case MESH:
        quadP = new MeshPortrayal(cm, 1f / 2000);
        break;
      case NOZ:
        quadP =
            new TilePortrayal(cm); // no height changes, but we need to raise the bugs a little bit
        bugPortrayal.translate(0, 0, 1.0f);
        break;
    }
    heatPortrayal.setPortrayalForAll(quadP);
    // With this line we can tell the bug portrayal to use two triangles rather than
    // a rect to draw each cell.  See the documentation for ValueGrid2DPortrayal3D for
    // why this would be useful and when it is not.
    //      heatPortrayal.setUsingTriangles(true);

    heatPortrayal.setField(((HeatBugs) state).valgrid);
    bugPortrayal.setField(((HeatBugs) state).buggrid);

    // reschedule the displayer
    display.reset();

    // rebuild the scene graph
    display.createSceneGraph();
  }