| [1963] | 1 | /* | 
|---|
|  | 2 | Bullet Continuous Collision Detection and Physics Library | 
|---|
|  | 3 | Copyright (c) 2003-2006 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 |  | 
|---|
|  | 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 |  | 
|---|
|  | 22 | class btTypedConstraint; | 
|---|
| [2882] | 23 | class btActionInterface; | 
|---|
| [1963] | 24 | class btConstraintSolver; | 
|---|
|  | 25 | class btDynamicsWorld; | 
|---|
|  | 26 |  | 
|---|
| [2882] | 27 |  | 
|---|
| [1963] | 28 | /// Type for the callback for each tick | 
|---|
|  | 29 | typedef void (*btInternalTickCallback)(btDynamicsWorld *world, btScalar timeStep); | 
|---|
|  | 30 |  | 
|---|
|  | 31 | enum btDynamicsWorldType | 
|---|
|  | 32 | { | 
|---|
|  | 33 | BT_SIMPLE_DYNAMICS_WORLD=1, | 
|---|
|  | 34 | BT_DISCRETE_DYNAMICS_WORLD=2, | 
|---|
| [8393] | 35 | BT_CONTINUOUS_DYNAMICS_WORLD=3, | 
|---|
|  | 36 | BT_SOFT_RIGID_DYNAMICS_WORLD=4 | 
|---|
| [1963] | 37 | }; | 
|---|
|  | 38 |  | 
|---|
|  | 39 | ///The btDynamicsWorld is the interface class for several dynamics implementation, basic, discrete, parallel, and continuous etc. | 
|---|
|  | 40 | class btDynamicsWorld : public btCollisionWorld | 
|---|
|  | 41 | { | 
|---|
|  | 42 |  | 
|---|
|  | 43 | protected: | 
|---|
|  | 44 | btInternalTickCallback m_internalTickCallback; | 
|---|
| [8351] | 45 | btInternalTickCallback m_internalPreTickCallback; | 
|---|
| [1963] | 46 | void*   m_worldUserInfo; | 
|---|
|  | 47 |  | 
|---|
|  | 48 | btContactSolverInfo     m_solverInfo; | 
|---|
|  | 49 |  | 
|---|
|  | 50 | public: | 
|---|
|  | 51 |  | 
|---|
|  | 52 |  | 
|---|
|  | 53 | btDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* broadphase,btCollisionConfiguration* collisionConfiguration) | 
|---|
| [8351] | 54 | :btCollisionWorld(dispatcher,broadphase,collisionConfiguration), m_internalTickCallback(0),m_internalPreTickCallback(0), m_worldUserInfo(0) | 
|---|
| [1963] | 55 | { | 
|---|
|  | 56 | } | 
|---|
|  | 57 |  | 
|---|
|  | 58 | virtual ~btDynamicsWorld() | 
|---|
|  | 59 | { | 
|---|
|  | 60 | } | 
|---|
|  | 61 |  | 
|---|
|  | 62 | ///stepSimulation proceeds the simulation over 'timeStep', units in preferably in seconds. | 
|---|
|  | 63 | ///By default, Bullet will subdivide the timestep in constant substeps of each 'fixedTimeStep'. | 
|---|
|  | 64 | ///in order to keep the simulation real-time, the maximum number of substeps can be clamped to 'maxSubSteps'. | 
|---|
|  | 65 | ///You can disable subdividing the timestep/substepping by passing maxSubSteps=0 as second argument to stepSimulation, but in that case you have to keep the timeStep constant. | 
|---|
|  | 66 | virtual int             stepSimulation( btScalar timeStep,int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.))=0; | 
|---|
|  | 67 |  | 
|---|
|  | 68 | virtual void    debugDrawWorld() = 0; | 
|---|
|  | 69 |  | 
|---|
|  | 70 | virtual void    addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies=false) | 
|---|
|  | 71 | { | 
|---|
|  | 72 | (void)constraint; (void)disableCollisionsBetweenLinkedBodies; | 
|---|
|  | 73 | } | 
|---|
|  | 74 |  | 
|---|
|  | 75 | virtual void    removeConstraint(btTypedConstraint* constraint) {(void)constraint;} | 
|---|
|  | 76 |  | 
|---|
| [2882] | 77 | virtual void    addAction(btActionInterface* action) = 0; | 
|---|
| [1963] | 78 |  | 
|---|
| [2882] | 79 | virtual void    removeAction(btActionInterface* action) = 0; | 
|---|
| [1963] | 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 |  | 
|---|
| [2430] | 86 | virtual void    synchronizeMotionStates() = 0; | 
|---|
|  | 87 |  | 
|---|
| [1963] | 88 | virtual void    addRigidBody(btRigidBody* body) = 0; | 
|---|
|  | 89 |  | 
|---|
| [8393] | 90 | virtual void    addRigidBody(btRigidBody* body, short group, short mask) = 0; | 
|---|
|  | 91 |  | 
|---|
| [1963] | 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)             {       (void)index;            return 0;               } | 
|---|
|  | 101 |  | 
|---|
|  | 102 | virtual const btTypedConstraint* getConstraint(int index) const {       (void)index;    return 0;       } | 
|---|
|  | 103 |  | 
|---|
|  | 104 | virtual btDynamicsWorldType     getWorldType() const=0; | 
|---|
|  | 105 |  | 
|---|
|  | 106 | virtual void    clearForces() = 0; | 
|---|
|  | 107 |  | 
|---|
|  | 108 | /// Set the callback for when an internal tick (simulation substep) happens, optional user info | 
|---|
| [8351] | 109 | void setInternalTickCallback(btInternalTickCallback cb, void* worldUserInfo=0,bool isPreTick=false) | 
|---|
| [1963] | 110 | { | 
|---|
| [8351] | 111 | if (isPreTick) | 
|---|
|  | 112 | { | 
|---|
|  | 113 | m_internalPreTickCallback = cb; | 
|---|
|  | 114 | } else | 
|---|
|  | 115 | { | 
|---|
|  | 116 | m_internalTickCallback = cb; | 
|---|
|  | 117 | } | 
|---|
| [1963] | 118 | m_worldUserInfo = worldUserInfo; | 
|---|
|  | 119 | } | 
|---|
|  | 120 |  | 
|---|
|  | 121 | void    setWorldUserInfo(void* worldUserInfo) | 
|---|
|  | 122 | { | 
|---|
|  | 123 | m_worldUserInfo = worldUserInfo; | 
|---|
|  | 124 | } | 
|---|
|  | 125 |  | 
|---|
|  | 126 | void*   getWorldUserInfo() const | 
|---|
|  | 127 | { | 
|---|
|  | 128 | return m_worldUserInfo; | 
|---|
|  | 129 | } | 
|---|
|  | 130 |  | 
|---|
|  | 131 | btContactSolverInfo& getSolverInfo() | 
|---|
|  | 132 | { | 
|---|
|  | 133 | return m_solverInfo; | 
|---|
|  | 134 | } | 
|---|
|  | 135 |  | 
|---|
|  | 136 |  | 
|---|
| [2882] | 137 | ///obsolete, use addAction instead. | 
|---|
|  | 138 | virtual void    addVehicle(btActionInterface* vehicle) {(void)vehicle;} | 
|---|
|  | 139 | ///obsolete, use removeAction instead | 
|---|
|  | 140 | virtual void    removeVehicle(btActionInterface* vehicle) {(void)vehicle;} | 
|---|
|  | 141 | ///obsolete, use addAction instead. | 
|---|
|  | 142 | virtual void    addCharacter(btActionInterface* character) {(void)character;} | 
|---|
|  | 143 | ///obsolete, use removeAction instead | 
|---|
|  | 144 | virtual void    removeCharacter(btActionInterface* character) {(void)character;} | 
|---|
|  | 145 |  | 
|---|
|  | 146 |  | 
|---|
| [1963] | 147 | }; | 
|---|
|  | 148 |  | 
|---|
|  | 149 | #endif //BT_DYNAMICS_WORLD_H | 
|---|
|  | 150 |  | 
|---|
|  | 151 |  | 
|---|