MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ClassifyPolygon

Function ClassifyPolygon

Descent3/bsp.cpp:278–318  ·  view source on GitHub ↗

Classifies whether or not a polygon is behind,in front, or straddles a plane

Source from the content-addressed store, hash-verified

276
277// Classifies whether or not a polygon is behind,in front, or straddles a plane
278int ClassifyPolygon(bspplane *plane, bsppolygon *poly) {
279 int numfront, numback, numon;
280 int i;
281 int nv = poly->nv;
282
283 ASSERT(nv >= 3);
284
285 numfront = numback = numon = 0;
286
287 for (i = 0; i < nv; i++) {
288 int fate;
289 vector *vec = &poly->verts[i];
290
291 fate = ClassifyVector(plane, vec);
292
293 switch (fate) {
294 case BSP_IN_FRONT:
295 numfront++;
296 break;
297 case BSP_BEHIND:
298 numback++;
299 break;
300 case BSP_ON_PLANE:
301 numfront++;
302 numback++;
303 numon++;
304 break;
305 }
306 }
307
308 if (numon == nv) {
309 return BSP_COINCIDENT;
310 } else if (numfront == nv) {
311 return BSP_IN_FRONT;
312 } else if (numback == nv) {
313 return BSP_BEHIND;
314 }
315
316 // The polygon straddles the plane
317 return BSP_SPANNING;
318}
319
320// Tries to split a polygon across a plane
321int SplitPolygon(bspplane *plane, bsppolygon *testpoly, bsppolygon **frontpoly, bsppolygon **backpoly) {

Callers 2

SelectPlaneFunction · 0.85
BuildBSPNodeFunction · 0.85

Calls 1

ClassifyVectorFunction · 0.85

Tested by

no test coverage detected