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