| | 1 | /* |
| | 2 | * KJL 15:13:43 7/17/97 - frustrum.c |
| | 3 | * |
| | 4 | * Contains all the functions connected |
| | 5 | * to the view frustrum and clipping |
| | 6 | * |
| | 7 | */ |
| | 8 | |
| | 9 | #include "system.h" |
| | 10 | #include "prototyp.h" |
| | 11 | #include <assert.h> |
| | 12 | #include "gamedef.h" |
| | 13 | #include "frustum.h" |
| | 14 | |
| | 15 | extern VECTORCH RotatedPts[]; |
| | 16 | |
| | 17 | #define ZCLIPPINGVALUE 64 |
| | 18 | #define FAR_Z_CLIP 0 |
| | 19 | #define FAR_Z_CLIP_RANGE 49000 |
| | 20 | |
| | 21 | /* clipping code macros - these are used as building blocks to assemble |
| | 22 | clipping fns for different polygon types with the minimum of fuss */ |
| | 23 | #define Clip_Z_Test(v) (ZCLIPPINGVALUE <= (v)->Z) |
| | 24 | #define Clip_NX_Test(v) (-(v)->X <= (v)->Z) |
| | 25 | #define Clip_PX_Test(v) ((v)->X <= (v)->Z) |
| | 26 | #define Clip_NY_Test(v) (-(v)->Y <= (v)->Z) |
| | 27 | #define Clip_PY_Test(v) ((v)->Y <= (v)->Z) |
| | 28 | |
| | 29 | #define Clip_LoopStart(b) \ |
| | 30 | do \ |
| | 31 | { \ |
| | 32 | RENDERVERTEX *nextVertexPtr; \ |
| | 33 | int nextVertexInside; \ |
| | 34 | \ |
| | 35 | /* setup pointer to next vertex, wrapping round if necessary */ \ |
| | 36 | if (!--verticesLeft) \ |
| | 37 | { \ |
| | 38 | nextVertexPtr = (b); \ |
| | 39 | } \ |
| | 40 | else \ |
| | 41 | { \ |
| | 42 | nextVertexPtr = curVertexPtr+1; \ |
| | 43 | } \ |
| | 44 | \ |
| | 45 | /* if current vertex is inside the plane, output it */ \ |
| | 46 | if (curVertexInside) \ |
| | 47 | { \ |
| | 48 | numberOfPointsOutputted++; \ |
| | 49 | *outputVerticesPtr++ = *curVertexPtr; \ |
| | 50 | } \ |
| | 51 | \ |
| | 52 | /* test if next vertex is inside the plane */ \ |
| | 53 | nextVertexInside = |
| | 54 | |
| | 55 | #define Clip_Z_OutputXYZ \ |
| | 56 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 57 | if (nextVertexInside != curVertexInside) \ |
| | 58 | { \ |
| | 59 | int lambda; \ |
| | 60 | \ |
| | 61 | lambda = DIV_FIXED \ |
| | 62 | ( \ |
| | 63 | (ZCLIPPINGVALUE - curVertexPtr->Z), \ |
| | 64 | (nextVertexPtr->Z - curVertexPtr->Z) \ |
| | 65 | ); \ |
| | 66 | \ |
| | 67 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); \ |
| | 68 | outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda,nextVertexPtr->Y-curVertexPtr->Y); \ |
| | 69 | outputVerticesPtr->Z = ZCLIPPINGVALUE; |
| | 70 | |
| | 71 | #define Clip_NX_OutputXYZ \ |
| | 72 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 73 | if (nextVertexInside != curVertexInside) \ |
| | 74 | { \ |
| | 75 | int lambda; \ |
| | 76 | \ |
| | 77 | lambda = DIV_FIXED \ |
| | 78 | ( \ |
| | 79 | (curVertexPtr->Z + curVertexPtr->X), \ |
| | 80 | -(nextVertexPtr->X-curVertexPtr->X) - (nextVertexPtr->Z-curVertexPtr->Z) \ |
| | 81 | ); \ |
| | 82 | \ |
| | 83 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); \ |
| | 84 | outputVerticesPtr->Z = -outputVerticesPtr->X; \ |
| | 85 | outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda,nextVertexPtr->Y-curVertexPtr->Y); |
| | 86 | |
| | 87 | #define Clip_PX_OutputXYZ \ |
| | 88 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 89 | if (nextVertexInside != curVertexInside) \ |
| | 90 | { \ |
| | 91 | int lambda; \ |
| | 92 | \ |
| | 93 | lambda = DIV_FIXED \ |
| | 94 | ( \ |
| | 95 | (curVertexPtr->Z - curVertexPtr->X), \ |
| | 96 | (nextVertexPtr->X-curVertexPtr->X) - (nextVertexPtr->Z-curVertexPtr->Z) \ |
| | 97 | ); \ |
| | 98 | \ |
| | 99 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); \ |
| | 100 | outputVerticesPtr->Z = outputVerticesPtr->X; \ |
| | 101 | outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda,nextVertexPtr->Y-curVertexPtr->Y); |
| | 102 | |
| | 103 | #define Clip_NY_OutputXYZ \ |
| | 104 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 105 | if (nextVertexInside != curVertexInside) \ |
| | 106 | { \ |
| | 107 | int lambda; \ |
| | 108 | \ |
| | 109 | lambda = DIV_FIXED \ |
| | 110 | ( \ |
| | 111 | (curVertexPtr->Z + curVertexPtr->Y), \ |
| | 112 | -(nextVertexPtr->Y-curVertexPtr->Y) - (nextVertexPtr->Z-curVertexPtr->Z) \ |
| | 113 | ); \ |
| | 114 | \ |
| | 115 | outputVerticesPtr->Z = curVertexPtr->Z + MUL_FIXED(lambda,nextVertexPtr->Z-curVertexPtr->Z); \ |
| | 116 | outputVerticesPtr->Y = -(outputVerticesPtr->Z); \ |
| | 117 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); |
| | 118 | |
| | 119 | #define Clip_PY_OutputXYZ \ |
| | 120 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 121 | if (nextVertexInside != curVertexInside) \ |
| | 122 | { \ |
| | 123 | int lambda; \ |
| | 124 | \ |
| | 125 | lambda = DIV_FIXED \ |
| | 126 | ( \ |
| | 127 | (curVertexPtr->Z - curVertexPtr->Y), \ |
| | 128 | (nextVertexPtr->Y-curVertexPtr->Y) - (nextVertexPtr->Z-curVertexPtr->Z) \ |
| | 129 | ); \ |
| | 130 | \ |
| | 131 | outputVerticesPtr->Z = curVertexPtr->Z + MUL_FIXED(lambda,nextVertexPtr->Z-curVertexPtr->Z); \ |
| | 132 | outputVerticesPtr->Y = (outputVerticesPtr->Z); \ |
| | 133 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); |
| | 134 | |
| | 135 | #define Clip_OutputUV \ |
| | 136 | outputVerticesPtr->U = curVertexPtr->U + MUL_FIXED(lambda,nextVertexPtr->U-curVertexPtr->U); \ |
| | 137 | outputVerticesPtr->V = curVertexPtr->V + MUL_FIXED(lambda,nextVertexPtr->V-curVertexPtr->V); |
| | 138 | |
| | 139 | #define Clip_OutputI \ |
| | 140 | outputVerticesPtr->A = curVertexPtr->A + MUL_FIXED(lambda,nextVertexPtr->A-curVertexPtr->A); \ |
| | 141 | outputVerticesPtr->R = curVertexPtr->R + MUL_FIXED(lambda,nextVertexPtr->R-curVertexPtr->R); \ |
| | 142 | outputVerticesPtr->G = curVertexPtr->G + MUL_FIXED(lambda,nextVertexPtr->G-curVertexPtr->G); \ |
| | 143 | outputVerticesPtr->B = curVertexPtr->B + MUL_FIXED(lambda,nextVertexPtr->B-curVertexPtr->B); \ |
| | 144 | outputVerticesPtr->SpecularR = curVertexPtr->SpecularR + MUL_FIXED(lambda,nextVertexPtr->SpecularR-curVertexPtr->SpecularR); \ |
| | 145 | outputVerticesPtr->SpecularG = curVertexPtr->SpecularG + MUL_FIXED(lambda,nextVertexPtr->SpecularG-curVertexPtr->SpecularG); \ |
| | 146 | outputVerticesPtr->SpecularB = curVertexPtr->SpecularB + MUL_FIXED(lambda,nextVertexPtr->SpecularB-curVertexPtr->SpecularB); |
| | 147 | |
| | 148 | #define Clip_LoopEnd(b) \ |
| | 149 | numberOfPointsOutputted++; \ |
| | 150 | outputVerticesPtr++; \ |
| | 151 | } \ |
| | 152 | \ |
| | 153 | /* okay, now the current vertex becomes what was the next vertex */ \ |
| | 154 | curVertexPtr = nextVertexPtr; \ |
| | 155 | curVertexInside = nextVertexInside; \ |
| | 156 | } \ |
| | 157 | while(verticesLeft); \ |
| | 158 | \ |
| | 159 | RenderPolygon.NumberOfVertices = numberOfPointsOutputted; |
| | 160 | |
| | 161 | /* Wide screen versions of clip macros */ |
| | 162 | |
| | 163 | #define Clip_Wide_NX_Test(v) (-(v)->X <= (v)->Z*2) |
| | 164 | #define Clip_Wide_PX_Test(v) ((v)->X <= (v)->Z*2) |
| | 165 | #define Clip_Wide_NY_Test(v) (-(v)->Y <= (v)->Z*2) |
| | 166 | #define Clip_Wide_PY_Test(v) ((v)->Y <= (v)->Z*2) |
| | 167 | #define Clip_Wide_NX_OutputXYZ \ |
| | 168 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 169 | if (nextVertexInside != curVertexInside) \ |
| | 170 | { \ |
| | 171 | int lambda; \ |
| | 172 | \ |
| | 173 | lambda = DIV_FIXED \ |
| | 174 | ( \ |
| | 175 | (-2*curVertexPtr->Z - curVertexPtr->X), \ |
| | 176 | (nextVertexPtr->X-curVertexPtr->X) - (-2)*(nextVertexPtr->Z-curVertexPtr->Z) \ |
| | 177 | ); \ |
| | 178 | \ |
| | 179 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); \ |
| | 180 | outputVerticesPtr->Z = -outputVerticesPtr->X/2; \ |
| | 181 | outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda,nextVertexPtr->Y-curVertexPtr->Y); |
| | 182 | |
| | 183 | #define Clip_Wide_PX_OutputXYZ \ |
| | 184 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 185 | if (nextVertexInside != curVertexInside) \ |
| | 186 | { \ |
| | 187 | int lambda; \ |
| | 188 | \ |
| | 189 | lambda = DIV_FIXED \ |
| | 190 | ( \ |
| | 191 | (2*curVertexPtr->Z - curVertexPtr->X), \ |
| | 192 | (nextVertexPtr->X-curVertexPtr->X) - 2*(nextVertexPtr->Z-curVertexPtr->Z) \ |
| | 193 | ); \ |
| | 194 | \ |
| | 195 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); \ |
| | 196 | outputVerticesPtr->Z = outputVerticesPtr->X/2; \ |
| | 197 | outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda,nextVertexPtr->Y-curVertexPtr->Y); |
| | 198 | |
| | 199 | #define Clip_Wide_NY_OutputXYZ \ |
| | 200 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 201 | if (nextVertexInside != curVertexInside) \ |
| | 202 | { \ |
| | 203 | int lambda; \ |
| | 204 | \ |
| | 205 | lambda = DIV_FIXED \ |
| | 206 | ( \ |
| | 207 | (2*curVertexPtr->Z + curVertexPtr->Y), \ |
| | 208 | -(nextVertexPtr->Y-curVertexPtr->Y) - 2*(nextVertexPtr->Z-curVertexPtr->Z) \ |
| | 209 | ); \ |
| | 210 | \ |
| | 211 | outputVerticesPtr->Z = curVertexPtr->Z + MUL_FIXED(lambda,nextVertexPtr->Z-curVertexPtr->Z); \ |
| | 212 | outputVerticesPtr->Y = -(outputVerticesPtr->Z*2); \ |
| | 213 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); |
| | 214 | |
| | 215 | #define Clip_Wide_PY_OutputXYZ \ |
| | 216 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 217 | if (nextVertexInside != curVertexInside) \ |
| | 218 | { \ |
| | 219 | int lambda; \ |
| | 220 | \ |
| | 221 | lambda = DIV_FIXED \ |
| | 222 | ( \ |
| | 223 | (2*curVertexPtr->Z - curVertexPtr->Y), \ |
| | 224 | (nextVertexPtr->Y-curVertexPtr->Y) - 2*(nextVertexPtr->Z-curVertexPtr->Z) \ |
| | 225 | ); \ |
| | 226 | \ |
| | 227 | outputVerticesPtr->Z = curVertexPtr->Z + MUL_FIXED(lambda,nextVertexPtr->Z-curVertexPtr->Z); \ |
| | 228 | outputVerticesPtr->Y = (outputVerticesPtr->Z*2); \ |
| | 229 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); |
| | 230 | |
| | 231 | /* GOURAUD POLYGON CLIPPING */ |
| | 232 | void (*GouraudPolygon_ClipWithNegativeX)(); |
| | 233 | void (*GouraudPolygon_ClipWithPositiveY)(); |
| | 234 | void (*GouraudPolygon_ClipWithNegativeY)(); |
| | 235 | void (*GouraudPolygon_ClipWithPositiveX)(); |
| | 236 | |
| | 237 | /* TEXTURED POLYGON CLIPPING */ |
| | 238 | void (*TexturedPolygon_ClipWithNegativeX)(); |
| | 239 | void (*TexturedPolygon_ClipWithPositiveY)(); |
| | 240 | void (*TexturedPolygon_ClipWithNegativeY)(); |
| | 241 | void (*TexturedPolygon_ClipWithPositiveX)(); |
| | 242 | |
| | 243 | /* GOURAUD TEXTURED POLYGON CLIPPING */ |
| | 244 | void (*GouraudTexturedPolygon_ClipWithNegativeX)(); |
| | 245 | void (*GouraudTexturedPolygon_ClipWithPositiveY)(); |
| | 246 | void (*GouraudTexturedPolygon_ClipWithNegativeY)(); |
| | 247 | void (*GouraudTexturedPolygon_ClipWithPositiveX)(); |
| | 248 | |
| | 249 | /* FRUSTRUM TESTS */ |
| | 250 | int (*ObjectWithinFrustrum)(DISPLAYBLOCK *dbPtr); |
| | 251 | static int (*VertexWithinFrustrum)(RENDERVERTEX *vertexPtr); |
| | 252 | void (*TestVerticesWithFrustrum)(int x); |
| | 253 | |
| | 254 | /* Clip against negative X plane */ |
| | 255 | static void GouraudPolygon_Norm_ClipWithNegativeX() |
| | 256 | { |
| | 257 | RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); |
| | 258 | RENDERVERTEX *outputVerticesPtr = VerticesBuffer; |
| | 259 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 260 | int numberOfPointsOutputted=0; |
| | 261 | |
| | 262 | int curVertexInside = Clip_NX_Test(curVertexPtr); |
| | 263 | |
| | 264 | Clip_LoopStart((RenderPolygon.Vertices)) |
| | 265 | Clip_NX_Test(nextVertexPtr); |
| | 266 | Clip_NX_OutputXYZ |
| | 267 | Clip_OutputI |
| | 268 | Clip_LoopEnd(VerticesBuffer) |
| | 269 | } |
| | 270 | |
| | 271 | static void GouraudPolygon_Wide_ClipWithNegativeX() |
| | 272 | { |
| | 273 | RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); |
| | 274 | RENDERVERTEX *outputVerticesPtr = VerticesBuffer; |
| | 275 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 276 | int numberOfPointsOutputted=0; |
| | 277 | |
| | 278 | int curVertexInside = Clip_Wide_NX_Test(curVertexPtr); |
| | 279 | |
| | 280 | Clip_LoopStart((RenderPolygon.Vertices)) |
| | 281 | Clip_Wide_NX_Test(nextVertexPtr); |
| | 282 | Clip_Wide_NX_OutputXYZ |
| | 283 | Clip_OutputI |
| | 284 | Clip_LoopEnd(VerticesBuffer) |
| | 285 | } |
| | 286 | |
| | 287 | static void GouraudPolygon_Norm_ClipWithPositiveY() |
| | 288 | { |
| | 289 | RENDERVERTEX *curVertexPtr = VerticesBuffer; |
| | 290 | RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); |
| | 291 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 292 | int numberOfPointsOutputted=0; |
| | 293 | |
| | 294 | int curVertexInside = Clip_PY_Test(curVertexPtr); |
| | 295 | |
| | 296 | Clip_LoopStart(VerticesBuffer) |
| | 297 | Clip_PY_Test(nextVertexPtr); |
| | 298 | Clip_PY_OutputXYZ |
| | 299 | Clip_OutputI |
| | 300 | Clip_LoopEnd((RenderPolygon.Vertices)) |
| | 301 | } |
| | 302 | |
| | 303 | static void GouraudPolygon_Wide_ClipWithPositiveY() |
| | 304 | { |
| | 305 | RENDERVERTEX *curVertexPtr = VerticesBuffer; |
| | 306 | RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); |
| | 307 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 308 | int numberOfPointsOutputted=0; |
| | 309 | |
| | 310 | int curVertexInside = Clip_Wide_PY_Test(curVertexPtr); |
| | 311 | |
| | 312 | Clip_LoopStart(VerticesBuffer) |
| | 313 | Clip_Wide_PY_Test(nextVertexPtr); |
| | 314 | Clip_Wide_PY_OutputXYZ |
| | 315 | Clip_OutputI |
| | 316 | Clip_LoopEnd((RenderPolygon.Vertices)) |
| | 317 | } |
| | 318 | |
| | 319 | static void GouraudPolygon_Norm_ClipWithNegativeY() |
| | 320 | { |
| | 321 | RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); |
| | 322 | RENDERVERTEX *outputVerticesPtr = VerticesBuffer; |
| | 323 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 324 | int numberOfPointsOutputted=0; |
| | 325 | |
| | 326 | int curVertexInside = Clip_NY_Test(curVertexPtr); |
| | 327 | |
| | 328 | Clip_LoopStart((RenderPolygon.Vertices)) |
| | 329 | Clip_NY_Test(nextVertexPtr); |
| | 330 | Clip_NY_OutputXYZ |
| | 331 | Clip_OutputI |
| | 332 | Clip_LoopEnd(VerticesBuffer) |
| | 333 | } |
| | 334 | |
| | 335 | static void GouraudPolygon_Wide_ClipWithNegativeY() |
| | 336 | { |
| | 337 | RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); |
| | 338 | RENDERVERTEX *outputVerticesPtr = VerticesBuffer; |
| | 339 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 340 | int numberOfPointsOutputted=0; |
| | 341 | |
| | 342 | int curVertexInside = Clip_Wide_NY_Test(curVertexPtr); |
| | 343 | |
| | 344 | Clip_LoopStart((RenderPolygon.Vertices)) |
| | 345 | Clip_Wide_NY_Test(nextVertexPtr); |
| | 346 | Clip_Wide_NY_OutputXYZ |
| | 347 | Clip_OutputI |
| | 348 | Clip_LoopEnd(VerticesBuffer) |
| | 349 | } |
| | 350 | |
| | 351 | static void GouraudPolygon_Norm_ClipWithPositiveX() |
| | 352 | { |
| | 353 | RENDERVERTEX *curVertexPtr = VerticesBuffer; |
| | 354 | RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); |
| | 355 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 356 | int numberOfPointsOutputted = 0; |
| | 357 | |
| | 358 | int curVertexInside = Clip_PX_Test(curVertexPtr); |
| | 359 | |
| | 360 | Clip_LoopStart(VerticesBuffer) |
| | 361 | Clip_PX_Test(nextVertexPtr); |
| | 362 | Clip_PX_OutputXYZ |
| | 363 | Clip_OutputI |
| | 364 | Clip_LoopEnd((RenderPolygon.Vertices)) |
| | 365 | } |
| | 366 | |
| | 367 | static void GouraudPolygon_Wide_ClipWithPositiveX() |
| | 368 | { |
| | 369 | RENDERVERTEX *curVertexPtr = VerticesBuffer; |
| | 370 | RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); |
| | 371 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 372 | int numberOfPointsOutputted=0; |
| | 373 | |
| | 374 | int curVertexInside = Clip_Wide_PX_Test(curVertexPtr); |
| | 375 | |
| | 376 | Clip_LoopStart(VerticesBuffer) |
| | 377 | Clip_Wide_PX_Test(nextVertexPtr); |
| | 378 | Clip_Wide_PX_OutputXYZ |
| | 379 | Clip_OutputI |
| | 380 | Clip_LoopEnd((RenderPolygon.Vertices)) |
| | 381 | } |
| | 382 | |
| | 383 | static void TexturedPolygon_Norm_ClipWithNegativeX() |
| | 384 | { |
| | 385 | RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); |
| | 386 | RENDERVERTEX *outputVerticesPtr = VerticesBuffer; |
| | 387 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 388 | int numberOfPointsOutputted=0; |
| | 389 | |
| | 390 | int curVertexInside = Clip_NX_Test(curVertexPtr); |
| | 391 | |
| | 392 | Clip_LoopStart((RenderPolygon.Vertices)) |
| | 393 | Clip_NX_Test(nextVertexPtr); |
| | 394 | Clip_NX_OutputXYZ |
| | 395 | Clip_OutputUV |
| | 396 | Clip_OutputI |
| | 397 | Clip_LoopEnd(VerticesBuffer) |
| | 398 | } |
| | 399 | |
| | 400 | static void TexturedPolygon_Wide_ClipWithNegativeX() |
| | 401 | { |
| | 402 | RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); |
| | 403 | RENDERVERTEX *outputVerticesPtr = VerticesBuffer; |
| | 404 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 405 | int numberOfPointsOutputted=0; |
| | 406 | |
| | 407 | int curVertexInside = Clip_Wide_NX_Test(curVertexPtr); |
| | 408 | |
| | 409 | Clip_LoopStart((RenderPolygon.Vertices)) |
| | 410 | Clip_Wide_NX_Test(nextVertexPtr); |
| | 411 | Clip_Wide_NX_OutputXYZ |
| | 412 | Clip_OutputUV |
| | 413 | Clip_OutputI |
| | 414 | Clip_LoopEnd(VerticesBuffer) |
| | 415 | } |
| | 416 | |
| | 417 | static void TexturedPolygon_Norm_ClipWithPositiveY() |
| | 418 | { |
| | 419 | RENDERVERTEX *curVertexPtr = VerticesBuffer; |
| | 420 | RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); |
| | 421 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 422 | int numberOfPointsOutputted=0; |
| | 423 | |
| | 424 | int curVertexInside = Clip_PY_Test(curVertexPtr); |
| | 425 | |
| | 426 | Clip_LoopStart(VerticesBuffer) |
| | 427 | Clip_PY_Test(nextVertexPtr); |
| | 428 | Clip_PY_OutputXYZ |
| | 429 | Clip_OutputUV |
| | 430 | Clip_OutputI |
| | 431 | Clip_LoopEnd((RenderPolygon.Vertices)) |
| | 432 | } |
| | 433 | |
| | 434 | static void TexturedPolygon_Wide_ClipWithPositiveY() |
| | 435 | { |
| | 436 | RENDERVERTEX *curVertexPtr = VerticesBuffer; |
| | 437 | RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); |
| | 438 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 439 | int numberOfPointsOutputted=0; |
| | 440 | |
| | 441 | int curVertexInside = Clip_Wide_PY_Test(curVertexPtr); |
| | 442 | |
| | 443 | Clip_LoopStart(VerticesBuffer) |
| | 444 | Clip_Wide_PY_Test(nextVertexPtr); |
| | 445 | Clip_Wide_PY_OutputXYZ |
| | 446 | Clip_OutputUV |
| | 447 | Clip_OutputI |
| | 448 | Clip_LoopEnd((RenderPolygon.Vertices)) |
| | 449 | } |
| | 450 | |
| | 451 | static void TexturedPolygon_Norm_ClipWithNegativeY() |
| | 452 | { |
| | 453 | RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); |
| | 454 | RENDERVERTEX *outputVerticesPtr = VerticesBuffer; |
| | 455 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 456 | int numberOfPointsOutputted=0; |
| | 457 | |
| | 458 | int curVertexInside = Clip_NY_Test(curVertexPtr); |
| | 459 | |
| | 460 | Clip_LoopStart((RenderPolygon.Vertices)) |
| | 461 | Clip_NY_Test(nextVertexPtr); |
| | 462 | Clip_NY_OutputXYZ |
| | 463 | Clip_OutputUV |
| | 464 | Clip_OutputI |
| | 465 | Clip_LoopEnd(VerticesBuffer) |
| | 466 | } |
| | 467 | |
| | 468 | static void TexturedPolygon_Wide_ClipWithNegativeY() |
| | 469 | { |
| | 470 | RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); |
| | 471 | RENDERVERTEX *outputVerticesPtr = VerticesBuffer; |
| | 472 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 473 | int numberOfPointsOutputted=0; |
| | 474 | |
| | 475 | int curVertexInside = Clip_Wide_NY_Test(curVertexPtr); |
| | 476 | |
| | 477 | Clip_LoopStart((RenderPolygon.Vertices)) |
| | 478 | Clip_Wide_NY_Test(nextVertexPtr); |
| | 479 | Clip_Wide_NY_OutputXYZ |
| | 480 | Clip_OutputUV |
| | 481 | Clip_OutputI |
| | 482 | Clip_LoopEnd(VerticesBuffer) |
| | 483 | } |
| | 484 | |
| | 485 | static void TexturedPolygon_Norm_ClipWithPositiveX() |
| | 486 | { |
| | 487 | RENDERVERTEX *curVertexPtr = VerticesBuffer; |
| | 488 | RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); |
| | 489 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 490 | int numberOfPointsOutputted=0; |
| | 491 | |
| | 492 | int curVertexInside = Clip_PX_Test(curVertexPtr); |
| | 493 | |
| | 494 | Clip_LoopStart(VerticesBuffer) |
| | 495 | Clip_PX_Test(nextVertexPtr); |
| | 496 | Clip_PX_OutputXYZ |
| | 497 | Clip_OutputUV |
| | 498 | Clip_OutputI |
| | 499 | Clip_LoopEnd((RenderPolygon.Vertices)) |
| | 500 | } |
| | 501 | |
| | 502 | static void TexturedPolygon_Wide_ClipWithPositiveX() |
| | 503 | { |
| | 504 | RENDERVERTEX *curVertexPtr = VerticesBuffer; |
| | 505 | RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); |
| | 506 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 507 | int numberOfPointsOutputted=0; |
| | 508 | |
| | 509 | int curVertexInside = Clip_Wide_PX_Test(curVertexPtr); |
| | 510 | |
| | 511 | Clip_LoopStart(VerticesBuffer) |
| | 512 | Clip_Wide_PX_Test(nextVertexPtr); |
| | 513 | Clip_Wide_PX_OutputXYZ |
| | 514 | Clip_OutputUV |
| | 515 | Clip_OutputI |
| | 516 | Clip_LoopEnd((RenderPolygon.Vertices)) |
| | 517 | } |
| | 518 | |
| | 519 | static void GouraudTexturedPolygon_Norm_ClipWithNegativeX() |
| | 520 | { |
| | 521 | RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); |
| | 522 | RENDERVERTEX *outputVerticesPtr = VerticesBuffer; |
| | 523 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 524 | int numberOfPointsOutputted=0; |
| | 525 | |
| | 526 | int curVertexInside = Clip_NX_Test(curVertexPtr); |
| | 527 | |
| | 528 | Clip_LoopStart((RenderPolygon.Vertices)) |
| | 529 | Clip_NX_Test(nextVertexPtr); |
| | 530 | Clip_NX_OutputXYZ |
| | 531 | Clip_OutputUV |
| | 532 | Clip_OutputI |
| | 533 | Clip_LoopEnd(VerticesBuffer) |
| | 534 | } |
| | 535 | |
| | 536 | static void GouraudTexturedPolygon_Wide_ClipWithNegativeX() |
| | 537 | { |
| | 538 | RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); |
| | 539 | RENDERVERTEX *outputVerticesPtr = VerticesBuffer; |
| | 540 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 541 | int numberOfPointsOutputted=0; |
| | 542 | |
| | 543 | int curVertexInside = Clip_Wide_NX_Test(curVertexPtr); |
| | 544 | |
| | 545 | Clip_LoopStart((RenderPolygon.Vertices)) |
| | 546 | Clip_Wide_NX_Test(nextVertexPtr); |
| | 547 | Clip_Wide_NX_OutputXYZ |
| | 548 | Clip_OutputUV |
| | 549 | Clip_OutputI |
| | 550 | Clip_LoopEnd(VerticesBuffer) |
| | 551 | } |
| | 552 | |
| | 553 | static void GouraudTexturedPolygon_Norm_ClipWithPositiveY() |
| | 554 | { |
| | 555 | RENDERVERTEX *curVertexPtr = VerticesBuffer; |
| | 556 | RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); |
| | 557 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 558 | int numberOfPointsOutputted=0; |
| | 559 | |
| | 560 | int curVertexInside = Clip_PY_Test(curVertexPtr); |
| | 561 | |
| | 562 | Clip_LoopStart(VerticesBuffer) |
| | 563 | Clip_PY_Test(nextVertexPtr); |
| | 564 | Clip_PY_OutputXYZ |
| | 565 | Clip_OutputUV |
| | 566 | Clip_OutputI |
| | 567 | Clip_LoopEnd((RenderPolygon.Vertices)) |
| | 568 | } |
| | 569 | |
| | 570 | static void GouraudTexturedPolygon_Wide_ClipWithPositiveY() |
| | 571 | { |
| | 572 | RENDERVERTEX *curVertexPtr = VerticesBuffer; |
| | 573 | RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); |
| | 574 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 575 | int numberOfPointsOutputted=0; |
| | 576 | |
| | 577 | int curVertexInside = Clip_Wide_PY_Test(curVertexPtr); |
| | 578 | |
| | 579 | Clip_LoopStart(VerticesBuffer) |
| | 580 | Clip_Wide_PY_Test(nextVertexPtr); |
| | 581 | Clip_Wide_PY_OutputXYZ |
| | 582 | Clip_OutputUV |
| | 583 | Clip_OutputI |
| | 584 | Clip_LoopEnd((RenderPolygon.Vertices)) |
| | 585 | } |
| | 586 | |
| | 587 | static void GouraudTexturedPolygon_Norm_ClipWithNegativeY() |
| | 588 | { |
| | 589 | RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); |
| | 590 | RENDERVERTEX *outputVerticesPtr = VerticesBuffer; |
| | 591 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 592 | int numberOfPointsOutputted=0; |
| | 593 | |
| | 594 | int curVertexInside = Clip_NY_Test(curVertexPtr); |
| | 595 | |
| | 596 | Clip_LoopStart((RenderPolygon.Vertices)) |
| | 597 | Clip_NY_Test(nextVertexPtr); |
| | 598 | Clip_NY_OutputXYZ |
| | 599 | Clip_OutputUV |
| | 600 | Clip_OutputI |
| | 601 | Clip_LoopEnd(VerticesBuffer) |
| | 602 | } |
| | 603 | |
| | 604 | static void GouraudTexturedPolygon_Wide_ClipWithNegativeY() |
| | 605 | { |
| | 606 | RENDERVERTEX *curVertexPtr = (RenderPolygon.Vertices); |
| | 607 | RENDERVERTEX *outputVerticesPtr = VerticesBuffer; |
| | 608 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 609 | int numberOfPointsOutputted=0; |
| | 610 | |
| | 611 | int curVertexInside = Clip_Wide_NY_Test(curVertexPtr); |
| | 612 | |
| | 613 | Clip_LoopStart((RenderPolygon.Vertices)) |
| | 614 | Clip_Wide_NY_Test(nextVertexPtr); |
| | 615 | Clip_Wide_NY_OutputXYZ |
| | 616 | Clip_OutputUV |
| | 617 | Clip_OutputI |
| | 618 | Clip_LoopEnd(VerticesBuffer) |
| | 619 | } |
| | 620 | |
| | 621 | static void GouraudTexturedPolygon_Norm_ClipWithPositiveX() |
| | 622 | { |
| | 623 | RENDERVERTEX *curVertexPtr = VerticesBuffer; |
| | 624 | RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); |
| | 625 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 626 | int numberOfPointsOutputted=0; |
| | 627 | |
| | 628 | int curVertexInside = Clip_PX_Test(curVertexPtr); |
| | 629 | |
| | 630 | Clip_LoopStart(VerticesBuffer) |
| | 631 | Clip_PX_Test(nextVertexPtr); |
| | 632 | Clip_PX_OutputXYZ |
| | 633 | Clip_OutputUV |
| | 634 | Clip_OutputI |
| | 635 | Clip_LoopEnd((RenderPolygon.Vertices)) |
| | 636 | } |
| | 637 | |
| | 638 | static void GouraudTexturedPolygon_Wide_ClipWithPositiveX() |
| | 639 | { |
| | 640 | RENDERVERTEX *curVertexPtr = VerticesBuffer; |
| | 641 | RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); |
| | 642 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 643 | int numberOfPointsOutputted=0; |
| | 644 | |
| | 645 | int curVertexInside = Clip_Wide_PX_Test(curVertexPtr); |
| | 646 | |
| | 647 | Clip_LoopStart(VerticesBuffer) |
| | 648 | Clip_Wide_PX_Test(nextVertexPtr); |
| | 649 | Clip_Wide_PX_OutputXYZ |
| | 650 | Clip_OutputUV |
| | 651 | Clip_OutputI |
| | 652 | Clip_LoopEnd((RenderPolygon.Vertices)) |
| | 653 | } |
| | 654 | |
| | 655 | /* KJL 16:18:59 7/7/97 - simple vertex test to be used in first |
| | 656 | pass of subdividing code */ |
| | 657 | static int VertexWithin_Norm_Frustrum(RENDERVERTEX *vertexPtr) |
| | 658 | { |
| | 659 | int vertexFlag = 0; |
| | 660 | |
| | 661 | if(Clip_Z_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_Z_PLANE; |
| | 662 | if(Clip_PX_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_PX_PLANE; |
| | 663 | if(Clip_NX_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_NX_PLANE; |
| | 664 | if(Clip_PY_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_PY_PLANE; |
| | 665 | if(Clip_NY_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_NY_PLANE; |
| | 666 | |
| | 667 | return vertexFlag; |
| | 668 | } |
| | 669 | |
| | 670 | static int VertexWithin_Wide_Frustrum(RENDERVERTEX *vertexPtr) |
| | 671 | { |
| | 672 | int vertexFlag = 0; |
| | 673 | |
| | 674 | if(Clip_Z_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_Z_PLANE; |
| | 675 | if(Clip_Wide_PX_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_PX_PLANE; |
| | 676 | if(Clip_Wide_NX_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_NX_PLANE; |
| | 677 | if(Clip_Wide_PY_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_PY_PLANE; |
| | 678 | if(Clip_Wide_NY_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_NY_PLANE; |
| | 679 | |
| | 680 | return vertexFlag; |
| | 681 | } |
| | 682 | |
| | 683 | /* KJL 15:32:52 7/17/97 - Test to see if an object is in the view frustrum */ |
| | 684 | static int ObjectWithin_Norm_Frustrum(DISPLAYBLOCK *dbPtr) |
| | 685 | { |
| | 686 | #if FAR_Z_CLIP |
| | 687 | if(dbPtr->ObView.vz - dbPtr->extent.radius <= FAR_Z_CLIP_RANGE) |
| | 688 | #endif |
| | 689 | if (dbPtr->ObView.vz + dbPtr->extent.radius >= ZCLIPPINGVALUE) |
| | 690 | { |
| | 691 | /* scale radius by square root of 2 */ |
| | 692 | int radius = MUL_FIXED(92682, dbPtr->extent.radius); |
| | 693 | |
| | 694 | return |
| | 695 | (((dbPtr->ObView.vx - dbPtr->ObView.vz) <= radius) |
| | 696 | && |
| | 697 | ((-dbPtr->ObView.vx - dbPtr->ObView.vz) <= radius) |
| | 698 | && |
| | 699 | ((dbPtr->ObView.vy - dbPtr->ObView.vz) <= radius) |
| | 700 | && |
| | 701 | ((-dbPtr->ObView.vy - dbPtr->ObView.vz) <= radius)); |
| | 702 | } |
| | 703 | |
| | 704 | return 0; |
| | 705 | } |
| | 706 | |
| | 707 | static int ObjectWithin_Wide_Frustrum(DISPLAYBLOCK *dbPtr) |
| | 708 | { |
| | 709 | if (dbPtr->ObView.vz + dbPtr->extent.radius >= ZCLIPPINGVALUE) |
| | 710 | { |
| | 711 | /* scale radius by square root of 5 */ |
| | 712 | int radius = MUL_FIXED(146543, dbPtr->extent.radius); |
| | 713 | |
| | 714 | return |
| | 715 | (((dbPtr->ObView.vx-2 * dbPtr->ObView.vz) <= radius) |
| | 716 | && |
| | 717 | ((-dbPtr->ObView.vx-2 * dbPtr->ObView.vz) <= radius) |
| | 718 | && |
| | 719 | ((dbPtr->ObView.vy-2 * dbPtr->ObView.vz) <= radius) |
| | 720 | && |
| | 721 | ((-dbPtr->ObView.vy-2 * dbPtr->ObView.vz) <= radius)); |
| | 722 | } |
| | 723 | |
| | 724 | return 0; |
| | 725 | } |
| | 726 | |
| | 727 | char FrustrumFlagForVertex[maxrotpts]; |
| | 728 | |
| | 729 | static void TestVerticesWith_Norm_Frustrum(int v) |
| | 730 | { |
| | 731 | assert(v > 0); |
| | 732 | |
| | 733 | while(v--) |
| | 734 | { |
| | 735 | char vertexFlag = 0; |
| | 736 | |
| | 737 | #if FAR_Z_CLIP |
| | 738 | if(ZCLIPPINGVALUE <= RotatedPts[v].vz && RotatedPts[v].vz <= FAR_Z_CLIP_RANGE) |
| | 739 | #else |
| | 740 | if(ZCLIPPINGVALUE <= RotatedPts[v].vz) |
| | 741 | #endif |
| | 742 | vertexFlag |= INSIDE_FRUSTRUM_Z_PLANE; |
| | 743 | |
| | 744 | if(-RotatedPts[v].vx <= RotatedPts[v].vz) |
| | 745 | vertexFlag |= INSIDE_FRUSTRUM_PX_PLANE; |
| | 746 | |
| | 747 | if(RotatedPts[v].vx <= RotatedPts[v].vz) |
| | 748 | vertexFlag |= INSIDE_FRUSTRUM_NX_PLANE; |
| | 749 | |
| | 750 | if(-RotatedPts[v].vy <= RotatedPts[v].vz) |
| | 751 | vertexFlag |= INSIDE_FRUSTRUM_PY_PLANE; |
| | 752 | |
| | 753 | if(RotatedPts[v].vy <= RotatedPts[v].vz) |
| | 754 | vertexFlag |= INSIDE_FRUSTRUM_NY_PLANE; |
| | 755 | |
| | 756 | FrustrumFlagForVertex[v] = vertexFlag; |
| | 757 | } |
| | 758 | } |
| | 759 | |
| | 760 | static void TestVerticesWith_Wide_Frustrum(int v) |
| | 761 | { |
| | 762 | assert(v > 0); |
| | 763 | |
| | 764 | while(v--) |
| | 765 | { |
| | 766 | char vertexFlag = 0; |
| | 767 | |
| | 768 | if(ZCLIPPINGVALUE <= RotatedPts[v].vz) |
| | 769 | vertexFlag |= INSIDE_FRUSTRUM_Z_PLANE; |
| | 770 | |
| | 771 | if(-RotatedPts[v].vx <= RotatedPts[v].vz * 2) |
| | 772 | vertexFlag |= INSIDE_FRUSTRUM_PX_PLANE; |
| | 773 | |
| | 774 | if(RotatedPts[v].vx <= RotatedPts[v].vz * 2) |
| | 775 | vertexFlag |= INSIDE_FRUSTRUM_NX_PLANE; |
| | 776 | |
| | 777 | if(-RotatedPts[v].vy <= RotatedPts[v].vz * 2) |
| | 778 | vertexFlag |= INSIDE_FRUSTRUM_PY_PLANE; |
| | 779 | |
| | 780 | if(RotatedPts[v].vy <= RotatedPts[v].vz * 2) |
| | 781 | vertexFlag |= INSIDE_FRUSTRUM_NY_PLANE; |
| | 782 | |
| | 783 | FrustrumFlagForVertex[v] = vertexFlag; |
| | 784 | } |
| | 785 | } |
| | 786 | |
| | 787 | void SetFrustrumType(enum FrustrumType frustrumType) |
| | 788 | { |
| | 789 | if(FRUSTRUM_TYPE_NORMAL == frustrumType) |
| | 790 | { |
| | 791 | GouraudPolygon_ClipWithNegativeX = GouraudPolygon_Norm_ClipWithNegativeX; |
| | 792 | GouraudPolygon_ClipWithPositiveY = GouraudPolygon_Norm_ClipWithPositiveY; |
| | 793 | GouraudPolygon_ClipWithNegativeY = GouraudPolygon_Norm_ClipWithNegativeY; |
| | 794 | GouraudPolygon_ClipWithPositiveX = GouraudPolygon_Norm_ClipWithPositiveX; |
| | 795 | |
| | 796 | TexturedPolygon_ClipWithNegativeX = TexturedPolygon_Norm_ClipWithNegativeX; |
| | 797 | TexturedPolygon_ClipWithPositiveY = TexturedPolygon_Norm_ClipWithPositiveY; |
| | 798 | TexturedPolygon_ClipWithNegativeY = TexturedPolygon_Norm_ClipWithNegativeY; |
| | 799 | TexturedPolygon_ClipWithPositiveX = TexturedPolygon_Norm_ClipWithPositiveX; |
| | 800 | |
| | 801 | GouraudTexturedPolygon_ClipWithNegativeX = GouraudTexturedPolygon_Norm_ClipWithNegativeX; |
| | 802 | GouraudTexturedPolygon_ClipWithPositiveY = GouraudTexturedPolygon_Norm_ClipWithPositiveY; |
| | 803 | GouraudTexturedPolygon_ClipWithNegativeY = GouraudTexturedPolygon_Norm_ClipWithNegativeY; |
| | 804 | GouraudTexturedPolygon_ClipWithPositiveX = GouraudTexturedPolygon_Norm_ClipWithPositiveX; |
| | 805 | |
| | 806 | /* FRUSTRUM TESTS */ |
| | 807 | TestVerticesWithFrustrum = TestVerticesWith_Norm_Frustrum; |
| | 808 | ObjectWithinFrustrum = ObjectWithin_Norm_Frustrum; |
| | 809 | VertexWithinFrustrum = VertexWithin_Norm_Frustrum; |
| | 810 | } |
| | 811 | else |
| | 812 | { |
| | 813 | GouraudPolygon_ClipWithNegativeX = GouraudPolygon_Wide_ClipWithNegativeX; |
| | 814 | GouraudPolygon_ClipWithPositiveY = GouraudPolygon_Wide_ClipWithPositiveY; |
| | 815 | GouraudPolygon_ClipWithNegativeY = GouraudPolygon_Wide_ClipWithNegativeY; |
| | 816 | GouraudPolygon_ClipWithPositiveX = GouraudPolygon_Wide_ClipWithPositiveX; |
| | 817 | |
| | 818 | TexturedPolygon_ClipWithNegativeX = TexturedPolygon_Wide_ClipWithNegativeX; |
| | 819 | TexturedPolygon_ClipWithPositiveY = TexturedPolygon_Wide_ClipWithPositiveY; |
| | 820 | TexturedPolygon_ClipWithNegativeY = TexturedPolygon_Wide_ClipWithNegativeY; |
| | 821 | TexturedPolygon_ClipWithPositiveX = TexturedPolygon_Wide_ClipWithPositiveX; |
| | 822 | |
| | 823 | GouraudTexturedPolygon_ClipWithNegativeX = GouraudTexturedPolygon_Wide_ClipWithNegativeX; |
| | 824 | GouraudTexturedPolygon_ClipWithPositiveY = GouraudTexturedPolygon_Wide_ClipWithPositiveY; |
| | 825 | GouraudTexturedPolygon_ClipWithNegativeY = GouraudTexturedPolygon_Wide_ClipWithNegativeY; |
| | 826 | GouraudTexturedPolygon_ClipWithPositiveX = GouraudTexturedPolygon_Wide_ClipWithPositiveX; |
| | 827 | |
| | 828 | /* FRUSTRUM TESTS */ |
| | 829 | TestVerticesWithFrustrum = TestVerticesWith_Wide_Frustrum; |
| | 830 | ObjectWithinFrustrum = ObjectWithin_Wide_Frustrum; |
| | 831 | VertexWithinFrustrum = VertexWithin_Wide_Frustrum; |
| | 832 | } |
| | 833 | } |
| | 834 | |
| | 835 | /* Clip against Z plane */ |
| | 836 | void GouraudPolygon_ClipWithZ() |
| | 837 | { |
| | 838 | RENDERVERTEX *curVertexPtr = VerticesBuffer; |
| | 839 | RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); |
| | 840 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 841 | int numberOfPointsOutputted = 0; |
| | 842 | |
| | 843 | int curVertexInside = Clip_Z_Test(curVertexPtr); |
| | 844 | |
| | 845 | Clip_LoopStart(VerticesBuffer) |
| | 846 | Clip_Z_Test(nextVertexPtr); |
| | 847 | Clip_Z_OutputXYZ |
| | 848 | Clip_OutputI |
| | 849 | Clip_LoopEnd((RenderPolygon.Vertices)) |
| | 850 | } |
| | 851 | |
| | 852 | /* Clip against Z plane */ |
| | 853 | void TexturedPolygon_ClipWithZ() |
| | 854 | { |
| | 855 | RENDERVERTEX *curVertexPtr = VerticesBuffer; |
| | 856 | RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); |
| | 857 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 858 | int numberOfPointsOutputted = 0; |
| | 859 | |
| | 860 | int curVertexInside = Clip_Z_Test(curVertexPtr); |
| | 861 | |
| | 862 | Clip_LoopStart(VerticesBuffer) |
| | 863 | Clip_Z_Test(nextVertexPtr); |
| | 864 | Clip_Z_OutputXYZ |
| | 865 | Clip_OutputUV |
| | 866 | Clip_OutputI |
| | 867 | Clip_LoopEnd((RenderPolygon.Vertices)) |
| | 868 | } |
| | 869 | |
| | 870 | /* Clip against Z plane */ |
| | 871 | void GouraudTexturedPolygon_ClipWithZ() |
| | 872 | { |
| | 873 | RENDERVERTEX *curVertexPtr = VerticesBuffer; |
| | 874 | RENDERVERTEX *outputVerticesPtr = (RenderPolygon.Vertices); |
| | 875 | int verticesLeft = RenderPolygon.NumberOfVertices; |
| | 876 | int numberOfPointsOutputted = 0; |
| | 877 | |
| | 878 | int curVertexInside = Clip_Z_Test(curVertexPtr); |
| | 879 | |
| | 880 | Clip_LoopStart(VerticesBuffer) |
| | 881 | Clip_Z_Test(nextVertexPtr); |
| | 882 | Clip_Z_OutputXYZ |
| | 883 | Clip_OutputUV |
| | 884 | Clip_OutputI |
| | 885 | Clip_LoopEnd((RenderPolygon.Vertices)) |
| | 886 | } |
| | 887 | |
| | 888 | int DecalWithinFrustrum(const DECAL *decalPtr) |
| | 889 | { |
| | 890 | char inFrustrumFlag = 0; |
| | 891 | char noClippingFlag = INSIDE_FRUSTRUM; |
| | 892 | |
| | 893 | int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[0]); |
| | 894 | inFrustrumFlag |= vertexFlag; |
| | 895 | noClippingFlag &= vertexFlag; |
| | 896 | |
| | 897 | vertexFlag = VertexWithinFrustrum(&VerticesBuffer[1]); |
| | 898 | inFrustrumFlag |= vertexFlag; |
| | 899 | noClippingFlag &= vertexFlag; |
| | 900 | |
| | 901 | vertexFlag = VertexWithinFrustrum(&VerticesBuffer[2]); |
| | 902 | inFrustrumFlag |= vertexFlag; |
| | 903 | noClippingFlag &= vertexFlag; |
| | 904 | |
| | 905 | vertexFlag = VertexWithinFrustrum(&VerticesBuffer[3]); |
| | 906 | inFrustrumFlag |= vertexFlag; |
| | 907 | noClippingFlag &= vertexFlag; |
| | 908 | |
| | 909 | return (inFrustrumFlag != INSIDE_FRUSTRUM) ? 0 : ((noClippingFlag == INSIDE_FRUSTRUM) ? 2 : 1); |
| | 910 | } |
| | 911 | |
| | 912 | int QuadWithinFrustrum() |
| | 913 | { |
| | 914 | char inFrustrumFlag = 0; |
| | 915 | char noClippingFlag = INSIDE_FRUSTRUM; |
| | 916 | |
| | 917 | int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[0]); |
| | 918 | inFrustrumFlag |= vertexFlag; |
| | 919 | noClippingFlag &= vertexFlag; |
| | 920 | |
| | 921 | vertexFlag = VertexWithinFrustrum(&VerticesBuffer[1]); |
| | 922 | inFrustrumFlag |= vertexFlag; |
| | 923 | noClippingFlag &= vertexFlag; |
| | 924 | |
| | 925 | vertexFlag = VertexWithinFrustrum(&VerticesBuffer[2]); |
| | 926 | inFrustrumFlag |= vertexFlag; |
| | 927 | noClippingFlag &= vertexFlag; |
| | 928 | |
| | 929 | vertexFlag = VertexWithinFrustrum(&VerticesBuffer[3]); |
| | 930 | inFrustrumFlag |= vertexFlag; |
| | 931 | noClippingFlag &= vertexFlag; |
| | 932 | |
| | 933 | return (inFrustrumFlag != INSIDE_FRUSTRUM) ? 0 : ((noClippingFlag == INSIDE_FRUSTRUM) ? 2 : 1); |
| | 934 | } |
| | 935 | |
| | 936 | int TriangleWithinFrustrum() |
| | 937 | { |
| | 938 | char inFrustrumFlag = 0; |
| | 939 | char noClippingFlag = INSIDE_FRUSTRUM; |
| | 940 | |
| | 941 | int vertexFlag = VertexWithinFrustrum(&VerticesBuffer[0]); |
| | 942 | inFrustrumFlag |= vertexFlag; |
| | 943 | noClippingFlag &= vertexFlag; |
| | 944 | |
| | 945 | vertexFlag = VertexWithinFrustrum(&VerticesBuffer[1]); |
| | 946 | inFrustrumFlag |= vertexFlag; |
| | 947 | noClippingFlag &= vertexFlag; |
| | 948 | |
| | 949 | vertexFlag = VertexWithinFrustrum(&VerticesBuffer[2]); |
| | 950 | inFrustrumFlag |= vertexFlag; |
| | 951 | noClippingFlag &= vertexFlag; |
| | 952 | |
| | 953 | return (inFrustrumFlag != INSIDE_FRUSTRUM) ? 0 : ((noClippingFlag == INSIDE_FRUSTRUM) ? 2 : 1); |
| | 954 | } |