btMultiSapBroadphase.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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_MULTI_SAP_BROADPHASE
  14. #define BT_MULTI_SAP_BROADPHASE
  15. #include "btBroadphaseInterface.h"
  16. #include "bullet/LinearMath/btAlignedObjectArray.h"
  17. #include "btOverlappingPairCache.h"
  18. class btBroadphaseInterface;
  19. class btSimpleBroadphase;
  20. typedef btAlignedObjectArray<btBroadphaseInterface*> btSapBroadphaseArray;
  21. ///The btMultiSapBroadphase is a research project, not recommended to use in production. Use btAxisSweep3 or btDbvtBroadphase instead.
  22. ///The btMultiSapBroadphase is a broadphase that contains multiple SAP broadphases.
  23. ///The user can add SAP broadphases that cover the world. A btBroadphaseProxy can be in multiple child broadphases at the same time.
  24. ///A btQuantizedBvh acceleration structures finds overlapping SAPs for each btBroadphaseProxy.
  25. ///See http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=328
  26. ///and http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1329
  27. class btMultiSapBroadphase :public btBroadphaseInterface
  28. {
  29. btSapBroadphaseArray m_sapBroadphases;
  30. btSimpleBroadphase* m_simpleBroadphase;
  31. btOverlappingPairCache* m_overlappingPairs;
  32. class btQuantizedBvh* m_optimizedAabbTree;
  33. bool m_ownsPairCache;
  34. btOverlapFilterCallback* m_filterCallback;
  35. int m_invalidPair;
  36. struct btBridgeProxy
  37. {
  38. btBroadphaseProxy* m_childProxy;
  39. btBroadphaseInterface* m_childBroadphase;
  40. };
  41. public:
  42. struct btMultiSapProxy : public btBroadphaseProxy
  43. {
  44. ///array with all the entries that this proxy belongs to
  45. btAlignedObjectArray<btBridgeProxy*> m_bridgeProxies;
  46. btVector3 m_aabbMin;
  47. btVector3 m_aabbMax;
  48. int m_shapeType;
  49. /* void* m_userPtr;
  50. short int m_collisionFilterGroup;
  51. short int m_collisionFilterMask;
  52. */
  53. btMultiSapProxy(const btVector3& aabbMin, const btVector3& aabbMax,int shapeType,void* userPtr, short int collisionFilterGroup,short int collisionFilterMask)
  54. :btBroadphaseProxy(aabbMin,aabbMax,userPtr,collisionFilterGroup,collisionFilterMask),
  55. m_aabbMin(aabbMin),
  56. m_aabbMax(aabbMax),
  57. m_shapeType(shapeType)
  58. {
  59. m_multiSapParentProxy =this;
  60. }
  61. };
  62. protected:
  63. btAlignedObjectArray<btMultiSapProxy*> m_multiSapProxies;
  64. public:
  65. btMultiSapBroadphase(int maxProxies = 16384,btOverlappingPairCache* pairCache=0);
  66. btSapBroadphaseArray& getBroadphaseArray()
  67. {
  68. return m_sapBroadphases;
  69. }
  70. const btSapBroadphaseArray& getBroadphaseArray() const
  71. {
  72. return m_sapBroadphases;
  73. }
  74. virtual ~btMultiSapBroadphase();
  75. virtual btBroadphaseProxy* createProxy( const btVector3& aabbMin, const btVector3& aabbMax,int shapeType,void* userPtr, short int collisionFilterGroup,short int collisionFilterMask, btDispatcher* dispatcher,void* multiSapProxy);
  76. virtual void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
  77. virtual void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher);
  78. virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
  79. virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback,const btVector3& aabbMin=btVector3(0,0,0),const btVector3& aabbMax=btVector3(0,0,0));
  80. void addToChildBroadphase(btMultiSapProxy* parentMultiSapProxy, btBroadphaseProxy* childProxy, btBroadphaseInterface* childBroadphase);
  81. ///calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb
  82. virtual void calculateOverlappingPairs(btDispatcher* dispatcher);
  83. bool testAabbOverlap(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1);
  84. virtual btOverlappingPairCache* getOverlappingPairCache()
  85. {
  86. return m_overlappingPairs;
  87. }
  88. virtual const btOverlappingPairCache* getOverlappingPairCache() const
  89. {
  90. return m_overlappingPairs;
  91. }
  92. ///getAabb returns the axis aligned bounding box in the 'global' coordinate frame
  93. ///will add some transform later
  94. virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const
  95. {
  96. aabbMin.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT);
  97. aabbMax.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
  98. }
  99. void buildTree(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax);
  100. virtual void printStats();
  101. void quicksort (btBroadphasePairArray& a, int lo, int hi);
  102. ///reset broadphase internal structures, to ensure determinism/reproducability
  103. virtual void resetPool(btDispatcher* dispatcher);
  104. };
  105. #endif //BT_MULTI_SAP_BROADPHASE