2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
15 * Graphical routines for drawing polygons.
24 //#define USE_POLY_CODE 1
26 #define MAX_SCAN_LINES 1200
30 int y_edge_list[MAX_SCAN_LINES];
32 void gr_upoly(int nverts, int *vert )
35 int startx, stopx; // X coordinates of both ends of current edge.
36 int firstx, firsty; // Saved copy of the first vertex to connect later.
37 int dx_dy; // Slope of current edge.
40 int starty, stopy; // Y coordinates of both ends of current edge.
44 // Find the min and max rows to clear out the minimun y_edge_list.
49 for (i=3; i<(nverts*2); i+=2 )
51 if (vert[i]>maxy) maxy=vert[i];
52 if (vert[i]<miny) miny=vert[i];
56 miny--; // -1 to be safe
58 maxy++; // +1 to be safe
60 // Clear only the part of the y_edge_list that w will be using
61 if (miny < 0) miny = 0;
62 if (maxy > MAX_SCAN_LINES) maxy = MAX_SCAN_LINES;
64 for (i=miny; i<maxy; i++ )
67 // Save the first vertex so that we can connect to it at the end.
69 firsty = vert[1] >> 16;
75 // Get the beginning coordinates of the current edge.
77 starty = vert[1] >> 16;
79 // Get the ending coordinates of the current edge.
82 stopy = vert[3] >> 16;
85 stopx = firstx; // Last edge, uses first vertex as endpoint
89 if (stopy < starty ) {
100 // Draw a edge going horizontally across screen
105 //gr_uscanline( x1, x2-1, stopy );
106 gr_uscanline( x1, x2, stopy );
108 //gr_uscanline( x2, x1-1, stopy );
109 gr_uscanline( x2, x1, stopy );
113 dx_dy = (stopx - startx) / (stopy - starty);
115 for (; starty < stopy; starty++ )
117 if (y_edge_list[starty]==-1)
118 y_edge_list[starty] = startx;
120 x1 = y_edge_list[starty]>>16;
124 //gr_uscanline( x1, x2-1, starty );
125 gr_uscanline( x1, x2, starty );
127 //gr_uscanline( x2, x1-1, starty );
128 gr_uscanline( x2, x1, starty );
135 } while (nverts > 0);
139 void gr_poly(int nverts, int *vert )
142 int startx, stopx; // X coordinates of both ends of current edge.
143 int firstx, firsty; // Saved copy of the first vertex to connect later.
144 int dx_dy; // Slope of current edge.
147 int starty, stopy; // Y coordinates of both ends of current edge.
151 // Find the min and max rows to clear out the minimun y_edge_list.
158 for (i=3; i<(nverts*2); i+=2 )
161 if ((maxy=vert[i]) > MAXY) j++;
166 if ((miny=vert[i]) < MINY) j++;
172 miny--; // -1 to be safe
174 maxy++; // +1 to be safe
176 if (miny < MINY) miny = MINY;
177 if (maxy > MAXY) maxy = MAXY+1;
179 // Clear only the part of the y_edge_list that w will be using
180 for (i=miny; i<maxy; i++ )
183 // Save the first vertex so that we can connect to it at the end.
185 firsty = vert[1] >> 16;
191 // Get the beginning coordinates of the current edge.
193 starty = vert[1] >> 16;
195 // Get the ending coordinates of the current edge.
198 stopy = vert[3] >> 16;
201 stopx = firstx; // Last edge, uses first vertex as endpoint
206 if (stopy < starty ) {
215 if (stopy == starty )
217 // Draw a edge going horizontally across screen
218 if ((stopy >= MINY) && (stopy <=MAXY )) {
228 if ((x1 <= MAXX ) && (x2 >= MINX))
230 if (x1 < MINX ) x1 = MINX;
231 if (x2 > MAXX ) x2 = MAXX+1;
232 //gr_uscanline( x1, x2-1, stopy );
233 gr_scanline( x1, x2, stopy );
238 dx_dy = (stopx - startx) / (stopy - starty);
240 if (starty < MINY ) {
241 startx = dx_dy*(MINY-starty)+startx;
246 stopx = dx_dy*(MAXY-starty)+startx;
250 for (; starty < stopy; starty++ )
251 { if (y_edge_list[starty]==-1)
252 y_edge_list[starty] = startx;
254 x1 = y_edge_list[starty]>>16;
263 if ((x1 <= MAXX ) && (x2 >= MINX))
265 if (x1 < MINX ) x1 = MINX;
266 if (x2 > MAXX ) x2 = MAXX+1;
267 //gr_uscanline( x1, x2-1, starty );
268 gr_scanline( x1, x2, starty );
276 } while (nverts > 0);