/*======== 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); }
/*======== public void addCurve() ========== Inputs: int x0 int y0 int x1 int y1 int x2 int y2 int x3 int y3 Returns: Generates the edges required to create a curve and adds them to the edge matrix 03/09/12 18:00:06 jonalf ====================*/ public void addCurve( double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, int type) { EdgeMatrix xcoefs = new EdgeMatrix(1); EdgeMatrix ycoefs = new EdgeMatrix(1); // a lower step value makes a more precise curve double step = 0.01; double x, y, z, ax, ay, bx, by, cx, cy, dx, dy; if (type == gui.HERMITE_MODE) { xcoefs.generateHermiteCoefs(x0, x1, x2, x3); ycoefs.generateHermiteCoefs(y0, y1, y2, y3); } else { xcoefs.generateBezierCoefs(x0, x1, x2, x3); ycoefs.generateBezierCoefs(y0, y1, y2, y3); } ax = xcoefs.getX(0); bx = xcoefs.getY(0); cx = xcoefs.getZ(0); dx = xcoefs.getD(0); ay = ycoefs.getX(0); by = ycoefs.getY(0); cy = ycoefs.getZ(0); dy = ycoefs.getD(0); double startx = x0; double starty = y0; for (double t = step; t <= 1; t += step) { x = ax * t * t * t + bx * t * t + cx * t + dx; y = ay * t * t * t + by * t * t + cy * t + dy; addEdge(startx, starty, 0, x, y, 0); startx = x; starty = y; } }
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++; } } }