Example #1
0
  public void clipW(Point3D pA, Point3D pB, Point3D pC, int color) {
    if (pA.w > pB.w) {
      Point3D p = pA;
      pA = pB;
      pB = p;
    }
    if (pB.w > pC.w) {
      Point3D p = pB;
      pB = pC;
      pC = p;
    }
    if (pA.w > pB.w) {
      Point3D p = pA;
      pA = pB;
      pB = p;
    }

    if (pC.w < wmin) {
      return;
    }

    if (pB.w < wmin) {
      double t = (wmin - pC.w) / (pA.w - pC.w);
      Point3D nv1 = pA.mul(t).add(pC.mul(1.0 - t));
      t = (wmin - pC.w) / (pB.w - pC.w);
      Point3D nv2 = pB.mul(t).add(pC.mul(1.0 - t));
      dehomog(nv1, nv2, pC, color, fill);
      return;
    }

    if (pA.w < wmin) {
      double t = (wmin - pB.w) / (pA.w - pB.w);
      Point3D nva = pA.mul(t).add(pB.mul(1.0 - t));
      t = (wmin - pC.w) / (pA.w - pC.w);
      Point3D nvb = pA.mul(t).add(pC.mul(1.0 - t));
      dehomog(nva, nvb, pC, color, fill);
      dehomog(nva, pB, pC, color, fill);
      return;
    }

    dehomog(pA, pB, pC, color, fill);
  }