Bullet Collision Detection & Physics Library: btDbvtBroadphase.h Source File

Bullet Collision Detection & Physics Library

btDbvtBroadphase.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
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
17 #ifndef BT_DBVT_BROADPHASE_H
18 #define BT_DBVT_BROADPHASE_H
19
20 #include "BulletCollision/BroadphaseCollision/btDbvt.h"
21 #include "BulletCollision/BroadphaseCollision/btOverlappingPairCache.h"
22
23 //
24 // Compile time config
25 //
26
27 #define DBVT_BP_PROFILE 0
28 //#define DBVT_BP_SORTPAIRS 1
29 #define DBVT_BP_PREVENTFALSEUPDATE 0
30 #define DBVT_BP_ACCURATESLEEPING 0
31 #define DBVT_BP_ENABLE_BENCHMARK 0
32 //#define DBVT_BP_MARGIN (btScalar)0.05
33 extern btScalar gDbvtMargin;
34
35 #if DBVT_BP_PROFILE
36 #define DBVT_BP_PROFILING_RATE 256
37 #include "LinearMath/btQuickprof.h"
38 #endif
39
40 //
41 // btDbvtProxy
42 //
43 struct btDbvtProxy : btBroadphaseProxy
44 {
45 /* Fields */
46 //btDbvtAabbMm aabb;
47 btDbvtNode* leaf;
48 btDbvtProxy* links[2];
49 int stage;
50 /* ctor */
51 btDbvtProxy(const btVector3& aabbMin, const btVector3& aabbMax, void* userPtr, int collisionFilterGroup, int collisionFilterMask) : btBroadphaseProxy(aabbMin, aabbMax, userPtr, collisionFilterGroup, collisionFilterMask)
52 {
53 links[0] = links[1] = 0;
54 }
55 };
56
57 typedef btAlignedObjectArray<btDbvtProxy*> btDbvtProxyArray;
58
62 struct btDbvtBroadphase : btBroadphaseInterface
63 {
64 /* Config */
65 enum
66 {
67 DYNAMIC_SET = 0, /* Dynamic set index */
68 FIXED_SET = 1, /* Fixed set index */
69 STAGECOUNT = 2 /* Number of stages */
70 };
71 /* Fields */
72 btDbvt m_sets[2]; // Dbvt sets
73 btDbvtProxy* m_stageRoots[STAGECOUNT + 1]; // Stages list
74 btOverlappingPairCache* m_paircache; // Pair cache
75 btScalar m_prediction; // Velocity prediction
76 int m_stageCurrent; // Current stage
77 int m_fupdates; // % of fixed updates per frame
78 int m_dupdates; // % of dynamic updates per frame
79 int m_cupdates; // % of cleanup updates per frame
80 int m_newpairs; // Number of pairs created
81 int m_fixedleft; // Fixed optimization left
82 unsigned m_updates_call; // Number of updates call
83 unsigned m_updates_done; // Number of updates done
84 btScalar m_updates_ratio; // m_updates_done/m_updates_call
85 int m_pid; // Parse id
86 int m_cid; // Cleanup index
87 int m_gid; // Gen id
88 bool m_releasepaircache; // Release pair cache on delete
89 bool m_deferedcollide; // Defere dynamic/static collision to collide call
90 bool m_needcleanup; // Need to run cleanup?
91 btAlignedObjectArray<btAlignedObjectArray<const btDbvtNode*> > m_rayTestStacks;
92 #if DBVT_BP_PROFILE
93 btClock m_clock;
94 struct
95 {
96 unsigned long m_total;
97 unsigned long m_ddcollide;
98 unsigned long m_fdcollide;
99 unsigned long m_cleanup;
100 unsigned long m_jobcount;
101 } m_profiling;
102 #endif
103 /* Methods */
104 btDbvtBroadphase(btOverlappingPairCache* paircache = 0);
105 ~btDbvtBroadphase();
106 void collide(btDispatcher* dispatcher);
107 void optimize();
108
109 /* btBroadphaseInterface Implementation */
110 btBroadphaseProxy* createProxy(const btVector3& aabbMin, const btVector3& aabbMax, int shapeType, void* userPtr, int collisionFilterGroup, int collisionFilterMask, btDispatcher* dispatcher);
111 virtual void destroyProxy(btBroadphaseProxy* proxy, btDispatcher* dispatcher);
112 virtual void setAabb(btBroadphaseProxy* proxy, const btVector3& aabbMin, const btVector3& aabbMax, btDispatcher* dispatcher);
113 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));
114 virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback);
115
116 virtual void getAabb(btBroadphaseProxy* proxy, btVector3& aabbMin, btVector3& aabbMax) const;
117 virtual void calculateOverlappingPairs(btDispatcher* dispatcher);
118 virtual btOverlappingPairCache* getOverlappingPairCache();
119 virtual const btOverlappingPairCache* getOverlappingPairCache() const;
120 virtual void getBroadphaseAabb(btVector3& aabbMin, btVector3& aabbMax) const;
121 virtual void printStats();
122
124 virtual void resetPool(btDispatcher* dispatcher);
125
126 void performDeferredRemoval(btDispatcher* dispatcher);
127
128 void setVelocityPrediction(btScalar prediction)
129 {
130 m_prediction = prediction;
131 }
132 btScalar getVelocityPrediction() const
133 {
134 return m_prediction;
135 }
136
141 void setAabbForceUpdate(btBroadphaseProxy* absproxy, const btVector3& aabbMin, const btVector3& aabbMax, btDispatcher* /*dispatcher*/);
142
143 static void benchmark(btBroadphaseInterface*);
144 };
145
146 #endif
btDbvtProxyArray
btAlignedObjectArray< btDbvtProxy * > btDbvtProxyArray
Definition: btDbvtBroadphase.h:57
gDbvtMargin
btScalar gDbvtMargin
btDbvtBroadphase implementation by Nathanael Presson
Definition: btDbvtBroadphase.cpp:20
btDbvt.h
btOverlappingPairCache.h
btQuickprof.h
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition: btAlignedObjectArray.h:46
btBroadphaseInterface
The btBroadphaseInterface class provides an interface to detect aabb-overlapping object pairs.
Definition: btBroadphaseInterface.h:50
btClock
The btClock is a portable basic clock that measures accurate time in seconds, use for profiling.
Definition: btQuickprof.h:23
btDispatcher
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:77
btOverlappingPairCache
The btOverlappingPairCache provides an interface for overlapping pair management (add,...
Definition: btOverlappingPairCache.h:51
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
btBroadphaseAabbCallback
Definition: btBroadphaseInterface.h:26
btBroadphaseProxy
The btBroadphaseProxy is the main class that can be used with the Bullet broadphases.
Definition: btBroadphaseProxy.h:86
btBroadphaseRayCallback
Definition: btBroadphaseInterface.h:32
btDbvtBroadphase
The btDbvtBroadphase implements a broadphase using two dynamic AABB bounding volume hierarchies/trees...
Definition: btDbvtBroadphase.h:63
btDbvtBroadphase::performDeferredRemoval
void performDeferredRemoval(btDispatcher *dispatcher)
Definition: btDbvtBroadphase.cpp:443
btDbvtBroadphase::calculateOverlappingPairs
virtual void calculateOverlappingPairs(btDispatcher *dispatcher)
calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during th...
Definition: btDbvtBroadphase.cpp:417
btDbvtBroadphase::benchmark
static void benchmark(btBroadphaseInterface *)
Definition: btDbvtBroadphase.cpp:821
btDbvtBroadphase::setVelocityPrediction
void setVelocityPrediction(btScalar prediction)
Definition: btDbvtBroadphase.h:128
btDbvtBroadphase::destroyProxy
virtual void destroyProxy(btBroadphaseProxy *proxy, btDispatcher *dispatcher)
Definition: btDbvtBroadphase.cpp:205
btDbvtBroadphase::m_updates_ratio
btScalar m_updates_ratio
Definition: btDbvtBroadphase.h:84
btDbvtBroadphase::getAabb
virtual void getAabb(btBroadphaseProxy *proxy, btVector3 &aabbMin, btVector3 &aabbMax) const
Definition: btDbvtBroadphase.cpp:219
btDbvtBroadphase::collide
void collide(btDispatcher *dispatcher)
Definition: btDbvtBroadphase.cpp:512
btDbvtBroadphase::m_stageRoots
btDbvtProxy * m_stageRoots[STAGECOUNT+1]
Definition: btDbvtBroadphase.h:73
btDbvtBroadphase::createProxy
btBroadphaseProxy * createProxy(const btVector3 &aabbMin, const btVector3 &aabbMax, int shapeType, void *userPtr, int collisionFilterGroup, int collisionFilterMask, btDispatcher *dispatcher)
Definition: btDbvtBroadphase.cpp:175
btDbvtBroadphase::m_dupdates
int m_dupdates
Definition: btDbvtBroadphase.h:78
btDbvtBroadphase::m_cid
int m_cid
Definition: btDbvtBroadphase.h:86
btDbvtBroadphase::resetPool
virtual void resetPool(btDispatcher *dispatcher)
reset broadphase internal structures, to ensure determinism/reproducability
Definition: btDbvtBroadphase.cpp:665
btDbvtBroadphase::getVelocityPrediction
btScalar getVelocityPrediction() const
Definition: btDbvtBroadphase.h:132
btDbvtBroadphase::m_updates_done
unsigned m_updates_done
Definition: btDbvtBroadphase.h:83
btDbvtBroadphase::m_gid
int m_gid
Definition: btDbvtBroadphase.h:87
btDbvtBroadphase::m_sets
btDbvt m_sets[2]
Definition: btDbvtBroadphase.h:72
btDbvtBroadphase::optimize
void optimize()
Definition: btDbvtBroadphase.cpp:627
btDbvtBroadphase::setAabbForceUpdate
void setAabbForceUpdate(btBroadphaseProxy *absproxy, const btVector3 &aabbMin, const btVector3 &aabbMax, btDispatcher *)
this setAabbForceUpdate is similar to setAabb but always forces the aabb update.
Definition: btDbvtBroadphase.cpp:376
btDbvtBroadphase::m_fupdates
int m_fupdates
Definition: btDbvtBroadphase.h:77
btDbvtBroadphase::m_stageCurrent
int m_stageCurrent
Definition: btDbvtBroadphase.h:76
btDbvtBroadphase::m_deferedcollide
bool m_deferedcollide
Definition: btDbvtBroadphase.h:89
btDbvtBroadphase::~btDbvtBroadphase
~btDbvtBroadphase()
Definition: btDbvtBroadphase.cpp:165
btDbvtBroadphase::m_prediction
btScalar m_prediction
Definition: btDbvtBroadphase.h:75
btDbvtBroadphase::btDbvtBroadphase
btDbvtBroadphase(btOverlappingPairCache *paircache=0)
Definition: btDbvtBroadphase.cpp:131
btDbvtBroadphase::rayTest
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))
Definition: btDbvtBroadphase.cpp:240
btDbvtBroadphase::aabbTest
virtual void aabbTest(const btVector3 &aabbMin, const btVector3 &aabbMax, btBroadphaseAabbCallback &callback)
Definition: btDbvtBroadphase.cpp:300
btDbvtBroadphase::STAGECOUNT
@ STAGECOUNT
Definition: btDbvtBroadphase.h:69
btDbvtBroadphase::DYNAMIC_SET
@ DYNAMIC_SET
Definition: btDbvtBroadphase.h:67
btDbvtBroadphase::FIXED_SET
@ FIXED_SET
Definition: btDbvtBroadphase.h:68
btDbvtBroadphase::m_releasepaircache
bool m_releasepaircache
Definition: btDbvtBroadphase.h:88
btDbvtBroadphase::m_pid
int m_pid
Definition: btDbvtBroadphase.h:85
btDbvtBroadphase::printStats
virtual void printStats()
Definition: btDbvtBroadphase.cpp:697
btDbvtBroadphase::getBroadphaseAabb
virtual void getBroadphaseAabb(btVector3 &aabbMin, btVector3 &aabbMax) const
getAabb returns the axis aligned bounding box in the 'global' coordinate frame will add some transfor...
Definition: btDbvtBroadphase.cpp:646
btDbvtBroadphase::m_fixedleft
int m_fixedleft
Definition: btDbvtBroadphase.h:81
btDbvtBroadphase::m_newpairs
int m_newpairs
Definition: btDbvtBroadphase.h:80
btDbvtBroadphase::m_rayTestStacks
btAlignedObjectArray< btAlignedObjectArray< const btDbvtNode * > > m_rayTestStacks
Definition: btDbvtBroadphase.h:91
btDbvtBroadphase::m_paircache
btOverlappingPairCache * m_paircache
Definition: btDbvtBroadphase.h:74
btDbvtBroadphase::m_cupdates
int m_cupdates
Definition: btDbvtBroadphase.h:79
btDbvtBroadphase::setAabb
virtual void setAabb(btBroadphaseProxy *proxy, const btVector3 &aabbMin, const btVector3 &aabbMax, btDispatcher *dispatcher)
Definition: btDbvtBroadphase.cpp:311
btDbvtBroadphase::m_updates_call
unsigned m_updates_call
Definition: btDbvtBroadphase.h:82
btDbvtBroadphase::getOverlappingPairCache
virtual btOverlappingPairCache * getOverlappingPairCache()
Definition: btDbvtBroadphase.cpp:634
btDbvtBroadphase::m_needcleanup
bool m_needcleanup
Definition: btDbvtBroadphase.h:90
btDbvtNode
Definition: btDbvt.h:181
btDbvtProxy
Definition: btDbvtBroadphase.h:44
btDbvtProxy::stage
int stage
Definition: btDbvtBroadphase.h:49
btDbvtProxy::btDbvtProxy
btDbvtProxy(const btVector3 &aabbMin, const btVector3 &aabbMax, void *userPtr, int collisionFilterGroup, int collisionFilterMask)
Definition: btDbvtBroadphase.h:51
btDbvtProxy::links
btDbvtProxy * links[2]
Definition: btDbvtBroadphase.h:48
btDbvtProxy::leaf
btDbvtNode * leaf
Definition: btDbvtBroadphase.h:47
btDbvt
The btDbvt class implements a fast dynamic bounding volume tree based on axis aligned bounding boxes ...
Definition: btDbvt.h:229