Changeset 2908 for code/branches/questsystem5/src/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
- Timestamp:
- Apr 8, 2009, 12:58:47 AM (16 years ago)
- Location:
- code/branches/questsystem5
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/questsystem5
- Property svn:mergeinfo changed
-
code/branches/questsystem5/src/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
r2907 r2908 52 52 btConvexConvexAlgorithm::CreateFunc::CreateFunc(btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver) 53 53 { 54 m_numPerturbationIterations = 0;55 m_minimumPointsPerturbationThreshold = 3;56 54 m_simplexSolver = simplexSolver; 57 55 m_pdSolver = pdSolver; … … 62 60 } 63 61 64 btConvexConvexAlgorithm::btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver ,int numPerturbationIterations, int minimumPointsPerturbationThreshold)62 btConvexConvexAlgorithm::btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver) 65 63 : btActivatingCollisionAlgorithm(ci,body0,body1), 66 64 m_simplexSolver(simplexSolver), … … 68 66 m_ownManifold (false), 69 67 m_manifoldPtr(mf), 70 m_lowLevelOfDetail(false) ,68 m_lowLevelOfDetail(false) 71 69 #ifdef USE_SEPDISTANCE_UTIL2 72 70 ,m_sepDistance((static_cast<btConvexShape*>(body0->getCollisionShape()))->getAngularMotionDisc(), 73 (static_cast<btConvexShape*>(body1->getCollisionShape()))->getAngularMotionDisc()) ,71 (static_cast<btConvexShape*>(body1->getCollisionShape()))->getAngularMotionDisc()) 74 72 #endif 75 m_numPerturbationIterations(numPerturbationIterations),76 m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold)77 73 { 78 74 (void)body0; … … 98 94 99 95 100 struct btPerturbedContactResult : public btManifoldResult 101 { 102 btManifoldResult* m_originalManifoldResult; 103 btTransform m_transformA; 104 btTransform m_transformB; 105 btTransform m_unPerturbedTransform; 106 bool m_perturbA; 107 btIDebugDraw* m_debugDrawer; 108 109 110 btPerturbedContactResult(btManifoldResult* originalResult,const btTransform& transformA,const btTransform& transformB,const btTransform& unPerturbedTransform,bool perturbA,btIDebugDraw* debugDrawer) 111 :m_originalManifoldResult(originalResult), 112 m_transformA(transformA), 113 m_transformB(transformB), 114 m_perturbA(perturbA), 115 m_unPerturbedTransform(unPerturbedTransform), 116 m_debugDrawer(debugDrawer) 117 { 118 } 119 virtual ~ btPerturbedContactResult() 120 { 121 } 122 123 virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar orgDepth) 124 { 125 btVector3 endPt,startPt; 126 btScalar newDepth; 127 btVector3 newNormal; 128 129 if (m_perturbA) 130 { 131 btVector3 endPtOrg = pointInWorld + normalOnBInWorld*orgDepth; 132 endPt = (m_unPerturbedTransform*m_transformA.inverse())(endPtOrg); 133 newDepth = (endPt - pointInWorld).dot(normalOnBInWorld); 134 startPt = endPt+normalOnBInWorld*newDepth; 135 } else 136 { 137 endPt = pointInWorld + normalOnBInWorld*orgDepth; 138 startPt = (m_unPerturbedTransform*m_transformB.inverse())(pointInWorld); 139 newDepth = (endPt - startPt).dot(normalOnBInWorld); 140 141 } 142 143 //#define DEBUG_CONTACTS 1 144 #ifdef DEBUG_CONTACTS 145 m_debugDrawer->drawLine(startPt,endPt,btVector3(1,0,0)); 146 m_debugDrawer->drawSphere(startPt,0.05,btVector3(0,1,0)); 147 m_debugDrawer->drawSphere(endPt,0.05,btVector3(0,0,1)); 148 #endif //DEBUG_CONTACTS 149 150 151 m_originalManifoldResult->addContactPoint(normalOnBInWorld,startPt,newDepth); 152 } 153 154 }; 155 156 extern btScalar gContactBreakingThreshold; 96 97 157 98 158 99 // … … 170 111 resultOut->setPersistentManifold(m_manifoldPtr); 171 112 172 //comment-out next line to test multi-contact generation173 //resultOut->getPersistentManifold()->clearManifold();174 113 175 114 … … 208 147 209 148 gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw); 149 210 150 btScalar sepDist = gjkPairDetector.getCachedSeparatingDistance()+dispatchInfo.m_convexConservativeDistanceThreshold; 211 212 //now perturbe directions to get multiple contact points213 btVector3 v0,v1;214 btVector3 sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis().normalized();215 btPlaneSpace1(sepNormalWorldSpace,v0,v1);216 //now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects217 218 //perform perturbation when more then 'm_minimumPointsPerturbationThreshold' points219 if (resultOut->getPersistentManifold()->getNumContacts() < m_minimumPointsPerturbationThreshold)220 {221 222 int i;223 224 bool perturbeA = true;225 const btScalar angleLimit = 0.125f * SIMD_PI;226 btScalar perturbeAngle;227 btScalar radiusA = min0->getAngularMotionDisc();228 btScalar radiusB = min1->getAngularMotionDisc();229 if (radiusA < radiusB)230 {231 perturbeAngle = gContactBreakingThreshold /radiusA;232 perturbeA = true;233 } else234 {235 perturbeAngle = gContactBreakingThreshold / radiusB;236 perturbeA = false;237 }238 if ( perturbeAngle > angleLimit )239 perturbeAngle = angleLimit;240 241 btTransform unPerturbedTransform;242 if (perturbeA)243 {244 unPerturbedTransform = input.m_transformA;245 } else246 {247 unPerturbedTransform = input.m_transformB;248 }249 250 for ( i=0;i<m_numPerturbationIterations;i++)251 {252 btQuaternion perturbeRot(v0,perturbeAngle);253 btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations));254 btQuaternion rotq(sepNormalWorldSpace,iterationAngle);255 256 257 if (perturbeA)258 {259 input.m_transformA.setBasis( btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*body0->getWorldTransform().getBasis());260 input.m_transformB = body1->getWorldTransform();261 #ifdef DEBUG_CONTACTS262 dispatchInfo.m_debugDraw->drawTransform(input.m_transformA,10.0);263 #endif //DEBUG_CONTACTS264 } else265 {266 input.m_transformA = body0->getWorldTransform();267 input.m_transformB.setBasis( btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*body1->getWorldTransform().getBasis());268 #ifdef DEBUG_CONTACTS269 dispatchInfo.m_debugDraw->drawTransform(input.m_transformB,10.0);270 #endif271 }272 273 btPerturbedContactResult perturbedResultOut(resultOut,input.m_transformA,input.m_transformB,unPerturbedTransform,perturbeA,dispatchInfo.m_debugDraw);274 gjkPairDetector.getClosestPoints(input,perturbedResultOut,dispatchInfo.m_debugDraw);275 276 277 }278 }279 280 281 151 282 152 #ifdef USE_SEPDISTANCE_UTIL2
Note: See TracChangeset
for help on using the changeset viewer.