private void drawStar(GL2 gl, GLAutoDrawable drawable, Float x, Float y, Float z) {
    // Pushing to matrix stack
    gl.glPushMatrix();

    // STAR
    // Moves the figure in the (x, y, z)-axis
    gl.glTranslatef(x, y, z);

    // BEGIN Star
    gl.glBegin(GL_LINE_LOOP);

    // Pushing to attribute stack
    gl.glPushAttrib(GL_ALL_ATTRIB_BITS);

    // Set color to GREEN
    gl.glColor3f(0.0f, 1.0f, 0.0f);

    // Draw the sides
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(0.2f, 0.2f, 0.0f);
    gl.glVertex3f(1.0f, 0.0f, 0.0f);
    gl.glVertex3f(0.2f, -0.2f, 0.0f);
    gl.glVertex3f(0.0f, -1.0f, 0.0f);
    gl.glVertex3f(-0.2f, -0.2f, 0.0f);
    gl.glVertex3f(-1.0f, 0.0f, 0.0f);
    gl.glVertex3f(-0.2f, 0.2f, 0.0f);

    // END Star
    gl.glEnd();

    // Popping state
    gl.glPopAttrib();
    gl.glPopMatrix();
  }
  private void drawSquare(GL2 gl, GLAutoDrawable drawable, Float x, Float y, Float z) {
    // Pushing to matrix stack
    gl.glPushMatrix();

    // SQUARE
    // Moves the figure in the (x, y, z)-axis
    gl.glTranslatef(x, y, z);

    // Makes so that square is filled in
    gl.glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    // BEGIN Square
    gl.glBegin(GL_QUADS);

    // Pushing to attribute stack
    gl.glPushAttrib(GL_ALL_ATTRIB_BITS);

    // Set color to BLUE
    gl.glColor3f(0.0f, 0.0f, 1.0f);

    // The Quad
    gl.glVertex3f(1.0f, 1.0f, 1.0f);
    gl.glVertex3f(-1.0f, 1.0f, 1.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);

    // END Square
    gl.glEnd();

    // Popping state
    gl.glPopAttrib();
    gl.glPopMatrix();
  }
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    // need a valid GL context for this ..

    /** OpenGL .. texture.updateSubImage(textureData, 0, 20, 20, 20, 20, 100, 100); */

    // Now draw one quad with the texture
    if (null != texture) {
      texture.enable();
      texture.bind();
      gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);
      TextureCoords coords = texture.getImageTexCoords();
      gl.glBegin(GL2.GL_QUADS);
      gl.glTexCoord2f(coords.left(), coords.bottom());
      gl.glVertex3f(0, 0, 0);
      gl.glTexCoord2f(coords.right(), coords.bottom());
      gl.glVertex3f(1, 0, 0);
      gl.glTexCoord2f(coords.right(), coords.top());
      gl.glVertex3f(1, 1, 0);
      gl.glTexCoord2f(coords.left(), coords.top());
      gl.glVertex3f(0, 1, 0);
      gl.glEnd();
      texture.disable();
    }
  }
Example #4
0
  /**
   * Draws a filled 2D circle centered on the specified point and contained in the XY plane (z=0).
   * Uses an efficient parametric algorithm to avoid expensive calls to triginometric functions.
   * Verticies are evenly spaced in parameter space.
   *
   * <p>Reference: Rogers, D.F., Adams, J.A., _Mathematical_Elements_For_Computer_Graphics_,
   * McGraw-Hill, 1976, pg 103, 216.
   *
   * @param gl Reference to the graphics context we are rendering into.
   * @param x X Coordinate of the center of the circle.
   * @param y Y Coordinate of the center of the circle.
   * @param radius The radius of the cirlce.
   * @param numVerts The number of verticies to use.
   */
  public static final void drawCircleFill(GL2 gl, float x, float y, float radius, int numVerts) {

    //  Calculate the parametric increment.
    double p = 2 * Math.PI / (numVerts - 1);
    float c1 = (float) Math.cos(p);
    float s1 = (float) Math.sin(p);

    //  Calculate the initial point.
    float xm1 = x + radius;
    float ym1 = y;

    //  Begin rendering the circle.
    gl.glBegin(GL2.GL_TRIANGLE_FAN);
    gl.glVertex3f(x, y, 0.0f); // origin
    for (int m = 0; m < numVerts; ++m) {
      float xm1mx = xm1 - x;
      float ym1mx = ym1 - y;
      float x1 = x + xm1mx * c1 - ym1mx * s1;
      float y1 = y + xm1mx * s1 + ym1mx * c1;

      //  Draw the next line segment.
      gl.glVertex3f(x1, y1, 0);

      //  Prepare for the next loop.
      xm1 = x1;
      ym1 = y1;
    }
    gl.glEnd();
  }
Example #5
0
  /** Called back by the animator to perform rendering. */
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
    gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers
    gl.glLoadIdentity(); // reset the model-view matrix

    gl.glTranslatef(0.0f, 0.0f, -12.0f);
    gl.glRotatef(rotateAnleX, 1.0f, 0.0f, 0.0f);
    gl.glRotatef(rotateAnleY, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(rotateAngleZ, 0.0f, 0.0f, 1.0f);

    // need to flip the image
    float textureHeight = textureTop - textureBottom;

    float x1, y1, x2, y2; // used to break the flag into tiny quads

    gl.glBegin(GL_QUADS);
    for (int x = 0; x < numPoints - 1; x++) {
      for (int y = 0; y < numPoints - 1; y++) {
        x1 = (float) x / 44.0f;
        y1 = (float) y / 44.0f;
        x2 = (float) (x + 1) / 44.0f;
        y2 = (float) (y + 1) / 44.0f;

        // Texture need to flip vertically
        gl.glTexCoord2f(x1, y1 * textureHeight + textureBottom);
        gl.glVertex3f(points[x][y][0], points[x][y][1], points[x][y][2]);

        gl.glTexCoord2f(x1, y2 * textureHeight + textureBottom);
        gl.glVertex3f(points[x][y + 1][0], points[x][y + 1][1], points[x][y + 1][2]);

        gl.glTexCoord2f(x2, y2 * textureHeight + textureBottom);
        gl.glVertex3f(points[x + 1][y + 1][0], points[x + 1][y + 1][1], points[x + 1][y + 1][2]);

        gl.glTexCoord2f(x2, y1 * textureHeight + textureBottom);
        gl.glVertex3f(points[x + 1][y][0], points[x + 1][y][1], points[x + 1][y][2]);
      }
    }
    gl.glEnd();

    if (wiggleCount == 2) { // Used To Slow Down The Wave (Every 2nd Frame Only)
      for (int y = 0; y < 45; y++) {
        float tempHold = points[0][y][2]; // Store current value One Left Side Of
        // Wave
        for (int x = 0; x < 44; x++) {
          // Current Wave Value Equals Value To The Right
          points[x][y][2] = points[x + 1][y][2];
        }
        points[44][y][2] = tempHold; // Last Value Becomes The Far Left Stored
        // Value
      }
      wiggleCount = 0; // Set Counter Back To Zero
    }
    wiggleCount++;

    // update the rotational position after each refresh
    rotateAnleX += roateSpeedX;
    rotateAnleY += rotateSpeedY;
    rotateAngleZ += rotateSpeedZ;
  }
Example #6
0
  @Override
  public void display(GLAutoDrawable gLDrawable) {
    final GL2 gl = gLDrawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f, 0.0f, -5.0f);

    // rotate about the three axes
    gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
    gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);

    // Draw A Quad
    gl.glBegin(GL2.GL_QUADS);
    gl.glColor3f(0.0f, 1.0f, 1.0f); // set the color of the quad
    gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
    gl.glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
    gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
    gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
    // Done Drawing The Quad
    gl.glEnd();

    // increasing rotation for the next iteration
    rotateT += 0.2f;
  }
Example #7
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();
  }
  @Override
  public void render(GL2 gl, float trajectory) {
    //		flat = true;

    gl.glPushMatrix();
    {
      gl.glTranslatef(c.x, c.y, c.z);
      gl.glRotatef(trajectory, 0, -1, 0);
      gl.glRotatef((flat) ? -90 : 0, 1, 0, 0);
      gl.glRotatef(rotation, 0, 0, 1);

      Vec3 scale = new Vec3(0.75f, 2.0f, 0);
      if (miniature) scale = scale.multiply(0.5f);
      scale = scale.multiply(0.8f);

      gl.glScalef(scale.x, scale.y, scale.z);
      gl.glTranslatef(0, 0.2f, 0);

      gl.glDepthMask(false);
      gl.glDisable(GL_LIGHTING);
      gl.glEnable(GL_BLEND);
      gl.glEnable(GL_TEXTURE_2D);

      gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE);

      whiteSpark.bind(gl);

      gl.glColor3f(colors[color][0], colors[color][1], colors[color][2]);

      gl.glBegin(GL_QUADS);
      {
        gl.glTexCoord2f(1.0f, 1.0f);
        gl.glVertex3f(-0.5f, -0.5f, 0.0f);
        gl.glTexCoord2f(1.0f, 0.0f);
        gl.glVertex3f(-0.5f, 0.5f, 0.0f);
        gl.glTexCoord2f(0.0f, 0.0f);
        gl.glVertex3f(0.5f, 0.5f, 0.0f);
        gl.glTexCoord2f(0.0f, 1.0f);
        gl.glVertex3f(0.5f, -0.5f, 0.0f);
      }
      gl.glEnd();

      gl.glDisable(GL_BLEND);
      gl.glEnable(GL_LIGHTING);
      gl.glDepthMask(true);

      gl.glColor3f(1, 1, 1);
    }
    gl.glPopMatrix();
  }
