Esempio n. 1
0
  private void makeCap(
      DrawContext dc,
      GeometryBuilder.IndexedTriangleArray ita,
      double altitude,
      boolean terrainConformant,
      int orientation,
      Matrix locationTransform,
      Vec4 referenceCenter,
      int indexPos,
      int[] indices,
      int vertexPos,
      float[] vertices,
      float[] normals) {
    GeometryBuilder gb = this.getGeometryBuilder();
    Globe globe = dc.getGlobe();

    int indexCount = ita.getIndexCount();
    int vertexCount = ita.getVertexCount();
    int[] locationIndices = ita.getIndices();
    float[] locationVerts = ita.getVertices();

    this.copyIndexArray(
        indexCount,
        (orientation == GeometryBuilder.INSIDE),
        locationIndices,
        vertexPos,
        indexPos,
        indices);

    for (int i = 0; i < vertexCount; i++) {
      int index = 3 * i;
      Vec4 vec = new Vec4(locationVerts[index], locationVerts[index + 1], locationVerts[index + 2]);
      vec = vec.transformBy4(locationTransform);

      Position pos = globe.computePositionFromPoint(vec);
      vec =
          this.computePointFromPosition(
              dc, pos.getLatitude(), pos.getLongitude(), altitude, terrainConformant);

      index = 3 * (vertexPos + i);
      vertices[index] = (float) (vec.x - referenceCenter.x);
      vertices[index + 1] = (float) (vec.y - referenceCenter.y);
      vertices[index + 2] = (float) (vec.z - referenceCenter.z);
    }

    gb.makeIndexedTriangleArrayNormals(
        indexPos, indexCount, indices, vertexPos, vertexCount, vertices, normals);
  }
Esempio n. 2
0
  private void makePolygon(
      DrawContext dc,
      List<LatLon> locations,
      List<Boolean> edgeFlags,
      double[] altitudes,
      boolean[] terrainConformant,
      boolean enableCaps,
      int subdivisions,
      Vec4 referenceCenter,
      PolygonGeometry dest) {
    if (locations.size() == 0) return;

    GeometryBuilder gb = this.getGeometryBuilder();

    Vec4[] polyPoints = new Vec4[locations.size() + 1];
    Boolean[] polyEdgeFlags = new Boolean[locations.size() + 1];
    Matrix[] polyTransform = new Matrix[1];
    int polyCount =
        this.computeCartesianPolygon(
            dc.getGlobe(), locations, edgeFlags, polyPoints, polyEdgeFlags, polyTransform);

    // Compute the winding order of the planar cartesian points. If the order is not
    // counter-clockwise, then
    // reverse the locations and points ordering.
    int winding = gb.computePolygonWindingOrder2(0, polyCount, polyPoints);
    if (winding != GeometryBuilder.COUNTER_CLOCKWISE) {
      gb.reversePoints(0, polyCount, polyPoints);
      gb.reversePoints(0, polyCount, polyEdgeFlags);
    }

    float[] polyVertices = new float[3 * polyCount];
    this.makePolygonVertices(polyCount, polyPoints, polyVertices);

    int fillDrawMode = GL.GL_TRIANGLES;
    int outlineDrawMode = GL.GL_LINES;

    int fillIndexCount = 0;
    int outlineIndexCount = 0;
    int vertexCount = 0;

    GeometryBuilder.IndexedTriangleArray ita = null;

    fillIndexCount += this.getEdgeFillIndexCount(polyCount, subdivisions);
    outlineIndexCount += this.getEdgeOutlineIndexCount(polyCount, subdivisions, polyEdgeFlags);
    vertexCount += this.getEdgeVertexCount(polyCount, subdivisions);

    if (enableCaps) {
      ita = gb.tessellatePolygon2(0, polyCount, polyVertices);
      for (int i = 0; i < subdivisions; i++) {
        gb.subdivideIndexedTriangleArray(ita);
      }

      fillIndexCount += ita.getIndexCount();
      vertexCount += ita.getVertexCount();
      // Bottom cap isn't drawn if airspace is collapsed.
      if (!this.isAirspaceCollapsed()) {
        fillIndexCount += ita.getIndexCount();
        vertexCount += ita.getVertexCount();
      }
    }

    int[] fillIndices = new int[fillIndexCount];
    int[] outlineIndices = new int[outlineIndexCount];
    float[] vertices = new float[3 * vertexCount];
    float[] normals = new float[3 * vertexCount];

    int fillIndexPos = 0;
    int outlineIndexPos = 0;
    int vertexPos = 0;

    this.makeEdge(
        dc,
        polyCount,
        polyVertices,
        polyEdgeFlags,
        altitudes,
        terrainConformant,
        subdivisions,
        GeometryBuilder.OUTSIDE,
        polyTransform[0],
        referenceCenter,
        fillIndexPos,
        fillIndices,
        outlineIndexPos,
        outlineIndices,
        vertexPos,
        vertices,
        normals);
    fillIndexPos += this.getEdgeFillIndexCount(polyCount, subdivisions);
    outlineIndexPos += this.getEdgeOutlineIndexCount(polyCount, subdivisions, polyEdgeFlags);
    vertexPos += this.getEdgeVertexCount(polyCount, subdivisions);

    if (enableCaps) {
      this.makeCap(
          dc,
          ita,
          altitudes[1],
          terrainConformant[1],
          GeometryBuilder.OUTSIDE,
          polyTransform[0],
          referenceCenter,
          fillIndexPos,
          fillIndices,
          vertexPos,
          vertices,
          normals);
      fillIndexPos += ita.getIndexCount();
      vertexPos += ita.getVertexCount();
      // Bottom cap isn't drawn if airspace is collapsed.
      if (!this.isAirspaceCollapsed()) {
        this.makeCap(
            dc,
            ita,
            altitudes[0],
            terrainConformant[0],
            GeometryBuilder.INSIDE,
            polyTransform[0],
            referenceCenter,
            fillIndexPos,
            fillIndices,
            vertexPos,
            vertices,
            normals);
        fillIndexPos += ita.getIndexCount();
        vertexPos += ita.getVertexCount();
      }
    }

    dest.getFillIndexGeometry().setElementData(fillDrawMode, fillIndexCount, fillIndices);
    dest.getOutlineIndexGeometry()
        .setElementData(outlineDrawMode, outlineIndexCount, outlineIndices);
    dest.getVertexGeometry().setVertexData(vertexCount, vertices);
    dest.getVertexGeometry().setNormalData(vertexCount, normals);
  }