Пример #1
0
    /**
     * Creates the unit normal to the polygon by taking the cross product of the first two edges.
     * Call with 'nsides' set to two if the polygon is visible from both sides.
     */
    void setNormal() {
      // We need three points to define two edges.
      if (n < 3) return;
      if (normal == null) normal = new float[3];

      float[] p0 = {ps[points[0]], ps[points[0] + 1], ps[points[0] + 2]};
      float[] p1 = {ps[points[1]], ps[points[1] + 1], ps[points[1] + 2]};
      float[] p2 = {ps[points[2]], ps[points[2] + 1], ps[points[2] + 2]};

      float[] e1 = new float[3];
      float[] e2 = new float[3];

      Tools3d.subtract(p1, p0, e1);
      Tools3d.subtract(p2, p1, e2);

      Tools3d.cross(e1, e2, normal);
      Tools3d.makeUnit(normal);

      dirtyNormal = false;
    }