Exemplo n.º 1
0
 /**
  * Draws a 3-Dimensional box onto the canvas whose center is the provided {@link Point}, whose
  * size (distance to a face from the center) is the provided size. Default box color is {@link
  * Colors#BLACK} and whose color is the {@link Colors} enum provided.
  *
  * @param point the {@link Point} center of the box.
  * @param size the size (distance from center to faces) of the box a float.
  * @param color the provided color of the box.
  */
 public void drawBox(final Point point, final float size, final Colors color) {
   if (wireMode) this.applet.stroke(wireframeColor.getRgb());
   else this.applet.noStroke();
   this.applet.fill(color.getRgb());
   this.applet.pushMatrix();
   this.applet.translate(point.x, point.y, point.z);
   this.applet.box(size);
   this.applet.popMatrix();
   this.applet.noFill();
 }
Exemplo n.º 2
0
 /**
  * Draws a 3-Dimensional {@link Point} onto the canvas with a given radius and color.
  *
  * @param point the {@link Point} to draw.
  * @param radius a radius, as a float.
  * @param color the {@link Colors} value for the object to be drawn.
  */
 public void drawPoint3D(final Point point, final float radius, final Colors color) {
   if (wireMode) this.applet.stroke(wireframeColor.getRgb());
   else this.applet.noStroke();
   this.applet.fill(color.getRgb());
   this.applet.pushMatrix();
   this.applet.translate(point.x, point.y, point.z);
   this.applet.sphere(radius);
   this.applet.noFill();
   this.applet.popMatrix();
 }
Exemplo n.º 3
0
  /**
   * Creates a 3D smooth object whose 'skeleton' is represented by the provided {@link Circle3D}
   * objects.
   *
   * @param circles the 'skeleton' circles.
   * @param color the color for shading.
   */
  public void drawSmoothShading(final List<Circle3D> circles, final Colors color) {
    for (int i = 0; i < circles.size() - 1; i++) {
      Circle3D circle = circles.get(i);
      Point center = circle.center;
      List<Point> points = circle.points;
      Circle3D nextCircle = circles.get(i + 1);
      Point nextCenter = nextCircle.center;
      List<Point> nextPoints = nextCircle.points;
      this.applet.fill(color.getRgb());
      this.applet.beginShape(QUADS);
      for (int j = 0; j < points.size(); j++) {
        int index = (j == points.size() - 1 ? points.size() - j : j + 1);
        Point topLeft = points.get(j), topRight = nextPoints.get(j);
        Point bottomLeft = points.get(index), bottomRight = nextPoints.get(index);
        Vector tlNormal = new Vector(center, topLeft).normal();
        Vector trNormal = new Vector(nextCenter, topRight).normal();
        Vector blNormal = new Vector(center, bottomLeft).normal();
        Vector brNormal = new Vector(nextCenter, bottomRight).normal();

        this.applet.normal(tlNormal.x, tlNormal.y, tlNormal.z);
        this.applet.vertex(topLeft.x, topLeft.y, topLeft.z);

        this.applet.normal(trNormal.x, trNormal.y, trNormal.z);
        this.applet.vertex(topRight.x, topRight.y, topRight.z);

        this.applet.normal(brNormal.x, brNormal.y, brNormal.z);
        this.applet.vertex(bottomRight.x, bottomRight.y, bottomRight.z);

        this.applet.normal(blNormal.x, blNormal.y, blNormal.z);
        this.applet.vertex(bottomLeft.x, bottomLeft.y, bottomLeft.z);
      }
      this.applet.endShape(CLOSE);
    }
  }