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

Bullet Collision Detection & Physics Library

btDynamicsWorld.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans https://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_DYNAMICS_WORLD_H
17#define BT_DYNAMICS_WORLD_H
18
19#include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
20#include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h"
21
22class btTypedConstraint;
23class btActionInterface;
24class btConstraintSolver;
25class btDynamicsWorld;
26
28 typedef void (*btInternalTickCallback)(btDynamicsWorld* world, btScalar timeStep);
29
30 enum btDynamicsWorldType
31{
32 BT_SIMPLE_DYNAMICS_WORLD = 1,
33 BT_DISCRETE_DYNAMICS_WORLD = 2,
34 BT_CONTINUOUS_DYNAMICS_WORLD = 3,
35 BT_SOFT_RIGID_DYNAMICS_WORLD = 4,
36 BT_GPU_DYNAMICS_WORLD = 5,
37 BT_SOFT_MULTIBODY_DYNAMICS_WORLD = 6,
38 BT_DEFORMABLE_MULTIBODY_DYNAMICS_WORLD = 7
39};
40
42 class btDynamicsWorld : public btCollisionWorld
43{
44protected:
45 btInternalTickCallback m_internalTickCallback;
46 btInternalTickCallback m_internalPreTickCallback;
47 void* m_worldUserInfo;
48
49 btContactSolverInfo m_solverInfo;
50
51public:
52 btDynamicsWorld(btDispatcher* dispatcher, btBroadphaseInterface* broadphase, btCollisionConfiguration* collisionConfiguration)
53 : btCollisionWorld(dispatcher, broadphase, collisionConfiguration), m_internalTickCallback(0), m_internalPreTickCallback(0), m_worldUserInfo(0)
54 {
55 }
56
57 virtual ~btDynamicsWorld()
58 {
59 }
60
65 virtual int stepSimulation(btScalar timeStep, int maxSubSteps = 1, btScalar fixedTimeStep = btScalar(1.) / btScalar(60.)) = 0;
66
67 virtual void debugDrawWorld() = 0;
68
69 virtual void addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies = false)
70 {
71 (void)constraint;
72 (void)disableCollisionsBetweenLinkedBodies;
73 }
74
75 virtual void removeConstraint(btTypedConstraint* constraint) { (void)constraint; }
76
77 virtual void addAction(btActionInterface* action) = 0;
78
79 virtual void removeAction(btActionInterface* action) = 0;
80
81 //once a rigidbody is added to the dynamics world, it will get this gravity assigned
82 //existing rigidbodies in the world get gravity assigned too, during this method
83 virtual void setGravity(const btVector3& gravity) = 0;
84 virtual btVector3 getGravity() const = 0;
85
86 virtual void synchronizeMotionStates() = 0;
87
88 virtual void addRigidBody(btRigidBody* body) = 0;
89
90 virtual void addRigidBody(btRigidBody* body, int group, int mask) = 0;
91
92 virtual void removeRigidBody(btRigidBody* body) = 0;
93
94 virtual void setConstraintSolver(btConstraintSolver* solver) = 0;
95
96 virtual btConstraintSolver* getConstraintSolver() = 0;
97
98 virtual int getNumConstraints() const { return 0; }
99
100 virtual btTypedConstraint* getConstraint(int index)
101 {
102 (void)index;
103 return 0;
104 }
105
106 virtual const btTypedConstraint* getConstraint(int index) const
107 {
108 (void)index;
109 return 0;
110 }
111
112 virtual btDynamicsWorldType getWorldType() const = 0;
113
114 virtual void clearForces() = 0;
115
117 void setInternalTickCallback(btInternalTickCallback cb, void* worldUserInfo = 0, bool isPreTick = false)
118 {
119 if (isPreTick)
120 {
121 m_internalPreTickCallback = cb;
122 }
123 else
124 {
125 m_internalTickCallback = cb;
126 }
127 m_worldUserInfo = worldUserInfo;
128 }
129
130 void setWorldUserInfo(void* worldUserInfo)
131 {
132 m_worldUserInfo = worldUserInfo;
133 }
134
135 void* getWorldUserInfo() const
136 {
137 return m_worldUserInfo;
138 }
139
140 btContactSolverInfo& getSolverInfo()
141 {
142 return m_solverInfo;
143 }
144
145 const btContactSolverInfo& getSolverInfo() const
146 {
147 return m_solverInfo;
148 }
149
151 virtual void addVehicle(btActionInterface* vehicle) { (void)vehicle; }
153 virtual void removeVehicle(btActionInterface* vehicle) { (void)vehicle; }
155 virtual void addCharacter(btActionInterface* character) { (void)character; }
157 virtual void removeCharacter(btActionInterface* character) { (void)character; }
158};
159
161 struct btDynamicsWorldDoubleData
162{
163 btContactSolverInfoDoubleData m_solverInfo;
164 btVector3DoubleData m_gravity;
165};
166
168 struct btDynamicsWorldFloatData
169{
170 btContactSolverInfoFloatData m_solverInfo;
171 btVector3FloatData m_gravity;
172};
173
174#endif //BT_DYNAMICS_WORLD_H
btCollisionWorld.h
btContactSolverInfo.h
btDynamicsWorldType
btDynamicsWorldType
Definition btDynamicsWorld.h:31
BT_SIMPLE_DYNAMICS_WORLD
@ BT_SIMPLE_DYNAMICS_WORLD
Definition btDynamicsWorld.h:32
BT_CONTINUOUS_DYNAMICS_WORLD
@ BT_CONTINUOUS_DYNAMICS_WORLD
Definition btDynamicsWorld.h:34
BT_DEFORMABLE_MULTIBODY_DYNAMICS_WORLD
@ BT_DEFORMABLE_MULTIBODY_DYNAMICS_WORLD
Definition btDynamicsWorld.h:38
BT_GPU_DYNAMICS_WORLD
@ BT_GPU_DYNAMICS_WORLD
Definition btDynamicsWorld.h:36
BT_SOFT_RIGID_DYNAMICS_WORLD
@ BT_SOFT_RIGID_DYNAMICS_WORLD
Definition btDynamicsWorld.h:35
BT_SOFT_MULTIBODY_DYNAMICS_WORLD
@ BT_SOFT_MULTIBODY_DYNAMICS_WORLD
Definition btDynamicsWorld.h:37
BT_DISCRETE_DYNAMICS_WORLD
@ BT_DISCRETE_DYNAMICS_WORLD
Definition btDynamicsWorld.h:33
btInternalTickCallback
void(* btInternalTickCallback)(btDynamicsWorld *world, btScalar timeStep)
Type for the callback for each tick.
Definition btDynamicsWorld.h:28
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
btActionInterface
Basic interface to allow actions such as vehicles and characters to be updated inside a btDynamicsWor...
Definition btActionInterface.h:27
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
btCollisionWorld::btCollisionWorld
btCollisionWorld(btDispatcher *dispatcher, btBroadphaseInterface *broadphasePairCache, btCollisionConfiguration *collisionConfiguration)
for debug drawing
Definition btCollisionWorld.cpp:67
btConstraintSolver
Definition btConstraintSolver.h:42
btDispatcher
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition btDispatcher.h:77
btDynamicsWorld
The btDynamicsWorld is the interface class for several dynamics implementation, basic,...
Definition btDynamicsWorld.h:43
btDynamicsWorld::removeRigidBody
virtual void removeRigidBody(btRigidBody *body)=0
btDynamicsWorld::getSolverInfo
const btContactSolverInfo & getSolverInfo() const
Definition btDynamicsWorld.h:145
btDynamicsWorld::getConstraintSolver
virtual btConstraintSolver * getConstraintSolver()=0
btDynamicsWorld::getGravity
virtual btVector3 getGravity() const =0
btDynamicsWorld::removeAction
virtual void removeAction(btActionInterface *action)=0
btDynamicsWorld::debugDrawWorld
virtual void debugDrawWorld()=0
btDynamicsWorld::m_solverInfo
btContactSolverInfo m_solverInfo
Definition btDynamicsWorld.h:49
btDynamicsWorld::getSolverInfo
btContactSolverInfo & getSolverInfo()
Definition btDynamicsWorld.h:140
btDynamicsWorld::addCharacter
virtual void addCharacter(btActionInterface *character)
obsolete, use addAction instead.
Definition btDynamicsWorld.h:155
btDynamicsWorld::stepSimulation
virtual int stepSimulation(btScalar timeStep, int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.))=0
stepSimulation proceeds the simulation over 'timeStep', units in preferably in seconds.
btDynamicsWorld::addRigidBody
virtual void addRigidBody(btRigidBody *body, int group, int mask)=0
btDynamicsWorld::getNumConstraints
virtual int getNumConstraints() const
Definition btDynamicsWorld.h:98
btDynamicsWorld::setConstraintSolver
virtual void setConstraintSolver(btConstraintSolver *solver)=0
btDynamicsWorld::setInternalTickCallback
void setInternalTickCallback(btInternalTickCallback cb, void *worldUserInfo=0, bool isPreTick=false)
Set the callback for when an internal tick (simulation substep) happens, optional user info.
Definition btDynamicsWorld.h:117
btDynamicsWorld::m_internalTickCallback
btInternalTickCallback m_internalTickCallback
Definition btDynamicsWorld.h:45
btDynamicsWorld::m_internalPreTickCallback
btInternalTickCallback m_internalPreTickCallback
Definition btDynamicsWorld.h:46
btDynamicsWorld::~btDynamicsWorld
virtual ~btDynamicsWorld()
Definition btDynamicsWorld.h:57
btDynamicsWorld::getConstraint
virtual const btTypedConstraint * getConstraint(int index) const
Definition btDynamicsWorld.h:106
btDynamicsWorld::getWorldType
virtual btDynamicsWorldType getWorldType() const =0
btDynamicsWorld::removeConstraint
virtual void removeConstraint(btTypedConstraint *constraint)
Definition btDynamicsWorld.h:75
btDynamicsWorld::addRigidBody
virtual void addRigidBody(btRigidBody *body)=0
btDynamicsWorld::clearForces
virtual void clearForces()=0
btDynamicsWorld::addConstraint
virtual void addConstraint(btTypedConstraint *constraint, bool disableCollisionsBetweenLinkedBodies=false)
Definition btDynamicsWorld.h:69
btDynamicsWorld::getWorldUserInfo
void * getWorldUserInfo() const
Definition btDynamicsWorld.h:135
btDynamicsWorld::addVehicle
virtual void addVehicle(btActionInterface *vehicle)
obsolete, use addAction instead.
Definition btDynamicsWorld.h:151
btDynamicsWorld::removeVehicle
virtual void removeVehicle(btActionInterface *vehicle)
obsolete, use removeAction instead
Definition btDynamicsWorld.h:153
btDynamicsWorld::m_worldUserInfo
void * m_worldUserInfo
Definition btDynamicsWorld.h:47
btDynamicsWorld::setWorldUserInfo
void setWorldUserInfo(void *worldUserInfo)
Definition btDynamicsWorld.h:130
btDynamicsWorld::addAction
virtual void addAction(btActionInterface *action)=0
btDynamicsWorld::btDynamicsWorld
btDynamicsWorld(btDispatcher *dispatcher, btBroadphaseInterface *broadphase, btCollisionConfiguration *collisionConfiguration)
Definition btDynamicsWorld.h:52
btDynamicsWorld::removeCharacter
virtual void removeCharacter(btActionInterface *character)
obsolete, use removeAction instead
Definition btDynamicsWorld.h:157
btDynamicsWorld::getConstraint
virtual btTypedConstraint * getConstraint(int index)
Definition btDynamicsWorld.h:100
btDynamicsWorld::synchronizeMotionStates
virtual void synchronizeMotionStates()=0
btDynamicsWorld::setGravity
virtual void setGravity(const btVector3 &gravity)=0
btRigidBody
The btRigidBody is the main class for rigid body objects.
Definition btRigidBody.h:60
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
btContactSolverInfoDoubleData
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
Definition btContactSolverInfo.h:118
btContactSolverInfoFloatData
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
Definition btContactSolverInfo.h:146
btContactSolverInfo
Definition btContactSolverInfo.h:76
btDynamicsWorldDoubleData
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
Definition btDynamicsWorld.h:162
btDynamicsWorldDoubleData::m_solverInfo
btContactSolverInfoDoubleData m_solverInfo
Definition btDynamicsWorld.h:163
btDynamicsWorldDoubleData::m_gravity
btVector3DoubleData m_gravity
Definition btDynamicsWorld.h:164
btDynamicsWorldFloatData
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
Definition btDynamicsWorld.h:169
btDynamicsWorldFloatData::m_gravity
btVector3FloatData m_gravity
Definition btDynamicsWorld.h:171
btDynamicsWorldFloatData::m_solverInfo
btContactSolverInfoFloatData m_solverInfo
Definition btDynamicsWorld.h:170
btVector3DoubleData
Definition btVector3.h:1287
btVector3FloatData
Definition btVector3.h:1282