| | 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 | static RENDERVERTEX VerticesClipped[9]; |
| | 17 | |
| | 18 | #define FAR_Z_CLIP 0 |
| | 19 | #define ZCLIPPINGVALUE 64 |
| | 20 | #define FAR_Z_CLIP_RANGE 49000 |
| | 21 | |
| | 22 | /* clipping code macros - these are used as building blocks to assemble |
| | 23 | clipping fns for different polygon types with the minimum of fuss */ |
| | 24 | |
| | 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_Wide_NX_Test(v) (-(v)->X <= (v)->Z*2) |
| | 30 | #define Clip_Wide_PX_Test(v) ((v)->X <= (v)->Z*2) |
| | 31 | #define Clip_Wide_NY_Test(v) (-(v)->Y <= (v)->Z*2) |
| | 32 | #define Clip_Wide_PY_Test(v) ((v)->Y <= (v)->Z*2) |
| | 33 | |
| | 34 | #define Clip_LoopStart(b) \ |
| | 35 | \ |
| | 36 | do \ |
| | 37 | { \ |
| | 38 | RENDERVERTEX *nextVertexPtr; \ |
| | 39 | \ |
| | 40 | /* setup pointer to next vertex, wrapping round if necessary */ \ |
| | 41 | if (!--verticesLeft) \ |
| | 42 | nextVertexPtr = (b); \ |
| | 43 | else \ |
| | 44 | nextVertexPtr = curVertexPtr+1; \ |
| | 45 | \ |
| | 46 | /* if current vertex is inside the plane, output it */ \ |
| | 47 | if (curVertexInside) \ |
| | 48 | { \ |
| | 49 | numberOfPointsOutputted++; \ |
| | 50 | *outputVerticesPtr++ = *curVertexPtr; \ |
| | 51 | } \ |
| | 52 | \ |
| | 53 | /* test if next vertex is inside the plane */ \ |
| | 54 | int nextVertexInside = |
| | 55 | |
| | 56 | #define Clip_OutputI \ |
| | 57 | outputVerticesPtr->U = curVertexPtr->U + MUL_FIXED(lambda, nextVertexPtr->U - curVertexPtr->U); \ |
| | 58 | outputVerticesPtr->V = curVertexPtr->V + MUL_FIXED(lambda, nextVertexPtr->V - curVertexPtr->V); \ |
| | 59 | outputVerticesPtr->A = curVertexPtr->A + MUL_FIXED(lambda, nextVertexPtr->A - curVertexPtr->A); \ |
| | 60 | outputVerticesPtr->R = curVertexPtr->R + MUL_FIXED(lambda, nextVertexPtr->R - curVertexPtr->R); \ |
| | 61 | outputVerticesPtr->G = curVertexPtr->G + MUL_FIXED(lambda, nextVertexPtr->G - curVertexPtr->G); \ |
| | 62 | outputVerticesPtr->B = curVertexPtr->B + MUL_FIXED(lambda, nextVertexPtr->B - curVertexPtr->B); \ |
| | 63 | outputVerticesPtr->SpecularR = curVertexPtr->SpecularR + MUL_FIXED(lambda, nextVertexPtr->SpecularR - curVertexPtr->SpecularR); \ |
| | 64 | outputVerticesPtr->SpecularG = curVertexPtr->SpecularG + MUL_FIXED(lambda, nextVertexPtr->SpecularG - curVertexPtr->SpecularG); \ |
| | 65 | outputVerticesPtr->SpecularB = curVertexPtr->SpecularB + MUL_FIXED(lambda, nextVertexPtr->SpecularB - curVertexPtr->SpecularB); \ |
| | 66 | \ |
| | 67 | numberOfPointsOutputted++; \ |
| | 68 | outputVerticesPtr++; \ |
| | 69 | } \ |
| | 70 | \ |
| | 71 | /* okay, now the current vertex becomes what was the next vertex */ \ |
| | 72 | curVertexPtr = nextVertexPtr; \ |
| | 73 | curVertexInside = nextVertexInside; \ |
| | 74 | } while(verticesLeft); \ |
| | 75 | \ |
| | 76 | RenderPolygon.NumberOfVertices = numberOfPointsOutputted; |
| | 77 | |
| | 78 | #define Clip_NX_OutputXYZ \ |
| | 79 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 80 | if (nextVertexInside != curVertexInside) \ |
| | 81 | { \ |
| | 82 | int lambda = DIV_FIXED((curVertexPtr->Z + curVertexPtr->X), \ |
| | 83 | -(nextVertexPtr->X-curVertexPtr->X) - (nextVertexPtr->Z-curVertexPtr->Z)); \ |
| | 84 | \ |
| | 85 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda, nextVertexPtr->X - curVertexPtr->X); \ |
| | 86 | outputVerticesPtr->Z = -outputVerticesPtr->X; \ |
| | 87 | outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda, nextVertexPtr->Y - curVertexPtr->Y); |
| | 88 | |
| | 89 | #define Clip_Wide_NX_OutputXYZ \ |
| | 90 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 91 | if (nextVertexInside != curVertexInside) \ |
| | 92 | { \ |
| | 93 | int lambda = DIV_FIXED( (-2*curVertexPtr->Z - curVertexPtr->X), \ |
| | 94 | (nextVertexPtr->X - curVertexPtr->X) - (-2)*(nextVertexPtr->Z - curVertexPtr->Z)); \ |
| | 95 | \ |
| | 96 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda, nextVertexPtr->X - curVertexPtr->X); \ |
| | 97 | outputVerticesPtr->Z = -outputVerticesPtr->X/2; \ |
| | 98 | outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda, nextVertexPtr->Y - curVertexPtr->Y); |
| | 99 | |
| | 100 | #define Clip_NY_OutputXYZ \ |
| | 101 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 102 | if (nextVertexInside != curVertexInside) \ |
| | 103 | { \ |
| | 104 | int lambda = DIV_FIXED((curVertexPtr->Z + curVertexPtr->Y), \ |
| | 105 | -(nextVertexPtr->Y - curVertexPtr->Y) - (nextVertexPtr->Z - curVertexPtr->Z)); \ |
| | 106 | \ |
| | 107 | outputVerticesPtr->Z = curVertexPtr->Z + MUL_FIXED(lambda, nextVertexPtr->Z - curVertexPtr->Z); \ |
| | 108 | outputVerticesPtr->Y = -(outputVerticesPtr->Z); \ |
| | 109 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda, nextVertexPtr->X - curVertexPtr->X); |
| | 110 | |
| | 111 | #define Clip_Wide_NY_OutputXYZ \ |
| | 112 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 113 | if (nextVertexInside != curVertexInside) \ |
| | 114 | { \ |
| | 115 | int lambda = DIV_FIXED((2*curVertexPtr->Z + curVertexPtr->Y), \ |
| | 116 | -(nextVertexPtr->Y-curVertexPtr->Y) - 2*(nextVertexPtr->Z - curVertexPtr->Z)); \ |
| | 117 | \ |
| | 118 | outputVerticesPtr->Z = curVertexPtr->Z + MUL_FIXED(lambda, nextVertexPtr->Z - curVertexPtr->Z); \ |
| | 119 | outputVerticesPtr->Y = -(outputVerticesPtr->Z*2); \ |
| | 120 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda, nextVertexPtr->X - curVertexPtr->X); |
| | 121 | |
| | 122 | #define Clip_PX_OutputXYZ \ |
| | 123 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 124 | if (nextVertexInside != curVertexInside) \ |
| | 125 | { \ |
| | 126 | int lambda = DIV_FIXED((curVertexPtr->Z - curVertexPtr->X), \ |
| | 127 | (nextVertexPtr->X - curVertexPtr->X) - (nextVertexPtr->Z - curVertexPtr->Z)); \ |
| | 128 | \ |
| | 129 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda, nextVertexPtr->X - curVertexPtr->X); \ |
| | 130 | outputVerticesPtr->Z = outputVerticesPtr->X; \ |
| | 131 | outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda, nextVertexPtr->Y - curVertexPtr->Y); |
| | 132 | |
| | 133 | #define Clip_Wide_PX_OutputXYZ \ |
| | 134 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 135 | if (nextVertexInside != curVertexInside) \ |
| | 136 | { \ |
| | 137 | int lambda = DIV_FIXED((2*curVertexPtr->Z - curVertexPtr->X), \ |
| | 138 | (nextVertexPtr->X - curVertexPtr->X) - 2*(nextVertexPtr->Z - curVertexPtr->Z)); \ |
| | 139 | \ |
| | 140 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda, nextVertexPtr->X - curVertexPtr->X); \ |
| | 141 | outputVerticesPtr->Z = outputVerticesPtr->X/2; \ |
| | 142 | outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda, nextVertexPtr->Y - curVertexPtr->Y); |
| | 143 | |
| | 144 | #define Clip_PY_OutputXYZ \ |
| | 145 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 146 | if (nextVertexInside != curVertexInside) \ |
| | 147 | { \ |
| | 148 | int lambda = DIV_FIXED((curVertexPtr->Z - curVertexPtr->Y), \ |
| | 149 | (nextVertexPtr->Y - curVertexPtr->Y) - (nextVertexPtr->Z - curVertexPtr->Z)); \ |
| | 150 | \ |
| | 151 | outputVerticesPtr->Z = curVertexPtr->Z + MUL_FIXED(lambda, nextVertexPtr->Z - curVertexPtr->Z); \ |
| | 152 | outputVerticesPtr->Y = (outputVerticesPtr->Z); \ |
| | 153 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda, nextVertexPtr->X - curVertexPtr->X); |
| | 154 | |
| | 155 | #define Clip_Wide_PY_OutputXYZ \ |
| | 156 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 157 | if (nextVertexInside != curVertexInside) \ |
| | 158 | { \ |
| | 159 | int lambda = DIV_FIXED((2*curVertexPtr->Z - curVertexPtr->Y), \ |
| | 160 | (nextVertexPtr->Y - curVertexPtr->Y) - 2*(nextVertexPtr->Z - curVertexPtr->Z)); \ |
| | 161 | \ |
| | 162 | outputVerticesPtr->Z = curVertexPtr->Z + MUL_FIXED(lambda, nextVertexPtr->Z - curVertexPtr->Z); \ |
| | 163 | outputVerticesPtr->Y = (outputVerticesPtr->Z*2); \ |
| | 164 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda, nextVertexPtr->X - curVertexPtr->X); |
| | 165 | |
| | 166 | #define Clip_Z_OutputXYZ \ |
| | 167 | /* if one is in, and the other is out, output a clipped vertex */ \ |
| | 168 | if (nextVertexInside != curVertexInside) \ |
| | 169 | { \ |
| | 170 | int lambda = DIV_FIXED( (ZCLIPPINGVALUE - curVertexPtr->Z), \ |
| | 171 | (nextVertexPtr->Z - curVertexPtr->Z)); \ |
| | 172 | \ |
| | 173 | outputVerticesPtr->X = curVertexPtr->X + MUL_FIXED(lambda,nextVertexPtr->X-curVertexPtr->X); \ |
| | 174 | outputVerticesPtr->Y = curVertexPtr->Y + MUL_FIXED(lambda,nextVertexPtr->Y-curVertexPtr->Y); \ |
| | 175 | outputVerticesPtr->Z = ZCLIPPINGVALUE; |
| | 176 | |
| | 177 | |
| | 178 | static int (*VertexWithinFrustrum)(RENDERVERTEX *vertexPtr); |
| | 179 | |
| | 180 | int (*ClipPolygon)(int NumberOfVertices); |
| | 181 | int (*ObjectWithinFrustrum)(DISPLAYBLOCK *dbPtr); |
| | 182 | void (*TestVerticesWithFrustrum)(int x); |
| | 183 | |
| | 184 | char FrustrumFlagForVertex[maxrotpts]; |
| | 185 | |
| | 186 | /* KJL 16:18:59 7/7/97 - simple vertex test to be used in first pass of subdividing code */ |
| | 187 | |
| | 188 | static int VertexWithin_Norm_Frustrum(RENDERVERTEX *vertexPtr) |
| | 189 | { |
| | 190 | int vertexFlag = 0; |
| | 191 | |
| | 192 | if(ZCLIPPINGVALUE <= vertexPtr->Z) |
| | 193 | vertexFlag |= INSIDE_FRUSTRUM_Z_PLANE; |
| | 194 | |
| | 195 | if(Clip_PX_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_PX_PLANE; |
| | 196 | |
| | 197 | if(-vertexPtr->X <= vertexPtr->Z) |
| | 198 | vertexFlag |= INSIDE_FRUSTRUM_NX_PLANE; |
| | 199 | |
| | 200 | if(Clip_PY_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_PY_PLANE; |
| | 201 | if(Clip_NY_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_NY_PLANE; |
| | 202 | |
| | 203 | return vertexFlag; |
| | 204 | } |
| | 205 | |
| | 206 | static int VertexWithin_Wide_Frustrum(RENDERVERTEX *vertexPtr) |
| | 207 | { |
| | 208 | int vertexFlag = 0; |
| | 209 | |
| | 210 | if(ZCLIPPINGVALUE <= vertexPtr->Z) |
| | 211 | vertexFlag |= INSIDE_FRUSTRUM_Z_PLANE; |
| | 212 | |
| | 213 | if(Clip_Wide_PX_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_PX_PLANE; |
| | 214 | if(Clip_Wide_NX_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_NX_PLANE; |
| | 215 | if(Clip_Wide_PY_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_PY_PLANE; |
| | 216 | if(Clip_Wide_NY_Test(vertexPtr)) vertexFlag |= INSIDE_FRUSTRUM_NY_PLANE; |
| | 217 | |
| | 218 | return vertexFlag; |
| | 219 | } |
| | 220 | |
| | 221 | /* KJL 15:32:52 7/17/97 - Test to see if an object is in the view frustrum */ |
| | 222 | static int ObjectWithin_Norm_Frustrum(DISPLAYBLOCK *dbPtr) |
| | 223 | { |
| | 224 | #if FAR_Z_CLIP |
| | 225 | if(dbPtr->ObView.vz - dbPtr->extent.radius <= FAR_Z_CLIP_RANGE) |
| | 226 | #endif |
| | 227 | if (dbPtr->ObView.vz + dbPtr->extent.radius >= ZCLIPPINGVALUE) |
| | 228 | { |
| | 229 | /* scale radius by square root of 2 */ |
| | 230 | int radius = MUL_FIXED(92682, dbPtr->extent.radius); |
| | 231 | |
| | 232 | return |
| | 233 | (((dbPtr->ObView.vx - dbPtr->ObView.vz) <= radius) |
| | 234 | && |
| | 235 | ((-dbPtr->ObView.vx - dbPtr->ObView.vz) <= radius) |
| | 236 | && |
| | 237 | ((dbPtr->ObView.vy - dbPtr->ObView.vz) <= radius) |
| | 238 | && |
| | 239 | ((-dbPtr->ObView.vy - dbPtr->ObView.vz) <= radius)); |
| | 240 | } |
| | 241 | |
| | 242 | return 0; |
| | 243 | } |
| | 244 | |
| | 245 | static int ObjectWithin_Wide_Frustrum(DISPLAYBLOCK *dbPtr) |
| | 246 | { |
| | 247 | if (dbPtr->ObView.vz + dbPtr->extent.radius >= ZCLIPPINGVALUE) |
| | 248 | { |
| | 249 | /* scale radius by square root of 5 */ |
| | 250 | int radius = MUL_FIXED(146543, dbPtr->extent.radius); |
| | 251 | |
| | 252 | return |
| | 253 | (((dbPtr->ObView.vx-2 * dbPtr->ObView.vz) <= radius) |
| | 254 | && |
| | 255 | ((-dbPtr->ObView.vx-2 * dbPtr->ObView.vz) <= radius) |
| | 256 | && |
| | 257 | ((dbPtr->ObView.vy-2 * dbPtr->ObView.vz) <= radius) |
| | 258 | && |
| | 259 | ((-dbPtr->ObView.vy-2 * dbPtr->ObView.vz) <= radius)); |
| | 260 | } |
| | 261 | |
| | 262 | return 0; |
| | 263 | } |
| | 264 | |
| | 265 | static void TestVerticesWith_Norm_Frustrum(int v) |
| | 266 | { |
| | 267 | assert(v > 0); |
| | 268 | |
| | 269 | while(v--) |
| | 270 | { |
| | 271 | char vertexFlag = 0; |
| | 272 | |
| | 273 | #if FAR_Z_CLIP |
| | 274 | if(ZCLIPPINGVALUE <= RotatedPts[v].vz && RotatedPts[v].vz <= FAR_Z_CLIP_RANGE) |
| | 275 | #else |
| | 276 | if(ZCLIPPINGVALUE <= RotatedPts[v].vz) |
| | 277 | #endif |
| | 278 | vertexFlag |= INSIDE_FRUSTRUM_Z_PLANE; |
| | 279 | |
| | 280 | if(-RotatedPts[v].vx <= RotatedPts[v].vz) |
| | 281 | vertexFlag |= INSIDE_FRUSTRUM_PX_PLANE; |
| | 282 | |
| | 283 | if(RotatedPts[v].vx <= RotatedPts[v].vz) |
| | 284 | vertexFlag |= INSIDE_FRUSTRUM_NX_PLANE; |
| | 285 | |
| | 286 | if(-RotatedPts[v].vy <= RotatedPts[v].vz) |
| | 287 | vertexFlag |= INSIDE_FRUSTRUM_PY_PLANE; |
| | 288 | |
| | 289 | if(RotatedPts[v].vy <= RotatedPts[v].vz) |
| | 290 | vertexFlag |= INSIDE_FRUSTRUM_NY_PLANE; |
| | 291 | |
| | 292 | FrustrumFlagForVertex[v] = vertexFlag; |
| | 293 | } |
| | 294 | } |
| | 295 | |
| | 296 | static void TestVerticesWith_Wide_Frustrum(int v) |
| | 297 | { |
| | 298 | assert(v > 0); |
| | 299 | |
| | 300 | while(v--) |
| | 301 | { |
| | 302 | char vertexFlag = 0; |
| | 303 | |
| | 304 | if(ZCLIPPINGVALUE <= RotatedPts[v].vz) |
| | 305 | vertexFlag |= INSIDE_FRUSTRUM_Z_PLANE; |
| | 306 | |
| | 307 | if(-RotatedPts[v].vx <= RotatedPts[v].vz * 2) |
| | 308 | vertexFlag |= INSIDE_FRUSTRUM_PX_PLANE; |
| | 309 | |
| | 310 | if(RotatedPts[v].vx <= RotatedPts[v].vz * 2) |
| | 311 | vertexFlag |= INSIDE_FRUSTRUM_NX_PLANE; |
| | 312 | |
| | 313 | if(-RotatedPts[v].vy <= RotatedPts[v].vz * 2) |
| | 314 | vertexFlag |= INSIDE_FRUSTRUM_PY_PLANE; |
| | 315 | |
| | 316 | if(RotatedPts[v].vy <= RotatedPts[v].vz * 2) |
| | 317 | vertexFlag |= INSIDE_FRUSTRUM_NY_PLANE; |
| | 318 | |
| | 319 | FrustrumFlagForVertex[v] = vertexFlag; |
| | 320 | } |
| | 321 | } |
| | 322 | |
| | 323 | int PolyWithinFrustrum(int NumberOfVertices) |
| | 324 | { |
| | 325 | char inFrustrumFlag = 0; |
| | 326 | char noClippingFlag = INSIDE_FRUSTRUM; |
| | 327 | RenderPolygon.NumberOfVertices = NumberOfVertices; |
| | 328 | |
| | 329 | while(--NumberOfVertices) |
| | 330 | { |
| | 331 | int vertexFlag = VertexWithinFrustrum(VerticesUnClipped + NumberOfVertices); |
| | 332 | |
| | 333 | if(!vertexFlag) |
| | 334 | return 0; |
| | 335 | |
| | 336 | inFrustrumFlag |= vertexFlag; |
| | 337 | noClippingFlag &= vertexFlag; |
| | 338 | } |
| | 339 | |
| | 340 | if(INSIDE_FRUSTRUM == inFrustrumFlag) |
| | 341 | { |
| | 342 | if(INSIDE_FRUSTRUM == noClippingFlag) |
| | 343 | { |
| | 344 | draw_vertices = VerticesUnClipped; |
| | 345 | return RenderPolygon.NumberOfVertices; |
| | 346 | } |
| | 347 | else |
| | 348 | { |
| | 349 | return ClipPolygon(RenderPolygon.NumberOfVertices); |
| | 350 | } |
| | 351 | } |
| | 352 | |
| | 353 | return 0; |
| | 354 | } |
| | 355 | |
| | 356 | static int ClipPolygonNorm(int verticesLeft) |
| | 357 | { |
| | 358 | int numberOfPointsOutputted = 0; |
| | 359 | int curVertexInside; |
| | 360 | RENDERVERTEX *curVertexPtr; |
| | 361 | RENDERVERTEX *outputVerticesPtr; |
| | 362 | |
| | 363 | //ClipWithZ |
| | 364 | //{ |
| | 365 | curVertexPtr = VerticesUnClipped; |
| | 366 | outputVerticesPtr = VerticesClipped; |
| | 367 | |
| | 368 | curVertexInside = (ZCLIPPINGVALUE <= VerticesUnClipped->Z); |
| | 369 | |
| | 370 | Clip_LoopStart(VerticesUnClipped) |
| | 371 | ZCLIPPINGVALUE <= nextVertexPtr->Z; |
| | 372 | |
| | 373 | Clip_Z_OutputXYZ |
| | 374 | Clip_OutputI |
| | 375 | //} |
| | 376 | if(numberOfPointsOutputted < 3) |
| | 377 | return 0; |
| | 378 | |
| | 379 | //ClipWithNegativeX |
| | 380 | //{ |
| | 381 | verticesLeft = numberOfPointsOutputted; |
| | 382 | numberOfPointsOutputted = 0; |
| | 383 | |
| | 384 | curVertexPtr = VerticesClipped; |
| | 385 | outputVerticesPtr = VerticesUnClipped; |
| | 386 | |
| | 387 | curVertexInside = (-VerticesClipped->X <= VerticesClipped->Z); |
| | 388 | |
| | 389 | Clip_LoopStart(VerticesClipped) |
| | 390 | |
| | 391 | (-nextVertexPtr->X <= nextVertexPtr->Z); |
| | 392 | |
| | 393 | Clip_NX_OutputXYZ |
| | 394 | Clip_OutputI |
| | 395 | //} |
| | 396 | if(numberOfPointsOutputted < 3) |
| | 397 | return 0; |
| | 398 | |
| | 399 | //ClipWithPositiveY |
| | 400 | //{ |
| | 401 | verticesLeft = numberOfPointsOutputted; |
| | 402 | numberOfPointsOutputted = 0; |
| | 403 | |
| | 404 | curVertexPtr = VerticesUnClipped; |
| | 405 | outputVerticesPtr = VerticesClipped; |
| | 406 | |
| | 407 | curVertexInside = Clip_PY_Test((VerticesUnClipped)); |
| | 408 | |
| | 409 | Clip_LoopStart((VerticesUnClipped)) |
| | 410 | Clip_PY_Test(nextVertexPtr); |
| | 411 | Clip_PY_OutputXYZ |
| | 412 | Clip_OutputI |
| | 413 | //} |
| | 414 | if(numberOfPointsOutputted < 3) |
| | 415 | return 0; |
| | 416 | |
| | 417 | //ClipWithNegativeY |
| | 418 | //{ |
| | 419 | verticesLeft = numberOfPointsOutputted; |
| | 420 | numberOfPointsOutputted = 0; |
| | 421 | |
| | 422 | curVertexPtr = VerticesClipped; |
| | 423 | outputVerticesPtr = VerticesUnClipped; |
| | 424 | |
| | 425 | curVertexInside = Clip_NY_Test(VerticesClipped); |
| | 426 | |
| | 427 | Clip_LoopStart(VerticesClipped) |
| | 428 | Clip_NY_Test(nextVertexPtr); |
| | 429 | Clip_NY_OutputXYZ |
| | 430 | Clip_OutputI |
| | 431 | //} |
| | 432 | if(numberOfPointsOutputted < 3) |
| | 433 | return 0; |
| | 434 | |
| | 435 | //ClipWithPositiveX |
| | 436 | //{ |
| | 437 | verticesLeft = numberOfPointsOutputted; |
| | 438 | numberOfPointsOutputted = 0; |
| | 439 | |
| | 440 | curVertexPtr = VerticesUnClipped; |
| | 441 | outputVerticesPtr = VerticesClipped; |
| | 442 | |
| | 443 | curVertexInside = Clip_PX_Test((VerticesUnClipped)); |
| | 444 | |
| | 445 | Clip_LoopStart((VerticesUnClipped)) |
| | 446 | Clip_PX_Test(nextVertexPtr); |
| | 447 | Clip_PX_OutputXYZ |
| | 448 | Clip_OutputI |
| | 449 | //} |
| | 450 | if(numberOfPointsOutputted < 3) |
| | 451 | return 0; |
| | 452 | |
| | 453 | RenderPolygon.NumberOfVertices = numberOfPointsOutputted; |
| | 454 | draw_vertices = VerticesClipped; |
| | 455 | |
| | 456 | return 1; |
| | 457 | } |
| | 458 | |
| | 459 | static int ClipPolygonWide(int verticesLeft) |
| | 460 | { |
| | 461 | int numberOfPointsOutputted = 0; |
| | 462 | int curVertexInside; |
| | 463 | RENDERVERTEX *curVertexPtr; |
| | 464 | RENDERVERTEX *outputVerticesPtr; |
| | 465 | |
| | 466 | //Polygon_ClipWithZ() |
| | 467 | //{ |
| | 468 | curVertexPtr = VerticesUnClipped; |
| | 469 | outputVerticesPtr = VerticesClipped; |
| | 470 | |
| | 471 | curVertexInside = (ZCLIPPINGVALUE <= VerticesUnClipped->Z); |
| | 472 | |
| | 473 | Clip_LoopStart(VerticesUnClipped) |
| | 474 | ZCLIPPINGVALUE <= nextVertexPtr->Z; |
| | 475 | |
| | 476 | Clip_Z_OutputXYZ |
| | 477 | Clip_OutputI |
| | 478 | //} |
| | 479 | if(numberOfPointsOutputted < 3) |
| | 480 | return 0; |
| | 481 | |
| | 482 | //Polygon_Wide_ClipWithNegativeX() |
| | 483 | //{ |
| | 484 | verticesLeft = numberOfPointsOutputted; |
| | 485 | numberOfPointsOutputted = 0; |
| | 486 | |
| | 487 | curVertexPtr = VerticesClipped; |
| | 488 | outputVerticesPtr = VerticesUnClipped; |
| | 489 | |
| | 490 | curVertexInside = Clip_Wide_NX_Test(VerticesClipped); |
| | 491 | |
| | 492 | Clip_LoopStart(VerticesClipped) |
| | 493 | Clip_Wide_NX_Test(nextVertexPtr); |
| | 494 | Clip_Wide_NX_OutputXYZ |
| | 495 | Clip_OutputI |
| | 496 | //} |
| | 497 | if(numberOfPointsOutputted < 3) |
| | 498 | return 0; |
| | 499 | |
| | 500 | //Polygon_Wide_ClipWithPositiveY() |
| | 501 | //{ |
| | 502 | verticesLeft = numberOfPointsOutputted; |
| | 503 | numberOfPointsOutputted = 0; |
| | 504 | |
| | 505 | curVertexPtr = VerticesUnClipped; |
| | 506 | outputVerticesPtr = VerticesClipped; |
| | 507 | |
| | 508 | curVertexInside = Clip_Wide_PY_Test((VerticesUnClipped)); |
| | 509 | |
| | 510 | Clip_LoopStart((VerticesUnClipped)) |
| | 511 | Clip_Wide_PY_Test(nextVertexPtr); |
| | 512 | Clip_Wide_PY_OutputXYZ |
| | 513 | Clip_OutputI |
| | 514 | //} |
| | 515 | if(numberOfPointsOutputted < 3) |
| | 516 | return 0; |
| | 517 | |
| | 518 | //Polygon_Wide_ClipWithNegativeY() |
| | 519 | //{ |
| | 520 | verticesLeft = numberOfPointsOutputted; |
| | 521 | numberOfPointsOutputted = 0; |
| | 522 | |
| | 523 | curVertexPtr = VerticesClipped; |
| | 524 | outputVerticesPtr = VerticesUnClipped; |
| | 525 | |
| | 526 | curVertexInside = Clip_Wide_NY_Test(VerticesClipped); |
| | 527 | |
| | 528 | Clip_LoopStart(VerticesClipped) |
| | 529 | Clip_Wide_NY_Test(nextVertexPtr); |
| | 530 | Clip_Wide_NY_OutputXYZ |
| | 531 | Clip_OutputI |
| | 532 | //} |
| | 533 | if(numberOfPointsOutputted < 3) |
| | 534 | return 0; |
| | 535 | |
| | 536 | //Polygon_Wide_ClipWithPositiveX() |
| | 537 | //{ |
| | 538 | verticesLeft = numberOfPointsOutputted; |
| | 539 | numberOfPointsOutputted = 0; |
| | 540 | |
| | 541 | curVertexPtr = VerticesUnClipped; |
| | 542 | outputVerticesPtr = VerticesClipped; |
| | 543 | |
| | 544 | curVertexInside = Clip_Wide_PX_Test((VerticesUnClipped)); |
| | 545 | |
| | 546 | Clip_LoopStart((VerticesUnClipped)) |
| | 547 | Clip_Wide_PX_Test(nextVertexPtr); |
| | 548 | Clip_Wide_PX_OutputXYZ |
| | 549 | Clip_OutputI |
| | 550 | //} |
| | 551 | if(numberOfPointsOutputted < 3) |
| | 552 | return 0; |
| | 553 | |
| | 554 | RenderPolygon.NumberOfVertices = numberOfPointsOutputted; |
| | 555 | draw_vertices = VerticesClipped; |
| | 556 | |
| | 557 | return 1; |
| | 558 | } |
| | 559 | |
| | 560 | void SetFrustrumType(enum FrustrumType frustrumType) |
| | 561 | { |
| | 562 | if(FRUSTRUM_TYPE_NORMAL == frustrumType) |
| | 563 | { |
| | 564 | ClipPolygon = ClipPolygonNorm; |
| | 565 | TestVerticesWithFrustrum = TestVerticesWith_Norm_Frustrum; |
| | 566 | ObjectWithinFrustrum = ObjectWithin_Norm_Frustrum; |
| | 567 | VertexWithinFrustrum = VertexWithin_Norm_Frustrum; |
| | 568 | } |
| | 569 | else |
| | 570 | { |
| | 571 | ClipPolygon = ClipPolygonWide; |
| | 572 | TestVerticesWithFrustrum = TestVerticesWith_Wide_Frustrum; |
| | 573 | ObjectWithinFrustrum = ObjectWithin_Wide_Frustrum; |
| | 574 | VertexWithinFrustrum = VertexWithin_Wide_Frustrum; |
| | 575 | } |
| | 576 | } |