Example #9
0
    /**
     * Render all particles to the OpenGL context
     *
     * @param gl
     */
    protected void render(GL2 gl) {
      gl.glBegin(GL2.GL_QUADS);

      for (int i = 0; i < (range.getGlobalSize(0) * 3); i += 3) {
        gl.glTexCoord2f(0, 1);
        gl.glVertex3f(xyz[i + 0], xyz[i + 1] + 1, xyz[i + 2]);
        gl.glTexCoord2f(0, 0);
        gl.glVertex3f(xyz[i + 0], xyz[i + 1], xyz[i + 2]);
        gl.glTexCoord2f(1, 0);
        gl.glVertex3f(xyz[i + 0] + 1, xyz[i + 1], xyz[i + 2]);
        gl.glTexCoord2f(1, 1);
        gl.glVertex3f(xyz[i + 0] + 1, xyz[i + 1] + 1, xyz[i + 2]);
      }
      gl.glEnd();
    }
  public void display(GLAutoDrawable drawable) {

    GL2 gl = drawable.getGL().getGL2();

    // Clear the drawing area
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    // Reset the current matrix to the "identity"
    gl.glLoadIdentity();

    // Move the "drawing cursor" around
    gl.glTranslatef(-1.5f, 0.0f, -6.0f);

    // Drawing Using Triangles
    gl.glBegin(GL2.GL_TRIANGLES);
    gl.glColor3f(1.0f, 0.0f, 0.0f); // Set the current drawing color to red
    gl.glVertex3f(0.0f, 1.0f, 0.0f); // Top
    gl.glColor3f(0.0f, 1.0f, 0.0f); // Set the current drawing color to green
    gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
    gl.glColor3f(0.0f, 0.0f, 1.0f); // Set the current drawing color to blue
    gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
    // Finished Drawing The Triangle
    gl.glEnd();

    // Move the "drawing cursor" to another position
    gl.glTranslatef(3.0f, 0.0f, 0.0f);
    // Draw A Quad
    gl.glBegin(GL2.GL_QUADS);
    gl.glColor3f(0.5f, 0.5f, 1.0f); // Set the current drawing color to light blue
    gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
    gl.glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
    gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
    gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
    // Done Drawing The Quad
    gl.glEnd();
  }
Example #11
0
  @Override
  protected void _render(GL2 gl, GLU glu, GLUT glut) {

    gl.glScalef(.3f, .3f, 1);

    gl.glBegin(GL2.GL_QUADS);

    for (int i = 12; i >= 1; i--) {

      gl.glColor3f(1 - (i / 12f), 1 - (i / 12f), 1 - (i / 12f));

      gl.glVertex3f(-i, -i, 0);
      gl.glVertex3f(i, -i, 0);
      gl.glVertex3f(i, i, 0);
      gl.glVertex3f(-i, i, 0);
    }

    gl.glEnd();
  }
Example #12
0
  /**
   * This method is a temporary helper method for draving the light for debuging purposes. Except it
   * to decome deprecated in the future.
   */
  public void renderLight(GL2 gl) {
    gl.glDisable(GLLightingFunc.GL_LIGHTING);
    ShaderProgram.unuseCurrent(gl);
    switch (type) {
      case Directional:
        gl.glBegin(GL2.GL_LINES);
        gl.glColor3f(0.0f, 0.0f, 0.0f);
        gl.glVertex3f(0.0f, 0.0f, 0.0f);
        gl.glColor3f(1.0f, 1.0f, 1.0f);
        gl.glVertex3f(position.x, position.y, position.z);
        gl.glEnd();
        break;
      case Point:
        gl.glBegin(GL2.GL_POINTS);
        gl.glColor3f(1.0f, 1.0f, 1.0f);
        gl.glVertex3f(position.x, position.y, position.z);
        gl.glEnd();
        break;
      case Spot:
        Vector3f p = position, d = new Vector3f();
        d.set(direction);
        d.scale(4);

        gl.glBegin(GL2.GL_LINES);
        gl.glColor3f(1.0f, 1.0f, 1.0f);
        gl.glVertex3f(p.x, p.y, p.z);
        gl.glColor3f(0.2f, 0.2f, 0.2f);
        gl.glVertex3f(p.x + d.x, p.y + d.y, p.z + d.z);

        /* Spot wireframe
        d.normalize();
        //d.
        d.cross(d, new Vector3f(0.0f, 1.0f, 0.0f));
        gl.glColor3f(1.0f, 1.0f, 1.0f);
        gl.glVertex3f(p.x, p.y, p.z);
        gl.glColor3f(0.4f, 0.2f, 0.2f);
        gl.glVertex3f(p.x+d.x, p.y+d.y, p.z+d.z);
        */
        gl.glEnd();
    }
    gl.glEnable(GLLightingFunc.GL_LIGHTING);
  }
Example #13
0
  /*
   * display() draws a triangle at an angle.
   */
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    if (key != null)
      switch (key.getKeyChar()) {
        case 'c':
          gl.glFogi(GL2.GL_FOG_COORDINATE_SOURCE, GL2.GL_FRAGMENT_DEPTH);
          break;
        case 'C':
          gl.glFogi(GL2.GL_FOG_COORDINATE_SOURCE, GL2.GL_FOG_COORDINATE);
          break;

        case 'b':
          gl.glMatrixMode(GL2.GL_MODELVIEW);
          gl.glTranslatef(0.0f, 0.0f, -0.25f);
          break;
        case 'f':
          gl.glMatrixMode(GL2.GL_MODELVIEW);
          gl.glTranslatef(0.0f, 0.0f, 0.25f);
          break;
        default:
          break;
      }

    gl.glColor3f(1.0f, 0.75f, 0.0f);
    gl.glBegin(GL2.GL_TRIANGLES);
    gl.glFogCoordf(f1);
    gl.glVertex3f(2.0f, -2.0f, 0.0f);
    gl.glFogCoordf(f2);
    gl.glVertex3f(-2.0f, 0.0f, -5.0f);
    gl.glFogCoordf(f3);
    gl.glVertex3f(0.0f, 2.0f, -10.0f);
    gl.glEnd();

    gl.glFlush();
  }
Example #14
0
  /**
   * Draws the outline of a 2D inclinded elliptical arc starting at "angle" and extending to angle +
   * sweep, centered on the specified point, and contained in the XY plane (z=0). Note that "angle"
   * is defined differently than it is for gluPartialDisk()! Uses an efficient parametric algorithm
   * to avoid expensive calls to triginometric functions. Verticies are evenly spaced in parameter
   * space. If "a" and "b" are equal, a circular arc will be rendered.
   *
   * <p>Reference: Rogers, D.F., Adams, J.A., _Mathematical_Elements_For_Computer_Graphics_,
   * McGraw-Hill, 1976, pg 104, 216.
   *
   * @param gl Reference to the graphics context we are rendering into.
   * @param x X Coordinate of the center of the ellipse defining the arc.
   * @param y Y Coordinate of the center of the ellipse defining the arc.
   * @param a Length of the semi-major axis of the ellipse defining the arc, oriented along the X
   *     axis.
   * @param b Length of the semi-minor axis of the ellipse defining the arc, oriented along the Y
   *     axis.
   * @param inc Inclination angle of the major axis in degrees.
   * @param angle The initial angle to begin the arc in degrees. 0 is along the + major axis (+X for
   *     zero inc), 90 is along the + minor axis (+Y for zero inc), 180 along the - major axis and
   *     270 degrees is along the - minor axis.
   * @param sweep The number of degrees to sweep the arc through.
   * @param numVerts The number of verticies to use.
   */
  public static final void drawArc(
      GL2 gl,
      float x,
      float y,
      float a,
      float b,
      float inc,
      float angle,
      float sweep,
      int numVerts) {

    //  Calculate the sine and cosine of the inclination angle.
    double p = inc * Math.PI / 180;
    float c1 = (float) Math.cos(p);
    float s1 = (float) Math.sin(p);

    //  Calculate the parametric increment.
    p = sweep * Math.PI / 180 / (numVerts - 1);

    //  Calculate the sine and cosine of the parametric increment.
    float c2 = (float) Math.cos(p);
    float s2 = (float) Math.sin(p);

    //  Initialize the accumulation variables.
    p = angle * Math.PI / 180;
    float c3 = (float) Math.cos(p);
    float s3 = (float) Math.sin(p);

    //  Begin rendering the arc.
    gl.glBegin(GL2.GL_LINE_STRIP);
    for (int m = 0; m < numVerts; ++m) {
      //  Calculate increments in X & Y.
      float x1 = a * c3;
      float y1 = b * s3;

      //  Calculate new X & Y.
      float xm = x + x1 * c1 - y1 * s1;
      float ym = y + x1 * s1 + y1 * c1;

      //  Draw the next line segment.
      gl.glVertex3f(xm, ym, 0);

      //  Calculate new angle values.
      float t1 = c3 * c2 - s3 * s2;
      s3 = s3 * c2 + c3 * s2;
      c3 = t1;
    }
    gl.glEnd();
  }
