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

Function ClipPlane

renderer/HardwareClipper.cpp:287–332  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285}
286
287int ClipPlane(int plane_flag, g3Point **src, g3Point **dest, int *nv, g3Codes *cc) {
288 int i, prev, next;
289 g3Point **save_dest = dest;
290
291 // Init codes
292 cc->cc_and = 0xff;
293 cc->cc_or = 0;
294
295 for (i = 0, prev = *nv - 1, next = 1; i < *nv; i++) {
296 if (src[i]->p3_codes & plane_flag) {
297 // cur point off?
298 if (!(src[prev]->p3_codes & plane_flag)) {
299 // prev not off?
300 *dest = ClipEdge(plane_flag, src[prev], src[i]);
301 cc->cc_or |= (*dest)->p3_codes;
302 cc->cc_and &= (*dest)->p3_codes;
303 dest++;
304 }
305
306 if (!(src[next]->p3_codes & plane_flag)) {
307 *dest = ClipEdge(plane_flag, src[next], src[i]);
308 cc->cc_or |= (*dest)->p3_codes;
309 cc->cc_and &= (*dest)->p3_codes;
310 dest++;
311 }
312
313 // see if must free discarded point
314 if (src[i]->p3_flags & PF_TEMP_POINT) {
315 FreeTempPoint(src[i]);
316 }
317 } else {
318 // cur not off, copy to dest buffer
319 *dest++ = src[i];
320
321 cc->cc_or |= src[i]->p3_codes;
322 cc->cc_and &= src[i]->p3_codes;
323 }
324
325 prev = i;
326 if (++next == *nv) {
327 next = 0;
328 }
329 }
330
331 return (dest - save_dest);
332}
333
334// temp buffers for clipping
335static g3Point *Vbuf0[MAX_POINTS_IN_POLY];

Callers 1

g3_ClipPolygonFunction · 0.85

Calls 2

FreeTempPointFunction · 0.85
ClipEdgeFunction · 0.70

Tested by

no test coverage detected