示例#1
0
  /**
   * Adds a series of polygons by rotating the points list (ps) steps times, and colouring them as
   * defined by the color array (stripes!).
   */
  public void lathePolygons(float[][] ps, Color[] color, int steps) {
    float _ps[][] = new float[ps.length][3];
    float stepAngle = (float) Math.PI * 2 / steps; // the angle of each step in radians
    int currColor = 0;
    float m[][];

    for (int step = 0; step < steps; step++) {
      // translate each point to it next step round
      m = Tools3d.rotateAboutZ(stepAngle);
      for (int i = 0; i < ps.length; i++) {
        Tools3d.applyTo(m, ps[i], _ps[i]);
      }

      // build the polygons
      for (int point = 0; point < ps.length - 1; point++) {
        this.addPolygon(
            new float[][] {_ps[point], ps[point], ps[point + 1], _ps[point + 1]}, color[currColor]);
      }

      // copy the translated array to the starting array read for the next iteration
      for (int i = 0; i < ps.length; i++) {
        ps[i][0] = _ps[i][0];
        ps[i][1] = _ps[i][1];
        ps[i][2] = _ps[i][2];
      }

      currColor++;
      if (currColor == color.length) {
        currColor = 0;
      }
    }
  }