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.
27 //#define USE_POLY_CODE 1
29 #define MAX_SCAN_LINES 1200
33 int y_edge_list[MAX_SCAN_LINES];
35 void gr_upoly(int nverts, int *vert )
38 int startx, stopx; // X coordinates of both ends of current edge.
39 int firstx, firsty; // Saved copy of the first vertex to connect later.
40 int dx_dy; // Slope of current edge.
43 int starty, stopy; // Y coordinates of both ends of current edge.
47 // Find the min and max rows to clear out the minimun y_edge_list.
52 for (i=3; i<(nverts*2); i+=2 )
54 if (vert[i]>maxy) maxy=vert[i];
55 if (vert[i]<miny) miny=vert[i];
59 miny--; // -1 to be safe
61 maxy++; // +1 to be safe
63 // Clear only the part of the y_edge_list that w will be using
64 if (miny < 0) miny = 0;
65 if (maxy > MAX_SCAN_LINES) maxy = MAX_SCAN_LINES;
67 for (i=miny; i<maxy; i++ )
70 // Save the first vertex so that we can connect to it at the end.
72 firsty = vert[1] >> 16;
78 // Get the beginning coordinates of the current edge.
80 starty = vert[1] >> 16;
82 // Get the ending coordinates of the current edge.
85 stopy = vert[3] >> 16;
88 stopx = firstx; // Last edge, uses first vertex as endpoint
92 if (stopy < starty ) {
101 if (stopy == starty )
103 // Draw a edge going horizontally across screen
108 //gr_uscanline( x1, x2-1, stopy );
109 gr_uscanline( x1, x2, stopy );
111 //gr_uscanline( x2, x1-1, stopy );
112 gr_uscanline( x2, x1, stopy );
116 dx_dy = (stopx - startx) / (stopy - starty);
118 for (; starty < stopy; starty++ )
120 if (y_edge_list[starty]==-1)
121 y_edge_list[starty] = startx;
123 x1 = y_edge_list[starty]>>16;
127 //gr_uscanline( x1, x2-1, starty );
128 gr_uscanline( x1, x2, starty );
130 //gr_uscanline( x2, x1-1, starty );
131 gr_uscanline( x2, x1, starty );
138 } while (nverts > 0);
142 void gr_poly(int nverts, int *vert )
145 int startx, stopx; // X coordinates of both ends of current edge.
146 int firstx, firsty; // Saved copy of the first vertex to connect later.
147 int dx_dy; // Slope of current edge.
150 int starty, stopy; // Y coordinates of both ends of current edge.
154 // Find the min and max rows to clear out the minimun y_edge_list.
161 for (i=3; i<(nverts*2); i+=2 )
164 if ((maxy=vert[i]) > MAXY) j++;
169 if ((miny=vert[i]) < MINY) j++;
175 miny--; // -1 to be safe
177 maxy++; // +1 to be safe
179 if (miny < MINY) miny = MINY;
180 if (maxy > MAXY) maxy = MAXY+1;
182 // Clear only the part of the y_edge_list that w will be using
183 for (i=miny; i<maxy; i++ )
186 // Save the first vertex so that we can connect to it at the end.
188 firsty = vert[1] >> 16;
194 // Get the beginning coordinates of the current edge.
196 starty = vert[1] >> 16;
198 // Get the ending coordinates of the current edge.
201 stopy = vert[3] >> 16;
204 stopx = firstx; // Last edge, uses first vertex as endpoint
209 if (stopy < starty ) {
218 if (stopy == starty )
220 // Draw a edge going horizontally across screen
221 if ((stopy >= MINY) && (stopy <=MAXY )) {
231 if ((x1 <= MAXX ) && (x2 >= MINX))
233 if (x1 < MINX ) x1 = MINX;
234 if (x2 > MAXX ) x2 = MAXX+1;
235 //gr_uscanline( x1, x2-1, stopy );
236 gr_scanline( x1, x2, stopy );
241 dx_dy = (stopx - startx) / (stopy - starty);
243 if (starty < MINY ) {
244 startx = dx_dy*(MINY-starty)+startx;
249 stopx = dx_dy*(MAXY-starty)+startx;
253 for (; starty < stopy; starty++ )
254 { if (y_edge_list[starty]==-1)
255 y_edge_list[starty] = startx;
257 x1 = y_edge_list[starty]>>16;
266 if ((x1 <= MAXX ) && (x2 >= MINX))
268 if (x1 < MINX ) x1 = MINX;
269 if (x2 > MAXX ) x2 = MAXX+1;
270 //gr_uscanline( x1, x2-1, starty );
271 gr_scanline( x1, x2, starty );
279 } while (nverts > 0);