Ejemplo n.º 1
0
  public void setVFromPointWithSize(Point2D start, double size) {
    // TODO attention ne marhce pas avec certains frustum
    Polygon p = bottomPolygon;

    double startLength = p.getLengthTo(start);

    vOffset = startLength;
    vScale = size / p.getLength();
  }
Ejemplo n.º 2
0
 public void extrudeToFrustum(double offset, double height) {
   Ring<Double> offsets = new Ring<Double>();
   // TODO aie
   for (int i = 0; i < bottomPolygon.size(); i++) {
     offsets.add(offset);
   }
   extrudeToFrustum(offsets, height);
 }
Ejemplo n.º 3
0
  public void closeSum() {
    Triangulator t = new Triangulator(topPolygon);
    int lastIndex = mesh.vertices.size();
    for (int i = 0; i < t.getIndices().size(); i++) {
      mesh.indices.add(t.getIndices().get(i) + lastIndex);
    }

    for (Point2D point : topPolygon.points) {
      mesh.vertices.add(new Point3D(point, top, 1));
      mesh.normals.add(new Point3D(0, 1, 0));
    }

    mesh.textCoord.addAll(topPolygon.getTextureMap());
  }
Ejemplo n.º 4
0
  public void closeBase() {
    Triangulator t = new Triangulator(bottomPolygon);
    int lastIndex = mesh.vertices.size();
    for (int i = t.getIndices().size() - 1; i >= 0; i--) {
      mesh.indices.add(t.getIndices().get(i) + lastIndex);
    }

    for (Point2D point : bottomPolygon.points) {
      mesh.vertices.add(new Point3D(point, bottom, 1));
      mesh.normals.add(new Point3D(0, -1, 0));
    }

    mesh.textCoord.addAll(bottomPolygon.getTextureMap());
  }
Ejemplo n.º 5
0
  public void setVFromPointToPoint(Point2D start, Point2D end) {
    // TODO attention ne marhce pas avec certains frustum
    Polygon p = bottomPolygon;

    double startLength = p.getLengthTo(start);
    double endLength = p.getLengthTo(end);
    double length;

    if (endLength > startLength) {
      length = endLength - startLength;
    } else if (startLength > endLength) {
      length = p.getLength() - startLength + endLength;
    } else {
      length = p.getLength();
    }

    vOffset = startLength;
    vScale = length / p.getLength();
  }
Ejemplo n.º 6
0
  public void extrude(double height) {
    if (height < top && height > bottom) {
      throw new IllegalArgumentException("Specified height is inside mesh.");
    }

    Polygon polygon;
    double base;
    double sum;
    if (height > top) {
      polygon = topPolygon;
      base = top;
      sum = height;
    } else {
      polygon = bottomPolygon;
      base = height;
      sum = bottom;
    }

    for (Point2D p : polygon.points) {
      add6Indices(mesh.vertices.size());

      Point2D prev = polygon.points.getPrevious(p);
      Point2D next = polygon.points.getNext(p);
      Point2D nextNext = polygon.points.getNext(next);

      // add 4 vertices
      mesh.vertices.add(new Point3D(p, sum, 1));
      mesh.vertices.add(new Point3D(next, sum, 1));
      mesh.vertices.add(new Point3D(p, base, 1));
      mesh.vertices.add(new Point3D(next, base, 1));

      // add 4 normals
      double wPrevNormal = getSmoothedNormal(prev, p, next, 0);
      double wNextNormal = getSmoothedNormal(p, next, nextNext, 1);

      mesh.normals.add(new Point3D(Math.cos(wPrevNormal), 0, Math.sin(wPrevNormal)));
      mesh.normals.add(new Point3D(Math.cos(wNextNormal), 0, Math.sin(wNextNormal)));
      mesh.normals.add(new Point3D(Math.cos(wPrevNormal), 0, Math.sin(wPrevNormal)));
      mesh.normals.add(new Point3D(Math.cos(wNextNormal), 0, Math.sin(wNextNormal)));

      // add 4 textCoord
      double pLength = polygon.getLengthTo(p);
      double nextLength = polygon.getLengthTo(next);

      //			Logutil.logger.info("sum : "+sum+"base : "+base);
      mesh.textCoord.add(
          new Point2D(
              (-uOffset + sum - base) / (sum - base) / uScale,
              1 - (pLength - vOffset) / polygon.getLength() / vScale));
      mesh.textCoord.add(
          new Point2D(
              (-uOffset + sum - base) / (sum - base) / uScale,
              1 - (nextLength - vOffset) / polygon.getLength() / vScale));
      mesh.textCoord.add(
          new Point2D(
              -uOffset / (sum - base) / uScale,
              1 - (pLength - vOffset) / polygon.getLength() / vScale));
      mesh.textCoord.add(
          new Point2D(
              -uOffset / (sum - base) / uScale,
              1 - (nextLength - vOffset) / polygon.getLength() / vScale));
    }
    prepare(polygon, height);
  }