Пример #1
0
 private void add() {
   Point2D coord = pencil.getCoord();
   for (Trinket t : ModelManager.getBattlefield().getMap().get(coord).getData(Trinket.class)) {
     if (t.pos.equals(coord)) {
       coord = coord.getTranslation(RandomUtil.between(AngleUtil.FLAT, -AngleUtil.FLAT), 0.1);
     }
   }
   Trinket t =
       BuilderManager.getAllEditableTrinketBuilders()
           .get(set.actual)
           .build(coord.get3D(ModelManager.getBattlefield().getMap().getAltitudeAt(coord)));
   MapArtisanUtil.attachTrinket(t, ModelManager.getBattlefield().getMap());
   t.drawOnBattlefield();
 }
Пример #2
0
  private double getSmoothedNormal(Point2D prev, Point2D p, Point2D next, int normalIndex) {
    double n = AngleUtil.normalize(next.getSubtraction(p).getAngle() - AngleUtil.RIGHT);
    double prevN = AngleUtil.normalize(p.getSubtraction(prev).getAngle() - AngleUtil.RIGHT);

    double diff = AngleUtil.getSmallestDifference(n, prevN);
    double bissector = AngleUtil.getBisector(prevN, n);
    double res;

    if (diff > NO_SMOOTH_ANGLE) {
      if (normalIndex == 0) {
        res = n;
      } else {
        res = prevN;
      }
    } else {
      res = bissector;
    }

    return res;
  }
Пример #3
0
 private void move() {
   if (!pencil.maintained) {
     pencil.maintain();
     actualTrinket = getPointedTrinket();
     actualTrinket.sowed = false;
     if (actualTrinket != null) {
       moveOffset = pencil.getCoord().getSubtraction(actualTrinket.getCoord());
     }
   }
   if (actualTrinket != null) {
     // TODO attention, l'elevation n'est pas forcement juste avec ce calcul
     double elevation =
         actualTrinket.pos.z
             - ModelManager.getBattlefield().getMap().getAltitudeAt(actualTrinket.pos.get2D());
     Point2D newPos = pencil.getCoord().getSubtraction(moveOffset);
     double z = ModelManager.getBattlefield().getMap().getAltitudeAt(newPos) + elevation;
     actualTrinket.pos = newPos.get3D(z);
     MapArtisanUtil.cleanSowing(
         ModelManager.getBattlefield().getMap(), pencil.getCoord(), actualTrinket.getRadius());
   }
 }
Пример #4
0
  public void extrudeToFrustum(Ring<Double> offsets, double height) {
    Polygon polygon;
    double base;
    double sum;
    if (height > top) {
      polygon = topPolygon;
      base = top;
      sum = height;
    } else {
      polygon = bottomPolygon;
      base = height;
      sum = bottom;
    }

    OffsetOperator op = new OffsetOperator(polygon);
    op.setOffsets(offsets);
    Polygon newPolygon = op.getRemainder();
    Ring<Integer> correspondences = op.correspondences;

    if (height < top && height > bottom) {
      throw new IllegalArgumentException("Specified height is inside mesh.");
    }

    for (int i = 0; i < polygon.points.size(); i++) {
      add6Indices(mesh.vertices.size());

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

      double offset = offsets.get(i);

      if (!horizontalNormalSet) {
        if (height > top) {
          topNormalAngle = new Point2D(offset, sum - base).getAngle() - AngleUtil.RIGHT;
        } else {
          topNormalAngle = new Point2D(offset, sum - base).getAngle() + AngleUtil.RIGHT;
        }
        bottomNormalAngle = topNormalAngle;
      }

      // add 4 vertices
      if (height > top) {
        mesh.vertices.add(new Point3D(newPolygon.points.get(correspondences.get(i)), sum, 1));
        mesh.vertices.add(new Point3D(newPolygon.points.get(correspondences.getNext(i)), sum, 1));
        mesh.vertices.add(new Point3D(p, base, 1));
        mesh.vertices.add(new Point3D(next, base, 1));
      } else {
        mesh.vertices.add(new Point3D(p, sum, 1));
        mesh.vertices.add(new Point3D(next, sum, 1));
        mesh.vertices.add(new Point3D(newPolygon.points.get(correspondences.get(i)), base, 1));
        mesh.vertices.add(new Point3D(newPolygon.points.get(correspondences.getNext(i)), base, 1));
      }

      // add 4 normals

      double wPrevNormal = getSmoothedNormal(prev, p, next, 0);
      double wNextNormal = getSmoothedNormal(p, next, nextNext, 1);

      mesh.normals.add(
          new Point3D(Point2D.ORIGIN.getTranslation(wPrevNormal, 1), topNormalAngle, 3));
      mesh.normals.add(
          new Point3D(Point2D.ORIGIN.getTranslation(wNextNormal, 1), topNormalAngle, 3));
      mesh.normals.add(
          new Point3D(Point2D.ORIGIN.getTranslation(wPrevNormal, 1), bottomNormalAngle, 3));
      mesh.normals.add(
          new Point3D(Point2D.ORIGIN.getTranslation(wNextNormal, 1), bottomNormalAngle, 3));

      // add 4 textCoord
      double width = p.getDistance(next);
      double heigth = sum - base;
      mesh.textCoord.add(new Point2D(0, heigth));
      mesh.textCoord.add(new Point2D(width, heigth));
      mesh.textCoord.add(new Point2D(0, 0));
      mesh.textCoord.add(new Point2D(width, 0));
    }
    prepare(newPolygon, height);
  }