예제 #1
0
  @Override
  public void render(GLCanvas canvas) {
    gui.getGL().glColor4f(bg_col.getR(), bg_col.getG(), bg_col.getB(), bg_col.getA());
    renderQuad(pos.x, pos.y, width, height);

    GL gl = canvas.getGL();

    if (texture != null) {
      texture.bind(0);

      gl.glColor4f(fg_col.getR(), fg_col.getG(), fg_col.getB(), fg_col.getA());
      gl.glBegin(GL.GL_QUADS);
      gl.glTexCoord2f(0, 0);
      gl.glVertex2f(pos.x, pos.y);
      gl.glTexCoord2f(texture.getImageWidth() / texture.getWidth(), 0);
      gl.glVertex2f(pos.x + width, pos.y);
      gl.glTexCoord2f(
          texture.getImageWidth() / texture.getWidth(),
          texture.getImageHeight() / texture.getHeight());
      gl.glVertex2f(pos.x + width, pos.y - height);
      gl.glTexCoord2f(0, texture.getImageHeight() / texture.getHeight());
      gl.glVertex2f(pos.x, pos.y - height);
      gl.glEnd();

      texture.unbind();
    }

    gui.getGL()
        .glColor4f(border_col.getR(), border_col.getG(), border_col.getB(), border_col.getA());
    renderOutlinedQuad(pos.x, pos.y, width, height);
  }
예제 #2
0
  public void display(GLCanvas canvas) {
    GL gl = canvas.getGL();

    //
    // render the simulation
    //
    try {
      sim.update();
    } catch (Exception e) {
      Log.println("[Editor] exception in simulation update/calculate paths: " + e.getMessage());
      e.printStackTrace();
    }
    renderer.render(sim, canvas);

    //
    // render the grid
    //
    gl.glColor4f(0.4f, 0.4f, 0.4f, 0.4f);
    gl.glEnable(GL.GL_BLEND);
    gl.glBegin(GL.GL_LINES);
    for (int x = 0; x < 100; x++) {
      gl.glVertex2f(
          -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4,
          -50 * Constants.PLANET_MAX_SIZE * 4);
      gl.glVertex2f(
          -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4,
          50 * Constants.PLANET_MAX_SIZE * 4);
    }

    for (int x = 0; x < 100; x++) {
      gl.glVertex2f(
          -50 * Constants.PLANET_MAX_SIZE * 4,
          -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4);
      gl.glVertex2f(
          +50 * Constants.PLANET_MAX_SIZE * 4,
          -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4);
    }
    gl.glDisable(GL.GL_BLEND);
    gl.glEnd();

    //
    // render rectangle selection
    //
    if (drag_start != null && drag_end != null && selected_planets.size() == 0) {
      gl.glLineWidth(2);
      gl.glColor4f(1, 1, 1, 1);
      Widget.renderOutlinedQuad(
          drag_start.x, drag_start.y, drag_end.x - drag_start.x, -(drag_end.y - drag_start.y));
      gl.glLineWidth(1);
    }

    //
    // render reference system
    //
    gl.glColor3f(1, 1, 1);
    gl.glBegin(GL.GL_LINES);
    gl.glColor3f(1, 0, 0);
    gl.glVertex2f(Constants.PLANET_MAX_SIZE * 50, 0);
    gl.glVertex2f(-Constants.PLANET_MAX_SIZE * 50, 0);
    gl.glColor3f(0, 1, 0);
    gl.glVertex2f(0, Constants.PLANET_MAX_SIZE * 50);
    gl.glVertex2f(0, -Constants.PLANET_MAX_SIZE * 50);
    gl.glEnd();

    try {
      Thread.sleep(5);
    } catch (InterruptedException e) {
    }

    //
    // check mouse over planet
    //
    if (sim.getPlanet(
                renderer.getCamera().getScreenToWorldX(mouse_pos.x),
                renderer.getCamera().getScreenToWorldY(mouse_pos.y))
            != null
        && !this.wasGuiIntersected(mouse_pos.x, mouse_pos.y)
        && drag_start != null) for (WorldAlignementContainer cont : conts) cont.setVisible(false);
    else for (WorldAlignementContainer cont : conts) cont.setVisible(true);
  }