Example #15
0
  /*
   * Sends a quadrilateral to the OpenGL pipeline. Mimics the other quad
   * function.
   */
  public static void quad(
      Vector3f v0, Vector3f v1, Vector3f v2, Vector3f v3, Vector3f n, Color3f c, GLAutoDrawable d) {

    GL2 gl = d.getGL().getGL2();

    gl.glBegin(GL2.GL_QUADS);

    gl.glColor3f(c.x, c.y, c.z);
    gl.glNormal3f(n.x, n.y, n.z);

    gl.glTexCoord2f(t0.x, t0.y);
    gl.glVertex3f(v0.x, v0.y, v0.z);

    gl.glTexCoord2f(t1.x, t1.y);
    gl.glVertex3f(v1.x, v1.y, v1.z);

    gl.glTexCoord2f(t2.x, t2.y);
    gl.glVertex3f(v2.x, v2.y, v2.z);

    gl.glTexCoord2f(t3.x, t3.y);
    gl.glVertex3f(v3.x, v3.y, v3.z);

    gl.glEnd();
  }
Example #16
0
  @Override
  public void draw(GL2 gl) {
    // Arbres triangles
    gl.glBegin(GL_TRIANGLES);

    gl.glColor3f(30.0f / 256.0f, 109.0f / 256.0f, 54.0f / 256.0f);
    gl.glVertex3f(0.0f, hauteurArbre, 0.0f);
    gl.glVertex3f(-largeurArbre, 0.0f, 0.0f);
    gl.glVertex3f(largeurArbre, 0.0f, 0.0f);
    gl.glColor3f(47.0f / 256.0f, 135.0f / 256.0f, 74.0f / 256.0f);
    gl.glVertex3f(0.0f, hauteurArbre, 0.0f);
    gl.glVertex3f(0.0f, 0.0f, -largeurArbre);
    gl.glVertex3f(0.0f, 0.0f, largeurArbre);

    gl.glEnd();
  }
