Ejemplo n.º 1
0
  /** ***************************************************** */
  public void draw(GL2 gl, GLU glu, Camera cam) {
    if (transform != null) transform.execute(gl);
    gl.glTranslatef(x, y, z);

    applyMaterial(gl);
    gl.glLineWidth(wfwidth);

    // Draw
    GLUquadric qobj = glu.gluNewQuadric();

    if (facestatus) {
      if (wfstatus) {
        gl.glEnable(GL2.GL_POLYGON_OFFSET_FILL);
        gl.glPolygonOffset(1.0f, 1.0f);
      }

      gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL);
      gl.glNormal3f(norm.x, norm.y, norm.z);
      gl.glColor4f(color.r, color.g, color.b, color.a);
      glu.gluDisk(qobj, radiusInner, radiusOuter, slices, loops);

      if (wfstatus) gl.glDisable(GL2.GL_POLYGON_OFFSET_FILL);
    }
    if (wfstatus) {
      gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE);
      gl.glNormal3f(norm.x, norm.y, norm.z);
      gl.glColor4f(wfcolor.r, wfcolor.g, wfcolor.b, wfcolor.a);
      glu.gluDisk(qobj, radiusInner, radiusOuter, slices, loops);
    }
  }
Ejemplo n.º 2
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();
  }
Ejemplo n.º 3
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();
    }
  }
Ejemplo n.º 4
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);
    }
  }