1 /* $Id: poly.c,v 1.4 2002-10-10 18:55:32 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
16 * Graphical routines for drawing polygons.
28 //#define USE_POLY_CODE 1
30 #define MAX_SCAN_LINES 1200
34 int y_edge_list[MAX_SCAN_LINES];
36 void gr_upoly(int nverts, int *vert )
39 int startx, stopx; // X coordinates of both ends of current edge.
40 int firstx, firsty; // Saved copy of the first vertex to connect later.
41 int dx_dy; // Slope of current edge.
44 int starty, stopy; // Y coordinates of both ends of current edge.
48 // Find the min and max rows to clear out the minimun y_edge_list.
53 for (i=3; i<(nverts*2); i+=2 )
55 if (vert[i]>maxy) maxy=vert[i];
56 if (vert[i]<miny) miny=vert[i];
60 miny--; // -1 to be safe
62 maxy++; // +1 to be safe
64 // Clear only the part of the y_edge_list that w will be using
65 if (miny < 0) miny = 0;
66 if (maxy > MAX_SCAN_LINES) maxy = MAX_SCAN_LINES;
68 for (i=miny; i<maxy; i++ )
71 // Save the first vertex so that we can connect to it at the end.
73 firsty = vert[1] >> 16;
79 // Get the beginning coordinates of the current edge.
81 starty = vert[1] >> 16;
83 // Get the ending coordinates of the current edge.
86 stopy = vert[3] >> 16;
89 stopx = firstx; // Last edge, uses first vertex as endpoint
93 if (stopy < starty ) {
102 if (stopy == starty )
104 // Draw a edge going horizontally across screen
109 //gr_uscanline( x1, x2-1, stopy );
110 gr_uscanline( x1, x2, stopy );
112 //gr_uscanline( x2, x1-1, stopy );
113 gr_uscanline( x2, x1, stopy );
117 dx_dy = (stopx - startx) / (stopy - starty);
119 for (; starty < stopy; starty++ )
121 if (y_edge_list[starty]==-1)
122 y_edge_list[starty] = startx;
124 x1 = y_edge_list[starty]>>16;
128 //gr_uscanline( x1, x2-1, starty );
129 gr_uscanline( x1, x2, starty );
131 //gr_uscanline( x2, x1-1, starty );
132 gr_uscanline( x2, x1, starty );
139 } while (nverts > 0);
143 void gr_poly(int nverts, int *vert )
146 int startx, stopx; // X coordinates of both ends of current edge.
147 int firstx, firsty; // Saved copy of the first vertex to connect later.
148 int dx_dy; // Slope of current edge.
151 int starty, stopy; // Y coordinates of both ends of current edge.
155 // Find the min and max rows to clear out the minimun y_edge_list.
162 for (i=3; i<(nverts*2); i+=2 )
165 if ((maxy=vert[i]) > MAXY) j++;
170 if ((miny=vert[i]) < MINY) j++;
176 miny--; // -1 to be safe
178 maxy++; // +1 to be safe
180 if (miny < MINY) miny = MINY;
181 if (maxy > MAXY) maxy = MAXY+1;
183 // Clear only the part of the y_edge_list that w will be using
184 for (i=miny; i<maxy; i++ )
187 // Save the first vertex so that we can connect to it at the end.
189 firsty = vert[1] >> 16;
195 // Get the beginning coordinates of the current edge.
197 starty = vert[1] >> 16;
199 // Get the ending coordinates of the current edge.
202 stopy = vert[3] >> 16;
205 stopx = firstx; // Last edge, uses first vertex as endpoint
210 if (stopy < starty ) {
219 if (stopy == starty )
221 // Draw a edge going horizontally across screen
222 if ((stopy >= MINY) && (stopy <=MAXY )) {
232 if ((x1 <= MAXX ) && (x2 >= MINX))
234 if (x1 < MINX ) x1 = MINX;
235 if (x2 > MAXX ) x2 = MAXX+1;
236 //gr_uscanline( x1, x2-1, stopy );
237 gr_scanline( x1, x2, stopy );
242 dx_dy = (stopx - startx) / (stopy - starty);
244 if (starty < MINY ) {
245 startx = dx_dy*(MINY-starty)+startx;
250 stopx = dx_dy*(MAXY-starty)+startx;
254 for (; starty < stopy; starty++ )
255 { if (y_edge_list[starty]==-1)
256 y_edge_list[starty] = startx;
258 x1 = y_edge_list[starty]>>16;
267 if ((x1 <= MAXX ) && (x2 >= MINX))
269 if (x1 < MINX ) x1 = MINX;
270 if (x2 > MAXX ) x2 = MAXX+1;
271 //gr_uscanline( x1, x2-1, starty );
272 gr_scanline( x1, x2, starty );
280 } while (nverts > 0);