Пример #1
0
  /*======== public void drawLines() ==========
  Inputs:  PointMatrix pm
  Color c
  Returns:
  calls drawLine so that it draws all the lines within PointMatrix pm
  ====================*/
  public void drawLines(EdgeMatrix pm, Color c) {

    for (int i = 0; i < pm.getLastCol() - 1; i += 2)
      drawLine(
          (int) pm.getX(i),
          (int) pm.getY(i),
          (int) pm.getZ(i),
          (int) pm.getX(i + 1),
          (int) pm.getY(i + 1),
          (int) pm.getZ(i + 1),
          c);
  }
Пример #2
0
  public void scanLine(EdgeMatrix pm, int i, Color c) {

    int y0, y1, y2;
    y0 = (int) pm.getY(i);
    y1 = (int) pm.getY(i + 1);
    y2 = (int) pm.getY(i + 2);
    int T, M, B;

    // y0 is Ty
    if (y0 >= y1 && y0 >= y2) {
      T = 0;
      // y1 is My
      if (y1 >= y2) {
        M = 1;
        B = 2;
      }
      // y2 is My
      else {
        M = 2;
        B = 1;
      }
    }
    // y1 is Ty
    else if (y1 >= y0 && y1 >= y2) {
      T = 1;
      // y0 is My
      if (y0 >= y2) {
        M = 0;
        B = 2;
      }
      // y2 is My
      else {
        M = 2;
        B = 0;
      }
    }
    // y2 is Ty
    else {
      T = 2;
      // y0 is My
      if (y0 >= y1) {
        M = 0;
        B = 1;
      }
      // y1 is My
      else {
        M = 1;
        B = 0;
      }
    }

    // Top vertices
    int Tx = (int) pm.getX(i + T);
    int Ty = (int) pm.getY(i + T);
    int Tz = (int) pm.getZ(i + T);
    // Mid vertices
    int Mx = (int) pm.getX(i + M);
    int My = (int) pm.getY(i + M);
    int Mz = (int) pm.getZ(i + M);
    // bot vertices
    int Bx = (int) pm.getX(i + B);
    int By = (int) pm.getY(i + B);
    int Bz = (int) pm.getZ(i + B);

    int d0, d1, dz0, dz1;
    if (Ty != By) {
      d0 = (Tx - Bx) / (Ty - By);
      dz0 = (Tz - Bz) / (Ty - By);
    } else {
      d0 = 999999999;
      dz0 = 999999999;
    }
    if (By != My) {
      d1 = (Mx - Bx) / (My - By);
      dz1 = (Mz - Bz) / (My - By);

      int TBcounter = 0;
      int counter = 0;
      int startx = Bx;
      int starty = By;
      int startz = Bz;
      int btom = My - By;
      while (counter <= btom) {
        drawLine(
            startx + d0 * TBcounter,
            starty + TBcounter,
            startz + dz0 * TBcounter,
            startx + d1 * counter,
            starty + counter,
            startz + dz1 * counter,
            c);
        TBcounter++;
        counter++;
      }

      if (Ty == My) return;
      d1 = (Tx - Mx) / (Ty - My);
      dz1 = (Tz - Mz) / (Ty - My);

      counter = 0;

      int mtot = Ty - My;
      d1 = (Tx - Mx) / (Ty - My);
      dz1 = (Tz - Mz) / (Ty - My);
      while (counter <= mtot) {
        drawLine(
            Bx + d0 * TBcounter,
            By + TBcounter,
            Bz + dz0 * TBcounter,
            Mx + d1 * counter,
            My + counter,
            Mz + dz1 * counter,
            c);
        counter++;
        TBcounter++;
      }
    } else {
      if (Ty == My) return;
      d1 = (Tx - Mx) / (Ty - My);
      dz1 = (Tz - Mz) / (Ty - My);

      int counter = 0;
      int TBcounter = 0;
      int mtot = Ty - My;
      while (counter <= mtot) {
        drawLine(
            Bx + d0 * TBcounter,
            By + TBcounter,
            Bz + dz0 * TBcounter,
            Mx + d1 * counter,
            My + counter,
            Mz + dz1 * counter,
            c);
        counter++;
        TBcounter++;
      }
    }
  }