[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; |
---|
| 23 | class btRaycastVehicle; |
---|
| 24 | class btConstraintSolver; |
---|
| 25 | class btDynamicsWorld; |
---|
| 26 | |
---|
| 27 | /// Type for the callback for each tick |
---|
| 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 | }; |
---|
| 36 | |
---|
| 37 | ///The btDynamicsWorld is the interface class for several dynamics implementation, basic, discrete, parallel, and continuous etc. |
---|
| 38 | class btDynamicsWorld : public btCollisionWorld |
---|
| 39 | { |
---|
| 40 | |
---|
| 41 | protected: |
---|
| 42 | btInternalTickCallback m_internalTickCallback; |
---|
| 43 | void* m_worldUserInfo; |
---|
| 44 | |
---|
| 45 | btContactSolverInfo m_solverInfo; |
---|
| 46 | |
---|
| 47 | public: |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | btDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* broadphase,btCollisionConfiguration* collisionConfiguration) |
---|
| 51 | :btCollisionWorld(dispatcher,broadphase,collisionConfiguration), m_internalTickCallback(0), m_worldUserInfo(0) |
---|
| 52 | { |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | virtual ~btDynamicsWorld() |
---|
| 56 | { |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | ///stepSimulation proceeds the simulation over 'timeStep', units in preferably in seconds. |
---|
| 60 | ///By default, Bullet will subdivide the timestep in constant substeps of each 'fixedTimeStep'. |
---|
| 61 | ///in order to keep the simulation real-time, the maximum number of substeps can be clamped to 'maxSubSteps'. |
---|
| 62 | ///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. |
---|
| 63 | virtual int stepSimulation( btScalar timeStep,int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.))=0; |
---|
| 64 | |
---|
| 65 | virtual void debugDrawWorld() = 0; |
---|
| 66 | |
---|
| 67 | virtual void addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies=false) |
---|
| 68 | { |
---|
| 69 | (void)constraint; (void)disableCollisionsBetweenLinkedBodies; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | virtual void removeConstraint(btTypedConstraint* constraint) {(void)constraint;} |
---|
| 73 | |
---|
| 74 | virtual void addVehicle(btRaycastVehicle* vehicle) {(void)vehicle;} |
---|
| 75 | |
---|
| 76 | virtual void removeVehicle(btRaycastVehicle* vehicle) {(void)vehicle;} |
---|
| 77 | |
---|
| 78 | //once a rigidbody is added to the dynamics world, it will get this gravity assigned |
---|
| 79 | //existing rigidbodies in the world get gravity assigned too, during this method |
---|
| 80 | virtual void setGravity(const btVector3& gravity) = 0; |
---|
| 81 | virtual btVector3 getGravity () const = 0; |
---|
| 82 | |
---|
| 83 | virtual void addRigidBody(btRigidBody* body) = 0; |
---|
| 84 | |
---|
| 85 | virtual void removeRigidBody(btRigidBody* body) = 0; |
---|
| 86 | |
---|
| 87 | virtual void setConstraintSolver(btConstraintSolver* solver) = 0; |
---|
| 88 | |
---|
| 89 | virtual btConstraintSolver* getConstraintSolver() = 0; |
---|
| 90 | |
---|
| 91 | virtual int getNumConstraints() const { return 0; } |
---|
| 92 | |
---|
| 93 | virtual btTypedConstraint* getConstraint(int index) { (void)index; return 0; } |
---|
| 94 | |
---|
| 95 | virtual const btTypedConstraint* getConstraint(int index) const { (void)index; return 0; } |
---|
| 96 | |
---|
| 97 | virtual btDynamicsWorldType getWorldType() const=0; |
---|
| 98 | |
---|
| 99 | virtual void clearForces() = 0; |
---|
| 100 | |
---|
| 101 | /// Set the callback for when an internal tick (simulation substep) happens, optional user info |
---|
| 102 | void setInternalTickCallback(btInternalTickCallback cb, void* worldUserInfo=0) |
---|
| 103 | { |
---|
| 104 | m_internalTickCallback = cb; |
---|
| 105 | m_worldUserInfo = worldUserInfo; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | void setWorldUserInfo(void* worldUserInfo) |
---|
| 109 | { |
---|
| 110 | m_worldUserInfo = worldUserInfo; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | void* getWorldUserInfo() const |
---|
| 114 | { |
---|
| 115 | return m_worldUserInfo; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | btContactSolverInfo& getSolverInfo() |
---|
| 119 | { |
---|
| 120 | return m_solverInfo; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | }; |
---|
| 125 | |
---|
| 126 | #endif //BT_DYNAMICS_WORLD_H |
---|
| 127 | |
---|
| 128 | |
---|