- Timestamp:
- Feb 27, 2011, 7:43:24 AM (14 years ago)
- Location:
- code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch
- Files:
-
- 6 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp
r5781 r7983 38 38 btScalar timeOfImpact = btScalar(1.); 39 39 btScalar depth = btScalar(0.); 40 // output.m_distance = btScalar( 1e30);40 // output.m_distance = btScalar(BT_LARGE_FLOAT); 41 41 //move sphere into triangle space 42 42 btTransform sphereInTr = transformB.inverseTimes(transformA); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.h
r5781 r7983 35 35 virtual ~SphereTriangleDetector() {}; 36 36 37 bool collide(const btVector3& sphereCenter,btVector3 &point, btVector3& resultNormal, btScalar& depth, btScalar &timeOfImpact, btScalar contactBreakingThreshold); 38 37 39 private: 38 40 39 bool collide(const btVector3& sphereCenter,btVector3 &point, btVector3& resultNormal, btScalar& depth, btScalar &timeOfImpact, btScalar contactBreakingThreshold);41 40 42 bool pointInTriangle(const btVector3 vertices[], const btVector3 &normal, btVector3 *p ); 41 43 bool facecontains(const btVector3 &p,const btVector3* vertices,btVector3& normal); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp
r5781 r7983 62 62 63 63 btDiscreteCollisionDetectorInterface::ClosestPointInput input; 64 input.m_maximumDistanceSquared = 1e30f;64 input.m_maximumDistanceSquared = BT_LARGE_FLOAT; 65 65 input.m_transformA = body0->getWorldTransform(); 66 66 input.m_transformB = body1->getWorldTransform(); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp
r5781 r7983 1 2 1 /* 3 2 * Box-Box collision detection re-distributed under the ZLib license with permission from Russell L. Smith … … 213 212 } else 214 213 { 215 a= 1e30f;214 a=BT_LARGE_FLOAT; 216 215 } 217 216 cx = a*(cx + q*(p[n*2-2]+p[0])); … … 268 267 { 269 268 const btScalar fudge_factor = btScalar(1.05); 270 btVector3 p,pp,normalC ;269 btVector3 p,pp,normalC(0.f,0.f,0.f); 271 270 const btScalar *normalR = 0; 272 271 btScalar A[3],B[3],R11,R12,R13,R21,R22,R23,R31,R32,R33, … … 334 333 #define TST(expr1,expr2,n1,n2,n3,cc) \ 335 334 s2 = btFabs(expr1) - (expr2); \ 336 if (s2 > 0) return 0; \335 if (s2 > SIMD_EPSILON) return 0; \ 337 336 l = btSqrt((n1)*(n1) + (n2)*(n2) + (n3)*(n3)); \ 338 if (l > 0) { \337 if (l > SIMD_EPSILON) { \ 339 338 s2 /= l; \ 340 339 if (s2*fudge_factor > s) { \ … … 346 345 } \ 347 346 } 347 348 btScalar fudge2 (1.0e-5f); 349 350 Q11 += fudge2; 351 Q12 += fudge2; 352 Q13 += fudge2; 353 354 Q21 += fudge2; 355 Q22 += fudge2; 356 Q23 += fudge2; 357 358 Q31 += fudge2; 359 Q32 += fudge2; 360 Q33 += fudge2; 348 361 349 362 // separating axis = u1 x (v1,v2,v3) … … 425 438 #else 426 439 output.addContactPoint(-normal,pb,-*depth); 440 427 441 #endif // 428 442 *return_code = code; … … 594 608 595 609 if (cnum <= maxc) { 610 611 if (code<4) 612 { 596 613 // we have less contacts than we need, so we use them all 597 for (j=0; j < cnum; j++) { 598 599 //AddContactPoint... 600 601 //dContactGeom *con = CONTACT(contact,skip*j); 602 //for (i=0; i<3; i++) con->pos[i] = point[j*3+i] + pa[i]; 603 //con->depth = dep[j]; 604 614 for (j=0; j < cnum; j++) 615 { 605 616 btVector3 pointInWorld; 606 617 for (i=0; i<3; i++) … … 609 620 610 621 } 622 } else 623 { 624 // we have less contacts than we need, so we use them all 625 for (j=0; j < cnum; j++) 626 { 627 btVector3 pointInWorld; 628 for (i=0; i<3; i++) 629 pointInWorld[i] = point[j*3+i] + pa[i]-normal[i]*dep[j]; 630 //pointInWorld[i] = point[j*3+i] + pa[i]; 631 output.addContactPoint(-normal,pointInWorld,-dep[j]); 632 } 633 } 611 634 } 612 635 else { … … 633 656 for (i=0; i<3; i++) 634 657 posInWorld[i] = point[iret[j]*3+i] + pa[i]; 635 output.addContactPoint(-normal,posInWorld,-dep[iret[j]]); 658 if (code<4) 659 { 660 output.addContactPoint(-normal,posInWorld,-dep[iret[j]]); 661 } else 662 { 663 output.addContactPoint(-normal,posInWorld-normal*dep[iret[j]],-dep[iret[j]]); 664 } 636 665 } 637 666 cnum = maxc; -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp
r5781 r7983 35 35 36 36 btCollisionDispatcher::btCollisionDispatcher (btCollisionConfiguration* collisionConfiguration): 37 m_count(0), 38 m_useIslands(true), 39 m_staticWarningReported(false), 37 m_dispatcherFlags(btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD), 40 38 m_collisionConfiguration(collisionConfiguration) 41 39 { … … 80 78 btCollisionObject* body1 = (btCollisionObject*)b1; 81 79 82 //test for Bullet 2.74: use a relative contact breaking threshold without clamping against 'gContactBreakingThreshold' 83 //btScalar contactBreakingThreshold = btMin(gContactBreakingThreshold,btMin(body0->getCollisionShape()->getContactBreakingThreshold(),body1->getCollisionShape()->getContactBreakingThreshold())); 84 btScalar contactBreakingThreshold = btMin(body0->getCollisionShape()->getContactBreakingThreshold(),body1->getCollisionShape()->getContactBreakingThreshold()); 80 //optional relative contact breaking threshold, turned on by default (use setDispatcherFlags to switch off feature for improved performance) 81 82 btScalar contactBreakingThreshold = (m_dispatcherFlags & btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD) ? 83 btMin(body0->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold) , body1->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold)) 84 : gContactBreakingThreshold ; 85 85 86 86 btScalar contactProcessingThreshold = btMin(body0->getContactProcessingThreshold(),body1->getContactProcessingThreshold()); … … 170 170 171 171 #ifdef BT_DEBUG 172 if (! m_staticWarningReported)172 if (!(m_dispatcherFlags & btCollisionDispatcher::CD_STATIC_STATIC_REPORTED)) 173 173 { 174 174 //broadphase filtering already deals with this … … 176 176 (body1->isStaticObject() || body1->isKinematicObject())) 177 177 { 178 m_ staticWarningReported = true;178 m_dispatcherFlags |= btCollisionDispatcher::CD_STATIC_STATIC_REPORTED; 179 179 printf("warning btCollisionDispatcher::needsCollision: static-static collision!\n"); 180 180 } -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.h
r5781 r7983 43 43 class btCollisionDispatcher : public btDispatcher 44 44 { 45 int m_count;45 int m_dispatcherFlags; 46 46 47 47 btAlignedObjectArray<btPersistentManifold*> m_manifoldsPtr; 48 48 49 bool m_useIslands;50 51 bool m_staticWarningReported;52 53 49 btManifoldResult m_defaultManifoldResult; 54 50 … … 60 56 61 57 btCollisionAlgorithmCreateFunc* m_doubleDispatch[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES]; 62 63 58 64 59 btCollisionConfiguration* m_collisionConfiguration; … … 66 61 67 62 public: 63 64 enum DispatcherFlags 65 { 66 CD_STATIC_STATIC_REPORTED = 1, 67 CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD = 2 68 }; 69 70 int getDispatcherFlags() const 71 { 72 return m_dispatcherFlags; 73 } 74 75 void setDispatcherFlags(int flags) 76 { 77 (void) flags; 78 m_dispatcherFlags = 0; 79 } 68 80 69 81 ///registerCollisionCreateFunc allows registration of custom/alternative collision create functions -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionObject.cpp
r5781 r7983 16 16 17 17 #include "btCollisionObject.h" 18 #include "LinearMath/btSerializer.h" 18 19 19 20 btCollisionObject::btCollisionObject() 20 21 : m_anisotropicFriction(1.f,1.f,1.f), 21 22 m_hasAnisotropicFriction(false), 22 m_contactProcessingThreshold( 1e30f),23 m_contactProcessingThreshold(BT_LARGE_FLOAT), 23 24 m_broadphaseHandle(0), 24 25 m_collisionShape(0), 26 m_extensionPointer(0), 25 27 m_rootCollisionShape(0), 26 28 m_collisionFlags(btCollisionObject::CF_STATIC_OBJECT), … … 31 33 m_friction(btScalar(0.5)), 32 34 m_restitution(btScalar(0.)), 35 m_internalType(CO_COLLISION_OBJECT), 33 36 m_userObjectPointer(0), 34 m_internalType(CO_COLLISION_OBJECT),35 37 m_hitFraction(btScalar(1.)), 36 38 m_ccdSweptSphereRadius(btScalar(0.)), … … 38 40 m_checkCollideWith(false) 39 41 { 40 42 m_worldTransform.setIdentity(); 41 43 } 42 44 … … 65 67 } 66 68 69 const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* serializer) const 70 { 71 72 btCollisionObjectData* dataOut = (btCollisionObjectData*)dataBuffer; 73 74 m_worldTransform.serialize(dataOut->m_worldTransform); 75 m_interpolationWorldTransform.serialize(dataOut->m_interpolationWorldTransform); 76 m_interpolationLinearVelocity.serialize(dataOut->m_interpolationLinearVelocity); 77 m_interpolationAngularVelocity.serialize(dataOut->m_interpolationAngularVelocity); 78 m_anisotropicFriction.serialize(dataOut->m_anisotropicFriction); 79 dataOut->m_hasAnisotropicFriction = m_hasAnisotropicFriction; 80 dataOut->m_contactProcessingThreshold = m_contactProcessingThreshold; 81 dataOut->m_broadphaseHandle = 0; 82 dataOut->m_collisionShape = serializer->getUniquePointer(m_collisionShape); 83 dataOut->m_rootCollisionShape = 0;//@todo 84 dataOut->m_collisionFlags = m_collisionFlags; 85 dataOut->m_islandTag1 = m_islandTag1; 86 dataOut->m_companionId = m_companionId; 87 dataOut->m_activationState1 = m_activationState1; 88 dataOut->m_activationState1 = m_activationState1; 89 dataOut->m_deactivationTime = m_deactivationTime; 90 dataOut->m_friction = m_friction; 91 dataOut->m_restitution = m_restitution; 92 dataOut->m_internalType = m_internalType; 93 94 char* name = (char*) serializer->findNameForPointer(this); 95 dataOut->m_name = (char*)serializer->getUniquePointer(name); 96 if (dataOut->m_name) 97 { 98 serializer->serializeName(name); 99 } 100 dataOut->m_hitFraction = m_hitFraction; 101 dataOut->m_ccdSweptSphereRadius = m_ccdSweptSphereRadius; 102 dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold; 103 dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold; 104 dataOut->m_checkCollideWith = m_checkCollideWith; 105 106 return btCollisionObjectDataName; 107 } 67 108 68 109 110 void btCollisionObject::serializeSingleObject(class btSerializer* serializer) const 111 { 112 int len = calculateSerializeBufferSize(); 113 btChunk* chunk = serializer->allocate(len,1); 114 const char* structType = serialize(chunk->m_oldPtr, serializer); 115 serializer->finalizeChunk(chunk,structType,BT_COLLISIONOBJECT_CODE,(void*)this); 116 } -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionObject.h
r5781 r7983 28 28 struct btBroadphaseProxy; 29 29 class btCollisionShape; 30 struct btCollisionShapeData; 30 31 #include "LinearMath/btMotionState.h" 31 32 #include "LinearMath/btAlignedAllocator.h" 32 33 #include "LinearMath/btAlignedObjectArray.h" 33 34 34 35 35 typedef btAlignedObjectArray<class btCollisionObject*> btCollisionObjectArray; 36 37 #ifdef BT_USE_DOUBLE_PRECISION 38 #define btCollisionObjectData btCollisionObjectDoubleData 39 #define btCollisionObjectDataName "btCollisionObjectDoubleData" 40 #else 41 #define btCollisionObjectData btCollisionObjectFloatData 42 #define btCollisionObjectDataName "btCollisionObjectFloatData" 43 #endif 36 44 37 45 … … 54 62 btVector3 m_interpolationAngularVelocity; 55 63 56 btVector3 57 boolm_hasAnisotropicFriction;58 btScalar 64 btVector3 m_anisotropicFriction; 65 int m_hasAnisotropicFriction; 66 btScalar m_contactProcessingThreshold; 59 67 60 68 btBroadphaseProxy* m_broadphaseHandle; 61 69 btCollisionShape* m_collisionShape; 70 ///m_extensionPointer is used by some internal low-level Bullet extensions. 71 void* m_extensionPointer; 62 72 63 73 ///m_rootCollisionShape is temporarily used to store the original collision shape … … 77 87 btScalar m_restitution; 78 88 79 ///users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPointer80 void* m_userObjectPointer;81 82 89 ///m_internalType is reserved to distinguish Bullet's btCollisionObject, btRigidBody, btSoftBody, btGhostObject etc. 83 90 ///do not assign your own m_internalType unless you write a new dynamics object class. 84 91 int m_internalType; 85 92 93 ///users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPointer 94 void* m_userObjectPointer; 95 86 96 ///time of impact calculation 87 97 btScalar m_hitFraction; … … 94 104 95 105 /// If some object should have elaborate collision filtering by sub-classes 96 bool m_checkCollideWith; 97 98 char m_pad[7]; 106 int m_checkCollideWith; 99 107 100 108 virtual bool checkCollideWithOverride(btCollisionObject* /* co */) … … 113 121 CF_NO_CONTACT_RESPONSE = 4, 114 122 CF_CUSTOM_MATERIAL_CALLBACK = 8,//this allows per-triangle material (friction/restitution) 115 CF_CHARACTER_OBJECT = 16 123 CF_CHARACTER_OBJECT = 16, 124 CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing 125 CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing 116 126 }; 117 127 … … 119 129 { 120 130 CO_COLLISION_OBJECT =1, 121 CO_RIGID_BODY ,131 CO_RIGID_BODY=2, 122 132 ///CO_GHOST_OBJECT keeps track of all objects overlapping its AABB and that pass its collision filter 123 133 ///It is useful for collision sensors, explosion objects, character controller etc. 124 CO_GHOST_OBJECT, 125 CO_SOFT_BODY, 126 CO_HF_FLUID 134 CO_GHOST_OBJECT=4, 135 CO_SOFT_BODY=8, 136 CO_HF_FLUID=16, 137 CO_USER_TYPE=32 127 138 }; 128 139 … … 144 155 bool hasAnisotropicFriction() const 145 156 { 146 return m_hasAnisotropicFriction ;157 return m_hasAnisotropicFriction!=0; 147 158 } 148 159 … … 214 225 } 215 226 227 ///Avoid using this internal API call, the extension pointer is used by some Bullet extensions. 228 ///If you need to store your own user pointer, use 'setUserPointer/getUserPointer' instead. 229 void* internalGetExtensionPointer() const 230 { 231 return m_extensionPointer; 232 } 233 ///Avoid using this internal API call, the extension pointer is used by some Bullet extensions 234 ///If you need to store your own user pointer, use 'setUserPointer/getUserPointer' instead. 235 void internalSetExtensionPointer(void* pointer) 236 { 237 m_extensionPointer = pointer; 238 } 239 216 240 SIMD_FORCE_INLINE int getActivationState() const { return m_activationState1;} 217 241 … … 394 418 void setCcdMotionThreshold(btScalar ccdMotionThreshold) 395 419 { 396 m_ccdMotionThreshold = ccdMotionThreshold *ccdMotionThreshold;420 m_ccdMotionThreshold = ccdMotionThreshold; 397 421 } 398 422 … … 417 441 return true; 418 442 } 443 444 virtual int calculateSerializeBufferSize() const; 445 446 ///fills the dataBuffer and returns the struct name (and 0 on failure) 447 virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const; 448 449 virtual void serializeSingleObject(class btSerializer* serializer) const; 450 419 451 }; 420 452 453 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 454 struct btCollisionObjectDoubleData 455 { 456 void *m_broadphaseHandle; 457 void *m_collisionShape; 458 btCollisionShapeData *m_rootCollisionShape; 459 char *m_name; 460 461 btTransformDoubleData m_worldTransform; 462 btTransformDoubleData m_interpolationWorldTransform; 463 btVector3DoubleData m_interpolationLinearVelocity; 464 btVector3DoubleData m_interpolationAngularVelocity; 465 btVector3DoubleData m_anisotropicFriction; 466 double m_contactProcessingThreshold; 467 double m_deactivationTime; 468 double m_friction; 469 double m_restitution; 470 double m_hitFraction; 471 double m_ccdSweptSphereRadius; 472 double m_ccdMotionThreshold; 473 474 int m_hasAnisotropicFriction; 475 int m_collisionFlags; 476 int m_islandTag1; 477 int m_companionId; 478 int m_activationState1; 479 int m_internalType; 480 int m_checkCollideWith; 481 482 char m_padding[4]; 483 }; 484 485 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 486 struct btCollisionObjectFloatData 487 { 488 void *m_broadphaseHandle; 489 void *m_collisionShape; 490 btCollisionShapeData *m_rootCollisionShape; 491 char *m_name; 492 493 btTransformFloatData m_worldTransform; 494 btTransformFloatData m_interpolationWorldTransform; 495 btVector3FloatData m_interpolationLinearVelocity; 496 btVector3FloatData m_interpolationAngularVelocity; 497 btVector3FloatData m_anisotropicFriction; 498 float m_contactProcessingThreshold; 499 float m_deactivationTime; 500 float m_friction; 501 float m_restitution; 502 float m_hitFraction; 503 float m_ccdSweptSphereRadius; 504 float m_ccdMotionThreshold; 505 506 int m_hasAnisotropicFriction; 507 int m_collisionFlags; 508 int m_islandTag1; 509 int m_companionId; 510 int m_activationState1; 511 int m_internalType; 512 int m_checkCollideWith; 513 }; 514 515 516 517 SIMD_FORCE_INLINE int btCollisionObject::calculateSerializeBufferSize() const 518 { 519 return sizeof(btCollisionObjectData); 520 } 521 522 523 421 524 #endif //COLLISION_OBJECT_H -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
r5781 r7983 27 27 #include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h" 28 28 #include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h" 29 29 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h" 30 30 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h" 31 31 #include "LinearMath/btAabbUtil2.h" 32 32 #include "LinearMath/btQuickprof.h" 33 33 #include "LinearMath/btStackAlloc.h" 34 #include "LinearMath/btSerializer.h" 34 35 35 36 //#define USE_BRUTEFORCE_RAYBROADPHASE 1 … … 43 44 44 45 46 ///for debug drawing 47 48 //for debug rendering 49 #include "BulletCollision/CollisionShapes/btBoxShape.h" 50 #include "BulletCollision/CollisionShapes/btCapsuleShape.h" 51 #include "BulletCollision/CollisionShapes/btCompoundShape.h" 52 #include "BulletCollision/CollisionShapes/btConeShape.h" 53 #include "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h" 54 #include "BulletCollision/CollisionShapes/btCylinderShape.h" 55 #include "BulletCollision/CollisionShapes/btMultiSphereShape.h" 56 #include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h" 57 #include "BulletCollision/CollisionShapes/btSphereShape.h" 58 #include "BulletCollision/CollisionShapes/btTriangleCallback.h" 59 #include "BulletCollision/CollisionShapes/btTriangleMeshShape.h" 60 #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h" 61 62 63 45 64 btCollisionWorld::btCollisionWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache, btCollisionConfiguration* collisionConfiguration) 46 65 :m_dispatcher1(dispatcher), 47 66 m_broadphasePairCache(pairCache), 48 m_debugDrawer(0) 67 m_debugDrawer(0), 68 m_forceUpdateAllAabbs(true) 49 69 { 50 70 m_stackAlloc = collisionConfiguration->getStackAllocator(); … … 89 109 { 90 110 111 btAssert(collisionObject); 112 91 113 //check that the object isn't already added 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 114 btAssert( m_collisionObjects.findLinearSearch(collisionObject) == m_collisionObjects.size()); 115 116 m_collisionObjects.push_back(collisionObject); 117 118 //calculate new AABB 119 btTransform trans = collisionObject->getWorldTransform(); 120 121 btVector3 minAabb; 122 btVector3 maxAabb; 123 collisionObject->getCollisionShape()->getAabb(trans,minAabb,maxAabb); 124 125 int type = collisionObject->getCollisionShape()->getShapeType(); 126 collisionObject->setBroadphaseHandle( getBroadphase()->createProxy( 127 minAabb, 128 maxAabb, 129 type, 130 collisionObject, 131 collisionFilterGroup, 132 collisionFilterMask, 133 m_dispatcher1,0 134 )) ; 113 135 114 136 … … 163 185 164 186 //only update aabb of active objects 165 if ( colObj->isActive())187 if (m_forceUpdateAllAabbs || colObj->isActive()) 166 188 { 167 189 updateSingleAabb(colObj); … … 226 248 227 249 void btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTransform& rayToTrans, 228 229 230 231 250 btCollisionObject* collisionObject, 251 const btCollisionShape* collisionShape, 252 const btTransform& colObjWorldTransform, 253 RayResultCallback& resultCallback) 232 254 { 233 255 btSphereShape pointShape(btScalar(0.0)); … … 237 259 if (collisionShape->isConvex()) 238 260 { 239 // BT_PROFILE("rayTestConvex");261 // BT_PROFILE("rayTestConvex"); 240 262 btConvexCast::CastResult castResult; 241 263 castResult.m_fraction = resultCallback.m_closestHitFraction; … … 266 288 btCollisionWorld::LocalRayResult localRayResult 267 289 ( 268 269 270 271 290 collisionObject, 291 0, 292 castResult.m_normal, 293 castResult.m_fraction 272 294 ); 273 295 … … 281 303 if (collisionShape->isConcave()) 282 304 { 283 // BT_PROFILE("rayTestConcave");305 // BT_PROFILE("rayTestConcave"); 284 306 if (collisionShape->getShapeType()==TRIANGLE_MESH_SHAPE_PROXYTYPE) 285 307 { … … 297 319 btTriangleMeshShape* m_triangleMesh; 298 320 321 btTransform m_colObjWorldTransform; 322 299 323 BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to, 300 btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh): 301 //@BP Mod 302 btTriangleRaycastCallback(from,to, resultCallback->m_flags), 303 m_resultCallback(resultCallback), 304 m_collisionObject(collisionObject), 305 m_triangleMesh(triangleMesh) 306 { 307 } 324 btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh,const btTransform& colObjWorldTransform): 325 //@BP Mod 326 btTriangleRaycastCallback(from,to, resultCallback->m_flags), 327 m_resultCallback(resultCallback), 328 m_collisionObject(collisionObject), 329 m_triangleMesh(triangleMesh), 330 m_colObjWorldTransform(colObjWorldTransform) 331 { 332 } 308 333 309 334 … … 314 339 shapeInfo.m_triangleIndex = triangleIndex; 315 340 341 btVector3 hitNormalWorld = m_colObjWorldTransform.getBasis() * hitNormalLocal; 342 316 343 btCollisionWorld::LocalRayResult rayResult 317 (m_collisionObject,344 (m_collisionObject, 318 345 &shapeInfo, 319 hitNormal Local,346 hitNormalWorld, 320 347 hitFraction); 321 348 322 bool normalInWorldSpace = false;349 bool normalInWorldSpace = true; 323 350 return m_resultCallback->addSingleResult(rayResult,normalInWorldSpace); 324 351 } … … 326 353 }; 327 354 328 BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,triangleMesh );355 BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,triangleMesh,colObjWorldTransform); 329 356 rcb.m_hitFraction = resultCallback.m_closestHitFraction; 330 357 triangleMesh->performRaycast(&rcb,rayFromLocal,rayToLocal); … … 347 374 btConcaveShape* m_triangleMesh; 348 375 376 btTransform m_colObjWorldTransform; 377 349 378 BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to, 350 btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape* triangleMesh): 351 //@BP Mod 352 btTriangleRaycastCallback(from,to, resultCallback->m_flags), 353 m_resultCallback(resultCallback), 354 m_collisionObject(collisionObject), 355 m_triangleMesh(triangleMesh) 356 { 357 } 379 btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape* triangleMesh, const btTransform& colObjWorldTransform): 380 //@BP Mod 381 btTriangleRaycastCallback(from,to, resultCallback->m_flags), 382 m_resultCallback(resultCallback), 383 m_collisionObject(collisionObject), 384 m_triangleMesh(triangleMesh), 385 m_colObjWorldTransform(colObjWorldTransform) 386 { 387 } 358 388 359 389 … … 364 394 shapeInfo.m_triangleIndex = triangleIndex; 365 395 396 btVector3 hitNormalWorld = m_colObjWorldTransform.getBasis() * hitNormalLocal; 397 366 398 btCollisionWorld::LocalRayResult rayResult 367 (m_collisionObject,399 (m_collisionObject, 368 400 &shapeInfo, 369 hitNormal Local,401 hitNormalWorld, 370 402 hitFraction); 371 403 372 bool normalInWorldSpace = false;404 bool normalInWorldSpace = true; 373 405 return m_resultCallback->addSingleResult(rayResult,normalInWorldSpace); 374 375 376 406 } 377 407 … … 379 409 380 410 381 BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,concaveShape );411 BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,concaveShape, colObjWorldTransform); 382 412 rcb.m_hitFraction = resultCallback.m_closestHitFraction; 383 413 … … 390 420 } 391 421 } else { 392 // BT_PROFILE("rayTestCompound");422 // BT_PROFILE("rayTestCompound"); 393 423 ///@todo: use AABB tree or other BVH acceleration structure, see btDbvt 394 424 if (collisionShape->isCompound()) … … 404 434 btCollisionShape* saveCollisionShape = collisionObject->getCollisionShape(); 405 435 collisionObject->internalSetTemporaryCollisionShape((btCollisionShape*)childCollisionShape); 436 struct LocalInfoAdder2 : public RayResultCallback { 437 RayResultCallback* m_userCallback; 438 int m_i; 439 LocalInfoAdder2 (int i, RayResultCallback *user) 440 : m_userCallback(user), 441 m_i(i) 442 { 443 m_closestHitFraction = m_userCallback->m_closestHitFraction; 444 } 445 virtual btScalar addSingleResult (btCollisionWorld::LocalRayResult &r, bool b) 446 { 447 btCollisionWorld::LocalShapeInfo shapeInfo; 448 shapeInfo.m_shapePart = -1; 449 shapeInfo.m_triangleIndex = m_i; 450 if (r.m_localShapeInfo == NULL) 451 r.m_localShapeInfo = &shapeInfo; 452 453 const btScalar result = m_userCallback->addSingleResult(r, b); 454 m_closestHitFraction = m_userCallback->m_closestHitFraction; 455 return result; 456 } 457 }; 458 459 LocalInfoAdder2 my_cb(i, &resultCallback); 460 406 461 rayTestSingle(rayFromTrans,rayToTrans, 407 462 collisionObject, 408 463 childCollisionShape, 409 464 childWorldTrans, 410 resultCallback);465 my_cb); 411 466 // restore 412 467 collisionObject->internalSetTemporaryCollisionShape(saveCollisionShape); … … 418 473 419 474 void btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const btTransform& convexFromTrans,const btTransform& convexToTrans, 420 421 422 423 475 btCollisionObject* collisionObject, 476 const btCollisionShape* collisionShape, 477 const btTransform& colObjWorldTransform, 478 ConvexResultCallback& resultCallback, btScalar allowedPenetration) 424 479 { 425 480 if (collisionShape->isConvex()) … … 433 488 btVoronoiSimplexSolver simplexSolver; 434 489 btGjkEpaPenetrationDepthSolver gjkEpaPenetrationSolver; 435 490 436 491 btContinuousConvexCollision convexCaster1(castShape,convexShape,&simplexSolver,&gjkEpaPenetrationSolver); 437 492 //btGjkConvexCast convexCaster2(castShape,convexShape,&simplexSolver); … … 439 494 440 495 btConvexCast* castPtr = &convexCaster1; 441 442 443 496 497 498 444 499 if (castPtr->calcTimeOfImpact(convexFromTrans,convexToTrans,colObjWorldTransform,colObjWorldTransform,castResult)) 445 500 { … … 451 506 castResult.m_normal.normalize(); 452 507 btCollisionWorld::LocalConvexResult localConvexResult 453 454 455 456 457 458 459 508 ( 509 collisionObject, 510 0, 511 castResult.m_normal, 512 castResult.m_hitPoint, 513 castResult.m_fraction 514 ); 460 515 461 516 bool normalInWorldSpace = true; … … 487 542 BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to, 488 543 btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh, const btTransform& triangleToWorld): 489 490 491 492 493 494 544 btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()), 545 m_resultCallback(resultCallback), 546 m_collisionObject(collisionObject), 547 m_triangleMesh(triangleMesh) 548 { 549 } 495 550 496 551 … … 504 559 505 560 btCollisionWorld::LocalConvexResult convexResult 506 (m_collisionObject,561 (m_collisionObject, 507 562 &shapeInfo, 508 563 hitNormalLocal, … … 544 599 BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to, 545 600 btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape* triangleMesh, const btTransform& triangleToWorld): 546 547 548 549 550 551 601 btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()), 602 m_resultCallback(resultCallback), 603 m_collisionObject(collisionObject), 604 m_triangleMesh(triangleMesh) 605 { 606 } 552 607 553 608 … … 561 616 562 617 btCollisionWorld::LocalConvexResult convexResult 563 (m_collisionObject,618 (m_collisionObject, 564 619 &shapeInfo, 565 620 hitNormalLocal, … … 604 659 btCollisionShape* saveCollisionShape = collisionObject->getCollisionShape(); 605 660 collisionObject->internalSetTemporaryCollisionShape((btCollisionShape*)childCollisionShape); 661 struct LocalInfoAdder : public ConvexResultCallback { 662 ConvexResultCallback* m_userCallback; 663 int m_i; 664 665 LocalInfoAdder (int i, ConvexResultCallback *user) 666 : m_userCallback(user), m_i(i) 667 { 668 m_closestHitFraction = m_userCallback->m_closestHitFraction; 669 } 670 virtual btScalar addSingleResult (btCollisionWorld::LocalConvexResult& r, bool b) 671 { 672 btCollisionWorld::LocalShapeInfo shapeInfo; 673 shapeInfo.m_shapePart = -1; 674 shapeInfo.m_triangleIndex = m_i; 675 if (r.m_localShapeInfo == NULL) 676 r.m_localShapeInfo = &shapeInfo; 677 const btScalar result = m_userCallback->addSingleResult(r, b); 678 m_closestHitFraction = m_userCallback->m_closestHitFraction; 679 return result; 680 681 } 682 }; 683 684 LocalInfoAdder my_cb(i, &resultCallback); 685 686 606 687 objectQuerySingle(castShape, convexFromTrans,convexToTrans, 607 688 collisionObject, 608 689 childCollisionShape, 609 690 childWorldTrans, 610 resultCallback, allowedPenetration);691 my_cb, allowedPenetration); 611 692 // restore 612 693 collisionObject->internalSetTemporaryCollisionShape(saveCollisionShape); … … 631 712 632 713 btSingleRayCallback(const btVector3& rayFromWorld,const btVector3& rayToWorld,const btCollisionWorld* world,btCollisionWorld::RayResultCallback& resultCallback) 633 :m_rayFromWorld(rayFromWorld),634 m_rayToWorld(rayToWorld),635 m_world(world),636 m_resultCallback(resultCallback)714 :m_rayFromWorld(rayFromWorld), 715 m_rayToWorld(rayToWorld), 716 m_world(world), 717 m_resultCallback(resultCallback) 637 718 { 638 719 m_rayFromTrans.setIdentity(); … … 644 725 645 726 rayDir.normalize (); 646 ///what about division by zero? --> just set rayDirection[i] to INF/ 1e30647 m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[0];648 m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[1];649 m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[2];727 ///what about division by zero? --> just set rayDirection[i] to INF/BT_LARGE_FLOAT 728 m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0]; 729 m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1]; 730 m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2]; 650 731 m_signs[0] = m_rayDirectionInverse[0] < 0.0; 651 732 m_signs[1] = m_rayDirectionInverse[1] < 0.0; … … 656 737 } 657 738 658 739 659 740 660 741 virtual bool process(const btBroadphaseProxy* proxy) … … 687 768 m_world->rayTestSingle(m_rayFromTrans,m_rayToTrans, 688 769 collisionObject, 689 690 691 770 collisionObject->getCollisionShape(), 771 collisionObject->getWorldTransform(), 772 m_resultCallback); 692 773 } 693 774 } … … 698 779 void btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const 699 780 { 700 BT_PROFILE("rayTest");781 //BT_PROFILE("rayTest"); 701 782 /// use the broadphase to accelerate the search for objects, based on their aabb 702 783 /// and for each object with ray-aabb overlap, perform an exact ray test … … 737 818 btVector3 unnormalizedRayDir = (m_convexToTrans.getOrigin()-m_convexFromTrans.getOrigin()); 738 819 btVector3 rayDir = unnormalizedRayDir.normalized(); 739 ///what about division by zero? --> just set rayDirection[i] to INF/ 1e30740 m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[0];741 m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[1];742 m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[2];820 ///what about division by zero? --> just set rayDirection[i] to INF/BT_LARGE_FLOAT 821 m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0]; 822 m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1]; 823 m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2]; 743 824 m_signs[0] = m_rayDirectionInverse[0] < 0.0; 744 825 m_signs[1] = m_rayDirectionInverse[1] < 0.0; … … 761 842 //RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject(); 762 843 m_world->objectQuerySingle(m_castShape, m_convexFromTrans,m_convexToTrans, 763 764 765 766 767 768 } 769 844 collisionObject, 845 collisionObject->getCollisionShape(), 846 collisionObject->getWorldTransform(), 847 m_resultCallback, 848 m_allowedCcdPenetration); 849 } 850 770 851 return true; 771 852 } … … 782 863 /// unfortunately the implementation for rayTest and convexSweepTest duplicated, albeit practically identical 783 864 784 865 785 866 786 867 btTransform convexFromTrans,convexToTrans; … … 825 906 objectQuerySingle(castShape, convexFromTrans,convexToTrans, 826 907 collisionObject, 827 828 829 830 908 collisionObject->getCollisionShape(), 909 collisionObject->getWorldTransform(), 910 resultCallback, 911 allowedCcdPenetration); 831 912 } 832 913 } … … 834 915 #endif //USE_BRUTEFORCE_RAYBROADPHASE 835 916 } 917 918 919 920 struct btBridgedManifoldResult : public btManifoldResult 921 { 922 923 btCollisionWorld::ContactResultCallback& m_resultCallback; 924 925 btBridgedManifoldResult( btCollisionObject* obj0,btCollisionObject* obj1,btCollisionWorld::ContactResultCallback& resultCallback ) 926 :btManifoldResult(obj0,obj1), 927 m_resultCallback(resultCallback) 928 { 929 } 930 931 virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth) 932 { 933 bool isSwapped = m_manifoldPtr->getBody0() != m_body0; 934 btVector3 pointA = pointInWorld + normalOnBInWorld * depth; 935 btVector3 localA; 936 btVector3 localB; 937 if (isSwapped) 938 { 939 localA = m_rootTransB.invXform(pointA ); 940 localB = m_rootTransA.invXform(pointInWorld); 941 } else 942 { 943 localA = m_rootTransA.invXform(pointA ); 944 localB = m_rootTransB.invXform(pointInWorld); 945 } 946 947 btManifoldPoint newPt(localA,localB,normalOnBInWorld,depth); 948 newPt.m_positionWorldOnA = pointA; 949 newPt.m_positionWorldOnB = pointInWorld; 950 951 //BP mod, store contact triangles. 952 if (isSwapped) 953 { 954 newPt.m_partId0 = m_partId1; 955 newPt.m_partId1 = m_partId0; 956 newPt.m_index0 = m_index1; 957 newPt.m_index1 = m_index0; 958 } else 959 { 960 newPt.m_partId0 = m_partId0; 961 newPt.m_partId1 = m_partId1; 962 newPt.m_index0 = m_index0; 963 newPt.m_index1 = m_index1; 964 } 965 966 //experimental feature info, for per-triangle material etc. 967 btCollisionObject* obj0 = isSwapped? m_body1 : m_body0; 968 btCollisionObject* obj1 = isSwapped? m_body0 : m_body1; 969 m_resultCallback.addSingleResult(newPt,obj0,newPt.m_partId0,newPt.m_index0,obj1,newPt.m_partId1,newPt.m_index1); 970 971 } 972 973 }; 974 975 976 977 struct btSingleContactCallback : public btBroadphaseAabbCallback 978 { 979 980 btCollisionObject* m_collisionObject; 981 btCollisionWorld* m_world; 982 btCollisionWorld::ContactResultCallback& m_resultCallback; 983 984 985 btSingleContactCallback(btCollisionObject* collisionObject, btCollisionWorld* world,btCollisionWorld::ContactResultCallback& resultCallback) 986 :m_collisionObject(collisionObject), 987 m_world(world), 988 m_resultCallback(resultCallback) 989 { 990 } 991 992 virtual bool process(const btBroadphaseProxy* proxy) 993 { 994 btCollisionObject* collisionObject = (btCollisionObject*)proxy->m_clientObject; 995 if (collisionObject == m_collisionObject) 996 return true; 997 998 //only perform raycast if filterMask matches 999 if(m_resultCallback.needsCollision(collisionObject->getBroadphaseHandle())) 1000 { 1001 btCollisionAlgorithm* algorithm = m_world->getDispatcher()->findAlgorithm(m_collisionObject,collisionObject); 1002 if (algorithm) 1003 { 1004 btBridgedManifoldResult contactPointResult(m_collisionObject,collisionObject, m_resultCallback); 1005 //discrete collision detection query 1006 algorithm->processCollision(m_collisionObject,collisionObject, m_world->getDispatchInfo(),&contactPointResult); 1007 1008 algorithm->~btCollisionAlgorithm(); 1009 m_world->getDispatcher()->freeCollisionAlgorithm(algorithm); 1010 } 1011 } 1012 return true; 1013 } 1014 }; 1015 1016 1017 ///contactTest performs a discrete collision test against all objects in the btCollisionWorld, and calls the resultCallback. 1018 ///it reports one or more contact points for every overlapping object (including the one with deepest penetration) 1019 void btCollisionWorld::contactTest( btCollisionObject* colObj, ContactResultCallback& resultCallback) 1020 { 1021 btVector3 aabbMin,aabbMax; 1022 colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(),aabbMin,aabbMax); 1023 btSingleContactCallback contactCB(colObj,this,resultCallback); 1024 1025 m_broadphasePairCache->aabbTest(aabbMin,aabbMax,contactCB); 1026 } 1027 1028 1029 ///contactTest performs a discrete collision test between two collision objects and calls the resultCallback if overlap if detected. 1030 ///it reports one or more contact points (including the one with deepest penetration) 1031 void btCollisionWorld::contactPairTest(btCollisionObject* colObjA, btCollisionObject* colObjB, ContactResultCallback& resultCallback) 1032 { 1033 btCollisionAlgorithm* algorithm = getDispatcher()->findAlgorithm(colObjA,colObjB); 1034 if (algorithm) 1035 { 1036 btBridgedManifoldResult contactPointResult(colObjA,colObjB, resultCallback); 1037 //discrete collision detection query 1038 algorithm->processCollision(colObjA,colObjB, getDispatchInfo(),&contactPointResult); 1039 1040 algorithm->~btCollisionAlgorithm(); 1041 getDispatcher()->freeCollisionAlgorithm(algorithm); 1042 } 1043 1044 } 1045 1046 1047 1048 1049 class DebugDrawcallback : public btTriangleCallback, public btInternalTriangleIndexCallback 1050 { 1051 btIDebugDraw* m_debugDrawer; 1052 btVector3 m_color; 1053 btTransform m_worldTrans; 1054 1055 public: 1056 1057 DebugDrawcallback(btIDebugDraw* debugDrawer,const btTransform& worldTrans,const btVector3& color) : 1058 m_debugDrawer(debugDrawer), 1059 m_color(color), 1060 m_worldTrans(worldTrans) 1061 { 1062 } 1063 1064 virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex) 1065 { 1066 processTriangle(triangle,partId,triangleIndex); 1067 } 1068 1069 virtual void processTriangle(btVector3* triangle,int partId, int triangleIndex) 1070 { 1071 (void)partId; 1072 (void)triangleIndex; 1073 1074 btVector3 wv0,wv1,wv2; 1075 wv0 = m_worldTrans*triangle[0]; 1076 wv1 = m_worldTrans*triangle[1]; 1077 wv2 = m_worldTrans*triangle[2]; 1078 btVector3 center = (wv0+wv1+wv2)*btScalar(1./3.); 1079 1080 btVector3 normal = (wv1-wv0).cross(wv2-wv0); 1081 normal.normalize(); 1082 btVector3 normalColor(1,1,0); 1083 m_debugDrawer->drawLine(center,center+normal,normalColor); 1084 1085 1086 1087 1088 m_debugDrawer->drawLine(wv0,wv1,m_color); 1089 m_debugDrawer->drawLine(wv1,wv2,m_color); 1090 m_debugDrawer->drawLine(wv2,wv0,m_color); 1091 } 1092 }; 1093 1094 1095 void btCollisionWorld::debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color) 1096 { 1097 // Draw a small simplex at the center of the object 1098 getDebugDrawer()->drawTransform(worldTransform,1); 1099 1100 if (shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE) 1101 { 1102 const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shape); 1103 for (int i=compoundShape->getNumChildShapes()-1;i>=0;i--) 1104 { 1105 btTransform childTrans = compoundShape->getChildTransform(i); 1106 const btCollisionShape* colShape = compoundShape->getChildShape(i); 1107 debugDrawObject(worldTransform*childTrans,colShape,color); 1108 } 1109 1110 } else 1111 { 1112 switch (shape->getShapeType()) 1113 { 1114 1115 case BOX_SHAPE_PROXYTYPE: 1116 { 1117 const btBoxShape* boxShape = static_cast<const btBoxShape*>(shape); 1118 btVector3 halfExtents = boxShape->getHalfExtentsWithMargin(); 1119 getDebugDrawer()->drawBox(-halfExtents,halfExtents,worldTransform,color); 1120 break; 1121 } 1122 1123 case SPHERE_SHAPE_PROXYTYPE: 1124 { 1125 const btSphereShape* sphereShape = static_cast<const btSphereShape*>(shape); 1126 btScalar radius = sphereShape->getMargin();//radius doesn't include the margin, so draw with margin 1127 1128 getDebugDrawer()->drawSphere(radius, worldTransform, color); 1129 break; 1130 } 1131 case MULTI_SPHERE_SHAPE_PROXYTYPE: 1132 { 1133 const btMultiSphereShape* multiSphereShape = static_cast<const btMultiSphereShape*>(shape); 1134 1135 btTransform childTransform; 1136 childTransform.setIdentity(); 1137 1138 for (int i = multiSphereShape->getSphereCount()-1; i>=0;i--) 1139 { 1140 childTransform.setOrigin(multiSphereShape->getSpherePosition(i)); 1141 getDebugDrawer()->drawSphere(multiSphereShape->getSphereRadius(i), worldTransform*childTransform, color); 1142 } 1143 1144 break; 1145 } 1146 case CAPSULE_SHAPE_PROXYTYPE: 1147 { 1148 const btCapsuleShape* capsuleShape = static_cast<const btCapsuleShape*>(shape); 1149 1150 btScalar radius = capsuleShape->getRadius(); 1151 btScalar halfHeight = capsuleShape->getHalfHeight(); 1152 1153 int upAxis = capsuleShape->getUpAxis(); 1154 1155 1156 btVector3 capStart(0.f,0.f,0.f); 1157 capStart[upAxis] = -halfHeight; 1158 1159 btVector3 capEnd(0.f,0.f,0.f); 1160 capEnd[upAxis] = halfHeight; 1161 1162 // Draw the ends 1163 { 1164 1165 btTransform childTransform = worldTransform; 1166 childTransform.getOrigin() = worldTransform * capStart; 1167 getDebugDrawer()->drawSphere(radius, childTransform, color); 1168 } 1169 1170 { 1171 btTransform childTransform = worldTransform; 1172 childTransform.getOrigin() = worldTransform * capEnd; 1173 getDebugDrawer()->drawSphere(radius, childTransform, color); 1174 } 1175 1176 // Draw some additional lines 1177 btVector3 start = worldTransform.getOrigin(); 1178 1179 1180 capStart[(upAxis+1)%3] = radius; 1181 capEnd[(upAxis+1)%3] = radius; 1182 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color); 1183 capStart[(upAxis+1)%3] = -radius; 1184 capEnd[(upAxis+1)%3] = -radius; 1185 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color); 1186 1187 capStart[(upAxis+1)%3] = 0.f; 1188 capEnd[(upAxis+1)%3] = 0.f; 1189 1190 capStart[(upAxis+2)%3] = radius; 1191 capEnd[(upAxis+2)%3] = radius; 1192 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color); 1193 capStart[(upAxis+2)%3] = -radius; 1194 capEnd[(upAxis+2)%3] = -radius; 1195 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color); 1196 1197 1198 break; 1199 } 1200 case CONE_SHAPE_PROXYTYPE: 1201 { 1202 const btConeShape* coneShape = static_cast<const btConeShape*>(shape); 1203 btScalar radius = coneShape->getRadius();//+coneShape->getMargin(); 1204 btScalar height = coneShape->getHeight();//+coneShape->getMargin(); 1205 btVector3 start = worldTransform.getOrigin(); 1206 1207 int upAxis= coneShape->getConeUpIndex(); 1208 1209 1210 btVector3 offsetHeight(0,0,0); 1211 offsetHeight[upAxis] = height * btScalar(0.5); 1212 btVector3 offsetRadius(0,0,0); 1213 offsetRadius[(upAxis+1)%3] = radius; 1214 btVector3 offset2Radius(0,0,0); 1215 offset2Radius[(upAxis+2)%3] = radius; 1216 1217 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color); 1218 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight-offsetRadius),color); 1219 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight+offset2Radius),color); 1220 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight-offset2Radius),color); 1221 1222 // Drawing the base of the cone 1223 btVector3 yaxis(0,0,0); 1224 yaxis[upAxis] = btScalar(1.0); 1225 btVector3 xaxis(0,0,0); 1226 xaxis[(upAxis+1)%3] = btScalar(1.0); 1227 getDebugDrawer()->drawArc(start-worldTransform.getBasis()*(offsetHeight),worldTransform.getBasis()*yaxis,worldTransform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,10.0); 1228 break; 1229 1230 } 1231 case CYLINDER_SHAPE_PROXYTYPE: 1232 { 1233 const btCylinderShape* cylinder = static_cast<const btCylinderShape*>(shape); 1234 int upAxis = cylinder->getUpAxis(); 1235 btScalar radius = cylinder->getRadius(); 1236 btScalar halfHeight = cylinder->getHalfExtentsWithMargin()[upAxis]; 1237 btVector3 start = worldTransform.getOrigin(); 1238 btVector3 offsetHeight(0,0,0); 1239 offsetHeight[upAxis] = halfHeight; 1240 btVector3 offsetRadius(0,0,0); 1241 offsetRadius[(upAxis+1)%3] = radius; 1242 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight+offsetRadius),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color); 1243 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight-offsetRadius),start+worldTransform.getBasis() * (-offsetHeight-offsetRadius),color); 1244 1245 // Drawing top and bottom caps of the cylinder 1246 btVector3 yaxis(0,0,0); 1247 yaxis[upAxis] = btScalar(1.0); 1248 btVector3 xaxis(0,0,0); 1249 xaxis[(upAxis+1)%3] = btScalar(1.0); 1250 getDebugDrawer()->drawArc(start-worldTransform.getBasis()*(offsetHeight),worldTransform.getBasis()*yaxis,worldTransform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,btScalar(10.0)); 1251 getDebugDrawer()->drawArc(start+worldTransform.getBasis()*(offsetHeight),worldTransform.getBasis()*yaxis,worldTransform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,btScalar(10.0)); 1252 break; 1253 } 1254 1255 case STATIC_PLANE_PROXYTYPE: 1256 { 1257 const btStaticPlaneShape* staticPlaneShape = static_cast<const btStaticPlaneShape*>(shape); 1258 btScalar planeConst = staticPlaneShape->getPlaneConstant(); 1259 const btVector3& planeNormal = staticPlaneShape->getPlaneNormal(); 1260 btVector3 planeOrigin = planeNormal * planeConst; 1261 btVector3 vec0,vec1; 1262 btPlaneSpace1(planeNormal,vec0,vec1); 1263 btScalar vecLen = 100.f; 1264 btVector3 pt0 = planeOrigin + vec0*vecLen; 1265 btVector3 pt1 = planeOrigin - vec0*vecLen; 1266 btVector3 pt2 = planeOrigin + vec1*vecLen; 1267 btVector3 pt3 = planeOrigin - vec1*vecLen; 1268 getDebugDrawer()->drawLine(worldTransform*pt0,worldTransform*pt1,color); 1269 getDebugDrawer()->drawLine(worldTransform*pt2,worldTransform*pt3,color); 1270 break; 1271 1272 } 1273 default: 1274 { 1275 1276 if (shape->isConcave()) 1277 { 1278 btConcaveShape* concaveMesh = (btConcaveShape*) shape; 1279 1280 ///@todo pass camera, for some culling? no -> we are not a graphics lib 1281 btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 1282 btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 1283 1284 DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color); 1285 concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax); 1286 1287 } 1288 1289 if (shape->getShapeType() == CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE) 1290 { 1291 btConvexTriangleMeshShape* convexMesh = (btConvexTriangleMeshShape*) shape; 1292 //todo: pass camera for some culling 1293 btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 1294 btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 1295 //DebugDrawcallback drawCallback; 1296 DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color); 1297 convexMesh->getMeshInterface()->InternalProcessAllTriangles(&drawCallback,aabbMin,aabbMax); 1298 } 1299 1300 1301 /// for polyhedral shapes 1302 if (shape->isPolyhedral()) 1303 { 1304 btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*) shape; 1305 1306 int i; 1307 for (i=0;i<polyshape->getNumEdges();i++) 1308 { 1309 btVector3 a,b; 1310 polyshape->getEdge(i,a,b); 1311 btVector3 wa = worldTransform * a; 1312 btVector3 wb = worldTransform * b; 1313 getDebugDrawer()->drawLine(wa,wb,color); 1314 1315 } 1316 1317 1318 } 1319 } 1320 } 1321 } 1322 } 1323 1324 1325 void btCollisionWorld::debugDrawWorld() 1326 { 1327 if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints) 1328 { 1329 int numManifolds = getDispatcher()->getNumManifolds(); 1330 btVector3 color(0,0,0); 1331 for (int i=0;i<numManifolds;i++) 1332 { 1333 btPersistentManifold* contactManifold = getDispatcher()->getManifoldByIndexInternal(i); 1334 //btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0()); 1335 //btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1()); 1336 1337 int numContacts = contactManifold->getNumContacts(); 1338 for (int j=0;j<numContacts;j++) 1339 { 1340 btManifoldPoint& cp = contactManifold->getContactPoint(j); 1341 getDebugDrawer()->drawContactPoint(cp.m_positionWorldOnB,cp.m_normalWorldOnB,cp.getDistance(),cp.getLifeTime(),color); 1342 } 1343 } 1344 } 1345 1346 if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb)) 1347 { 1348 int i; 1349 1350 for ( i=0;i<m_collisionObjects.size();i++) 1351 { 1352 btCollisionObject* colObj = m_collisionObjects[i]; 1353 if ((colObj->getCollisionFlags() & btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT)==0) 1354 { 1355 if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe) 1356 { 1357 btVector3 color(btScalar(1.),btScalar(1.),btScalar(1.)); 1358 switch(colObj->getActivationState()) 1359 { 1360 case ACTIVE_TAG: 1361 color = btVector3(btScalar(1.),btScalar(1.),btScalar(1.)); break; 1362 case ISLAND_SLEEPING: 1363 color = btVector3(btScalar(0.),btScalar(1.),btScalar(0.));break; 1364 case WANTS_DEACTIVATION: 1365 color = btVector3(btScalar(0.),btScalar(1.),btScalar(1.));break; 1366 case DISABLE_DEACTIVATION: 1367 color = btVector3(btScalar(1.),btScalar(0.),btScalar(0.));break; 1368 case DISABLE_SIMULATION: 1369 color = btVector3(btScalar(1.),btScalar(1.),btScalar(0.));break; 1370 default: 1371 { 1372 color = btVector3(btScalar(1),btScalar(0.),btScalar(0.)); 1373 } 1374 }; 1375 1376 debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color); 1377 } 1378 if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb)) 1379 { 1380 btVector3 minAabb,maxAabb; 1381 btVector3 colorvec(1,0,0); 1382 colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb); 1383 m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec); 1384 } 1385 } 1386 1387 } 1388 } 1389 } 1390 1391 1392 void btCollisionWorld::serializeCollisionObjects(btSerializer* serializer) 1393 { 1394 int i; 1395 //serialize all collision objects 1396 for (i=0;i<m_collisionObjects.size();i++) 1397 { 1398 btCollisionObject* colObj = m_collisionObjects[i]; 1399 if (colObj->getInternalType() == btCollisionObject::CO_COLLISION_OBJECT) 1400 { 1401 colObj->serializeSingleObject(serializer); 1402 } 1403 } 1404 1405 ///keep track of shapes already serialized 1406 btHashMap<btHashPtr,btCollisionShape*> serializedShapes; 1407 1408 for (i=0;i<m_collisionObjects.size();i++) 1409 { 1410 btCollisionObject* colObj = m_collisionObjects[i]; 1411 btCollisionShape* shape = colObj->getCollisionShape(); 1412 1413 if (!serializedShapes.find(shape)) 1414 { 1415 serializedShapes.insert(shape,shape); 1416 shape->serializeSingleShape(serializer); 1417 } 1418 } 1419 1420 } 1421 1422 1423 void btCollisionWorld::serialize(btSerializer* serializer) 1424 { 1425 1426 serializer->startSerialization(); 1427 1428 serializeCollisionObjects(serializer); 1429 1430 serializer->finishSerialization(); 1431 } 1432 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.h
r5781 r7983 23 23 * Bullet is a Collision Detection and Rigid Body Dynamics Library. The Library is Open Source and free for commercial use, under the ZLib license ( http://opensource.org/licenses/zlib-license.php ). 24 24 * 25 * The main documentation is Bullet_User_Manual.pdf, included in the source code distribution. 25 26 * There is the Physics Forum for feedback and general Collision Detection and Physics discussions. 26 27 * Please visit http://www.bulletphysics.com … … 30 31 * @subsection step1 Step 1: Download 31 32 * You can download the Bullet Physics Library from the Google Code repository: http://code.google.com/p/bullet/downloads/list 33 * 32 34 * @subsection step2 Step 2: Building 33 * Bullet comes with autogenerated Project Files for Microsoft Visual Studio 6, 7, 7.1 and 8. 34 * The main Workspace/Solution is located in Bullet/msvc/8/wksbullet.sln (replace 8 with your version). 35 * 36 * Under other platforms, like Linux or Mac OS-X, Bullet can be build using either using make, cmake, http://www.cmake.org , or jam, http://www.perforce.com/jam/jam.html . cmake can autogenerate Xcode, KDevelop, MSVC and other build systems. just run cmake . in the root of Bullet. 37 * So if you are not using MSVC or cmake, you can run ./autogen.sh ./configure to create both Makefile and Jamfile and then run make or jam. 38 * Jam is a build system that can build the library, demos and also autogenerate the MSVC Project Files. 39 * If you don't have jam installed, you can make jam from the included jam-2.5 sources, or download jam from ftp://ftp.perforce.com/jam 35 * Bullet main build system for all platforms is cmake, you can download http://www.cmake.org 36 * cmake can autogenerate projectfiles for Microsoft Visual Studio, Apple Xcode, KDevelop and Unix Makefiles. 37 * The easiest is to run the CMake cmake-gui graphical user interface and choose the options and generate projectfiles. 38 * You can also use cmake in the command-line. Here are some examples for various platforms: 39 * cmake . -G "Visual Studio 9 2008" 40 * cmake . -G Xcode 41 * cmake . -G "Unix Makefiles" 42 * Although cmake is recommended, you can also use autotools for UNIX: ./autogen.sh ./configure to create a Makefile and then run make. 40 43 * 41 44 * @subsection step3 Step 3: Testing demos … … 54 57 * 55 58 * @section copyright Copyright 56 * Copyright (C) 2005-2008 Erwin Coumans, some contributions Copyright Gino van den Bergen, Christer Ericson, Simon Hobbs, Ricardo Padrela, F Richter(res), Stephane Redon 57 * Special thanks to all visitors of the Bullet Physics forum, and in particular above contributors, John McCutchan, Nathanael Presson, Dave Eberle, Dirk Gregorius, Erin Catto, Dave Eberle, Adam Moravanszky, 58 * Pierre Terdiman, Kenny Erleben, Russell Smith, Oliver Strunk, Jan Paul van Waveren, Marten Svanfeldt. 59 * For up-to-data information and copyright and contributors list check out the Bullet_User_Manual.pdf 59 60 * 60 61 */ 61 62 63 62 64 63 … … 71 70 class btConvexShape; 72 71 class btBroadphaseInterface; 72 class btSerializer; 73 73 74 #include "LinearMath/btVector3.h" 74 75 #include "LinearMath/btTransform.h" … … 82 83 { 83 84 84 85 85 86 86 protected: 87 87 88 88 btAlignedObjectArray<btCollisionObject*> m_collisionObjects; 89 90 89 91 90 btDispatcher* m_dispatcher1; … … 99 98 btIDebugDraw* m_debugDrawer; 100 99 101 102 100 ///m_forceUpdateAllAabbs can be set to false as an optimization to only update active object AABBs 101 ///it is true by default, because it is error-prone (setting the position of static objects wouldn't update their AABB) 102 bool m_forceUpdateAllAabbs; 103 104 void serializeCollisionObjects(btSerializer* serializer); 105 103 106 public: 104 107 … … 142 145 143 146 virtual void updateAabbs(); 144 145 147 146 148 virtual void setDebugDrawer(btIDebugDraw* debugDrawer) … … 153 155 return m_debugDrawer; 154 156 } 157 158 virtual void debugDrawWorld(); 159 160 virtual void debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color); 155 161 156 162 … … 161 167 int m_shapePart; 162 168 int m_triangleIndex; 163 164 169 165 170 //const btCollisionShape* m_shapeTemp; … … 239 244 btVector3 m_hitNormalWorld; 240 245 btVector3 m_hitPointWorld; 241 242 246 243 247 virtual btScalar addSingleResult(LocalRayResult& rayResult,bool normalInWorldSpace) … … 245 249 //caller already does the filter on the m_closestHitFraction 246 250 btAssert(rayResult.m_hitFraction <= m_closestHitFraction); 247 248 251 249 252 m_closestHitFraction = rayResult.m_hitFraction; … … 262 265 }; 263 266 267 struct AllHitsRayResultCallback : public RayResultCallback 268 { 269 AllHitsRayResultCallback(const btVector3& rayFromWorld,const btVector3& rayToWorld) 270 :m_rayFromWorld(rayFromWorld), 271 m_rayToWorld(rayToWorld) 272 { 273 } 274 275 btAlignedObjectArray<btCollisionObject*> m_collisionObjects; 276 277 btVector3 m_rayFromWorld;//used to calculate hitPointWorld from hitFraction 278 btVector3 m_rayToWorld; 279 280 btAlignedObjectArray<btVector3> m_hitNormalWorld; 281 btAlignedObjectArray<btVector3> m_hitPointWorld; 282 btAlignedObjectArray<btScalar> m_hitFractions; 283 284 virtual btScalar addSingleResult(LocalRayResult& rayResult,bool normalInWorldSpace) 285 { 286 m_collisionObject = rayResult.m_collisionObject; 287 m_collisionObjects.push_back(rayResult.m_collisionObject); 288 btVector3 hitNormalWorld; 289 if (normalInWorldSpace) 290 { 291 hitNormalWorld = rayResult.m_hitNormalLocal; 292 } else 293 { 294 ///need to transform normal into worldspace 295 hitNormalWorld = m_collisionObject->getWorldTransform().getBasis()*rayResult.m_hitNormalLocal; 296 } 297 m_hitNormalWorld.push_back(hitNormalWorld); 298 btVector3 hitPointWorld; 299 hitPointWorld.setInterpolate3(m_rayFromWorld,m_rayToWorld,rayResult.m_hitFraction); 300 m_hitPointWorld.push_back(hitPointWorld); 301 m_hitFractions.push_back(rayResult.m_hitFraction); 302 return m_closestHitFraction; 303 } 304 }; 305 264 306 265 307 struct LocalConvexResult … … 292 334 short int m_collisionFilterGroup; 293 335 short int m_collisionFilterMask; 294 295 336 296 337 ConvexResultCallback() … … 304 345 { 305 346 } 306 307 347 308 348 bool hasHit() const … … 310 350 return (m_closestHitFraction < btScalar(1.)); 311 351 } 312 313 352 314 353 … … 339 378 btVector3 m_hitPointWorld; 340 379 btCollisionObject* m_hitCollisionObject; 341 342 380 343 381 virtual btScalar addSingleResult(LocalConvexResult& convexResult,bool normalInWorldSpace) … … 345 383 //caller already does the filter on the m_closestHitFraction 346 384 btAssert(convexResult.m_hitFraction <= m_closestHitFraction); 347 348 385 349 386 m_closestHitFraction = convexResult.m_hitFraction; … … 362 399 }; 363 400 401 ///ContactResultCallback is used to report contact points 402 struct ContactResultCallback 403 { 404 short int m_collisionFilterGroup; 405 short int m_collisionFilterMask; 406 407 ContactResultCallback() 408 :m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter), 409 m_collisionFilterMask(btBroadphaseProxy::AllFilter) 410 { 411 } 412 413 virtual ~ContactResultCallback() 414 { 415 } 416 417 virtual bool needsCollision(btBroadphaseProxy* proxy0) const 418 { 419 bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0; 420 collides = collides && (m_collisionFilterGroup & proxy0->m_collisionFilterMask); 421 return collides; 422 } 423 424 virtual btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1) = 0; 425 }; 426 427 428 364 429 int getNumCollisionObjects() const 365 430 { … … 369 434 /// rayTest performs a raycast on all objects in the btCollisionWorld, and calls the resultCallback 370 435 /// This allows for several queries: first hit, all hits, any hit, dependent on the value returned by the callback. 371 v oidrayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const;372 373 // convexTest performs a swept convex cast on all objects in the btCollisionWorld, and calls the resultCallback374 // This allows for several queries: first hit, all hits, any hit, dependent on the value return by the callback.436 virtual void rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const; 437 438 /// convexTest performs a swept convex cast on all objects in the btCollisionWorld, and calls the resultCallback 439 /// This allows for several queries: first hit, all hits, any hit, dependent on the value return by the callback. 375 440 void convexSweepTest (const btConvexShape* castShape, const btTransform& from, const btTransform& to, ConvexResultCallback& resultCallback, btScalar allowedCcdPenetration = btScalar(0.)) const; 441 442 ///contactTest performs a discrete collision test between colObj against all objects in the btCollisionWorld, and calls the resultCallback. 443 ///it reports one or more contact points for every overlapping object (including the one with deepest penetration) 444 void contactTest(btCollisionObject* colObj, ContactResultCallback& resultCallback); 445 446 ///contactTest performs a discrete collision test between two collision objects and calls the resultCallback if overlap if detected. 447 ///it reports one or more contact points (including the one with deepest penetration) 448 void contactPairTest(btCollisionObject* colObjA, btCollisionObject* colObjB, ContactResultCallback& resultCallback); 376 449 377 450 … … 392 465 ConvexResultCallback& resultCallback, btScalar allowedPenetration); 393 466 394 v oid addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup=btBroadphaseProxy::DefaultFilter,short int collisionFilterMask=btBroadphaseProxy::AllFilter);467 virtual void addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup=btBroadphaseProxy::DefaultFilter,short int collisionFilterMask=btBroadphaseProxy::AllFilter); 395 468 396 469 btCollisionObjectArray& getCollisionObjectArray() … … 405 478 406 479 407 v oid removeCollisionObject(btCollisionObject* collisionObject);480 virtual void removeCollisionObject(btCollisionObject* collisionObject); 408 481 409 482 virtual void performDiscreteCollisionDetection(); … … 418 491 return m_dispatchInfo; 419 492 } 493 494 bool getForceUpdateAllAabbs() const 495 { 496 return m_forceUpdateAllAabbs; 497 } 498 void setForceUpdateAllAabbs( bool forceUpdateAllAabbs) 499 { 500 m_forceUpdateAllAabbs = forceUpdateAllAabbs; 501 } 502 503 ///Preliminary serialization test for Bullet 2.76. Loading those files requires a separate parser (Bullet/Demos/SerializeDemo) 504 virtual void serialize(btSerializer* serializer); 420 505 421 506 }; -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp
r5781 r7983 115 115 void ProcessChildShape(btCollisionShape* childShape,int index) 116 116 { 117 117 btAssert(index>=0); 118 118 btCompoundShape* compoundShape = static_cast<btCompoundShape*>(m_compoundColObj->getCollisionShape()); 119 btAssert(index<compoundShape->getNumChildShapes()); 119 120 120 121 … … 142 143 if (!m_childCollisionAlgorithms[index]) 143 144 m_childCollisionAlgorithms[index] = m_dispatcher->findAlgorithm(m_compoundColObj,m_otherObj,m_sharedManifold); 145 146 ///detect swapping case 147 if (m_resultOut->getBody0Internal() == m_compoundColObj) 148 { 149 m_resultOut->setShapeIdentifiersA(-1,index); 150 } else 151 { 152 m_resultOut->setShapeIdentifiersB(-1,index); 153 } 144 154 145 155 m_childCollisionAlgorithms[index]->processCollision(m_compoundColObj,m_otherObj,m_dispatchInfo,m_resultOut); … … 258 268 int i; 259 269 btManifoldArray manifoldArray; 260 270 btCollisionShape* childShape = 0; 271 btTransform orgTrans; 272 btTransform orgInterpolationTrans; 273 btTransform newChildWorldTrans; 274 btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1; 275 261 276 for (i=0;i<numChildren;i++) 262 277 { 263 278 if (m_childCollisionAlgorithms[i]) 264 279 { 265 btCollisionShape*childShape = compoundShape->getChildShape(i);280 childShape = compoundShape->getChildShape(i); 266 281 //if not longer overlapping, remove the algorithm 267 btTransformorgTrans = colObj->getWorldTransform();268 btTransformorgInterpolationTrans = colObj->getInterpolationWorldTransform();282 orgTrans = colObj->getWorldTransform(); 283 orgInterpolationTrans = colObj->getInterpolationWorldTransform(); 269 284 const btTransform& childTrans = compoundShape->getChildTransform(i); 270 btTransformnewChildWorldTrans = orgTrans*childTrans ;285 newChildWorldTrans = orgTrans*childTrans ; 271 286 272 287 //perform an AABB check first 273 btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;274 288 childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0); 275 289 otherObj->getCollisionShape()->getAabb(otherObj->getWorldTransform(),aabbMin1,aabbMax1); … … 281 295 m_childCollisionAlgorithms[i] = 0; 282 296 } 283 284 297 } 285 286 } 287 288 289 298 } 290 299 } 291 300 } … … 312 321 int numChildren = m_childCollisionAlgorithms.size(); 313 322 int i; 323 btTransform orgTrans; 324 btScalar frac; 314 325 for (i=0;i<numChildren;i++) 315 326 { … … 318 329 319 330 //backup 320 btTransformorgTrans = colObj->getWorldTransform();331 orgTrans = colObj->getWorldTransform(); 321 332 322 333 const btTransform& childTrans = compoundShape->getChildTransform(i); … … 326 337 btCollisionShape* tmpShape = colObj->getCollisionShape(); 327 338 colObj->internalSetTemporaryCollisionShape( childShape ); 328 btScalarfrac = m_childCollisionAlgorithms[i]->calculateTimeOfImpact(colObj,otherObj,dispatchInfo,resultOut);339 frac = m_childCollisionAlgorithms[i]->calculateTimeOfImpact(colObj,otherObj,dispatchInfo,resultOut); 329 340 if (frac<hitFraction) 330 341 { -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp
r5781 r7983 96 96 if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe )) 97 97 { 98 btVector3 color( 255,255,0);98 btVector3 color(1,1,0); 99 99 btTransform& tr = ob->getWorldTransform(); 100 100 m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(triangle[1]),color); … … 122 122 123 123 btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_convexBody,m_triBody,m_manifoldPtr); 124 ///this should use the btDispatcher, so the actual registered algorithm is used 125 // btConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_convexBody,m_triBody); 126 127 m_resultOut->setShapeIdentifiers(-1,-1,partId,triangleIndex); 128 // cvxcvxalgo.setShapeIdentifiers(-1,-1,partId,triangleIndex); 129 // cvxcvxalgo.processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut); 124 125 if (m_resultOut->getBody0Internal() == m_triBody) 126 { 127 m_resultOut->setShapeIdentifiersA(partId,triangleIndex); 128 } 129 else 130 { 131 m_resultOut->setShapeIdentifiersB(partId,triangleIndex); 132 } 133 130 134 colAlgo->processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut); 131 135 colAlgo->~btCollisionAlgorithm(); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
r5781 r7983 14 14 */ 15 15 16 ///Specialized capsule-capsule collision algorithm has been added for Bullet 2.75 release to increase ragdoll performance 17 ///If you experience problems with capsule-capsule collision, try to define BT_DISABLE_CAPSULE_CAPSULE_COLLIDER and report it in the Bullet forums 18 ///with reproduction case 19 //define BT_DISABLE_CAPSULE_CAPSULE_COLLIDER 1 20 16 21 #include "btConvexConvexAlgorithm.h" 17 22 … … 21 26 #include "BulletCollision/CollisionDispatch/btCollisionObject.h" 22 27 #include "BulletCollision/CollisionShapes/btConvexShape.h" 28 #include "BulletCollision/CollisionShapes/btCapsuleShape.h" 29 30 23 31 #include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h" 24 32 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" … … 44 52 45 53 46 54 /////////// 55 56 57 58 static SIMD_FORCE_INLINE void segmentsClosestPoints( 59 btVector3& ptsVector, 60 btVector3& offsetA, 61 btVector3& offsetB, 62 btScalar& tA, btScalar& tB, 63 const btVector3& translation, 64 const btVector3& dirA, btScalar hlenA, 65 const btVector3& dirB, btScalar hlenB ) 66 { 67 // compute the parameters of the closest points on each line segment 68 69 btScalar dirA_dot_dirB = btDot(dirA,dirB); 70 btScalar dirA_dot_trans = btDot(dirA,translation); 71 btScalar dirB_dot_trans = btDot(dirB,translation); 72 73 btScalar denom = 1.0f - dirA_dot_dirB * dirA_dot_dirB; 74 75 if ( denom == 0.0f ) { 76 tA = 0.0f; 77 } else { 78 tA = ( dirA_dot_trans - dirB_dot_trans * dirA_dot_dirB ) / denom; 79 if ( tA < -hlenA ) 80 tA = -hlenA; 81 else if ( tA > hlenA ) 82 tA = hlenA; 83 } 84 85 tB = tA * dirA_dot_dirB - dirB_dot_trans; 86 87 if ( tB < -hlenB ) { 88 tB = -hlenB; 89 tA = tB * dirA_dot_dirB + dirA_dot_trans; 90 91 if ( tA < -hlenA ) 92 tA = -hlenA; 93 else if ( tA > hlenA ) 94 tA = hlenA; 95 } else if ( tB > hlenB ) { 96 tB = hlenB; 97 tA = tB * dirA_dot_dirB + dirA_dot_trans; 98 99 if ( tA < -hlenA ) 100 tA = -hlenA; 101 else if ( tA > hlenA ) 102 tA = hlenA; 103 } 104 105 // compute the closest points relative to segment centers. 106 107 offsetA = dirA * tA; 108 offsetB = dirB * tB; 109 110 ptsVector = translation - offsetA + offsetB; 111 } 112 113 114 static SIMD_FORCE_INLINE btScalar capsuleCapsuleDistance( 115 btVector3& normalOnB, 116 btVector3& pointOnB, 117 btScalar capsuleLengthA, 118 btScalar capsuleRadiusA, 119 btScalar capsuleLengthB, 120 btScalar capsuleRadiusB, 121 int capsuleAxisA, 122 int capsuleAxisB, 123 const btTransform& transformA, 124 const btTransform& transformB, 125 btScalar distanceThreshold ) 126 { 127 btVector3 directionA = transformA.getBasis().getColumn(capsuleAxisA); 128 btVector3 translationA = transformA.getOrigin(); 129 btVector3 directionB = transformB.getBasis().getColumn(capsuleAxisB); 130 btVector3 translationB = transformB.getOrigin(); 131 132 // translation between centers 133 134 btVector3 translation = translationB - translationA; 135 136 // compute the closest points of the capsule line segments 137 138 btVector3 ptsVector; // the vector between the closest points 139 140 btVector3 offsetA, offsetB; // offsets from segment centers to their closest points 141 btScalar tA, tB; // parameters on line segment 142 143 segmentsClosestPoints( ptsVector, offsetA, offsetB, tA, tB, translation, 144 directionA, capsuleLengthA, directionB, capsuleLengthB ); 145 146 btScalar distance = ptsVector.length() - capsuleRadiusA - capsuleRadiusB; 147 148 if ( distance > distanceThreshold ) 149 return distance; 150 151 btScalar lenSqr = ptsVector.length2(); 152 if (lenSqr<= (SIMD_EPSILON*SIMD_EPSILON)) 153 { 154 //degenerate case where 2 capsules are likely at the same location: take a vector tangential to 'directionA' 155 btVector3 q; 156 btPlaneSpace1(directionA,normalOnB,q); 157 } else 158 { 159 // compute the contact normal 160 normalOnB = ptsVector*-btRecipSqrt(lenSqr); 161 } 162 pointOnB = transformB.getOrigin()+offsetB + normalOnB * capsuleRadiusB; 163 164 return distance; 165 } 166 167 168 169 170 171 172 173 ////////// 47 174 48 175 … … 70 197 m_lowLevelOfDetail(false), 71 198 #ifdef USE_SEPDISTANCE_UTIL2 72 ,m_sepDistance((static_cast<btConvexShape*>(body0->getCollisionShape()))->getAngularMotionDisc(),199 m_sepDistance((static_cast<btConvexShape*>(body0->getCollisionShape()))->getAngularMotionDisc(), 73 200 (static_cast<btConvexShape*>(body1->getCollisionShape()))->getAngularMotionDisc()), 74 201 #endif … … 112 239 m_transformA(transformA), 113 240 m_transformB(transformB), 241 m_unPerturbedTransform(unPerturbedTransform), 114 242 m_perturbA(perturbA), 115 m_unPerturbedTransform(unPerturbedTransform),116 243 m_debugDrawer(debugDrawer) 117 244 { … … 156 283 extern btScalar gContactBreakingThreshold; 157 284 285 158 286 // 159 287 // Convex-Convex collision algorithm … … 177 305 btConvexShape* min1 = static_cast<btConvexShape*>(body1->getCollisionShape()); 178 306 307 btVector3 normalOnB; 308 btVector3 pointOnBWorld; 309 #ifndef BT_DISABLE_CAPSULE_CAPSULE_COLLIDER 310 if ((min0->getShapeType() == CAPSULE_SHAPE_PROXYTYPE) && (min1->getShapeType() == CAPSULE_SHAPE_PROXYTYPE)) 311 { 312 btCapsuleShape* capsuleA = (btCapsuleShape*) min0; 313 btCapsuleShape* capsuleB = (btCapsuleShape*) min1; 314 btVector3 localScalingA = capsuleA->getLocalScaling(); 315 btVector3 localScalingB = capsuleB->getLocalScaling(); 316 317 btScalar threshold = m_manifoldPtr->getContactBreakingThreshold(); 318 319 btScalar dist = capsuleCapsuleDistance(normalOnB, pointOnBWorld,capsuleA->getHalfHeight(),capsuleA->getRadius(), 320 capsuleB->getHalfHeight(),capsuleB->getRadius(),capsuleA->getUpAxis(),capsuleB->getUpAxis(), 321 body0->getWorldTransform(),body1->getWorldTransform(),threshold); 322 323 if (dist<threshold) 324 { 325 btAssert(normalOnB.length2()>=(SIMD_EPSILON*SIMD_EPSILON)); 326 resultOut->addContactPoint(normalOnB,pointOnBWorld,dist); 327 } 328 resultOut->refreshContactPoints(); 329 return; 330 } 331 #endif //BT_DISABLE_CAPSULE_CAPSULE_COLLIDER 332 333 179 334 #ifdef USE_SEPDISTANCE_UTIL2 180 m_sepDistance.updateSeparatingDistance(body0->getWorldTransform(),body1->getWorldTransform()); 335 if (dispatchInfo.m_useConvexConservativeDistanceUtil) 336 { 337 m_sepDistance.updateSeparatingDistance(body0->getWorldTransform(),body1->getWorldTransform()); 338 } 339 181 340 if (!dispatchInfo.m_useConvexConservativeDistanceUtil || m_sepDistance.getConservativeSeparatingDistance()<=0.f) 182 341 #endif //USE_SEPDISTANCE_UTIL2 … … 195 354 if (dispatchInfo.m_useConvexConservativeDistanceUtil) 196 355 { 197 input.m_maximumDistanceSquared = 1e30f;356 input.m_maximumDistanceSquared = BT_LARGE_FLOAT; 198 357 } else 199 358 #endif //USE_SEPDISTANCE_UTIL2 200 359 { 201 input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold(); 360 if (dispatchInfo.m_convexMaxDistanceUseCPT) 361 { 362 input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactProcessingThreshold(); 363 } else 364 { 365 input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold(); 366 } 202 367 input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared; 203 368 } … … 208 373 209 374 gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw); 210 btScalar sepDist = gjkPairDetector.getCachedSeparatingDistance()+dispatchInfo.m_convexConservativeDistanceThreshold; 211 212 //now perturbe directions to get multiple contact points 213 btVector3 v0,v1; 214 btVector3 sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis().normalized(); 215 btPlaneSpace1(sepNormalWorldSpace,v0,v1); 375 376 377 378 #ifdef USE_SEPDISTANCE_UTIL2 379 btScalar sepDist = 0.f; 380 if (dispatchInfo.m_useConvexConservativeDistanceUtil) 381 { 382 sepDist = gjkPairDetector.getCachedSeparatingDistance(); 383 if (sepDist>SIMD_EPSILON) 384 { 385 sepDist += dispatchInfo.m_convexConservativeDistanceThreshold; 386 //now perturbe directions to get multiple contact points 387 388 } 389 } 390 #endif //USE_SEPDISTANCE_UTIL2 391 216 392 //now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects 217 393 218 394 //perform perturbation when more then 'm_minimumPointsPerturbationThreshold' points 219 if ( resultOut->getPersistentManifold()->getNumContacts() < m_minimumPointsPerturbationThreshold)395 if (m_numPerturbationIterations && resultOut->getPersistentManifold()->getNumContacts() < m_minimumPointsPerturbationThreshold) 220 396 { 221 397 222 398 int i; 399 btVector3 v0,v1; 400 btVector3 sepNormalWorldSpace; 401 402 sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis().normalized(); 403 btPlaneSpace1(sepNormalWorldSpace,v0,v1); 404 223 405 224 406 bool perturbeA = true; … … 250 432 for ( i=0;i<m_numPerturbationIterations;i++) 251 433 { 434 if (v0.length2()>SIMD_EPSILON) 435 { 252 436 btQuaternion perturbeRot(v0,perturbeAngle); 253 437 btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations)); … … 273 457 btPerturbedContactResult perturbedResultOut(resultOut,input.m_transformA,input.m_transformB,unPerturbedTransform,perturbeA,dispatchInfo.m_debugDraw); 274 458 gjkPairDetector.getClosestPoints(input,perturbedResultOut,dispatchInfo.m_debugDraw); 459 } 275 460 276 277 461 } 278 462 } … … 281 465 282 466 #ifdef USE_SEPDISTANCE_UTIL2 283 if (dispatchInfo.m_useConvexConservativeDistanceUtil )467 if (dispatchInfo.m_useConvexConservativeDistanceUtil && (sepDist>SIMD_EPSILON)) 284 468 { 285 469 m_sepDistance.initSeparatingDistance(gjkPairDetector.getCachedSeparatingAxis(),sepDist,body0->getWorldTransform(),body1->getWorldTransform()); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h
r5781 r7983 32 32 ///Either improve GJK for large size ratios (testing a 100 units versus a 0.1 unit object) or only enable the util 33 33 ///for certain pairs that have a small size ratio 34 ///#define USE_SEPDISTANCE_UTIL2 1 34 35 //#define USE_SEPDISTANCE_UTIL2 1 35 36 36 37 ///The convexConvexAlgorithm collision algorithm implements time of impact, convex closest points and penetration depth calculations between two convex objects. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp
r5781 r7983 103 103 btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape(); 104 104 105 bool hasCollision = false;105 106 106 const btVector3& planeNormal = planeShape->getPlaneNormal(); 107 const btScalar& planeConstant = planeShape->getPlaneConstant();107 //const btScalar& planeConstant = planeShape->getPlaneConstant(); 108 108 109 109 //first perform a collision query with the non-perturbated collision objects -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h
r5781 r7983 61 61 62 62 CreateFunc() 63 : m_numPerturbationIterations( 3),64 m_minimumPointsPerturbationThreshold( 3)63 : m_numPerturbationIterations(1), 64 m_minimumPointsPerturbationThreshold(1) 65 65 { 66 66 } -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp
r5781 r7983 46 46 void* mem = btAlignedAlloc(sizeof(btVoronoiSimplexSolver),16); 47 47 m_simplexSolver = new (mem)btVoronoiSimplexSolver(); 48 49 #define USE_EPA 1 50 #ifdef USE_EPA 51 mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16);52 m_pdSolver = new (mem)btGjkEpaPenetrationDepthSolver;53 #else54 mem = btAlignedAlloc(sizeof(btMinkowskiPenetrationDepthSolver),16);55 m_pdSolver = new (mem)btMinkowskiPenetrationDepthSolver;56 #endif//USE_EPA 57 58 48 49 if (constructionInfo.m_useEpaPenetrationAlgorithm) 50 { 51 mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16); 52 m_pdSolver = new (mem)btGjkEpaPenetrationDepthSolver; 53 }else 54 { 55 mem = btAlignedAlloc(sizeof(btMinkowskiPenetrationDepthSolver),16); 56 m_pdSolver = new (mem)btMinkowskiPenetrationDepthSolver; 57 } 58 59 59 //default CreationFunctions, filling the m_doubleDispatch table 60 60 mem = btAlignedAlloc(sizeof(btConvexConvexAlgorithm::CreateFunc),16); … … 103 103 int sl = sizeof(btConvexSeparatingDistanceUtil); 104 104 sl = sizeof(btGjkPairDetector); 105 int collisionAlgorithmMaxElementSize = btMax(maxSize,maxSize2); 105 int collisionAlgorithmMaxElementSize = btMax(maxSize,constructionInfo.m_customCollisionAlgorithmMaxElementSize); 106 collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize2); 106 107 collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize3); 107 108 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h
r5781 r7983 28 28 int m_defaultMaxPersistentManifoldPoolSize; 29 29 int m_defaultMaxCollisionAlgorithmPoolSize; 30 int m_customCollisionAlgorithmMaxElementSize; 30 31 int m_defaultStackAllocatorSize; 32 int m_useEpaPenetrationAlgorithm; 31 33 32 34 btDefaultCollisionConstructionInfo() … … 36 38 m_defaultMaxPersistentManifoldPoolSize(4096), 37 39 m_defaultMaxCollisionAlgorithmPoolSize(4096), 38 m_defaultStackAllocatorSize(0) 40 m_customCollisionAlgorithmMaxElementSize(0), 41 m_defaultStackAllocatorSize(0), 42 m_useEpaPenetrationAlgorithm(true) 39 43 { 40 44 } … … 109 113 } 110 114 115 virtual btVoronoiSimplexSolver* getSimplexSolver() 116 { 117 return m_simplexSolver; 118 } 119 111 120 112 121 virtual btCollisionAlgorithmCreateFunc* getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btGhostObject.h
r5781 r7983 161 161 } 162 162 163 virtual void removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy0,btDispatcher* dispatcher)163 virtual void removeOverlappingPairsContainingProxy(btBroadphaseProxy* /*proxy0*/,btDispatcher* /*dispatcher*/) 164 164 { 165 165 btAssert(0); … … 173 173 174 174 #endif 175 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btManifoldResult.cpp
r5781 r7983 48 48 m_body0(body0), 49 49 m_body1(body1) 50 #ifdef DEBUG_PART_INDEX 51 ,m_partId0(-1), 52 m_partId1(-1), 53 m_index0(-1), 54 m_index1(-1) 55 #endif //DEBUG_PART_INDEX 50 56 { 51 57 m_rootTransA = body0->getWorldTransform(); … … 89 95 90 96 //BP mod, store contact triangles. 91 newPt.m_partId0 = m_partId0; 92 newPt.m_partId1 = m_partId1; 93 newPt.m_index0 = m_index0; 94 newPt.m_index1 = m_index1; 97 if (isSwapped) 98 { 99 newPt.m_partId0 = m_partId1; 100 newPt.m_partId1 = m_partId0; 101 newPt.m_index0 = m_index1; 102 newPt.m_index1 = m_index0; 103 } else 104 { 105 newPt.m_partId0 = m_partId0; 106 newPt.m_partId1 = m_partId1; 107 newPt.m_index0 = m_index0; 108 newPt.m_index1 = m_index1; 109 } 95 110 //printf("depth=%f\n",depth); 96 111 ///@todo, check this for any side effects … … 113 128 btCollisionObject* obj0 = isSwapped? m_body1 : m_body0; 114 129 btCollisionObject* obj1 = isSwapped? m_body0 : m_body1; 115 (*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0, m_partId0,m_index0,obj1,m_partId1,m_index1);130 (*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0,newPt.m_partId0,newPt.m_index0,obj1,newPt.m_partId1,newPt.m_index1); 116 131 } 117 132 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btManifoldResult.h
r5781 r7983 29 29 extern ContactAddedCallback gContactAddedCallback; 30 30 31 //#define DEBUG_PART_INDEX 1 31 32 32 33 … … 34 35 class btManifoldResult : public btDiscreteCollisionDetectorInterface::Result 35 36 { 37 protected: 38 36 39 btPersistentManifold* m_manifoldPtr; 37 40 … … 51 54 52 55 btManifoldResult() 56 #ifdef DEBUG_PART_INDEX 57 : 58 m_partId0(-1), 59 m_partId1(-1), 60 m_index0(-1), 61 m_index1(-1) 62 #endif //DEBUG_PART_INDEX 53 63 { 54 64 } … … 72 82 } 73 83 74 virtual void setShapeIdentifiers (int partId0,int index0, int partId1,int index1)84 virtual void setShapeIdentifiersA(int partId0,int index0) 75 85 { 76 m_partId0=partId0; 77 m_partId1=partId1; 78 m_index0=index0; 79 m_index1=index1; 86 m_partId0=partId0; 87 m_index0=index0; 88 } 89 90 virtual void setShapeIdentifiersB( int partId1,int index1) 91 { 92 m_partId1=partId1; 93 m_index1=index1; 80 94 } 81 95 … … 100 114 } 101 115 116 const btCollisionObject* getBody0Internal() const 117 { 118 return m_body0; 119 } 102 120 121 const btCollisionObject* getBody1Internal() const 122 { 123 return m_body1; 124 } 125 103 126 }; 104 127 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp
r5781 r7983 1 1 2 /* 2 3 Bullet Continuous Collision Detection and Physics Library … … 45 46 46 47 { 48 btOverlappingPairCache* pairCachePtr = colWorld->getPairCache(); 49 const int numOverlappingPairs = pairCachePtr->getNumOverlappingPairs(); 50 btBroadphasePair* pairPtr = pairCachePtr->getOverlappingPairArrayPtr(); 47 51 48 for (int i=0;i<colWorld->getPairCache()->getNumOverlappingPairs();i++) 49 { 50 btBroadphasePair* pairPtr = colWorld->getPairCache()->getOverlappingPairArrayPtr(); 52 for (int i=0;i<numOverlappingPairs;i++) 53 { 51 54 const btBroadphasePair& collisionPair = pairPtr[i]; 52 55 btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject; … … 64 67 } 65 68 66 69 #ifdef STATIC_SIMULATION_ISLAND_OPTIMIZATION 70 void btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld,btDispatcher* dispatcher) 71 { 72 73 // put the index into m_controllers into m_tag 74 int index = 0; 75 { 76 77 int i; 78 for (i=0;i<colWorld->getCollisionObjectArray().size(); i++) 79 { 80 btCollisionObject* collisionObject= colWorld->getCollisionObjectArray()[i]; 81 //Adding filtering here 82 if (!collisionObject->isStaticOrKinematicObject()) 83 { 84 collisionObject->setIslandTag(index++); 85 } 86 collisionObject->setCompanionId(-1); 87 collisionObject->setHitFraction(btScalar(1.)); 88 } 89 } 90 // do the union find 91 92 initUnionFind( index ); 93 94 findUnions(dispatcher,colWorld); 95 } 96 97 void btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* colWorld) 98 { 99 // put the islandId ('find' value) into m_tag 100 { 101 int index = 0; 102 int i; 103 for (i=0;i<colWorld->getCollisionObjectArray().size();i++) 104 { 105 btCollisionObject* collisionObject= colWorld->getCollisionObjectArray()[i]; 106 if (!collisionObject->isStaticOrKinematicObject()) 107 { 108 collisionObject->setIslandTag( m_unionFind.find(index) ); 109 //Set the correct object offset in Collision Object Array 110 m_unionFind.getElement(index).m_sz = i; 111 collisionObject->setCompanionId(-1); 112 index++; 113 } else 114 { 115 collisionObject->setIslandTag(-1); 116 collisionObject->setCompanionId(-2); 117 } 118 } 119 } 120 } 121 122 123 #else //STATIC_SIMULATION_ISLAND_OPTIMIZATION 67 124 void btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld,btDispatcher* dispatcher) 68 125 { 69 126 70 127 initUnionFind( int (colWorld->getCollisionObjectArray().size())); 71 128 72 129 // put the index into m_controllers into m_tag 73 130 { 74 131 75 132 int index = 0; 76 133 int i; … … 82 139 collisionObject->setHitFraction(btScalar(1.)); 83 140 index++; 84 141 85 142 } 86 143 } 87 144 // do the union find 88 145 89 146 findUnions(dispatcher,colWorld); 90 91 92 93 } 94 95 96 147 } 97 148 98 149 void btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* colWorld) … … 100 151 // put the islandId ('find' value) into m_tag 101 152 { 102 103 153 154 104 155 int index = 0; 105 156 int i; … … 120 171 } 121 172 } 173 174 #endif //STATIC_SIMULATION_ISLAND_OPTIMIZATION 122 175 123 176 inline int getIslandId(const btPersistentManifold* lhs) -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp
r5781 r7983 60 60 61 61 btDiscreteCollisionDetectorInterface::ClosestPointInput input; 62 input.m_maximumDistanceSquared = btScalar( 1e30);///@todo: tighter bounds62 input.m_maximumDistanceSquared = btScalar(BT_LARGE_FLOAT);///@todo: tighter bounds 63 63 input.m_transformA = sphereObj->getWorldTransform(); 64 64 input.m_transformB = triObj->getWorldTransform(); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btUnionFind.cpp
r5781 r7983 71 71 { 72 72 m_elements[i].m_id = find(i); 73 #ifndef STATIC_SIMULATION_ISLAND_OPTIMIZATION 73 74 m_elements[i].m_sz = i; 75 #endif //STATIC_SIMULATION_ISLAND_OPTIMIZATION 74 76 } 75 77 … … 79 81 80 82 } 81 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btUnionFind.h
r5781 r7983 19 19 #include "LinearMath/btAlignedObjectArray.h" 20 20 21 #define USE_PATH_COMPRESSION 1 21 #define USE_PATH_COMPRESSION 1 22 23 ///see for discussion of static island optimizations by Vroonsh here: http://code.google.com/p/bullet/issues/detail?id=406 24 #define STATIC_SIMULATION_ISLAND_OPTIMIZATION 1 22 25 23 26 struct btElement … … 107 110 108 111 #ifdef USE_PATH_COMPRESSION 109 // 110 m_elements[x].m_id = m_elements[m_elements[x].m_id].m_id; 111 #endif // 112 const btElement* elementPtr = &m_elements[m_elements[x].m_id]; 113 m_elements[x].m_id = elementPtr->m_id; 114 x = elementPtr->m_id; 115 #else// 112 116 x = m_elements[x].m_id; 117 #endif 113 118 //btAssert(x < m_N); 114 119 //btAssert(x >= 0);
Note: See TracChangeset
for help on using the changeset viewer.