Changeset 8284 for code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp
- Timestamp:
- Apr 21, 2011, 6:58:23 PM (14 years ago)
- Location:
- code/branches/kicklib2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/kicklib2
- Property svn:mergeinfo changed
-
code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp
r5781 r8284 21 21 22 22 #define NUM_UNITSPHERE_POINTS 42 23 static btVector3 sPenetrationDirections[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] =24 {25 btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)),26 btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)),27 btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)),28 btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)),29 btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)),30 btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)),31 btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)),32 btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)),33 btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)),34 btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)),35 btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)),36 btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)),37 btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)),38 btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)),39 btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)),40 btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)),41 btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)),42 btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)),43 btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)),44 btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)),45 btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)),46 btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)),47 btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)),48 btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)),49 btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)),50 btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)),51 btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)),52 btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)),53 btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)),54 btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)),55 btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)),56 btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)),57 btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)),58 btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)),59 btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)),60 btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)),61 btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)),62 btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)),63 btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)),64 btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)),65 btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)),66 btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654))67 };68 23 69 24 … … 79 34 (void)v; 80 35 36 bool check2d= convexA->isConvex2d() && convexB->isConvex2d(); 81 37 82 38 struct btIntermediateResult : public btDiscreteCollisionDetectorInterface::Result … … 92 48 bool m_hasResult; 93 49 94 virtual void setShapeIdentifiers (int partId0,int index0, int partId1,int index1)50 virtual void setShapeIdentifiersA(int partId0,int index0) 95 51 { 96 52 (void)partId0; 97 53 (void)index0; 54 } 55 virtual void setShapeIdentifiersB(int partId1,int index1) 56 { 98 57 (void)partId1; 99 58 (void)index1; … … 109 68 110 69 //just take fixed number of orientation, and sample the penetration depth in that direction 111 btScalar minProj = btScalar( 1e30);70 btScalar minProj = btScalar(BT_LARGE_FLOAT); 112 71 btVector3 minNorm(btScalar(0.), btScalar(0.), btScalar(0.)); 113 72 btVector3 minA,minB; … … 130 89 for (i=0;i<numSampleDirections;i++) 131 90 { 132 const btVector3& norm = sPenetrationDirections[i];91 btVector3 norm = getPenetrationDirections()[i]; 133 92 seperatingAxisInABatch[i] = (-norm) * transA.getBasis() ; 134 93 seperatingAxisInBBatch[i] = norm * transB.getBasis() ; … … 144 103 convexA->getPreferredPenetrationDirection(i,norm); 145 104 norm = transA.getBasis() * norm; 146 sPenetrationDirections[numSampleDirections] = norm;105 getPenetrationDirections()[numSampleDirections] = norm; 147 106 seperatingAxisInABatch[numSampleDirections] = (-norm) * transA.getBasis(); 148 107 seperatingAxisInBBatch[numSampleDirections] = norm * transB.getBasis(); … … 161 120 convexB->getPreferredPenetrationDirection(i,norm); 162 121 norm = transB.getBasis() * norm; 163 sPenetrationDirections[numSampleDirections] = norm;122 getPenetrationDirections()[numSampleDirections] = norm; 164 123 seperatingAxisInABatch[numSampleDirections] = (-norm) * transA.getBasis(); 165 124 seperatingAxisInBBatch[numSampleDirections] = norm * transB.getBasis(); … … 171 130 172 131 132 173 133 convexA->batchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInABatch,supportVerticesABatch,numSampleDirections); 174 134 convexB->batchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInBBatch,supportVerticesBBatch,numSampleDirections); … … 176 136 for (i=0;i<numSampleDirections;i++) 177 137 { 178 const btVector3& norm = sPenetrationDirections[i]; 179 seperatingAxisInA = seperatingAxisInABatch[i]; 180 seperatingAxisInB = seperatingAxisInBBatch[i]; 181 182 pInA = supportVerticesABatch[i]; 183 qInB = supportVerticesBBatch[i]; 184 185 pWorld = transA(pInA); 186 qWorld = transB(qInB); 187 w = qWorld - pWorld; 188 btScalar delta = norm.dot(w); 189 //find smallest delta 190 if (delta < minProj) 191 { 192 minProj = delta; 193 minNorm = norm; 194 minA = pWorld; 195 minB = qWorld; 138 btVector3 norm = getPenetrationDirections()[i]; 139 if (check2d) 140 { 141 norm[2] = 0.f; 142 } 143 if (norm.length2()>0.01) 144 { 145 146 seperatingAxisInA = seperatingAxisInABatch[i]; 147 seperatingAxisInB = seperatingAxisInBBatch[i]; 148 149 pInA = supportVerticesABatch[i]; 150 qInB = supportVerticesBBatch[i]; 151 152 pWorld = transA(pInA); 153 qWorld = transB(qInB); 154 if (check2d) 155 { 156 pWorld[2] = 0.f; 157 qWorld[2] = 0.f; 158 } 159 160 w = qWorld - pWorld; 161 btScalar delta = norm.dot(w); 162 //find smallest delta 163 if (delta < minProj) 164 { 165 minProj = delta; 166 minNorm = norm; 167 minA = pWorld; 168 minB = qWorld; 169 } 196 170 } 197 171 } … … 210 184 convexA->getPreferredPenetrationDirection(i,norm); 211 185 norm = transA.getBasis() * norm; 212 sPenetrationDirections[numSampleDirections] = norm;186 getPenetrationDirections()[numSampleDirections] = norm; 213 187 numSampleDirections++; 214 188 } … … 225 199 convexB->getPreferredPenetrationDirection(i,norm); 226 200 norm = transB.getBasis() * norm; 227 sPenetrationDirections[numSampleDirections] = norm;201 getPenetrationDirections()[numSampleDirections] = norm; 228 202 numSampleDirections++; 229 203 } … … 234 208 for (int i=0;i<numSampleDirections;i++) 235 209 { 236 const btVector3& norm = sPenetrationDirections[i];210 const btVector3& norm = getPenetrationDirections()[i]; 237 211 seperatingAxisInA = (-norm)* transA.getBasis(); 238 212 seperatingAxisInB = norm* transB.getBasis(); … … 262 236 return false; 263 237 264 minProj += (convexA->getMarginNonVirtual() + convexB->getMarginNonVirtual()); 238 btScalar extraSeparation = 0.5f;///scale dependent 239 minProj += extraSeparation+(convexA->getMarginNonVirtual() + convexB->getMarginNonVirtual()); 265 240 266 241 … … 300 275 input.m_transformA = displacedTrans; 301 276 input.m_transformB = transB; 302 input.m_maximumDistanceSquared = btScalar( 1e30);//minProj;277 input.m_maximumDistanceSquared = btScalar(BT_LARGE_FLOAT);//minProj; 303 278 304 279 btIntermediateResult res; 280 gjkdet.setCachedSeperatingAxis(-minNorm); 305 281 gjkdet.getClosestPoints(input,res,debugDraw); 306 282 … … 311 287 btScalar penetration_relaxation= btScalar(1.); 312 288 minNorm*=penetration_relaxation; 289 313 290 314 291 if (res.m_hasResult) … … 317 294 pa = res.m_pointInWorld - minNorm * correctedMinNorm; 318 295 pb = res.m_pointInWorld; 296 v = minNorm; 319 297 320 298 #ifdef DEBUG_DRAW … … 331 309 } 332 310 333 334 311 btVector3* btMinkowskiPenetrationDepthSolver::getPenetrationDirections() 312 { 313 static btVector3 sPenetrationDirections[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] = 314 { 315 btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)), 316 btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)), 317 btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)), 318 btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)), 319 btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)), 320 btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)), 321 btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)), 322 btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)), 323 btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)), 324 btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)), 325 btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)), 326 btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)), 327 btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)), 328 btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)), 329 btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)), 330 btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)), 331 btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)), 332 btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)), 333 btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)), 334 btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)), 335 btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)), 336 btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)), 337 btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)), 338 btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)), 339 btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)), 340 btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)), 341 btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)), 342 btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)), 343 btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)), 344 btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)), 345 btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)), 346 btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)), 347 btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)), 348 btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)), 349 btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)), 350 btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)), 351 btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)), 352 btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)), 353 btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)), 354 btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)), 355 btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)), 356 btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654)) 357 }; 358 359 return sPenetrationDirections; 360 } 361 362
Note: See TracChangeset
for help on using the changeset viewer.