MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / splitPoly

Method splitPoly

Engine/source/collision/depthSortList.cpp:524–682  ·  view source on GitHub ↗

Split source poly into front and back. If either front or back is degenerate, don't do anything. If we have a front and a back, then add the verts to our vertex list and fill out the poly structures.

Source from the content-addressed store, hash-verified

522// Split source poly into front and back. If either front or back is degenerate, don't do anything.
523// If we have a front and a back, then add the verts to our vertex list and fill out the poly structures.
524bool DepthSortList::splitPoly(const Poly & src, Point3F & normal, F32 k, Poly & frontPoly, Poly & backPoly)
525{
526 frontVerts.clear();
527 backVerts.clear();
528
529 // already degenerate...
530 AssertFatal(src.vertexCount>=3,"DepthSortList::splitPoly - Don't need to split a triangle!");
531
532 S32 startSize = mVertexList.size();
533
534 // Assume back and front are degenerate polygons until proven otherwise.
535 bool backDegen = true, frontDegen = true;
536
537 U32 bIdx;
538 Point3F * a, * b;
539 F32 dota, dotb;
540 S32 signA, signB;
541
542 F32 splitTolSq = SPLIT_TOL * SPLIT_TOL * mDot(normal,normal);
543
544 bIdx = mIndexList[src.vertexStart+src.vertexCount-1];
545 b = &mVertexList[bIdx].point;
546 dotb = mDot(normal,*b)-k;
547
548 // Sign variable coded as follows: 1 for outside, 0 on the plane and -1 for inside.
549 if (dotb*dotb > splitTolSq)
550 signB = dotb > 0.0f ? 1 : -1;
551 else
552 signB = 0;
553
554 S32 i;
555 for (i = 0; i<src.vertexCount; i++)
556 {
557 a = b;
558 bIdx = mIndexList[src.vertexStart+i];
559 b = &mVertexList[bIdx].point;
560 dota = dotb;
561 dotb = mDot(normal,*b)-k;
562 signA = signB;
563 if (dotb*dotb > splitTolSq)
564 signB = dotb > 0.0f ? 1 : -1;
565 else
566 signB = 0;
567
568 switch(signA*3 + signB + 4) // +4 is to make values go from 0 up...hopefully enticing compiler to make a jump-table
569 {
570 case 0: // A-, B-
571 case 3: // A., B-
572 backVerts.push_back(bIdx);
573 backDegen = false;
574 break;
575 case 8: // A+, B+
576 case 5: // A., B+
577 frontVerts.push_back(bIdx);
578 frontDegen = false;
579 break;
580
581 case 1: // A-, B.

Callers

nothing calls this directly

Calls 7

mDotFunction · 0.50
dMemcpyFunction · 0.50
clearMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
setSizeMethod · 0.45
addressMethod · 0.45

Tested by

no test coverage detected