[1963] | 1 | /* |
---|
| 2 | Bullet Continuous Collision Detection and Physics Library |
---|
| 3 | Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/ |
---|
| 4 | |
---|
| 5 | This software is provided 'as-is', without any express or implied warranty. |
---|
| 6 | In no event will the authors be held liable for any damages arising from the use of this software. |
---|
| 7 | Permission is granted to anyone to use this software for any purpose, |
---|
| 8 | including commercial applications, and to alter it and redistribute it freely, |
---|
| 9 | subject to the following restrictions: |
---|
| 10 | |
---|
| 11 | 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. |
---|
| 12 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. |
---|
| 13 | 3. This notice may not be removed or altered from any source distribution. |
---|
| 14 | */ |
---|
| 15 | ///btDbvtBroadphase implementation by Nathanael Presson |
---|
| 16 | #ifndef BT_DBVT_BROADPHASE_H |
---|
| 17 | #define BT_DBVT_BROADPHASE_H |
---|
| 18 | |
---|
| 19 | #include "BulletCollision/BroadphaseCollision/btDbvt.h" |
---|
| 20 | #include "BulletCollision/BroadphaseCollision/btOverlappingPairCache.h" |
---|
| 21 | |
---|
| 22 | // |
---|
| 23 | // Compile time config |
---|
| 24 | // |
---|
| 25 | |
---|
| 26 | #define DBVT_BP_PROFILE 0 |
---|
| 27 | #define DBVT_BP_SORTPAIRS 1 |
---|
| 28 | #define DBVT_BP_PREVENTFALSEUPDATE 0 |
---|
| 29 | #define DBVT_BP_ACCURATESLEEPING 0 |
---|
| 30 | #define DBVT_BP_ENABLE_BENCHMARK 0 |
---|
| 31 | #define DBVT_BP_MARGIN (btScalar)0.05 |
---|
| 32 | |
---|
| 33 | #if DBVT_BP_PROFILE |
---|
[2430] | 34 | #define DBVT_BP_PROFILING_RATE 256 |
---|
| 35 | #include "LinearMath/btQuickprof.h" |
---|
[1963] | 36 | #endif |
---|
| 37 | |
---|
| 38 | // |
---|
| 39 | // btDbvtProxy |
---|
| 40 | // |
---|
| 41 | struct btDbvtProxy : btBroadphaseProxy |
---|
| 42 | { |
---|
[2430] | 43 | /* Fields */ |
---|
| 44 | //btDbvtAabbMm aabb; |
---|
| 45 | btDbvtNode* leaf; |
---|
| 46 | btDbvtProxy* links[2]; |
---|
| 47 | int stage; |
---|
| 48 | /* ctor */ |
---|
| 49 | btDbvtProxy(const btVector3& aabbMin,const btVector3& aabbMax,void* userPtr,short int collisionFilterGroup, short int collisionFilterMask) : |
---|
| 50 | btBroadphaseProxy(aabbMin,aabbMax,userPtr,collisionFilterGroup,collisionFilterMask) |
---|
[1963] | 51 | { |
---|
[2430] | 52 | links[0]=links[1]=0; |
---|
[1963] | 53 | } |
---|
| 54 | }; |
---|
| 55 | |
---|
| 56 | typedef btAlignedObjectArray<btDbvtProxy*> btDbvtProxyArray; |
---|
| 57 | |
---|
| 58 | ///The btDbvtBroadphase implements a broadphase using two dynamic AABB bounding volume hierarchies/trees (see btDbvt). |
---|
| 59 | ///One tree is used for static/non-moving objects, and another tree is used for dynamic objects. Objects can move from one tree to the other. |
---|
| 60 | ///This is a very fast broadphase, especially for very dynamic worlds where many objects are moving. Its insert/add and remove of objects is generally faster than the sweep and prune broadphases btAxisSweep3 and bt32BitAxisSweep3. |
---|
| 61 | struct btDbvtBroadphase : btBroadphaseInterface |
---|
| 62 | { |
---|
[2430] | 63 | /* Config */ |
---|
| 64 | enum { |
---|
[1963] | 65 | DYNAMIC_SET = 0, /* Dynamic set index */ |
---|
| 66 | FIXED_SET = 1, /* Fixed set index */ |
---|
| 67 | STAGECOUNT = 2 /* Number of stages */ |
---|
[2430] | 68 | }; |
---|
| 69 | /* Fields */ |
---|
| 70 | btDbvt m_sets[2]; // Dbvt sets |
---|
| 71 | btDbvtProxy* m_stageRoots[STAGECOUNT+1]; // Stages list |
---|
| 72 | btOverlappingPairCache* m_paircache; // Pair cache |
---|
| 73 | btScalar m_prediction; // Velocity prediction |
---|
| 74 | int m_stageCurrent; // Current stage |
---|
| 75 | int m_fupdates; // % of fixed updates per frame |
---|
| 76 | int m_dupdates; // % of dynamic updates per frame |
---|
| 77 | int m_cupdates; // % of cleanup updates per frame |
---|
| 78 | int m_newpairs; // Number of pairs created |
---|
| 79 | int m_fixedleft; // Fixed optimization left |
---|
| 80 | unsigned m_updates_call; // Number of updates call |
---|
| 81 | unsigned m_updates_done; // Number of updates done |
---|
| 82 | btScalar m_updates_ratio; // m_updates_done/m_updates_call |
---|
| 83 | int m_pid; // Parse id |
---|
| 84 | int m_cid; // Cleanup index |
---|
| 85 | int m_gid; // Gen id |
---|
| 86 | bool m_releasepaircache; // Release pair cache on delete |
---|
| 87 | bool m_deferedcollide; // Defere dynamic/static collision to collide call |
---|
| 88 | bool m_needcleanup; // Need to run cleanup? |
---|
[1963] | 89 | #if DBVT_BP_PROFILE |
---|
[2430] | 90 | btClock m_clock; |
---|
| 91 | struct { |
---|
[1963] | 92 | unsigned long m_total; |
---|
| 93 | unsigned long m_ddcollide; |
---|
| 94 | unsigned long m_fdcollide; |
---|
| 95 | unsigned long m_cleanup; |
---|
| 96 | unsigned long m_jobcount; |
---|
[2430] | 97 | } m_profiling; |
---|
[1963] | 98 | #endif |
---|
[2430] | 99 | /* Methods */ |
---|
| 100 | btDbvtBroadphase(btOverlappingPairCache* paircache=0); |
---|
| 101 | ~btDbvtBroadphase(); |
---|
| 102 | void collide(btDispatcher* dispatcher); |
---|
| 103 | void optimize(); |
---|
| 104 | /* btBroadphaseInterface Implementation */ |
---|
| 105 | btBroadphaseProxy* createProxy(const btVector3& aabbMin,const btVector3& aabbMax,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,btDispatcher* dispatcher,void* multiSapProxy); |
---|
| 106 | void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher); |
---|
| 107 | void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher); |
---|
| 108 | 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)); |
---|
| 109 | |
---|
| 110 | virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const; |
---|
| 111 | void calculateOverlappingPairs(btDispatcher* dispatcher); |
---|
| 112 | btOverlappingPairCache* getOverlappingPairCache(); |
---|
| 113 | const btOverlappingPairCache* getOverlappingPairCache() const; |
---|
| 114 | void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const; |
---|
| 115 | void printStats(); |
---|
| 116 | static void benchmark(btBroadphaseInterface*); |
---|
[1963] | 117 | }; |
---|
| 118 | |
---|
| 119 | #endif |
---|