[1963] | 1 | /* |
---|
| 2 | Bullet Continuous Collision Detection and Physics Library |
---|
[8351] | 3 | Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org |
---|
[1963] | 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 | |
---|
[8351] | 16 | |
---|
[1963] | 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; |
---|
[2882] | 27 | class btActionInterface; |
---|
[1963] | 28 | |
---|
| 29 | class btIDebugDraw; |
---|
| 30 | #include "LinearMath/btAlignedObjectArray.h" |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | ///btDiscreteDynamicsWorld provides discrete rigid body simulation |
---|
| 34 | ///those classes replace the obsolete CcdPhysicsEnvironment/CcdPhysicsController |
---|
| 35 | class btDiscreteDynamicsWorld : public btDynamicsWorld |
---|
| 36 | { |
---|
| 37 | protected: |
---|
| 38 | |
---|
| 39 | btConstraintSolver* m_constraintSolver; |
---|
| 40 | |
---|
| 41 | btSimulationIslandManager* m_islandManager; |
---|
| 42 | |
---|
| 43 | btAlignedObjectArray<btTypedConstraint*> m_constraints; |
---|
| 44 | |
---|
[8351] | 45 | btAlignedObjectArray<btRigidBody*> m_nonStaticRigidBodies; |
---|
| 46 | |
---|
[1963] | 47 | btVector3 m_gravity; |
---|
| 48 | |
---|
| 49 | //for variable timesteps |
---|
| 50 | btScalar m_localTime; |
---|
| 51 | //for variable timesteps |
---|
| 52 | |
---|
| 53 | bool m_ownsIslandManager; |
---|
| 54 | bool m_ownsConstraintSolver; |
---|
[8351] | 55 | bool m_synchronizeAllMotionStates; |
---|
[1963] | 56 | |
---|
[2882] | 57 | btAlignedObjectArray<btActionInterface*> m_actions; |
---|
[1963] | 58 | |
---|
| 59 | int m_profileTimings; |
---|
| 60 | |
---|
| 61 | virtual void predictUnconstraintMotion(btScalar timeStep); |
---|
| 62 | |
---|
| 63 | virtual void integrateTransforms(btScalar timeStep); |
---|
| 64 | |
---|
[2430] | 65 | virtual void calculateSimulationIslands(); |
---|
[1963] | 66 | |
---|
[2430] | 67 | virtual void solveConstraints(btContactSolverInfo& solverInfo); |
---|
[1963] | 68 | |
---|
| 69 | void updateActivationState(btScalar timeStep); |
---|
| 70 | |
---|
[2882] | 71 | void updateActions(btScalar timeStep); |
---|
[1963] | 72 | |
---|
| 73 | void startProfiling(btScalar timeStep); |
---|
| 74 | |
---|
| 75 | virtual void internalSingleStepSimulation( btScalar timeStep); |
---|
| 76 | |
---|
| 77 | |
---|
[2430] | 78 | virtual void saveKinematicState(btScalar timeStep); |
---|
[1963] | 79 | |
---|
[8351] | 80 | void serializeRigidBodies(btSerializer* serializer); |
---|
[1963] | 81 | |
---|
| 82 | public: |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | ///this btDiscreteDynamicsWorld constructor gets created objects from the user, and will not delete those |
---|
| 86 | btDiscreteDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration); |
---|
| 87 | |
---|
| 88 | virtual ~btDiscreteDynamicsWorld(); |
---|
| 89 | |
---|
| 90 | ///if maxSubSteps > 0, it will interpolate motion between fixedTimeStep's |
---|
| 91 | virtual int stepSimulation( btScalar timeStep,int maxSubSteps=1, btScalar fixedTimeStep=btScalar(1.)/btScalar(60.)); |
---|
| 92 | |
---|
| 93 | |
---|
[2430] | 94 | virtual void synchronizeMotionStates(); |
---|
[1963] | 95 | |
---|
[2430] | 96 | ///this can be useful to synchronize a single rigid body -> graphics object |
---|
| 97 | void synchronizeSingleMotionState(btRigidBody* body); |
---|
[1963] | 98 | |
---|
[2430] | 99 | virtual void addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies=false); |
---|
[1963] | 100 | |
---|
[2430] | 101 | virtual void removeConstraint(btTypedConstraint* constraint); |
---|
[1963] | 102 | |
---|
[2882] | 103 | virtual void addAction(btActionInterface*); |
---|
[2430] | 104 | |
---|
[2882] | 105 | virtual void removeAction(btActionInterface*); |
---|
[2430] | 106 | |
---|
[1963] | 107 | btSimulationIslandManager* getSimulationIslandManager() |
---|
| 108 | { |
---|
| 109 | return m_islandManager; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | const btSimulationIslandManager* getSimulationIslandManager() const |
---|
| 113 | { |
---|
| 114 | return m_islandManager; |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | btCollisionWorld* getCollisionWorld() |
---|
| 118 | { |
---|
| 119 | return this; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | virtual void setGravity(const btVector3& gravity); |
---|
[2882] | 123 | |
---|
[1963] | 124 | virtual btVector3 getGravity () const; |
---|
| 125 | |
---|
[8351] | 126 | virtual void addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup=btBroadphaseProxy::StaticFilter,short int collisionFilterMask=btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter); |
---|
| 127 | |
---|
[1963] | 128 | virtual void addRigidBody(btRigidBody* body); |
---|
| 129 | |
---|
| 130 | virtual void addRigidBody(btRigidBody* body, short group, short mask); |
---|
| 131 | |
---|
| 132 | virtual void removeRigidBody(btRigidBody* body); |
---|
| 133 | |
---|
[8351] | 134 | ///removeCollisionObject will first check if it is a rigid body, if so call removeRigidBody otherwise call btCollisionWorld::removeCollisionObject |
---|
| 135 | virtual void removeCollisionObject(btCollisionObject* collisionObject); |
---|
[1963] | 136 | |
---|
[8351] | 137 | |
---|
[2882] | 138 | void debugDrawConstraint(btTypedConstraint* constraint); |
---|
| 139 | |
---|
[1963] | 140 | virtual void debugDrawWorld(); |
---|
| 141 | |
---|
| 142 | virtual void setConstraintSolver(btConstraintSolver* solver); |
---|
| 143 | |
---|
| 144 | virtual btConstraintSolver* getConstraintSolver(); |
---|
| 145 | |
---|
| 146 | virtual int getNumConstraints() const; |
---|
| 147 | |
---|
| 148 | virtual btTypedConstraint* getConstraint(int index) ; |
---|
| 149 | |
---|
| 150 | virtual const btTypedConstraint* getConstraint(int index) const; |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | virtual btDynamicsWorldType getWorldType() const |
---|
| 154 | { |
---|
| 155 | return BT_DISCRETE_DYNAMICS_WORLD; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | ///the forces on each rigidbody is accumulating together with gravity. clear this after each timestep. |
---|
| 159 | virtual void clearForces(); |
---|
| 160 | |
---|
| 161 | ///apply gravity, call this once per timestep |
---|
| 162 | virtual void applyGravity(); |
---|
| 163 | |
---|
| 164 | virtual void setNumTasks(int numTasks) |
---|
| 165 | { |
---|
[2430] | 166 | (void) numTasks; |
---|
[1963] | 167 | } |
---|
| 168 | |
---|
[2882] | 169 | ///obsolete, use updateActions instead |
---|
| 170 | virtual void updateVehicles(btScalar timeStep) |
---|
| 171 | { |
---|
| 172 | updateActions(timeStep); |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | ///obsolete, use addAction instead |
---|
| 176 | virtual void addVehicle(btActionInterface* vehicle); |
---|
| 177 | ///obsolete, use removeAction instead |
---|
| 178 | virtual void removeVehicle(btActionInterface* vehicle); |
---|
| 179 | ///obsolete, use addAction instead |
---|
| 180 | virtual void addCharacter(btActionInterface* character); |
---|
| 181 | ///obsolete, use removeAction instead |
---|
| 182 | virtual void removeCharacter(btActionInterface* character); |
---|
| 183 | |
---|
[8351] | 184 | void setSynchronizeAllMotionStates(bool synchronizeAll) |
---|
| 185 | { |
---|
| 186 | m_synchronizeAllMotionStates = synchronizeAll; |
---|
| 187 | } |
---|
| 188 | bool getSynchronizeAllMotionStates() const |
---|
| 189 | { |
---|
| 190 | return m_synchronizeAllMotionStates; |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | ///Preliminary serialization test for Bullet 2.76. Loading those files requires a separate parser (see Bullet/Demos/SerializeDemo) |
---|
| 194 | virtual void serialize(btSerializer* serializer); |
---|
| 195 | |
---|
[1963] | 196 | }; |
---|
| 197 | |
---|
| 198 | #endif //BT_DISCRETE_DYNAMICS_WORLD_H |
---|