1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
/*
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
*/
/*
* $Source: /cvsroot/dxx-rebirth/d1x-rebirth/2d/poly.c,v $
* $Revision: 1.1.1.1 $
* $Author: zicodxx $
* $Date: 2006/03/17 19:39:00 $
*
* Graphical routines for drawing polygons.
*
* $Log: poly.c,v $
* Revision 1.1.1.1 2006/03/17 19:39:00 zicodxx
* initial import
*
* Revision 1.1.1.1 1999/06/14 21:57:32 donut
* Import of d1x 1.37 source.
*
* Revision 1.5 1994/11/13 13:03:43 john
* Added paged out bit in bitmap structure. Commented out the
* poly code that is never used.
*
* Revision 1.4 1994/03/14 16:56:13 john
* Changed grs_bitmap structure to include bm_flags.
*
* Revision 1.3 1993/10/15 16:23:14 john
* y
*
* Revision 1.2 1993/10/08 14:30:39 john
* *** empty log message ***
*
* Revision 1.1 1993/09/08 11:44:13 john
* Initial revision
*
*
*/
#include "u_mem.h"
#include "gr.h"
#include "grdef.h"
//#define USE_POLY_CODE 1
#define MAX_SCAN_LINES 1200
#ifdef USE_POLY_CODE
int y_edge_list[MAX_SCAN_LINES];
void gr_upoly(int nverts, int *vert )
{
int temp;
int startx, stopx; // X coordinates of both ends of current edge.
int firstx, firsty; // Saved copy of the first vertex to connect later.
int dx_dy; // Slope of current edge.
int miny, maxy;
int starty, stopy; // Y coordinates of both ends of current edge.
int x1, x2, i;
// Find the min and max rows to clear out the minimun y_edge_list.
// (Is it worth it?)
maxy = vert[1];
miny = vert[1];
for (i=3; i<(nverts*2); i+=2 )
{
if (vert[i]>maxy) maxy=vert[i];
if (vert[i]<miny) miny=vert[i];
}
miny >>= 16;
miny--; // -1 to be safe
maxy >>= 16;
maxy++; // +1 to be safe
// Clear only the part of the y_edge_list that w will be using
if (miny < 0) miny = 0;
if (maxy > MAX_SCAN_LINES) maxy = MAX_SCAN_LINES;
for (i=miny; i<maxy; i++ )
y_edge_list[i] = -1;
// Save the first vertex so that we can connect to it at the end.
firstx = vert[0];
firsty = vert[1] >> 16;
do
{
nverts--;
// Get the beginning coordinates of the current edge.
startx = vert[0];
starty = vert[1] >> 16;
// Get the ending coordinates of the current edge.
if (nverts > 0 ) {
stopx = vert[2];
stopy = vert[3] >> 16;
vert += 2;
} else {
stopx = firstx; // Last edge, uses first vertex as endpoint
stopy = firsty;
}
if (stopy < starty ) {
temp = stopy;
stopy = starty;
starty = temp;
temp = stopx;
stopx = startx;
startx = temp;
}
if (stopy == starty )
{
// Draw a edge going horizontally across screen
x1 = startx>>16;
x2 = stopx>>16;
if (x2 > x1 )
//gr_uscanline( x1, x2-1, stopy );
gr_uscanline( x1, x2, stopy );
else
//gr_uscanline( x2, x1-1, stopy );
gr_uscanline( x2, x1, stopy );
} else {
dx_dy = (stopx - startx) / (stopy - starty);
for (; starty < stopy; starty++ )
{
if (y_edge_list[starty]==-1)
y_edge_list[starty] = startx;
else {
x1 = y_edge_list[starty]>>16;
x2 = startx>>16;
if (x2 > x1 )
//gr_uscanline( x1, x2-1, starty );
gr_uscanline( x1, x2, starty );
else
//gr_uscanline( x2, x1-1, starty );
gr_uscanline( x2, x1, starty );
}
startx += dx_dy;
}
}
} while (nverts > 0);
}
void gr_poly(int nverts, int *vert )
{
int temp;
int startx, stopx; // X coordinates of both ends of current edge.
int firstx, firsty; // Saved copy of the first vertex to connect later.
int dx_dy; // Slope of current edge.
int miny, maxy;
int starty, stopy; // Y coordinates of both ends of current edge.
int x1, x2, i, j;
// Find the min and max rows to clear out the minimun y_edge_list.
// (Is it worth it?)
maxy = vert[1];
miny = vert[1];
j = 0;
for (i=3; i<(nverts*2); i+=2 )
{
if (vert[i]>maxy) {
if ((maxy=vert[i]) > MAXY) j++;
//if (j>1) break;
}
if (vert[i]<miny) {
if ((miny=vert[i]) < MINY) j++;
//if (j>1) break;
}
}
miny >>= 16;
miny--; // -1 to be safe
maxy >>= 16;
maxy++; // +1 to be safe
if (miny < MINY) miny = MINY;
if (maxy > MAXY) maxy = MAXY+1;
// Clear only the part of the y_edge_list that w will be using
for (i=miny; i<maxy; i++ )
y_edge_list[i] = -1;
// Save the first vertex so that we can connect to it at the end.
firstx = vert[0];
firsty = vert[1] >> 16;
do
{
nverts--;
// Get the beginning coordinates of the current edge.
startx = vert[0];
starty = vert[1] >> 16;
// Get the ending coordinates of the current edge.
if (nverts > 0 ) {
stopx = vert[2];
stopy = vert[3] >> 16;
vert += 2;
} else {
stopx = firstx; // Last edge, uses first vertex as endpoint
stopy = firsty;
}
if (stopy < starty ) {
temp = stopy;
stopy = starty;
starty = temp;
temp = stopx;
stopx = startx;
startx = temp;
}
if (stopy == starty )
{
// Draw a edge going horizontally across screen
if ((stopy >= MINY) && (stopy <=MAXY )) {
x1 = startx>>16;
x2 = stopx>>16;
if (x1 > x2 ) {
temp = x2;
x2 = x1;
x1 = temp;
}
if ((x1 <= MAXX ) && (x2 >= MINX))
{
if (x1 < MINX ) x1 = MINX;
if (x2 > MAXX ) x2 = MAXX+1;
//gr_uscanline( x1, x2-1, stopy );
gr_scanline( x1, x2, stopy );
}
}
} else {
dx_dy = (stopx - startx) / (stopy - starty);
if (starty < MINY ) {
startx = dx_dy*(MINY-starty)+startx;
starty = MINY;
}
if (stopy > MAXY ) {
stopx = dx_dy*(MAXY-starty)+startx;
stopy = MAXY+1;
}
for (; starty < stopy; starty++ )
{ if (y_edge_list[starty]==-1)
y_edge_list[starty] = startx;
else {
x1 = y_edge_list[starty]>>16;
x2 = startx>>16;
if (x1 > x2 ) {
temp = x2;
x2 = x1;
x1 = temp;
}
if ((x1 <= MAXX ) && (x2 >= MINX))
{
if (x1 < MINX ) x1 = MINX;
if (x2 > MAXX ) x2 = MAXX+1;
//gr_uscanline( x1, x2-1, starty );
gr_scanline( x1, x2, starty );
}
}
startx += dx_dy;
}
}
} while (nverts > 0);
}
#endif
|