/* ***************************************************************************** * Author: David S. Ebert * ***************************************************************************** * This software was developed as part of on going research in the CIS * * department at The Ohio State University. Any derivative of this code must * * credit the original author, The Ohio State University and must leave this * * paragraph unaltered. * ***************************************************************************** */ #include #include void my_dither(); /************************************************************************ * SCAN CONVERT THE OBJECT * ************************************************************************/ scan_them(e_w, face_ptr, ymin, ymax, size_polys, intensity) edge_td *e_w; xyz_td *face_ptr; /* edge_td *buffer; */ int ymin,ymax; long size_polys; int intensity; { xyzw_td edge[20]; int k; double z, zl, zr, dz, xr, xl, xlc, *z_buffer; double *x_coord, *z_coord; long yline, num_inter, x1; int y_screen; z_coord = (double *)malloc(sizeof(double)*20); x_coord = (double *)malloc(sizeof(double)*20); /* calc distance between 2 pixels */ for(yline=ymax; yline>ymin; yline--) { intersect_scan_line(&num_inter,z_coord,x_coord,(int)yline,edge, size_polys, face_ptr); /* sort the intersections */ sort(x_coord,z_coord,edge,num_inter); for(k=0; k < num_inter/2; k++) { xl = x_coord[k*2]; xlc = xl; ceiling(&xlc); xr = (double) ((int)(x_coord[k*2+1])); for(x1=xlc; x1<=xr; x1++) { my_dither(e_w, (int)x1, (int)yline, intensity); /* edge_plotpoint(e_w, x1, (int)yline);*/ /* draw it into the frame_buffer */ } /* end for xleft to xright loop */ } /* end k loop - */ } /* end for scanline loop*/ } /* ********************************************************************** * INTERSECT_SCAN_LINE * ********************************************************************** * Pick out the points a pair(edge) at a time, perspect the points,* * and calculate the edges' intersection with the scan line. * * * ********************************************************************** */ intersect_scan_line(num_inter, z_coord, x_coord, y_coord, edge, size_poly, face_ptr) long *num_inter, size_poly; double *z_coord, *x_coord; int y_coord; xyz_td *edge, *face_ptr; { long pnt, vindex; xyz_td point1, point2; *num_inter = 0; for(pnt = 0; pnt < size_poly; pnt++) { point1 = face_ptr[pnt]; if (pnt == size_poly-1) vindex = 0; else vindex = pnt + 1; point2 = face_ptr[vindex]; /* see if it intersects this scan line */ if ((point1.y >= y_coord && point2.y <= y_coord) || (point1.y <= y_coord && point2.y >= y_coord)) { /* nv1 = v_norm[pnt]; nv2 = v_norm[vindex]; */ calc_intersect(point1,point2,x_coord,y_coord, z_coord, num_inter,edge); } } } ceiling(x) double *x; { int y; y = (int)*x; if ((double) y != *x) *x = (double) (y + 1); else *x = (double) y; }