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

Function BuildBSPNode

Descent3/bsp.cpp:531–739  ·  view source on GitHub ↗

This is the routine that recursively builds the bsptree

Source from the content-addressed store, hash-verified

529
530// This is the routine that recursively builds the bsptree
531int BuildBSPNode(bspnode *tree, listnode **polylist, int numpolys) {
532 bsppolygon *partition_poly;
533 listnode *lnode = *polylist;
534 listnode *next;
535 bspnode *frontnode, *backnode;
536 listnode *frontlist = NULL, *backlist = NULL;
537 bspplane partition_plane;
538 int numfront = 0, numback = 0, numsplits = 0;
539
540 ASSERT(numpolys > 0);
541 partition_poly = SelectPlane(polylist);
542
543 mprintf_at(2, 5, 0, "Node = %c", Twirly[(Node_twirl++) % 4]);
544
545 if (partition_poly == NULL) {
546 // We hit a leaf! Fill in the appropriate leaf stuff
547
548 /*vector center;
549 int total=0;
550
551 vm_MakeZero (&center);
552
553 for (int i=0;i<numpolys;i++)
554 {
555 bsppolygon *poly=(bsppolygon *)GetListItem (polylist,i);
556 ASSERT (poly!=NULL);
557 AddListItem (&tree->polylist,poly);
558 tree->num_polys++;
559 vector polycenter;
560
561 ConvexPolys++;
562 vm_MakeZero (&polycenter);
563
564 // Find out if this is a solid or empty leaf
565 // This routine may cause some problems because of convex subspace
566 for (int t=0;t<poly->nv;t++)
567 {
568 polycenter+=poly->verts[t];
569
570 }
571
572 polycenter/=poly->nv;
573 center+=polycenter;
574
575 }
576
577 center/=numpolys;
578 int ins=0,outs=0;
579
580 for (i=0;i<numpolys;i++)
581 {
582 bsppolygon *thispoly=(bsppolygon *)GetListItem (polylist,i);
583 int fate=ClassifyVector (&thispoly->plane,&center);
584
585 if (fate==BSP_IN_FRONT || fate==BSP_ON_PLANE)
586 {
587 outs++;
588 }

Callers 2

BuildBSPTreeFunction · 0.85
BuildSingleBSPTreeFunction · 0.85

Calls 8

SelectPlaneFunction · 0.85
ClassifyPolygonFunction · 0.85
AddListItemFunction · 0.85
SplitPolygonFunction · 0.85
RemoveListItemFunction · 0.85
FreePolygonFunction · 0.85
NewBSPNodeFunction · 0.85
DestroyListFunction · 0.85

Tested by

no test coverage detected