Ejemplo n.º 1
0
  /**
   * Render the arrow as a line and a _head.
   *
   * @param gl OpenGL Context
   */
  public void render(GL2 gl) {
    // save Light Attributes and remove lighting to get "full" RGB colors
    // gl.glPushAttrib( GL2.GL_LIGHTING_BIT );
    gl.glPushAttrib(GL2.GL_ENABLE_BIT);
    gl.glDisable(GL2.GL_LIGHTING);

    if (_fg_verb) {
      System.out.println(
          "Arrow pos="
              + _pos.toString()
              + "  angZ1="
              + _angZ1
              + "  angY2="
              + _angY2
              + "  length="
              + _length);
      _fg_verb = false;
    }

    // save transformation matrix, then translate and scale.
    gl.glPushMatrix();
    gl.glTranslatef(_pos.x, _pos.y, _pos.z);
    gl.glRotatef(Matrix.rad2Deg(_angZ1), 0, 0, 1); // rotation around 0z
    gl.glRotatef(Matrix.rad2Deg(_angY2), 0, 1, 0); // rotation around 0y

    // draw line
    gl.glColor4f(_color_fg.x, _color_fg.y, _color_fg.z, _color_fg.w);
    gl.glLineWidth(1.0f);
    gl.glBegin(GL.GL_LINES);
    {
      gl.glVertex3f(0, 0, 0);
      gl.glVertex3f(_length, 0, 0);
    }
    gl.glEnd();

    // draw head
    gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
    gl.glTranslatef(_length, 0, 0);
    gl.glBegin(GL.GL_TRIANGLES);
    {
      for (float[] face : _head_faces) {
        gl.glVertex3f(face[0], face[1], face[2]);
        gl.glVertex3f(face[3], face[4], face[5]);
        gl.glVertex3f(face[6], face[7], face[8]);
      }
    }
    gl.glEnd();

    // restore transformation matrix
    gl.glPopMatrix();
    // restore attributes
    gl.glPopAttrib();
  }