Changeset 7983 for code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp
- Timestamp:
- Feb 27, 2011, 7:43:24 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp
r5781 r7983 39 39 40 40 41 42 41 btGjkPairDetector::btGjkPairDetector(const btConvexShape* objectA,const btConvexShape* objectB,btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver) 43 :m_cachedSeparatingAxis(btScalar(0.),btScalar( 0.),btScalar(1.)),42 :m_cachedSeparatingAxis(btScalar(0.),btScalar(1.),btScalar(0.)), 44 43 m_penetrationDepthSolver(penetrationDepthSolver), 45 44 m_simplexSolver(simplexSolver), 46 45 m_minkowskiA(objectA), 47 46 m_minkowskiB(objectB), 47 m_shapeTypeA(objectA->getShapeType()), 48 m_shapeTypeB(objectB->getShapeType()), 49 m_marginA(objectA->getMargin()), 50 m_marginB(objectB->getMargin()), 48 51 m_ignoreMargin(false), 49 52 m_lastUsedMethod(-1), … … 51 54 { 52 55 } 53 54 void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults) 56 btGjkPairDetector::btGjkPairDetector(const btConvexShape* objectA,const btConvexShape* objectB,int shapeTypeA,int shapeTypeB,btScalar marginA, btScalar marginB, btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver) 57 :m_cachedSeparatingAxis(btScalar(0.),btScalar(1.),btScalar(0.)), 58 m_penetrationDepthSolver(penetrationDepthSolver), 59 m_simplexSolver(simplexSolver), 60 m_minkowskiA(objectA), 61 m_minkowskiB(objectB), 62 m_shapeTypeA(shapeTypeA), 63 m_shapeTypeB(shapeTypeB), 64 m_marginA(marginA), 65 m_marginB(marginB), 66 m_ignoreMargin(false), 67 m_lastUsedMethod(-1), 68 m_catchDegeneracies(1) 69 { 70 } 71 72 void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults) 73 { 74 (void)swapResults; 75 76 getClosestPointsNonVirtual(input,output,debugDraw); 77 } 78 79 #ifdef __SPU__ 80 void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw) 81 #else 82 void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw) 83 #endif 55 84 { 56 85 m_cachedSeparatingDistance = 0.f; … … 65 94 localTransB.getOrigin() -= positionOffset; 66 95 67 #ifdef __SPU__ 68 btScalar marginA = m_minkowskiA->getMarginNonVirtual(); 69 btScalar marginB = m_minkowskiB->getMarginNonVirtual(); 70 #else 71 btScalar marginA = m_minkowskiA->getMargin(); 72 btScalar marginB = m_minkowskiB->getMargin(); 73 #ifdef TEST_NON_VIRTUAL 74 btScalar marginAv = m_minkowskiA->getMarginNonVirtual(); 75 btScalar marginBv = m_minkowskiB->getMarginNonVirtual(); 76 btAssert(marginA == marginAv); 77 btAssert(marginB == marginBv); 78 #endif //TEST_NON_VIRTUAL 79 #endif 80 81 96 bool check2d = m_minkowskiA->isConvex2d() && m_minkowskiB->isConvex2d(); 97 98 btScalar marginA = m_marginA; 99 btScalar marginB = m_marginB; 82 100 83 101 gNumGjkChecks++; … … 108 126 109 127 { 110 btScalar squaredDistance = SIMD_INFINITY;128 btScalar squaredDistance = BT_LARGE_FLOAT; 111 129 btScalar delta = btScalar(0.); 112 130 … … 124 142 btVector3 seperatingAxisInB = m_cachedSeparatingAxis* input.m_transformB.getBasis(); 125 143 144 #if 1 145 146 btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA); 147 btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB); 148 149 // btVector3 pInA = localGetSupportingVertexWithoutMargin(m_shapeTypeA, m_minkowskiA, seperatingAxisInA,input.m_convexVertexData[0]);//, &featureIndexA); 150 // btVector3 qInB = localGetSupportingVertexWithoutMargin(m_shapeTypeB, m_minkowskiB, seperatingAxisInB,input.m_convexVertexData[1]);//, &featureIndexB); 151 152 #else 126 153 #ifdef __SPU__ 127 154 btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA); … … 137 164 #endif // 138 165 #endif //__SPU__ 166 #endif 167 139 168 140 169 btVector3 pWorld = localTransA(pInA); … … 145 174 #endif 146 175 176 if (check2d) 177 { 178 pWorld[2] = 0.f; 179 qWorld[2] = 0.f; 180 } 181 147 182 btVector3 w = pWorld - qWorld; 148 183 delta = m_cachedSeparatingAxis.dot(w); … … 151 186 if ((delta > btScalar(0.0)) && (delta * delta > squaredDistance * input.m_maximumDistanceSquared)) 152 187 { 188 m_degenerateSimplex = 10; 153 189 checkSimplex=true; 154 190 //checkPenetration = false; … … 172 208 { 173 209 m_degenerateSimplex = 2; 210 } else 211 { 212 m_degenerateSimplex = 11; 174 213 } 175 214 checkSimplex = true; … … 185 224 spu_printf("addVertex 2\n"); 186 225 #endif 226 btVector3 newCachedSeparatingAxis; 227 187 228 //calculate the closest point to the origin (update vector v) 188 if (!m_simplexSolver->closest( m_cachedSeparatingAxis))229 if (!m_simplexSolver->closest(newCachedSeparatingAxis)) 189 230 { 190 231 m_degenerateSimplex = 3; … … 193 234 } 194 235 195 if( m_cachedSeparatingAxis.length2()<REL_ERROR2)236 if(newCachedSeparatingAxis.length2()<REL_ERROR2) 196 237 { 238 m_cachedSeparatingAxis = newCachedSeparatingAxis; 197 239 m_degenerateSimplex = 6; 198 240 checkSimplex = true; … … 201 243 202 244 btScalar previousSquaredDistance = squaredDistance; 203 squaredDistance = m_cachedSeparatingAxis.length2(); 245 squaredDistance = newCachedSeparatingAxis.length2(); 246 #if 0 247 ///warning: this termination condition leads to some problems in 2d test case see Bullet/Demos/Box2dDemo 248 if (squaredDistance>previousSquaredDistance) 249 { 250 m_degenerateSimplex = 7; 251 squaredDistance = previousSquaredDistance; 252 checkSimplex = false; 253 break; 254 } 255 #endif // 204 256 257 m_cachedSeparatingAxis = newCachedSeparatingAxis; 258 205 259 //redundant m_simplexSolver->compute_points(pointOnA, pointOnB); 206 260 … … 210 264 m_simplexSolver->backup_closest(m_cachedSeparatingAxis); 211 265 checkSimplex = true; 266 m_degenerateSimplex = 12; 267 212 268 break; 213 269 } … … 240 296 //do we need this backup_closest here ? 241 297 m_simplexSolver->backup_closest(m_cachedSeparatingAxis); 298 m_degenerateSimplex = 13; 242 299 break; 243 300 } … … 248 305 m_simplexSolver->compute_points(pointOnA, pointOnB); 249 306 normalInB = pointOnA-pointOnB; 250 btScalar lenSqr = m_cachedSeparatingAxis.length2(); 307 btScalar lenSqr =m_cachedSeparatingAxis.length2(); 308 251 309 //valid normal 252 310 if (lenSqr < 0.0001) … … 280 338 { 281 339 //penetration case 282 340 283 341 //if there is no way to handle penetrations, bail out 284 342 if (m_penetrationDepthSolver) … … 288 346 289 347 gNumDeepPenetrationChecks++; 348 m_cachedSeparatingAxis.setZero(); 290 349 291 350 bool isValid2 = m_penetrationDepthSolver->calcPenDepth( … … 297 356 ); 298 357 358 299 359 if (isValid2) 300 360 { 301 361 btVector3 tmpNormalInB = tmpPointOnB-tmpPointOnA; 302 362 btScalar lenSqr = tmpNormalInB.length2(); 363 if (lenSqr <= (SIMD_EPSILON*SIMD_EPSILON)) 364 { 365 tmpNormalInB = m_cachedSeparatingAxis; 366 lenSqr = m_cachedSeparatingAxis.length2(); 367 } 368 303 369 if (lenSqr > (SIMD_EPSILON*SIMD_EPSILON)) 304 370 { … … 316 382 } else 317 383 { 318 384 m_lastUsedMethod = 8; 319 385 } 320 386 } else 321 387 { 322 //isValid = false; 323 m_lastUsedMethod = 4; 388 m_lastUsedMethod = 9; 324 389 } 325 390 } else 391 326 392 { 327 m_lastUsedMethod = 5; 393 ///this is another degenerate case, where the initial GJK calculation reports a degenerate case 394 ///EPA reports no penetration, and the second GJK (using the supporting vector without margin) 395 ///reports a valid positive distance. Use the results of the second GJK instead of failing. 396 ///thanks to Jacob.Langford for the reproduction case 397 ///http://code.google.com/p/bullet/issues/detail?id=250 398 399 400 if (m_cachedSeparatingAxis.length2() > btScalar(0.)) 401 { 402 btScalar distance2 = (tmpPointOnA-tmpPointOnB).length()-margin; 403 //only replace valid distances when the distance is less 404 if (!isValid || (distance2 < distance)) 405 { 406 distance = distance2; 407 pointOnA = tmpPointOnA; 408 pointOnB = tmpPointOnB; 409 pointOnA -= m_cachedSeparatingAxis * marginA ; 410 pointOnB += m_cachedSeparatingAxis * marginB ; 411 normalInB = m_cachedSeparatingAxis; 412 normalInB.normalize(); 413 isValid = true; 414 m_lastUsedMethod = 6; 415 } else 416 { 417 m_lastUsedMethod = 5; 418 } 419 } 328 420 } 329 421 330 422 } 423 331 424 } 332 425 } 333 426 334 if (isValid) 427 428 429 if (isValid && ((distance < 0) || (distance*distance < input.m_maximumDistanceSquared))) 335 430 { 336 #ifdef __SPU__ 337 //spu_printf("distance\n"); 338 #endif //__CELLOS_LV2__ 339 340 341 #ifdef DEBUG_SPU_COLLISION_DETECTION 342 spu_printf("output 1\n"); 343 #endif 431 #if 0 432 ///some debugging 433 // if (check2d) 434 { 435 printf("n = %2.3f,%2.3f,%2.3f. ",normalInB[0],normalInB[1],normalInB[2]); 436 printf("distance = %2.3f exit=%d deg=%d\n",distance,m_lastUsedMethod,m_degenerateSimplex); 437 } 438 #endif 439 344 440 m_cachedSeparatingAxis = normalInB; 345 441 m_cachedSeparatingDistance = distance; … … 350 446 distance); 351 447 352 #ifdef DEBUG_SPU_COLLISION_DETECTION353 spu_printf("output 2\n");354 #endif355 //printf("gjk add:%f",distance);356 448 } 357 449
Note: See TracChangeset
for help on using the changeset viewer.