Example #17
0
  @Override
  protected void draw(GL2 gl, AbstractCamera camera, Vec3 sun) {
    // by default, active sets visibility of entity
    if (!active) {
      return;
    }

    worldMatrix = createWorldMatrix();

    if (shader != null) {
      shader.use(gl);
      shader.updateUniform(gl, "world", worldMatrix);
      shader.updateUniform(gl, "view", camera.view);
      shader.updateUniform(gl, "projection", camera.projection);

      if (colour != null) {
        shader.updateUniform(gl, "colour", colour);
      }

      shader.updateUniform(gl, "opacity", opacity);
    }

    if (opacity < 1.0f) {
      gl.glEnable(GL.GL_BLEND);
    }

    gl.glBegin(GL.GL_LINE_STRIP);
    {
      for (int i = 0; i < line.length; i++) {
        gl.glVertex3f(line[i].getX(), line[i].getY(), line[i].getZ());
      }
    }
    gl.glEnd();

    if (opacity < 1.0f) {
      gl.glDisable(GL.GL_BLEND);
    }
  }
  public void draw(GL2 gl) {
    if (particles.size() == 0) return;
    switch (blendMode) {
      case 0: // '\0'
        gl.glDisable(3042);
        gl.glDisable(3008);
        break;

      case 1: // '\001'
        gl.glEnable(3042);
        gl.glDisable(3008);
        gl.glBlendFunc(768, 1);
        break;

      case 2: // '\002'
        gl.glEnable(3042);
        gl.glDisable(3008);
        gl.glBlendFunc(770, 1);
        break;

      case 3: // '\003'
        gl.glDisable(3042);
        gl.glEnable(3008);
        break;

      case 4: // '\004'
        gl.glEnable(3042);
        gl.glDisable(3008);
        gl.glBlendFunc(770, 1);
        break;
    }
    gl.glBindTexture(3553, model.mMaterials[texture].mTextureId);
    gl.glPushMatrix();
    if (particleType == 0 || particleType == 2) {
      if ((flags & 0x1000) == 0) {
        Vec3 view = new Vec3(viewer.getCamera().getPosition());
        view.normalize();
        Vec3 right = Vec3.cross(view, new Vec3(0.0F, 0.0F, 1.0F)).normalize();
        Vec3 up = Vec3.cross(right, view).normalize();
        int tcStart = 0;
        if (flags == 0x40019) tcStart++;
        gl.glBegin(7);
        int count = particles.size();
        Vec3 pos = new Vec3();
        Vec3 cPos = new Vec3();
        Vec3 ofs = new Vec3();
        for (int i = 0; i < count; i++) {
          Particle p = (Particle) particles.get(i);
          if (p.tile < texCoords.size()) {
            gl.glColor4f(p.color.x, p.color.y, p.color.z, p.color.w);
            Point2f tc[] = (Point2f[]) texCoords.get(p.tile);
            Vec3.add(right, up, ofs);
            cPos.set(p.pos);
            Vec3.sub(cPos, ofs.scale(p.size), pos);
            gl.glTexCoord2f(tc[tcStart % 4].x, tc[tcStart % 4].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.sub(right, up, ofs);
            Vec3.add(cPos, ofs.scale(p.size), pos);
            gl.glTexCoord2f(tc[(tcStart + 1) % 4].x, tc[(tcStart + 1) % 4].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.add(right, up, ofs);
            Vec3.add(cPos, ofs.scale(p.size), pos);
            gl.glTexCoord2f(tc[(tcStart + 2) % 4].x, tc[(tcStart + 2) % 4].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.sub(right, up, ofs);
            Vec3.sub(cPos, ofs.scale(p.size), pos);
            gl.glTexCoord2f(tc[(tcStart + 3) % 4].x, tc[(tcStart + 3) % 4].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
          }
        }

        gl.glEnd();
      } else {
        gl.glBegin(7);
        int count = particles.size();
        Vec3 pos = new Vec3();
        Vec3 ofs = new Vec3();
        for (int i = 0; i < count; i++) {
          Particle p = (Particle) particles.get(i);
          if (p.tile < texCoords.size()) {
            gl.glColor4f(p.color.x, p.color.y, p.color.z, p.color.w);
            Point2f tc[] = (Point2f[]) texCoords.get(p.tile);
            Vec3.add(p.pos, Vec3.scale(p.corners[0], p.size, ofs), pos);
            gl.glTexCoord2f(tc[0].x, tc[0].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.add(p.pos, Vec3.scale(p.corners[1], p.size, ofs), pos);
            gl.glTexCoord2f(tc[1].x, tc[1].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.add(p.pos, Vec3.scale(p.corners[2], p.size, ofs), pos);
            gl.glTexCoord2f(tc[2].x, tc[2].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
            Vec3.add(p.pos, Vec3.scale(p.corners[3], p.size, ofs), pos);
            gl.glTexCoord2f(tc[3].x, tc[3].y);
            gl.glVertex3f(pos.x, pos.y, pos.z);
          }
        }

        gl.glEnd();
      }
    } else if (particleType == 1) {
      gl.glBegin(7);
      int count = particles.size();
      Vec3 pos = new Vec3();
      Vec3 ofs = new Vec3();
      float f = 1.0F;
      Vec3 bv0 = new Vec3(-f, f, 0.0F);
      Vec3 bv1 = new Vec3(f, f, 0.0F);
      for (int i = 0; i < count; i++) {
        Particle p = (Particle) particles.get(i);
        if (p.tile >= texCoords.size() - 1) break;
        gl.glColor4f(p.color.x, p.color.y, p.color.z, p.color.w);
        Point2f tc[] = (Point2f[]) texCoords.get(p.tile);
        Vec3.add(p.pos, Vec3.scale(bv0, p.size, ofs), pos);
        gl.glTexCoord2f(tc[0].x, tc[0].y);
        gl.glVertex3f(pos.x, pos.y, pos.z);
        Vec3.add(p.pos, Vec3.scale(bv1, p.size, ofs), pos);
        gl.glTexCoord2f(tc[1].x, tc[1].y);
        gl.glVertex3f(pos.x, pos.y, pos.z);
        Vec3.add(p.origin, Vec3.scale(bv1, p.size, ofs), pos);
        gl.glTexCoord2f(tc[2].x, tc[2].y);
        gl.glVertex3f(pos.x, pos.y, pos.z);
        Vec3.add(p.origin, Vec3.scale(bv0, p.size, ofs), pos);
        gl.glTexCoord2f(tc[3].x, tc[3].y);
        gl.glVertex3f(pos.x, pos.y, pos.z);
      }

      gl.glEnd();
    }
    gl.glPopMatrix();
  }
Example #19
0
  public void display(GLAutoDrawable drawable) {
    update();

    GL2 gl = drawable.getGL().getGL2();
    // Clear Color Buffer, Depth Buffer
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);

    Matrix TmpMatrix = new Matrix(); // Temporary MATRIX Structure ( NEW )
    Vector TmpVector = new Vector(), TmpNormal = new Vector(); // Temporary
    // VECTOR
    // Structures
    // ( NEW )

    gl.glLoadIdentity(); // Reset The Matrix

    if (outlineSmooth) { // Check To See If We Want Anti-Aliased Lines ( NEW
      // )
      gl.glHint(GL2.GL_LINE_SMOOTH_HINT, GL2.GL_NICEST); // Use The Good
      // Calculations
      // ( NEW )
      gl.glEnable(GL2.GL_LINE_SMOOTH); // Enable Anti-Aliasing ( NEW )
    } else
      // We Don't Want Smooth Lines ( NEW )
      gl.glDisable(GL2.GL_LINE_SMOOTH); // Disable Anti-Aliasing ( NEW )

    gl.glTranslatef(0.0f, 0.0f, -2.0f); // Move 2 Units Away From The Screen
    // ( NEW )
    gl.glRotatef(modelAngle, 0.0f, 1.0f, 0.0f); // Rotate The Model On It's
    // Y-Axis ( NEW )

    gl.glGetFloatv(GLMatrixFunc.GL_MODELVIEW_MATRIX, TmpMatrix.Data, 0); // Get
    // The
    // Generated
    // Matrix
    // (
    // NEW
    // )

    // Cel-Shading Code //
    gl.glEnable(GL2.GL_TEXTURE_1D); // Enable 1D Texturing ( NEW )
    gl.glBindTexture(GL2.GL_TEXTURE_1D, shaderTexture[0]); // Bind Our
    // Texture ( NEW
    // )
    gl.glColor3f(1.0f, 1.0f, 1.0f); // Set The Color Of The Model ( NEW )

    gl.glBegin(GL2.GL_TRIANGLES); // Tell OpenGL That We're Drawing
    // Triangles
    // Loop Through Each Polygon
    for (int i = 0; i < polyNum; i++)
      // Loop Through Each Vertex
      for (int j = 0; j < 3; j++) {

        // Fill Up The TmpNormal Structure With
        TmpNormal.X = polyData[i].Verts[j].Nor.X;
        // The Current Vertices' Normal Values
        TmpNormal.Y = polyData[i].Verts[j].Nor.Y;
        TmpNormal.Z = polyData[i].Verts[j].Nor.Z;
        // Rotate This By The Matrix
        TmpMatrix.rotateVector(TmpNormal, TmpVector);
        // Normalize The New Normal
        TmpVector.normalize();

        // Calculate The Shade Value
        float TmpShade = Vector.dotProduct(TmpVector, lightAngle);

        // Clamp The Value to 0 If Negative ( NEW )
        if (TmpShade < 0.0f) {
          TmpShade = 0.0f;
        }
        // Set The Texture Co-ordinate As The Shade Value
        gl.glTexCoord1f(TmpShade);
        // Send The Vertex Position
        gl.glVertex3f(
            polyData[i].Verts[j].Pos.X, polyData[i].Verts[j].Pos.Y, polyData[i].Verts[j].Pos.Z);
      }

    gl.glEnd(); // Tell OpenGL To Finish Drawing
    gl.glDisable(GL2.GL_TEXTURE_1D); // Disable 1D Textures ( NEW )

    // Outline Code
    // Check To See If We Want To Draw The Outline
    if (outlineDraw) {
      // Enable Blending
      gl.glEnable(GL2.GL_BLEND);
      // Set The Blend Mode
      gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);

      // Draw Backfacing Polygons As Wireframes
      gl.glPolygonMode(GL2.GL_BACK, GL2.GL_LINE);
      // Set The Line Width
      gl.glLineWidth(outlineWidth);
      // Don't Draw Any Front-Facing Polygons
      gl.glCullFace(GL2.GL_FRONT);

      // Change The Depth Mode
      gl.glDepthFunc(GL2.GL_LEQUAL);
      // Set The Outline Color
      gl.glColor3fv(outlineColor, 0);

      // Tell OpenGL What We Want To Draw
      gl.glBegin(GL2.GL_TRIANGLES);

      // Loop Through Each Polygon
      for (int i = 0; i < polyNum; i++) {

        // Loop Through Each Vertex
        for (int j = 0; j < 3; j++) {

          // Send The Vertex Position
          gl.glVertex3f(
              polyData[i].Verts[j].Pos.X, polyData[i].Verts[j].Pos.Y, polyData[i].Verts[j].Pos.Z);
        }
      }
      gl.glEnd(); // Tell OpenGL We've Finished
      // Reset The Depth-Testing Mode
      gl.glDepthFunc(GL2.GL_LESS);
      // Reset The Face To Be Culled
      gl.glCullFace(GL2.GL_BACK);
      // Reset Back-Facing Polygon Drawing Mode
      gl.glPolygonMode(GL2.GL_BACK, GL2.GL_FILL);

      // Disable Blending
      gl.glDisable(GL2.GL_BLEND);
    }

    // Check To See If Rotation Is Enabled
    if (modelRotate) {
      // Update Angle Based On The Clock
      modelAngle += .2f;
    }
  }
Example #20
0
	public void display(GLAutoDrawable gLDrawable) {
		final GL2 gl = gLDrawable.getGL().getGL2();
		gl.glClear(GL.GL_COLOR_BUFFER_BIT);
		gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
		gl.glLoadIdentity();
		gl.glTranslatef(0.0f, 0.0f, -5.0f);
		
		
		
		//for(int i=0;i>3;i++)
		//	kube[i][0][0]=[red,yellow,green,blue,white];
		
		
		// rotate on the three axis
		//gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
		gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
		//gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);
		// Draw A Quad
		
		for(int i=0;i<=2;i++)
			for(int j=0;j<=2;j++)
				for(int k=0;k<=2;k++)
				{
					kube[i][j][k][0]=green;
					kube[i][j][k][1]=white;
					kube[i][j][k][2]=orange;
					kube[i][j][k][3]=yellow;
					kube[i][j][k][4]=blue;
					kube[i][j][k][5]=red;
				}
		Clr[] tmp=new Clr[3];
		tmp[0]=kube[0][2][2][0];
		tmp[1]=kube[1][2][2][0];
		tmp[2]=kube[2][2][2][0];
		
		kube[0][2][2][0]=kube[2][2][2][1];
		kube[1][2][2][0]=kube[2][2][1][1];
		kube[2][2][2][0]=kube[2][2][0][1];
		
		kube[2][2][2][1]=kube[2][2][0][5];
		kube[2][2][1][1]=kube[1][2][0][5];
		kube[2][2][0][1]=kube[0][2][0][5];
		
		kube[2][2][0][5]=kube[0][2][0][4];
		kube[1][2][0][5]=kube[0][2][1][4];
		kube[0][2][0][5]=kube[0][2][2][4];
		
		kube[0][2][0][4]=tmp[0];
		kube[0][2][1][4]=tmp[1];
		kube[0][2][2][4]=tmp[2];
		
		Clr[] tmp1=new Clr[3];
		tmp1[0]=kube[2][1][2][0];
		tmp1[1]=kube[2][1][1][0];
		tmp1[2]=kube[2][1][0][0];
		
		kube[0][1][2][0]=kube[0][1][0][4];
		kube[1][1][2][0]=kube[0][1][1][4];
		kube[2][1][2][0]=kube[0][1][2][4];
		
		kube[0][1][0][1]=kube[2][1][0][5];
		kube[0][1][1][1]=kube[1][1][0][5];
		kube[0][1][2][1]=kube[0][1][0][5];
		
		kube[2][1][0][5]=kube[2][1][2][4];
		kube[1][1][0][5]=kube[2][1][1][4];
		kube[0][1][0][5]=kube[2][1][0][4];
		
		kube[2][1][2][4]=tmp1[0];
		kube[2][1][1][4]=tmp1[1];
		kube[2][1][0][4]=tmp1[2];
		
		gl.glBegin(GL2.GL_QUADS);
		for(int i=0;i<=2;i++)
			for(int j=0;j<=2;j++)
				for(int k=0;k<=2;k++)
				{
					
					//0
					gl.glColor3f(kube[i][j][k][0].r,kube[i][j][k][0].g,kube[i][j][k][0].b);          
					gl.glVertex3f(-0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Top Left
					gl.glVertex3f(0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Top Right
					gl.glVertex3f(0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Bottom Right
					gl.glVertex3f(-0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Bottom Left
					
                    //1
					gl.glColor3f(kube[i][j][k][1].r,kube[i][j][k][1].g,kube[i][j][k][1].b); 
					gl.glVertex3f(0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Top Left
					gl.glVertex3f(0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Top Right
					gl.glVertex3f(0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Bottom Right
					gl.glVertex3f(0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Bottom Left
					
					//2
					gl.glColor3f(kube[i][j][k][2].r,kube[i][j][k][2].g,kube[i][j][k][2].b); 
					gl.glVertex3f(-0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Top Left
					gl.glVertex3f(-0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Top Right
					gl.glVertex3f(0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Bottom Right
					gl.glVertex3f(0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Bottom Left
						
					//3
					gl.glColor3f(kube[i][j][k][3].r,kube[i][j][k][3].g,kube[i][j][k][3].b); 
					gl.glVertex3f(-0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Top Left
					gl.glVertex3f(-0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Top Right
					gl.glVertex3f(0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Bottom Right
					gl.glVertex3f(0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Bottom Left
					
					//4
					gl.glColor3f(kube[i][j][k][4].r,kube[i][j][k][4].g,kube[i][j][k][4].b); 
					gl.glVertex3f(-0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Top Left
					gl.glVertex3f(-0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Top Right
					gl.glVertex3f(-0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, 0.3f+(k-1)*0.65f); // Bottom Right
					gl.glVertex3f(-0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Bottom Left
					
					//5
					gl.glColor3f(kube[i][j][k][5].r,kube[i][j][k][5].g,kube[i][j][k][5].b); 
					gl.glVertex3f(-0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Top Left
					gl.glVertex3f(0.3f+(i-1)*0.65f, 0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Top Right
					gl.glVertex3f(0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Bottom Right
					gl.glVertex3f(-0.3f+(i-1)*0.65f, -0.3f+(j-1)*0.65f, -0.3f+(k-1)*0.65f); // Bottom Left
				}
		// Done Drawing The Quad
		gl.glEnd();

		// increasing rotation for the next iteration
		rotateT += 0.3f;
	}
Example #21
0
  public void drawTrees(GL2 gl, Texture[] textures) {

    for (int i = 0; i < nbArbres; i++) {

      RandomCoordonnees ran = listeCoord.get(i);

      // On dessine que les arbres au dessus du niveau de la mer
      if (tableauNiveaux[ran.getX()][ran.getY()] >= GameConstants.NIVEAU_EAU) {
        int x = ran.getX() - (tableauNiveaux.length / 2);
        int z = ran.getY() - (tableauNiveaux[0].length / 2);

        // Arbres textures

        textures[indicesTypeArbres[i]].enable(gl);
        textures[indicesTypeArbres[i]].bind(gl);

        // Transparence des PNG : Assombrit l'image !!!
        gl.glEnable(GL_BLEND);
        gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

        gl.glBegin(GL_QUADS);

        /*
         * Ordre des coins
         * 10
         * 00
         * 01
         * 11
         *
         * */

        // Dessin des deux faces avec textures
        gl.glTexCoord2d(1.0, 0.0);
        gl.glVertex3f(
            (x * GameConstants.LARGEUR_CARRE) + (largeurArbre / 2.0f),
            tableauNiveaux[ran.getX()][ran.getY()] + hauteurArbre,
            z * GameConstants.LARGEUR_CARRE);
        gl.glTexCoord2d(0.0, 0.0);
        gl.glVertex3f(
            (x * GameConstants.LARGEUR_CARRE) - (largeurArbre / 2.0f),
            tableauNiveaux[ran.getX()][ran.getY()] + hauteurArbre,
            z * GameConstants.LARGEUR_CARRE);
        gl.glTexCoord2d(0.0, 1.0);
        gl.glVertex3f(
            (x * GameConstants.LARGEUR_CARRE) - (largeurArbre / 2.0f),
            tableauNiveaux[ran.getX()][ran.getY()],
            z * GameConstants.LARGEUR_CARRE);
        gl.glTexCoord2d(1.0, 1.0);
        gl.glVertex3f(
            (x * GameConstants.LARGEUR_CARRE) + (largeurArbre / 2.0f),
            tableauNiveaux[ran.getX()][ran.getY()],
            z * GameConstants.LARGEUR_CARRE);

        gl.glTexCoord2d(1.0, 0.0);
        gl.glVertex3f(
            x * GameConstants.LARGEUR_CARRE,
            tableauNiveaux[ran.getX()][ran.getY()] + hauteurArbre,
            (z * GameConstants.LARGEUR_CARRE) + (largeurArbre / 2.0f));
        gl.glTexCoord2d(0.0, 0.0);
        gl.glVertex3f(
            x * GameConstants.LARGEUR_CARRE,
            tableauNiveaux[ran.getX()][ran.getY()] + hauteurArbre,
            (z * GameConstants.LARGEUR_CARRE) - (largeurArbre / 2.0f));
        gl.glTexCoord2d(0.0, 1.0);
        gl.glVertex3f(
            x * GameConstants.LARGEUR_CARRE,
            tableauNiveaux[ran.getX()][ran.getY()],
            (z * GameConstants.LARGEUR_CARRE) - (largeurArbre / 2.0f));
        gl.glTexCoord2d(1.0, 1.0);
        gl.glVertex3f(
            x * GameConstants.LARGEUR_CARRE,
            tableauNiveaux[ran.getX()][ran.getY()],
            (z * GameConstants.LARGEUR_CARRE) + (largeurArbre / 2.0f));

        gl.glEnd();

        textures[indicesTypeArbres[i]].disable(gl);

        // gl.glDisable(GL_TEXTURE_2D);
        gl.glDisable(GL_BLEND);
      }
    }
  }
  @Override
  public void draw(GL2 gl) {
    gl.glTranslatef(x, y, z);
    // ----- Render the Color Cube -----
    gl.glBegin(GL_QUADS); // of the color cube

    gl.glColor3f(red, green, blue);
    gl.glVertex3f(-demiWidth, -demiWidth, -demiWidth);
    gl.glVertex3f(+demiWidth, -demiWidth, -demiWidth);
    gl.glVertex3f(+demiWidth, +demiWidth, -demiWidth);
    gl.glVertex3f(-demiWidth, +demiWidth, -demiWidth);

    gl.glVertex3f(-demiWidth, -demiWidth, -demiWidth);
    gl.glVertex3f(-demiWidth, -demiWidth, +demiWidth);
    gl.glVertex3f(-demiWidth, +demiWidth, +demiWidth);
    gl.glVertex3f(-demiWidth, +demiWidth, -demiWidth);

    gl.glVertex3f(-demiWidth, -demiWidth, +demiWidth);
    gl.glVertex3f(-demiWidth, +demiWidth, +demiWidth);
    gl.glVertex3f(+demiWidth, +demiWidth, +demiWidth);
    gl.glVertex3f(+demiWidth, -demiWidth, +demiWidth);

    gl.glVertex3f(+demiWidth, -demiWidth, -demiWidth);
    gl.glVertex3f(+demiWidth, +demiWidth, -demiWidth);
    gl.glVertex3f(+demiWidth, +demiWidth, +demiWidth);
    gl.glVertex3f(+demiWidth, -demiWidth, +demiWidth);

    gl.glVertex3f(+demiWidth, -demiWidth, -demiWidth);
    gl.glVertex3f(-demiWidth, -demiWidth, -demiWidth);
    gl.glVertex3f(-demiWidth, -demiWidth, +demiWidth);
    gl.glVertex3f(+demiWidth, -demiWidth, +demiWidth);

    gl.glVertex3f(-demiWidth, +demiWidth, +demiWidth);
    gl.glVertex3f(+demiWidth, +demiWidth, +demiWidth);
    gl.glVertex3f(+demiWidth, +demiWidth, -demiWidth);
    gl.glVertex3f(-demiWidth, +demiWidth, -demiWidth);

    gl.glEnd(); // of the color cube
    gl.glTranslatef(-x, -y, -z);
  }
  @SuppressWarnings("unused")
  private static void drawBox(GL2 gl) {
    gl.glDisable(GLLightingFunc.GL_LIGHTING);
    gl.glDisable(GL.GL_TEXTURE_2D);

    gl.glColor3f(1.0f, 1.0f, 1.0f);
    gl.glBegin(GL.GL_LINE_STRIP);
    gl.glVertex3f(-0.5f, -0.5f, 0.5f);
    gl.glVertex3f(0.5f, -0.5f, 0.5f);
    gl.glVertex3f(0.5f, 0.5f, 0.5f);
    gl.glVertex3f(-0.5f, 0.5f, 0.5f);
    gl.glVertex3f(-0.5f, -0.5f, 0.5f);
    gl.glVertex3f(-0.5f, -0.5f, -0.5f);
    gl.glVertex3f(0.5f, -0.5f, -0.5f);
    gl.glVertex3f(0.5f, 0.5f, -0.5f);
    gl.glVertex3f(-0.5f, 0.5f, -0.5f);
    gl.glVertex3f(-0.5f, -0.5f, -0.5f);
    gl.glEnd();
    gl.glBegin(GL.GL_LINE_STRIP);
    gl.glVertex3f(-0.5f, 0.5f, 0.5f);
    gl.glVertex3f(-0.5f, 0.5f, -0.5f);
    gl.glEnd();
    gl.glBegin(GL.GL_LINE_STRIP);
    gl.glVertex3f(0.5f, 0.5f, 0.5f);
    gl.glVertex3f(0.5f, 0.5f, -0.5f);
    gl.glEnd();
    gl.glBegin(GL.GL_LINE_STRIP);
    gl.glVertex3f(0.5f, -0.5f, 0.5f);
    gl.glVertex3f(0.5f, -0.5f, -0.5f);
    gl.glEnd();

    gl.glEnable(GL.GL_TEXTURE_2D);
    gl.glEnable(GLLightingFunc.GL_LIGHTING);
    gl.glEnable(GLLightingFunc.GL_LIGHT0);
  }
  public void render(GL2 gl2) {
    int i;

    boolean draw_finger_star = false;
    boolean draw_base_star = false;
    boolean draw_shoulder_to_elbow = false;
    boolean draw_shoulder_star = false;
    boolean draw_elbow_star = false;
    boolean draw_wrist_star = false;
    boolean draw_stl = true;

    // RebuildShoulders(motion_now);

    gl2.glPushMatrix();
    gl2.glTranslated(position.x, position.y, position.z);

    if (draw_stl) {
      // base
      gl2.glPushMatrix();
      gl2.glColor3f(0, 0, 1);
      gl2.glTranslatef(0, 0, BASE_TO_SHOULDER_Z + 0.6f);
      gl2.glRotatef(90, 0, 0, 1);
      gl2.glRotatef(90, 1, 0, 0);
      modelBase.render(gl2);
      gl2.glPopMatrix();

      // arms
      for (i = 0; i < 3; ++i) {
        gl2.glColor3f(1, 0, 1);
        gl2.glPushMatrix();
        gl2.glTranslatef(
            motion_now.arms[i * 2 + 0].shoulder.x,
            motion_now.arms[i * 2 + 0].shoulder.y,
            motion_now.arms[i * 2 + 0].shoulder.z);
        gl2.glRotatef(120.0f * i, 0, 0, 1);
        gl2.glRotatef(90, 0, 1, 0);
        gl2.glRotatef(180 - motion_now.arms[i * 2 + 0].angle, 0, 0, 1);
        modelArm.render(gl2);
        gl2.glPopMatrix();

        gl2.glColor3f(1, 1, 0);
        gl2.glPushMatrix();
        gl2.glTranslatef(
            motion_now.arms[i * 2 + 1].shoulder.x,
            motion_now.arms[i * 2 + 1].shoulder.y,
            motion_now.arms[i * 2 + 1].shoulder.z);
        gl2.glRotatef(120.0f * i, 0, 0, 1);
        gl2.glRotatef(90, 0, 1, 0);
        gl2.glRotatef(+motion_now.arms[i * 2 + 1].angle, 0, 0, 1);
        modelArm.render(gl2);
        gl2.glPopMatrix();
      }
      // top
      gl2.glPushMatrix();
      gl2.glColor3f(0, 1, 0);
      gl2.glTranslatef(motion_now.finger_tip.x, motion_now.finger_tip.y, motion_now.finger_tip.z);
      gl2.glRotatef(motion_now.iku, 1, 0, 0);
      gl2.glRotatef(motion_now.ikv, 0, 1, 0);
      gl2.glRotatef(motion_now.ikw, 0, 0, 1);
      gl2.glRotatef(90, 0, 0, 1);
      gl2.glRotatef(180, 1, 0, 0);
      modelTop.render(gl2);
      gl2.glPopMatrix();
    }

    // draw the forearms

    Cylinder tube = new Cylinder();
    gl2.glColor3f(0.8f, 0.8f, 0.8f);
    tube.setRadius(0.15f);
    for (i = 0; i < 6; ++i) {
      // gl2.glBegin(GL2.GL_LINES);
      // gl2.glColor3f(1,0,0);
      // gl2.glVertex3f(motion_now.arms[i].wrist.x,motion_now.arms[i].wrist.y,motion_now.arms[i].wrist.z);
      // gl2.glColor3f(0,1,0);
      // gl2.glVertex3f(motion_now.arms[i].elbow.x,motion_now.arms[i].elbow.y,motion_now.arms[i].elbow.z);
      // gl2.glEnd();
      tube.SetP1(motion_now.arms[i].wrist);
      tube.SetP2(motion_now.arms[i].elbow);
      PrimitiveSolids.drawCylinder(gl2, tube);
    }

    gl2.glDisable(GL2.GL_LIGHTING);
    // debug info
    gl2.glPushMatrix();
    for (i = 0; i < 6; ++i) {
      gl2.glColor3f(1, 1, 1);
      if (draw_shoulder_star) PrimitiveSolids.drawStar(gl2, motion_now.arms[i].shoulder, 5);
      if (draw_elbow_star) PrimitiveSolids.drawStar(gl2, motion_now.arms[i].elbow, 3);
      if (draw_wrist_star) PrimitiveSolids.drawStar(gl2, motion_now.arms[i].wrist, 1);

      if (draw_shoulder_to_elbow) {
        gl2.glBegin(GL2.GL_LINES);
        gl2.glColor3f(0, 1, 0);
        gl2.glVertex3f(
            motion_now.arms[i].elbow.x, motion_now.arms[i].elbow.y, motion_now.arms[i].elbow.z);
        gl2.glColor3f(0, 0, 1);
        gl2.glVertex3f(
            motion_now.arms[i].shoulder.x,
            motion_now.arms[i].shoulder.y,
            motion_now.arms[i].shoulder.z);
        gl2.glEnd();
      }
    }
    gl2.glPopMatrix();

    if (draw_finger_star) {
      // draw finger orientation
      float s = 2;
      gl2.glBegin(GL2.GL_LINES);
      gl2.glColor3f(1, 1, 1);
      gl2.glVertex3f(motion_now.finger_tip.x, motion_now.finger_tip.y, motion_now.finger_tip.z);
      gl2.glVertex3f(
          motion_now.finger_tip.x + motion_now.finger_forward.x * s,
          motion_now.finger_tip.y + motion_now.finger_forward.y * s,
          motion_now.finger_tip.z + motion_now.finger_forward.z * s);
      gl2.glVertex3f(motion_now.finger_tip.x, motion_now.finger_tip.y, motion_now.finger_tip.z);
      gl2.glVertex3f(
          motion_now.finger_tip.x + motion_now.finger_up.x * s,
          motion_now.finger_tip.y + motion_now.finger_up.y * s,
          motion_now.finger_tip.z + motion_now.finger_up.z * s);
      gl2.glVertex3f(motion_now.finger_tip.x, motion_now.finger_tip.y, motion_now.finger_tip.z);
      gl2.glVertex3f(
          motion_now.finger_tip.x + motion_now.finger_left.x * s,
          motion_now.finger_tip.y + motion_now.finger_left.y * s,
          motion_now.finger_tip.z + motion_now.finger_left.z * s);

      gl2.glEnd();
    }

    if (draw_base_star) {
      // draw finger orientation
      float s = 2;
      gl2.glDisable(GL2.GL_DEPTH_TEST);
      gl2.glBegin(GL2.GL_LINES);
      gl2.glColor3f(1, 0, 0);
      gl2.glVertex3f(motion_now.base.x, motion_now.base.y, motion_now.base.z);
      gl2.glVertex3f(
          motion_now.base.x + motion_now.base_forward.x * s,
          motion_now.base.y + motion_now.base_forward.y * s,
          motion_now.base.z + motion_now.base_forward.z * s);
      gl2.glColor3f(0, 1, 0);
      gl2.glVertex3f(motion_now.base.x, motion_now.base.y, motion_now.base.z);
      gl2.glVertex3f(
          motion_now.base.x + motion_now.base_up.x * s,
          motion_now.base.y + motion_now.base_up.y * s,
          motion_now.base.z + motion_now.base_up.z * s);
      gl2.glColor3f(0, 0, 1);
      gl2.glVertex3f(motion_now.base.x, motion_now.base.y, motion_now.base.z);
      gl2.glVertex3f(
          motion_now.base.x + motion_now.finger_left.x * s,
          motion_now.base.y + motion_now.finger_left.y * s,
          motion_now.base.z + motion_now.finger_left.z * s);

      gl2.glEnd();
      gl2.glEnable(GL2.GL_DEPTH_TEST);
    }

    gl2.glEnable(GL2.GL_LIGHTING);

    gl2.glPopMatrix();
  }
Example #25
0
  /** Called back by the animator to perform rendering. */
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
    gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers

    for (int i = 0; i < stars.length; i++) {
      // Reset the view (x, y, z axes back to normal)
      gl.glLoadIdentity();
      gl.glTranslatef(0.0f, 0.0f, z);

      // The stars are texture quad square drawn on x-y plane and
      // distributed on on x-z plane around the y-axis

      // Initial 90 degree tile in the x-axis, y-axis pointing out of screen
      gl.glRotatef(tilt, 1.0f, 0.0f, 0.0f);
      // Rotate about y-axis (pointing out of screen), initial angle is 0
      gl.glRotatef(stars[i].angle, 0.0f, 1.0f, 0.0f);
      // Translate about the x-axis (pointing right) to its current distance
      gl.glTranslatef(stars[i].distance, 0.0f, 0.0f);

      // The stars have initial angle of 0, and initial distance linearly
      // distributed between 0 and 5.0f

      // Rotate the axes back, so that z-axis is again facing us, to ensure that
      // the quad (with texture) on x-y plane is facing us
      gl.glRotatef(-stars[i].angle, 0.0f, 1.0f, 0.0f);
      gl.glRotatef(-tilt, 1.0f, 0.0f, 0.0f);

      // Take note that without the two rotations and undo, there is only one
      // translation along the x-axis
      // Matrix operation is non-commutative. That is, AB != BA.
      // Hence, ABCB'A' != C

      // Draw the star, which spins on the z axis (pointing out of the screen)
      gl.glRotatef(starSpinAngle, 0.0f, 0.0f, 1.0f);
      // Set the star's color using bytes (why bytes? not float or int?)
      gl.glColor4ub(stars[i].r, stars[i].g, stars[i].b, (byte) 255);
      gl.glBegin(GL_QUADS);
      // draw a square on x-y plane
      gl.glTexCoord2f(textureCoordLeft, textureCoordBottom);
      gl.glVertex3f(-1.0f, -1.0f, 0.0f);
      gl.glTexCoord2f(textureCoordRight, textureCoordBottom);
      gl.glVertex3f(1.0f, -1.0f, 0.0f);
      gl.glTexCoord2f(textureCoordRight, textureCoordTop);
      gl.glVertex3f(1.0f, 1.0f, 0.0f);
      gl.glTexCoord2f(textureCoordLeft, textureCoordTop);
      gl.glVertex3f(-1.0f, 1.0f, 0.0f);
      gl.glEnd();

      // If twinkling, overlay with another drawing of an arbitrary color
      if (twinkleOn) {
        // Assign a color using bytes
        gl.glColor4ub(
            stars[(numStars - i) - 1].r,
            stars[(numStars - i) - 1].g,
            stars[(numStars - i) - 1].b,
            (byte) 255);
        gl.glBegin(GL_QUADS);
        // draw a square on x-y plane
        gl.glTexCoord2f(textureCoordLeft, textureCoordBottom);
        gl.glVertex3f(-1.0f, -1.0f, 0.0f);
        gl.glTexCoord2f(textureCoordRight, textureCoordBottom);
        gl.glVertex3f(1.0f, -1.0f, 0.0f);
        gl.glTexCoord2f(textureCoordRight, textureCoordTop);
        gl.glVertex3f(1.0f, 1.0f, 0.0f);
        gl.glTexCoord2f(textureCoordLeft, textureCoordTop);
        gl.glVertex3f(-1.0f, 1.0f, 0.0f);
        gl.glEnd();
      }

      // Update for the next refresh
      // The star spins about the z-axis (pointing out of the screen), and spiral
      // inwards and collapse towards the center, by increasing the angle on x-y
      // plane and reducing the distance.

      starSpinAngle += 0.01f; // used to spin the stars about the z-axis
      // spiral pattern
      stars[i].angle += (float) i / numStars; // changes the angle of a star
      // collapsing the star to the center
      stars[i].distance -= 0.01f; // changes the distance of a star
      // re-bone at the edge
      if (stars[i].distance < 0.0f) { // Is the star collapsed to the center?
        stars[i].distance += 5.0f; // move to the outer ring
        stars[i].setRandomRGB(); // choose a random color for the star
      }
    }
  }
Example #26
0
  public void draw(GL2 gl, GLU glu, GLDrawState ds) {
    final Color4f highColor = new Color4f(0.0f, 1.0f, 0.0f, 1.0f);
    final Color4f lowColor = new Color4f(1.0f, 1.0f, 1.0f, 1.0f);

    Color4f[][] trueCols = new Color4f[mapHeight][mapWidth];
    //		InternalTerrainTile tiles[][] = ds.getGameMap().getTerrainMatrix();
    // Update colors

    for (int j = 0; j < mapHeight; j++) {
      for (int i = 0; i < mapWidth; i++) {

        // float fluxAmount = getMapHeight(i, j)/64.f;
        //	System.out.println(flux[j/DENSITY][i/DENSITY] + " " + fluxAmount);

        // float fluxAmount = (float)tiles[i/DENSITY][j/DENSITY].getFlux();

        Color4f tintColor = new Color4f();
        Color4f trueColor = new Color4f();

        tintColor.interpolate(lowColor, highColor, 0);
        // System.out.println(actualHeight/maxHeight);

        trueColor.interpolate(cols[j][i], tintColor, 1.0f);
        trueColor.w = cols[j][i].w;
        trueCols[j][i] = trueColor;

        // If void, see through to the background.
        /*if(tiles[i/DENSITY][j/DENSITY] == TerrainType.VOID){
        trueCols[j][i].w = 0.0f;
        }*/

      }
    }
    // System.out.println(map.getTerrainMatrix()[0][0].getFlux() + " " + MAX_FLUX_PER_TILE + " " +
    // trueCols[0][0].x);

    int k = 0;
    for (int j = 0; j < mapHeight; j++) {
      for (int i = 0; i < mapWidth; i++) {
        colors[k] = trueCols[j][i].x;
        colors[k + 1] = trueCols[j][i].y;
        colors[k + 2] = trueCols[j][i].z;
        colors[k + 3] = trueCols[j][i].w;

        float norm =
            (float)
                Math.sqrt(
                    trueCols[j][i].x * trueCols[j][i].x
                        + trueCols[j][i].y * trueCols[j][i].y
                        + trueCols[j][i].z * trueCols[j][i].z);
        float val = (norm < 0.3f) ? 0.0f : 0.9f;
        colorNorm[k] = val;
        colorNorm[k + 1] = val;
        colorNorm[k + 2] = val;
        colorNorm[k + 3] = 1.0f;
        k += 4;
      }
    }

    if (tex == null && texturePath != null) {
      tex = GLGameRenderer.textureCache.getResource(texturePath, texturePath).tex;
      texturePath = null;
    }
    gl.glPushMatrix();
    //	gl.glTranslatef(1.5f, 0.0f, 1.5f);
    if (tex != null) {
      System.out.println("Using texture");
      gl.glEnable(GL2.GL_TEXTURE_2D);
      tex.bind(gl);
      gl.glBegin(GL2.GL_TRIANGLE_STRIP);
      for (int i = 0; i < indices.length; i++) {
        gl.glTexCoord2f(texCoords[indices[i] * 2], texCoords[indices[i] * 2 + 1]);
        gl.glColor4f(
            colorNorm[indices[i] * 4],
            colorNorm[indices[i] * 4 + 1],
            colorNorm[indices[i] * 4 + 2],
            colorNorm[indices[i] * 4 + 3]);
        gl.glNormal3f(
            normals[indices[i] * 3], normals[indices[i] * 3 + 1], normals[indices[i] * 3 + 2]);
        gl.glVertex3f(
            vertices[indices[i] * 3], vertices[indices[i] * 3 + 1], vertices[indices[i] * 3 + 2]);
      }
      gl.glEnd();
    } else {
      gl.glEnable(gl.GL_BLEND);
      gl.glBegin(GL2.GL_TRIANGLE_STRIP);
      for (int i = 0; i < indices.length; i++) {
        gl.glColor4f(
            colors[indices[i] * 4],
            colors[indices[i] * 4 + 1],
            colors[indices[i] * 4 + 2],
            colors[indices[i] * 4 + 3]);
        gl.glNormal3f(
            normals[indices[i] * 3], normals[indices[i] * 3 + 1], normals[indices[i] * 3 + 2]);
        gl.glVertex3f(
            vertices[indices[i] * 3], vertices[indices[i] * 3 + 1], vertices[indices[i] * 3 + 2]);
      }
      gl.glEnd();
      gl.glDisable(gl.GL_BLEND);
    }
    gl.glPopMatrix();

    boolean showGrid = RenderConfiguration.showGridlines();
    if (showGrid) {
      gl.glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
      gl.glNormal3f(0.0f, 1.0f, 0.0f);
      gl.glLineWidth(1.0f);

      // do the horizontal gridlines
      /*
      gl.glBegin(GL2.GL_LINES);
      for (int j = 1; j < map.getHeight(); ++j) {
      	gl.glVertex3f(0.0f, 0.0f, j);
      	gl.glVertex3f(map.getWidth(), 0.0f, j);
      }
      gl.glEnd();
      */
      gl.glBegin(GL2.GL_LINE_STRIP);
      for (int j = 0; j < mapHeight; j++) {
        if ((j + 1) % DENSITY != 0) {
          continue;
        }
        if ((j + 1) % (DENSITY * 2) == 0) {
          for (int i = 0; i < mapWidth; i++) {
            Vector3f p;
            Vector3f pOne;
            Vector3f pTwo;

            pOne = points[j][i];
            p = new Vector3f(0.0f, 0.0f, 0.0f);
            p.add(pOne);
            if (j < mapHeight - 1 && i > 0) {
              pTwo = points[j + 1][i - 1];
              p.add(pTwo);
              p.scale(.5f);
            }

            gl.glVertex3f(p.x, p.y + 0.01f, p.z);

            pOne = points[j][i];
            p = new Vector3f(0.0f, 0.0f, 0.0f);
            p.add(pOne);
            if (j < mapHeight - 1) {
              pTwo = points[j + 1][i];
              p.add(pTwo);
              p.scale(.5f);
            }

            gl.glVertex3f(p.x, p.y + 0.01f, p.z);
          }
        } else {
          for (int i = mapWidth - 1; i >= 0; i--) {
            Vector3f p;
            Vector3f pOne;
            Vector3f pTwo;

            pOne = points[j][i];
            p = new Vector3f(0.0f, 0.0f, 0.0f);
            p.add(pOne);
            if (j < mapHeight - 1) {
              pTwo = points[j + 1][i];
              p.add(pTwo);
              p.scale(.5f);
            }

            gl.glVertex3f(p.x, p.y + 0.01f, p.z);
            pOne = points[j][i];
            p = new Vector3f(0.0f, 0.0f, 0.0f);
            p.add(pOne);
            if (j < mapHeight - 1 && i > 0) {

              pTwo = points[j + 1][i - 1];
              p.add(pTwo);
              p.scale(.5f);
            }

            gl.glVertex3f(p.x, p.y + 0.01f, p.z);
          }
        }
      }
      gl.glEnd();

      // do the vertical gridlines
      /*
      gl.glBegin(GL2.GL_LINES);
      for (int j = 1; j < map.getWidth(); ++j) {
      	gl.glVertex3f(j, 0.0f, 0.0f);
      	gl.glVertex3f(j, 0.0f, map.getHeight());
      }
      gl.glEnd();
      */
      gl.glBegin(GL2.GL_LINE_STRIP);
      for (int i = 0; i < mapWidth; i++) {
        if ((i + 1) % DENSITY != 0) {
          continue;
        }
        if ((i + 1) % (DENSITY * 2) == 0) {
          for (int j = 0; j < mapHeight; j++) {
            Vector3f p;
            Vector3f pOne;
            Vector3f pTwo;

            pOne = points[j][i];
            p = new Vector3f(0.0f, 0.0f, 0.0f);
            p.add(pOne);
            if (j > 0 && i < mapWidth - 1) {
              pTwo = points[j - 1][i + 1];
              p.add(pTwo);
              p.scale(.5f);
            }

            gl.glVertex3f(p.x, p.y + 0.01f, p.z);

            pOne = points[j][i];
            p = new Vector3f(0.0f, 0.0f, 0.0f);
            p.add(pOne);
            if (i < mapWidth - 1) {
              pTwo = points[j][i + 1];
              p.add(pTwo);
              p.scale(.5f);
            }

            gl.glVertex3f(p.x, p.y + 0.01f, p.z);
          }
        } else {
          for (int j = mapHeight - 1; j >= 0; j--) {
            Vector3f p;
            Vector3f pOne;
            Vector3f pTwo;

            pOne = points[j][i];
            p = new Vector3f(0.0f, 0.0f, 0.0f);
            p.add(pOne);
            if (i < mapWidth - 1) {
              pTwo = points[j][i + 1];
              p.add(pTwo);
              p.scale(.5f);
            }

            gl.glVertex3f(p.x, p.y + 0.01f, p.z);

            pOne = points[j][i];
            p = new Vector3f(0.0f, 0.0f, 0.0f);
            p.add(pOne);
            if (j > 0 && i < mapWidth - 1) {
              pTwo = points[j - 1][i + 1];
              p.add(pTwo);
              p.scale(.5f);
            }

            gl.glVertex3f(p.x, p.y + 0.01f, p.z);
          }
        }
      }
      gl.glEnd();
    }
  }
Example #27
0
  /*
   * Recursively generates a sphere using triangles and puts the resulting
   * polygons into the OpenGL pipeline. Mimics the other spheretri function.
   */
  private static void spheretri(
      int n, Vector3f v0, Vector3f v1, Vector3f v2, Color3f c, GLAutoDrawable d) {

    GL2 gl = d.getGL().getGL2();

    if (n == 0) {
      if (pipe.isFlatShaded()) {
        nrml.add(v0, v1);
        nrml.add(v2);
        nrml.normalize();

        gl.glBegin(GL.GL_TRIANGLES);

        gl.glColor3f(c.x, c.y, c.z);
        gl.glNormal3f(nrml.x, nrml.y, nrml.z);

        gl.glVertex3f(v0.x, v0.y, v0.z);
        gl.glVertex3f(v1.x, v1.y, v1.z);
        gl.glVertex3f(v2.x, v2.y, v2.z);

        gl.glEnd();
      } else {
        gl.glBegin(GL.GL_TRIANGLES);

        gl.glColor3f(c.x, c.y, c.z);
        xyTex(v0, texs[0]);
        xyTex(v1, texs[1]);
        xyTex(v2, texs[2]);

        gl.glNormal3f(v0.x, v0.y, v0.z);
        gl.glTexCoord2f(texs[0].x, texs[0].y);
        gl.glVertex3f(v0.x, v0.y, v0.z);

        gl.glNormal3f(v1.x, v1.y, v1.z);
        gl.glTexCoord2f(texs[1].x, texs[1].y);
        gl.glVertex3f(v1.x, v1.y, v1.z);

        gl.glNormal3f(v2.x, v2.y, v2.z);
        gl.glTexCoord2f(texs[2].x, texs[2].y);
        gl.glVertex3f(v2.x, v2.y, v2.z);

        gl.glEnd();
      }
    } else {
      Vector3f v01 = new Vector3f();
      Vector3f v12 = new Vector3f();
      Vector3f v20 = new Vector3f();

      v01.add(v0, v1);
      v01.normalize();
      v12.add(v1, v2);
      v12.normalize();
      v20.add(v2, v0);
      v20.normalize();

      spheretri(n - 1, v01, v12, v20, c, d);
      spheretri(n - 1, v0, v01, v20, c, d);
      spheretri(n - 1, v1, v12, v01, c, d);
      spheretri(n - 1, v2, v20, v12, c, d);
    }
  }
  // Support Methods
  private void drawPyramid(GL2 gl, GLAutoDrawable drawable, Float x, Float y, Float z) {
    // Pushing to matrix stack
    gl.glPushMatrix();

    // PYRAMID
    // Moves the figure in the (x, y, z)-axis
    gl.glTranslatef(x, y, z);

    // Rotates the pyramid, just for "fun"
    gl.glRotatef(-55.0f, 0.0f, 1.0f, 0.0f);

    // Makes only the outlines
    gl.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

    // BEGIN Pyramid
    gl.glBegin(GL_TRIANGLES);

    // Pushing current color to stack
    gl.glPushAttrib(GL_ALL_ATTRIB_BITS);

    // Set color to RED
    gl.glColor3f(1.0f, 0.0f, 0.0f);

    // Front triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);

    // Right triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);
    gl.glVertex3f(1.0f, -1.0f, -1.0f);

    // Left triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, -1.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);

    // Back triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(1.0f, -1.0f, -1.0f);
    gl.glVertex3f(-1.0f, -1.0f, -1.0f);

    // END Pyramid
    gl.glEnd();

    // Popping state
    gl.glPopAttrib();
    gl.glPopMatrix();
  }
Example #29
0
 public static void drawLine(GL2 gl, Vector3f start, Vector3f end) {
   gl.glBegin(GL2.GL_LINES);
   gl.glVertex3f(start.x, start.y, start.z);
   gl.glVertex3f(end.x, end.y, end.z);
   gl.glEnd();
 }