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

Method handleOverlap

Engine/source/collision/depthSortList.cpp:303–418  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

301//----------------------------------------------------------------------------
302
303void DepthSortList::handleOverlap(Poly * testPoly, Point3F & testNormal, F32 testDot, S32 & testOffset, bool & switched)
304{
305 // first reverse the plane tests (i.e., test to see if basePoly behind testPoly or testPoly in front of basePoly...
306 // if either succeeds, switch poly
307 // if they both fail, split base poly
308 // But split anyway if basePoly has already been switched...
309 bool doSwitch = false;
310
311 if (!switched)
312 {
313 S32 v;
314 for (v=0; v<mBasePoly->vertexCount; v++)
315 if (mDot(mVertexList[mIndexList[mBasePoly->vertexStart+v]].point,testNormal)>testDot+DEPTH_TOL)
316 break;
317 if (v==mBasePoly->vertexCount)
318 doSwitch = true;
319 else
320 {
321 for (v=0; v<testPoly->vertexCount; v++)
322 if (mDot(mVertexList[mIndexList[testPoly->vertexStart+v]].point,*mBaseNormal)<mBaseDot-DEPTH_TOL)
323 break;
324 if (v==testPoly->vertexCount)
325 doSwitch = true;
326 }
327 }
328
329 // try to split base poly along plane of test poly
330 Poly frontPoly, backPoly;
331 bool splitBase = false, splitTest = false;
332 if (!doSwitch)
333 {
334 splitBase = splitPoly(*mBasePoly,testNormal,testDot,frontPoly,backPoly);
335 if (!splitBase)
336 // didn't take...no splitting happened...try splitting test poly by base poly
337 splitTest = splitPoly(*testPoly,*mBaseNormal,mBaseDot,frontPoly,backPoly);
338 }
339
340 U32 testIdx = mPolyIndexList[mBase+testOffset];
341
342 // should we switch order of test and base poly? Might have to even if we
343 // don't want to if there's no splitting to do...
344 // Note: possibility that infinite loop can be introduced here...if that happens,
345 // then we need to split along edges of polys
346 if (doSwitch || (!splitTest && !splitBase))
347 {
348 if (!doSwitch && gBadSpots++ > (mPolyIndexList.size()-mBase)<<1)
349 // got here one too many times...just leave and don't touch poly -- avoid infinite loop
350 return;
351
352 // move test poly to the front of the order
353 dMemmove(&mPolyIndexList[mBase+1],&mPolyIndexList[mBase],testOffset*sizeof(U32));
354 mPolyIndexList[mBase] = testIdx;
355
356 // base poly changed...
357 setBase(mBase);
358
359 if (mBase+testOffset>mMaxTouched)
360 mMaxTouched=mBase+testOffset;

Callers

nothing calls this directly

Calls 7

incrementMethod · 0.80
mDotFunction · 0.50
dMemmoveFunction · 0.50
sizeMethod · 0.45
lastMethod · 0.45
insertMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected