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

Bullet Collision Detection & Physics Library

btDiscreteDynamicsWorld.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#ifndef BT_DISCRETE_DYNAMICS_WORLD_H
17#define BT_DISCRETE_DYNAMICS_WORLD_H
18
19#include "btDynamicsWorld.h"
20class btDispatcher;
21class btOverlappingPairCache;
22class btConstraintSolver;
23class btSimulationIslandManager;
24class btTypedConstraint;
25class btActionInterface;
26class btPersistentManifold;
27class btIDebugDraw;
28
29struct InplaceSolverIslandCallback;
30
31#include "LinearMath/btAlignedObjectArray.h"
32#include "LinearMath/btThreads.h"
33
36 ATTRIBUTE_ALIGNED16(class)
37 btDiscreteDynamicsWorld : public btDynamicsWorld
38{
39protected:
40 btAlignedObjectArray<btTypedConstraint*> m_sortedConstraints;
41 InplaceSolverIslandCallback* m_solverIslandCallback;
42
43 btConstraintSolver* m_constraintSolver;
44
45 btSimulationIslandManager* m_islandManager;
46
47 btAlignedObjectArray<btTypedConstraint*> m_constraints;
48
49 btAlignedObjectArray<btRigidBody*> m_nonStaticRigidBodies;
50
51 btVector3 m_gravity;
52
53 //for variable timesteps
54 btScalar m_localTime;
55 btScalar m_fixedTimeStep;
56 //for variable timesteps
57
58 bool m_ownsIslandManager;
59 bool m_ownsConstraintSolver;
60 bool m_synchronizeAllMotionStates;
61 bool m_applySpeculativeContactRestitution;
62
63 btAlignedObjectArray<btActionInterface*> m_actions;
64
65 int m_profileTimings;
66
67 bool m_latencyMotionStateInterpolation;
68
69 btAlignedObjectArray<btPersistentManifold*> m_predictiveManifolds;
70 btSpinMutex m_predictiveManifoldsMutex; // used to synchronize threads creating predictive contacts
71
72 virtual void predictUnconstraintMotion(btScalar timeStep);
73
74 void integrateTransformsInternal(btRigidBody * *bodies, int numBodies, btScalar timeStep); // can be called in parallel
75 virtual void integrateTransforms(btScalar timeStep);
76
77 virtual void calculateSimulationIslands();
78
79
80
81 virtual void updateActivationState(btScalar timeStep);
82
83 void updateActions(btScalar timeStep);
84
85 void startProfiling(btScalar timeStep);
86
87 virtual void internalSingleStepSimulation(btScalar timeStep);
88
89 void releasePredictiveContacts();
90 void createPredictiveContactsInternal(btRigidBody * *bodies, int numBodies, btScalar timeStep); // can be called in parallel
91 virtual void createPredictiveContacts(btScalar timeStep);
92
93 virtual void saveKinematicState(btScalar timeStep);
94
95 void serializeRigidBodies(btSerializer * serializer);
96
97 void serializeDynamicsWorldInfo(btSerializer * serializer);
98
99public:
100 BT_DECLARE_ALIGNED_ALLOCATOR();
101
103 btDiscreteDynamicsWorld(btDispatcher * dispatcher, btBroadphaseInterface * pairCache, btConstraintSolver * constraintSolver, btCollisionConfiguration * collisionConfiguration);
104
105 virtual ~btDiscreteDynamicsWorld();
106
108 virtual int stepSimulation(btScalar timeStep, int maxSubSteps = 1, btScalar fixedTimeStep = btScalar(1.) / btScalar(60.));
109
110 virtual void solveConstraints(btContactSolverInfo & solverInfo);
111
112 virtual void synchronizeMotionStates();
113
115 void synchronizeSingleMotionState(btRigidBody * body);
116
117 virtual void addConstraint(btTypedConstraint * constraint, bool disableCollisionsBetweenLinkedBodies = false);
118
119 virtual void removeConstraint(btTypedConstraint * constraint);
120
121 virtual void addAction(btActionInterface*);
122
123 virtual void removeAction(btActionInterface*);
124
125 btSimulationIslandManager* getSimulationIslandManager()
126 {
127 return m_islandManager;
128 }
129
130 const btSimulationIslandManager* getSimulationIslandManager() const
131 {
132 return m_islandManager;
133 }
134
135 btCollisionWorld* getCollisionWorld()
136 {
137 return this;
138 }
139
140 virtual void setGravity(const btVector3& gravity);
141
142 virtual btVector3 getGravity() const;
143
144 virtual void addCollisionObject(btCollisionObject * collisionObject, int collisionFilterGroup = btBroadphaseProxy::StaticFilter, int collisionFilterMask = btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter);
145
146 virtual void addRigidBody(btRigidBody * body);
147
148 virtual void addRigidBody(btRigidBody * body, int group, int mask);
149
150 virtual void removeRigidBody(btRigidBody * body);
151
153 virtual void removeCollisionObject(btCollisionObject * collisionObject);
154
155 virtual void debugDrawConstraint(btTypedConstraint * constraint);
156
157 virtual void debugDrawWorld();
158
159 virtual void setConstraintSolver(btConstraintSolver * solver);
160
161 virtual btConstraintSolver* getConstraintSolver();
162
163 virtual int getNumConstraints() const;
164
165 virtual btTypedConstraint* getConstraint(int index);
166
167 virtual const btTypedConstraint* getConstraint(int index) const;
168
169 virtual btDynamicsWorldType getWorldType() const
170 {
171 return BT_DISCRETE_DYNAMICS_WORLD;
172 }
173
175 virtual void clearForces();
176
178 virtual void applyGravity();
179
180 virtual void setNumTasks(int numTasks)
181 {
182 (void)numTasks;
183 }
184
186 virtual void updateVehicles(btScalar timeStep)
187 {
188 updateActions(timeStep);
189 }
190
192 virtual void addVehicle(btActionInterface * vehicle);
194 virtual void removeVehicle(btActionInterface * vehicle);
196 virtual void addCharacter(btActionInterface * character);
198 virtual void removeCharacter(btActionInterface * character);
199
200 void setSynchronizeAllMotionStates(bool synchronizeAll)
201 {
202 m_synchronizeAllMotionStates = synchronizeAll;
203 }
204 bool getSynchronizeAllMotionStates() const
205 {
206 return m_synchronizeAllMotionStates;
207 }
208
209 void setApplySpeculativeContactRestitution(bool enable)
210 {
211 m_applySpeculativeContactRestitution = enable;
212 }
213
214 bool getApplySpeculativeContactRestitution() const
215 {
216 return m_applySpeculativeContactRestitution;
217 }
218
220 virtual void serialize(btSerializer * serializer);
221
224 void setLatencyMotionStateInterpolation(bool latencyInterpolation)
225 {
226 m_latencyMotionStateInterpolation = latencyInterpolation;
227 }
228 bool getLatencyMotionStateInterpolation() const
229 {
230 return m_latencyMotionStateInterpolation;
231 }
232
233 btAlignedObjectArray<btRigidBody*>& getNonStaticRigidBodies()
234 {
235 return m_nonStaticRigidBodies;
236 }
237
238 const btAlignedObjectArray<btRigidBody*>& getNonStaticRigidBodies() const
239 {
240 return m_nonStaticRigidBodies;
241 }
242};
243
244#endif //BT_DISCRETE_DYNAMICS_WORLD_H
btAlignedObjectArray.h
btDynamicsWorld.h
btDynamicsWorldType
btDynamicsWorldType
Definition btDynamicsWorld.h:31
BT_DISCRETE_DYNAMICS_WORLD
@ BT_DISCRETE_DYNAMICS_WORLD
Definition btDynamicsWorld.h:33
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition btScalar.h:99
btThreads.h
btActionInterface
Basic interface to allow actions such as vehicles and characters to be updated inside a btDynamicsWor...
Definition btActionInterface.h:27
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
btCollisionConfiguration
btCollisionConfiguration allows to configure Bullet collision detection stack allocator size,...
Definition btCollisionConfiguration.h:27
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition btCollisionObject.h:51
btCollisionWorld::btCollisionWorld
btCollisionWorld(btDispatcher *dispatcher, btBroadphaseInterface *broadphasePairCache, btCollisionConfiguration *collisionConfiguration)
for debug drawing
Definition btCollisionWorld.cpp:67
btConstraintSolver
Definition btConstraintSolver.h:42
btDiscreteDynamicsWorld::updateActions
void updateActions(btScalar timeStep)
Definition btDiscreteDynamicsWorld.cpp:584
btDiscreteDynamicsWorld::removeAction
virtual void removeAction(btActionInterface *)
Definition btDiscreteDynamicsWorld.cpp:656
btDiscreteDynamicsWorld::m_predictiveManifolds
btAlignedObjectArray< btPersistentManifold * > m_predictiveManifolds
Definition btDiscreteDynamicsWorld.h:69
btDiscreteDynamicsWorld::integrateTransformsInternal
void integrateTransformsInternal(btRigidBody **bodies, int numBodies, btScalar timeStep)
Definition btDiscreteDynamicsWorld.cpp:951
btDiscreteDynamicsWorld::getLatencyMotionStateInterpolation
bool getLatencyMotionStateInterpolation() const
Definition btDiscreteDynamicsWorld.h:228
btDiscreteDynamicsWorld::calculateSimulationIslands
virtual void calculateSimulationIslands()
Definition btDiscreteDynamicsWorld.cpp:709
btDiscreteDynamicsWorld::removeConstraint
virtual void removeConstraint(btTypedConstraint *constraint)
Definition btDiscreteDynamicsWorld.cpp:644
btDiscreteDynamicsWorld::integrateTransforms
virtual void integrateTransforms(btScalar timeStep)
Definition btDiscreteDynamicsWorld.cpp:1047
btDiscreteDynamicsWorld::synchronizeSingleMotionState
void synchronizeSingleMotionState(btRigidBody *body)
this can be useful to synchronize a single rigid body -> graphics object
Definition btDiscreteDynamicsWorld.cpp:335
btDiscreteDynamicsWorld::m_latencyMotionStateInterpolation
bool m_latencyMotionStateInterpolation
Definition btDiscreteDynamicsWorld.h:67
btDiscreteDynamicsWorld::createPredictiveContactsInternal
void createPredictiveContactsInternal(btRigidBody **bodies, int numBodies, btScalar timeStep)
Definition btDiscreteDynamicsWorld.cpp:849
btDiscreteDynamicsWorld::setSynchronizeAllMotionStates
void setSynchronizeAllMotionStates(bool synchronizeAll)
Definition btDiscreteDynamicsWorld.h:200
btDiscreteDynamicsWorld::serializeRigidBodies
void serializeRigidBodies(btSerializer *serializer)
Definition btDiscreteDynamicsWorld.cpp:1379
btDiscreteDynamicsWorld::setLatencyMotionStateInterpolation
void setLatencyMotionStateInterpolation(bool latencyInterpolation)
Interpolate motion state between previous and current transform, instead of current and next transfor...
Definition btDiscreteDynamicsWorld.h:224
btDiscreteDynamicsWorld::internalSingleStepSimulation
virtual void internalSingleStepSimulation(btScalar timeStep)
Definition btDiscreteDynamicsWorld.cpp:452
btDiscreteDynamicsWorld::setApplySpeculativeContactRestitution
void setApplySpeculativeContactRestitution(bool enable)
Definition btDiscreteDynamicsWorld.h:209
btDiscreteDynamicsWorld::getSimulationIslandManager
const btSimulationIslandManager * getSimulationIslandManager() const
Definition btDiscreteDynamicsWorld.h:130
btDiscreteDynamicsWorld::setNumTasks
virtual void setNumTasks(int numTasks)
Definition btDiscreteDynamicsWorld.h:180
btDiscreteDynamicsWorld::serializeDynamicsWorldInfo
void serializeDynamicsWorldInfo(btSerializer *serializer)
Definition btDiscreteDynamicsWorld.cpp:1405
btDiscreteDynamicsWorld::m_applySpeculativeContactRestitution
bool m_applySpeculativeContactRestitution
Definition btDiscreteDynamicsWorld.h:61
btDiscreteDynamicsWorld::addAction
virtual void addAction(btActionInterface *)
Definition btDiscreteDynamicsWorld.cpp:651
btDiscreteDynamicsWorld::m_profileTimings
int m_profileTimings
Definition btDiscreteDynamicsWorld.h:65
btDiscreteDynamicsWorld::m_sortedConstraints
btAlignedObjectArray< btTypedConstraint * > m_sortedConstraints
Definition btDiscreteDynamicsWorld.h:40
btDiscreteDynamicsWorld::getWorldType
virtual btDynamicsWorldType getWorldType() const
Definition btDiscreteDynamicsWorld.h:169
btDiscreteDynamicsWorld::btDiscreteDynamicsWorld
btDiscreteDynamicsWorld(btDispatcher *dispatcher, btBroadphaseInterface *pairCache, btConstraintSolver *constraintSolver, btCollisionConfiguration *collisionConfiguration)
this btDiscreteDynamicsWorld constructor gets created objects from the user, and will not delete thos...
Definition btDiscreteDynamicsWorld.cpp:191
btDiscreteDynamicsWorld::m_localTime
btScalar m_localTime
Definition btDiscreteDynamicsWorld.h:54
btDiscreteDynamicsWorld::BT_DECLARE_ALIGNED_ALLOCATOR
BT_DECLARE_ALIGNED_ALLOCATOR()
btDiscreteDynamicsWorld::m_gravity
btVector3 m_gravity
Definition btDiscreteDynamicsWorld.h:51
btDiscreteDynamicsWorld::getApplySpeculativeContactRestitution
bool getApplySpeculativeContactRestitution() const
Definition btDiscreteDynamicsWorld.h:214
btDiscreteDynamicsWorld::m_fixedTimeStep
btScalar m_fixedTimeStep
Definition btDiscreteDynamicsWorld.h:55
btDiscreteDynamicsWorld::synchronizeMotionStates
virtual void synchronizeMotionStates()
Definition btDiscreteDynamicsWorld.cpp:356
btDiscreteDynamicsWorld::stepSimulation
virtual int stepSimulation(btScalar timeStep, int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.))
if maxSubSteps > 0, it will interpolate motion between fixedTimeStep's
Definition btDiscreteDynamicsWorld.cpp:382
btDiscreteDynamicsWorld::saveKinematicState
virtual void saveKinematicState(btScalar timeStep)
Definition btDiscreteDynamicsWorld.cpp:249
btDiscreteDynamicsWorld::addConstraint
virtual void addConstraint(btTypedConstraint *constraint, bool disableCollisionsBetweenLinkedBodies=false)
Definition btDiscreteDynamicsWorld.cpp:631
btDiscreteDynamicsWorld::getNonStaticRigidBodies
const btAlignedObjectArray< btRigidBody * > & getNonStaticRigidBodies() const
Definition btDiscreteDynamicsWorld.h:238
btDiscreteDynamicsWorld::m_solverIslandCallback
InplaceSolverIslandCallback * m_solverIslandCallback
Definition btDiscreteDynamicsWorld.h:41
btDiscreteDynamicsWorld::getNonStaticRigidBodies
btAlignedObjectArray< btRigidBody * > & getNonStaticRigidBodies()
Definition btDiscreteDynamicsWorld.h:233
btDiscreteDynamicsWorld::getSynchronizeAllMotionStates
bool getSynchronizeAllMotionStates() const
Definition btDiscreteDynamicsWorld.h:204
btDiscreteDynamicsWorld::m_islandManager
btSimulationIslandManager * m_islandManager
Definition btDiscreteDynamicsWorld.h:45
btDiscreteDynamicsWorld::createPredictiveContacts
virtual void createPredictiveContacts(btScalar timeStep)
Definition btDiscreteDynamicsWorld.cpp:941
btDiscreteDynamicsWorld::m_constraints
btAlignedObjectArray< btTypedConstraint * > m_constraints
Definition btDiscreteDynamicsWorld.h:47
btDiscreteDynamicsWorld::m_nonStaticRigidBodies
btAlignedObjectArray< btRigidBody * > m_nonStaticRigidBodies
Definition btDiscreteDynamicsWorld.h:49
btDiscreteDynamicsWorld::m_actions
btAlignedObjectArray< btActionInterface * > m_actions
Definition btDiscreteDynamicsWorld.h:63
btDiscreteDynamicsWorld::m_ownsConstraintSolver
bool m_ownsConstraintSolver
Definition btDiscreteDynamicsWorld.h:59
btDiscreteDynamicsWorld::m_ownsIslandManager
bool m_ownsIslandManager
Definition btDiscreteDynamicsWorld.h:58
btDiscreteDynamicsWorld::getSimulationIslandManager
btSimulationIslandManager * getSimulationIslandManager()
Definition btDiscreteDynamicsWorld.h:125
btDiscreteDynamicsWorld::m_predictiveManifoldsMutex
btSpinMutex m_predictiveManifoldsMutex
Definition btDiscreteDynamicsWorld.h:70
btDiscreteDynamicsWorld::updateActivationState
virtual void updateActivationState(btScalar timeStep)
Definition btDiscreteDynamicsWorld.cpp:594
btDiscreteDynamicsWorld::m_constraintSolver
btConstraintSolver * m_constraintSolver
Definition btDiscreteDynamicsWorld.h:43
btDiscreteDynamicsWorld::getCollisionWorld
btCollisionWorld * getCollisionWorld()
Definition btDiscreteDynamicsWorld.h:135
btDiscreteDynamicsWorld::m_synchronizeAllMotionStates
bool m_synchronizeAllMotionStates
Definition btDiscreteDynamicsWorld.h:60
btDiscreteDynamicsWorld::solveConstraints
virtual void solveConstraints(btContactSolverInfo &solverInfo)
Definition btDiscreteDynamicsWorld.cpp:681
btDiscreteDynamicsWorld::updateVehicles
virtual void updateVehicles(btScalar timeStep)
obsolete, use updateActions instead
Definition btDiscreteDynamicsWorld.h:186
btDiscreteDynamicsWorld::predictUnconstraintMotion
virtual void predictUnconstraintMotion(btScalar timeStep)
Definition btDiscreteDynamicsWorld.cpp:1091
btDiscreteDynamicsWorld::releasePredictiveContacts
void releasePredictiveContacts()
Definition btDiscreteDynamicsWorld.cpp:929
btDiscreteDynamicsWorld::startProfiling
void startProfiling(btScalar timeStep)
Definition btDiscreteDynamicsWorld.cpp:1108
btDispatcher
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition btDispatcher.h:77
btDynamicsWorld::btDynamicsWorld
btDynamicsWorld(btDispatcher *dispatcher, btBroadphaseInterface *broadphase, btCollisionConfiguration *collisionConfiguration)
Definition btDynamicsWorld.h:52
btIDebugDraw
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
Definition btIDebugDraw.h:27
btOverlappingPairCache
The btOverlappingPairCache provides an interface for overlapping pair management (add,...
Definition btOverlappingPairCache.h:51
btPersistentManifold
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
Definition btPersistentManifold.h:65
btRigidBody
The btRigidBody is the main class for rigid body objects.
Definition btRigidBody.h:60
btSerializer
Definition btSerializer.h:66
btSimulationIslandManager
SimulationIslandManager creates and handles simulation islands, using btUnionFind.
Definition btSimulationIslandManager.h:31
btSpinMutex
btSpinMutex – lightweight spin-mutex implemented with atomic ops, never puts a thread to sleep becaus...
Definition btThreads.h:46
btTypedConstraint
TypedConstraint is the baseclass for Bullet constraints and vehicles.
Definition btTypedConstraint.h:76
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
InplaceSolverIslandCallback
Definition btDiscreteDynamicsWorld.cpp:79
btBroadphaseProxy::AllFilter
@ AllFilter
Definition btBroadphaseProxy.h:98
btBroadphaseProxy::StaticFilter
@ StaticFilter
Definition btBroadphaseProxy.h:93
btContactSolverInfo
Definition btContactSolverInfo.h:76