Example #1
0
  /**
   * @param renderer GL renderer
   * @param polygon polygon
   * @param pt polygon triangulation
   * @param vertices vertices of the polygon
   * @param verticesLength vertices length (may <> vertices.length due to cache)
   */
  public static final void drawPolygon(
      Renderer renderer,
      GeoPolygon polygon,
      PolygonTriangulation pt,
      Coords[] vertices,
      int verticesLength) {

    Coords n = polygon.getMainDirection();

    pt.clear();

    try {
      // simplify the polygon and check if there are at least 3 points
      // left
      if (pt.updatePoints() > 2) {

        // check if the polygon is convex
        Convexity convexity = pt.checkIsConvex();
        if (convexity != Convexity.NOT) {
          boolean reverse =
              polygon.getReverseNormalForDrawing() ^ (convexity == Convexity.CLOCKWISE);
          renderer.getGeometryManager().drawPolygonConvex(n, vertices, verticesLength, reverse);
        } else {
          // set intersections (if needed) and divide the polygon into
          // non self-intersecting polygons
          pt.setIntersections();

          // convert the set of polygons to triangle fans
          pt.triangulate();

          // compute 3D coords for intersections
          Coords[] verticesWithIntersections =
              pt.getCompleteVertices(vertices, polygon.getCoordSys(), verticesLength);

          // draw the triangle fans
          renderer
              .getGeometryManager()
              .drawTriangleFans(
                  n, verticesWithIntersections, pt.getMaxPointIndex(), pt.getTriangleFans());
        }
      }
    } catch (Exception e) {
      App.debug(e.getMessage());
      e.printStackTrace();
    }
  }
Example #2
0
  /**
   * Constructor for previewable
   *
   * @param a_view3D
   * @param selectedPoints
   */
  @SuppressWarnings("unchecked")
  public DrawPolygon3D(EuclidianView3D a_view3D, ArrayList<GeoPointND> selectedPoints) {

    super(a_view3D);

    Kernel3D kernel = getView3D().getKernel();

    setGeoElement(new GeoPolygon3D(kernel.getConstruction(), null));
    getGeoElement().setIsPickable(false);

    pt.setPolygon((GeoPolygon) getGeoElement());

    this.selectedPoints = selectedPoints;

    segments = new ArrayList<DrawSegment3D>();
    segmentsPoints = new ArrayList<ArrayList>();

    setPickingType(PickingType.SURFACE);

    isPreview = true;

    updatePreview();
  }