btCollisionDispatcher.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. #ifndef BT_COLLISION__DISPATCHER_H
  14. #define BT_COLLISION__DISPATCHER_H
  15. #include "bullet/BulletCollision//BroadphaseCollision/btDispatcher.h"
  16. #include "bullet/BulletCollision//NarrowPhaseCollision/btPersistentManifold.h"
  17. #include "bullet/BulletCollision//CollisionDispatch/btManifoldResult.h"
  18. #include "bullet/BulletCollision//BroadphaseCollision/btBroadphaseProxy.h"
  19. #include "bullet/LinearMath/btAlignedObjectArray.h"
  20. class btIDebugDraw;
  21. class btOverlappingPairCache;
  22. class btPoolAllocator;
  23. class btCollisionConfiguration;
  24. #include "btCollisionCreateFunc.h"
  25. #define USE_DISPATCH_REGISTRY_ARRAY 1
  26. class btCollisionDispatcher;
  27. ///user can override this nearcallback for collision filtering and more finegrained control over collision detection
  28. typedef void (*btNearCallback)(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo);
  29. ///btCollisionDispatcher supports algorithms that handle ConvexConvex and ConvexConcave collision pairs.
  30. ///Time of Impact, Closest Points and Penetration Depth.
  31. class btCollisionDispatcher : public btDispatcher
  32. {
  33. protected:
  34. int m_dispatcherFlags;
  35. btAlignedObjectArray<btPersistentManifold*> m_manifoldsPtr;
  36. btManifoldResult m_defaultManifoldResult;
  37. btNearCallback m_nearCallback;
  38. btPoolAllocator* m_collisionAlgorithmPoolAllocator;
  39. btPoolAllocator* m_persistentManifoldPoolAllocator;
  40. btCollisionAlgorithmCreateFunc* m_doubleDispatch[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES];
  41. btCollisionConfiguration* m_collisionConfiguration;
  42. public:
  43. enum DispatcherFlags
  44. {
  45. CD_STATIC_STATIC_REPORTED = 1,
  46. CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD = 2,
  47. CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION = 4
  48. };
  49. int getDispatcherFlags() const
  50. {
  51. return m_dispatcherFlags;
  52. }
  53. void setDispatcherFlags(int flags)
  54. {
  55. m_dispatcherFlags = flags;
  56. }
  57. ///registerCollisionCreateFunc allows registration of custom/alternative collision create functions
  58. void registerCollisionCreateFunc(int proxyType0,int proxyType1, btCollisionAlgorithmCreateFunc* createFunc);
  59. int getNumManifolds() const
  60. {
  61. return int( m_manifoldsPtr.size());
  62. }
  63. btPersistentManifold** getInternalManifoldPointer()
  64. {
  65. return m_manifoldsPtr.size()? &m_manifoldsPtr[0] : 0;
  66. }
  67. btPersistentManifold* getManifoldByIndexInternal(int index)
  68. {
  69. return m_manifoldsPtr[index];
  70. }
  71. const btPersistentManifold* getManifoldByIndexInternal(int index) const
  72. {
  73. return m_manifoldsPtr[index];
  74. }
  75. btCollisionDispatcher (btCollisionConfiguration* collisionConfiguration);
  76. virtual ~btCollisionDispatcher();
  77. virtual btPersistentManifold* getNewManifold(const btCollisionObject* b0,const btCollisionObject* b1);
  78. virtual void releaseManifold(btPersistentManifold* manifold);
  79. virtual void clearManifold(btPersistentManifold* manifold);
  80. btCollisionAlgorithm* findAlgorithm(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btPersistentManifold* sharedManifold = 0);
  81. virtual bool needsCollision(const btCollisionObject* body0,const btCollisionObject* body1);
  82. virtual bool needsResponse(const btCollisionObject* body0,const btCollisionObject* body1);
  83. virtual void dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,const btDispatcherInfo& dispatchInfo,btDispatcher* dispatcher) ;
  84. void setNearCallback(btNearCallback nearCallback)
  85. {
  86. m_nearCallback = nearCallback;
  87. }
  88. btNearCallback getNearCallback() const
  89. {
  90. return m_nearCallback;
  91. }
  92. //by default, Bullet will use this near callback
  93. static void defaultNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo);
  94. virtual void* allocateCollisionAlgorithm(int size);
  95. virtual void freeCollisionAlgorithm(void* ptr);
  96. btCollisionConfiguration* getCollisionConfiguration()
  97. {
  98. return m_collisionConfiguration;
  99. }
  100. const btCollisionConfiguration* getCollisionConfiguration() const
  101. {
  102. return m_collisionConfiguration;
  103. }
  104. void setCollisionConfiguration(btCollisionConfiguration* config)
  105. {
  106. m_collisionConfiguration = config;
  107. }
  108. virtual btPoolAllocator* getInternalManifoldPool()
  109. {
  110. return m_persistentManifoldPoolAllocator;
  111. }
  112. virtual const btPoolAllocator* getInternalManifoldPool() const
  113. {
  114. return m_persistentManifoldPoolAllocator;
  115. }
  116. };
  117. #endif //BT_COLLISION__DISPATCHER_H