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

Bullet Collision Detection & Physics Library

btDiscreteDynamicsWorld.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
16
17 #ifndef BT_DISCRETE_DYNAMICS_WORLD_H
18 #define BT_DISCRETE_DYNAMICS_WORLD_H
19
20 #include "btDynamicsWorld.h"
21
22 class btDispatcher;
23 class btOverlappingPairCache;
24 class btConstraintSolver;
25 class btSimulationIslandManager;
26 class btTypedConstraint;
27 class btActionInterface;
28 class btPersistentManifold;
29 class btIDebugDraw;
30 struct InplaceSolverIslandCallback;
31
32 #include "LinearMath/btAlignedObjectArray.h"
33 #include "LinearMath/btThreads.h"
34
35
38 ATTRIBUTE_ALIGNED16(class) btDiscreteDynamicsWorld : public btDynamicsWorld
39 {
40 protected:
41
42 btAlignedObjectArray<btTypedConstraint*> m_sortedConstraints;
43 InplaceSolverIslandCallback* m_solverIslandCallback;
44
45 btConstraintSolver* m_constraintSolver;
46
47 btSimulationIslandManager* m_islandManager;
48
49 btAlignedObjectArray<btTypedConstraint*> m_constraints;
50
51 btAlignedObjectArray<btRigidBody*> m_nonStaticRigidBodies;
52
53 btVector3 m_gravity;
54
55 //for variable timesteps
56 btScalar m_localTime;
57 btScalar m_fixedTimeStep;
58 //for variable timesteps
59
60 bool m_ownsIslandManager;
61 bool m_ownsConstraintSolver;
62 bool m_synchronizeAllMotionStates;
63 bool m_applySpeculativeContactRestitution;
64
65 btAlignedObjectArray<btActionInterface*> m_actions;
66
67 int m_profileTimings;
68
69 bool m_latencyMotionStateInterpolation;
70
71 btAlignedObjectArray<btPersistentManifold*> m_predictiveManifolds;
72 btSpinMutex m_predictiveManifoldsMutex; // used to synchronize threads creating predictive contacts
73
74 virtual void predictUnconstraintMotion(btScalar timeStep);
75
76 void integrateTransformsInternal( btRigidBody** bodies, int numBodies, btScalar timeStep ); // can be called in parallel
77 virtual void integrateTransforms(btScalar timeStep);
78
79 virtual void calculateSimulationIslands();
80
81 virtual void solveConstraints(btContactSolverInfo& solverInfo);
82
83 virtual void updateActivationState(btScalar timeStep);
84
85 void updateActions(btScalar timeStep);
86
87 void startProfiling(btScalar timeStep);
88
89 virtual void internalSingleStepSimulation( btScalar timeStep);
90
91 void releasePredictiveContacts();
92 void createPredictiveContactsInternal( btRigidBody** bodies, int numBodies, btScalar timeStep ); // can be called in parallel
93 virtual void createPredictiveContacts(btScalar timeStep);
94
95 virtual void saveKinematicState(btScalar timeStep);
96
97 void serializeRigidBodies(btSerializer* serializer);
98
99 void serializeDynamicsWorldInfo(btSerializer* serializer);
100
101 public:
102
103
104 BT_DECLARE_ALIGNED_ALLOCATOR();
105
107 btDiscreteDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration);
108
109 virtual ~btDiscreteDynamicsWorld();
110
112 virtual int stepSimulation( btScalar timeStep,int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.));
113
114
115 virtual void synchronizeMotionStates();
116
118 void synchronizeSingleMotionState(btRigidBody* body);
119
120 virtual void addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies=false);
121
122 virtual void removeConstraint(btTypedConstraint* constraint);
123
124 virtual void addAction(btActionInterface*);
125
126 virtual void removeAction(btActionInterface*);
127
128 btSimulationIslandManager* getSimulationIslandManager()
129 {
130 return m_islandManager;
131 }
132
133 const btSimulationIslandManager* getSimulationIslandManager() const
134 {
135 return m_islandManager;
136 }
137
138 btCollisionWorld* getCollisionWorld()
139 {
140 return this;
141 }
142
143 virtual void setGravity(const btVector3& gravity);
144
145 virtual btVector3 getGravity () const;
146
147 virtual void addCollisionObject(btCollisionObject* collisionObject, int collisionFilterGroup=btBroadphaseProxy::StaticFilter, int collisionFilterMask=btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter);
148
149 virtual void addRigidBody(btRigidBody* body);
150
151 virtual void addRigidBody(btRigidBody* body, int group, int mask);
152
153 virtual void removeRigidBody(btRigidBody* body);
154
156 virtual void removeCollisionObject(btCollisionObject* collisionObject);
157
158
159 virtual void debugDrawConstraint(btTypedConstraint* constraint);
160
161 virtual void debugDrawWorld();
162
163 virtual void setConstraintSolver(btConstraintSolver* solver);
164
165 virtual btConstraintSolver* getConstraintSolver();
166
167 virtual int getNumConstraints() const;
168
169 virtual btTypedConstraint* getConstraint(int index) ;
170
171 virtual const btTypedConstraint* getConstraint(int index) const;
172
173
174 virtual btDynamicsWorldType getWorldType() const
175 {
176 return BT_DISCRETE_DYNAMICS_WORLD;
177 }
178
180 virtual void clearForces();
181
183 virtual void applyGravity();
184
185 virtual void setNumTasks(int numTasks)
186 {
187 (void) numTasks;
188 }
189
191 virtual void updateVehicles(btScalar timeStep)
192 {
193 updateActions(timeStep);
194 }
195
197 virtual void addVehicle(btActionInterface* vehicle);
199 virtual void removeVehicle(btActionInterface* vehicle);
201 virtual void addCharacter(btActionInterface* character);
203 virtual void removeCharacter(btActionInterface* character);
204
205 void setSynchronizeAllMotionStates(bool synchronizeAll)
206 {
207 m_synchronizeAllMotionStates = synchronizeAll;
208 }
209 bool getSynchronizeAllMotionStates() const
210 {
211 return m_synchronizeAllMotionStates;
212 }
213
214 void setApplySpeculativeContactRestitution(bool enable)
215 {
216 m_applySpeculativeContactRestitution = enable;
217 }
218
219 bool getApplySpeculativeContactRestitution() const
220 {
221 return m_applySpeculativeContactRestitution;
222 }
223
225 virtual void serialize(btSerializer* serializer);
226
229 void setLatencyMotionStateInterpolation(bool latencyInterpolation )
230 {
231 m_latencyMotionStateInterpolation = latencyInterpolation;
232 }
233 bool getLatencyMotionStateInterpolation() const
234 {
235 return m_latencyMotionStateInterpolation;
236 }
237 };
238
239 #endif //BT_DISCRETE_DYNAMICS_WORLD_H
btPersistentManifold
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
Definition: btPersistentManifold.h:63
btDiscreteDynamicsWorld::m_localTime
btScalar m_localTime
Definition: btDiscreteDynamicsWorld.h:56
btDiscreteDynamicsWorld::m_islandManager
btSimulationIslandManager * m_islandManager
Definition: btDiscreteDynamicsWorld.h:47
btDiscreteDynamicsWorld::m_nonStaticRigidBodies
btAlignedObjectArray< btRigidBody * > m_nonStaticRigidBodies
Definition: btDiscreteDynamicsWorld.h:51
InplaceSolverIslandCallback
Definition: btDiscreteDynamicsWorld.cpp:84
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition: btAlignedObjectArray.h:53
btDiscreteDynamicsWorld::setSynchronizeAllMotionStates
void setSynchronizeAllMotionStates(bool synchronizeAll)
Definition: btDiscreteDynamicsWorld.h:205
btDiscreteDynamicsWorld::m_sortedConstraints
btAlignedObjectArray< btTypedConstraint * > m_sortedConstraints
Definition: btDiscreteDynamicsWorld.h:42
btDiscreteDynamicsWorld
btDiscreteDynamicsWorld provides discrete rigid body simulation those classes replace the obsolete Cc...
Definition: btDiscreteDynamicsWorld.h:38
btSimulationIslandManager
SimulationIslandManager creates and handles simulation islands, using btUnionFind.
Definition: btSimulationIslandManager.h:31
btDynamicsWorld
The btDynamicsWorld is the interface class for several dynamics implementation, basic, discrete, parallel, and continuous etc.
Definition: btDynamicsWorld.h:42
btCollisionConfiguration
btCollisionConfiguration allows to configure Bullet collision detection stack allocator size...
Definition: btCollisionConfiguration.h:26
btDiscreteDynamicsWorld::m_actions
btAlignedObjectArray< btActionInterface * > m_actions
Definition: btDiscreteDynamicsWorld.h:65
btDiscreteDynamicsWorld::getSimulationIslandManager
btSimulationIslandManager * getSimulationIslandManager()
Definition: btDiscreteDynamicsWorld.h:128
btDiscreteDynamicsWorld::updateVehicles
virtual void updateVehicles(btScalar timeStep)
obsolete, use updateActions instead
Definition: btDiscreteDynamicsWorld.h:191
btSpinMutex
btSpinMutex – lightweight spin-mutex implemented with atomic ops, never puts a thread to sleep beca...
Definition: btThreads.h:45
btDiscreteDynamicsWorld::m_ownsConstraintSolver
bool m_ownsConstraintSolver
Definition: btDiscreteDynamicsWorld.h:61
btActionInterface
Basic interface to allow actions such as vehicles and characters to be updated inside a btDynamicsWor...
Definition: btActionInterface.h:26
btDynamicsWorld.h
btSerializer
Definition: btSerializer.h:68
btOverlappingPairCache
The btOverlappingPairCache provides an interface for overlapping pair management (add, remove, storage), used by the btBroadphaseInterface broadphases.
Definition: btOverlappingPairCache.h:60
btDiscreteDynamicsWorld::getCollisionWorld
btCollisionWorld * getCollisionWorld()
Definition: btDiscreteDynamicsWorld.h:138
btDiscreteDynamicsWorld::getApplySpeculativeContactRestitution
bool getApplySpeculativeContactRestitution() const
Definition: btDiscreteDynamicsWorld.h:219
btBroadphaseProxy::StaticFilter
Definition: btBroadphaseProxy.h:94
btDiscreteDynamicsWorld::m_gravity
btVector3 m_gravity
Definition: btDiscreteDynamicsWorld.h:53
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:49
btIDebugDraw
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations...
Definition: btIDebugDraw.h:29
btDiscreteDynamicsWorld::getWorldType
virtual btDynamicsWorldType getWorldType() const
Definition: btDiscreteDynamicsWorld.h:174
btDiscreteDynamicsWorld::m_predictiveManifolds
btAlignedObjectArray< btPersistentManifold * > m_predictiveManifolds
Definition: btDiscreteDynamicsWorld.h:71
btRigidBody
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:62
btBroadphaseInterface
The btBroadphaseInterface class provides an interface to detect aabb-overlapping object pairs...
Definition: btBroadphaseInterface.h:55
btDiscreteDynamicsWorld::m_fixedTimeStep
btScalar m_fixedTimeStep
Definition: btDiscreteDynamicsWorld.h:57
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:82
btContactSolverInfo
Definition: btContactSolverInfo.h:69
btCollisionWorld
CollisionWorld is interface and container for the collision detection.
Definition: btCollisionWorld.h:88
btDiscreteDynamicsWorld::getLatencyMotionStateInterpolation
bool getLatencyMotionStateInterpolation() const
Definition: btDiscreteDynamicsWorld.h:233
btDiscreteDynamicsWorld::m_latencyMotionStateInterpolation
bool m_latencyMotionStateInterpolation
Definition: btDiscreteDynamicsWorld.h:69
btDiscreteDynamicsWorld::getSimulationIslandManager
const btSimulationIslandManager * getSimulationIslandManager() const
Definition: btDiscreteDynamicsWorld.h:133
btTypedConstraint
TypedConstraint is the baseclass for Bullet constraints and vehicles.
Definition: btTypedConstraint.h:78
btThreads.h
btDiscreteDynamicsWorld::m_synchronizeAllMotionStates
bool m_synchronizeAllMotionStates
Definition: btDiscreteDynamicsWorld.h:62
btDiscreteDynamicsWorld::setNumTasks
virtual void setNumTasks(int numTasks)
Definition: btDiscreteDynamicsWorld.h:185
BT_DISCRETE_DYNAMICS_WORLD
Definition: btDynamicsWorld.h:34
BT_DECLARE_ALIGNED_ALLOCATOR
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:403
btDynamicsWorldType
btDynamicsWorldType
Definition: btDynamicsWorld.h:31
btDiscreteDynamicsWorld::m_solverIslandCallback
InplaceSolverIslandCallback * m_solverIslandCallback
Definition: btDiscreteDynamicsWorld.h:43
btAlignedObjectArray.h
btDiscreteDynamicsWorld::m_predictiveManifoldsMutex
btSpinMutex m_predictiveManifoldsMutex
Definition: btDiscreteDynamicsWorld.h:72
btDiscreteDynamicsWorld::m_applySpeculativeContactRestitution
bool m_applySpeculativeContactRestitution
Definition: btDiscreteDynamicsWorld.h:63
btBroadphaseProxy::AllFilter
Definition: btBroadphaseProxy.h:99
btDiscreteDynamicsWorld::m_constraintSolver
btConstraintSolver * m_constraintSolver
Definition: btDiscreteDynamicsWorld.h:45
btDiscreteDynamicsWorld::m_ownsIslandManager
bool m_ownsIslandManager
Definition: btDiscreteDynamicsWorld.h:60
btDiscreteDynamicsWorld::setApplySpeculativeContactRestitution
void setApplySpeculativeContactRestitution(bool enable)
Definition: btDiscreteDynamicsWorld.h:214
btDiscreteDynamicsWorld::m_profileTimings
int m_profileTimings
Definition: btDiscreteDynamicsWorld.h:67
btDispatcher
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:75
btDiscreteDynamicsWorld::setLatencyMotionStateInterpolation
void setLatencyMotionStateInterpolation(bool latencyInterpolation)
Interpolate motion state between previous and current transform, instead of current and next transfor...
Definition: btDiscreteDynamicsWorld.h:229
btDiscreteDynamicsWorld::getSynchronizeAllMotionStates
bool getSynchronizeAllMotionStates() const
Definition: btDiscreteDynamicsWorld.h:209
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292
btDiscreteDynamicsWorld::m_constraints
btAlignedObjectArray< btTypedConstraint * > m_constraints
Definition: btDiscreteDynamicsWorld.h:49
btConstraintSolver
Definition: btConstraintSolver.h:40