35 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
36 #include "BulletCollision/BroadphaseCollision/btDbvtBroadphase.h"
37 #include "BulletCollision/BroadphaseCollision/btAxisSweep3.h"
38 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
39 #include "BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h"
40 #include "BulletCollision/CollisionShapes/btBoxShape.h"
41 #include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
42 #include "BulletCollision/CollisionShapes/btCompoundShape.h"
43 #include "BulletDynamics/Dynamics/btRigidBody.h"
44 #include "BulletDynamics/Dynamics/btDynamicsWorld.h"
45 #include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h"
46 #include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h"
47 #include "BulletSoftBody/btSoftRigidDynamicsWorld.h"
48 #include "LinearMath/btDefaultMotionState.h"
49 #include "LinearMath/btScalar.h"
50 #include "LinearMath/btTransform.h"
51 #include "LinearMath/btVector3.h"
52 #include "LinearMath/btQuickprof.h"
55 #include "BulletCollision/CollisionDispatch/btGhostObject.h"
56 #include "BulletCollision/BroadphaseCollision/btOverlappingPairCache.h"
62 #include "BulletDynamics/MLCPSolvers/btDantzigSolver.h"
63 #include "BulletDynamics/MLCPSolvers/btSolveProjectedGaussSeidel.h"
64 #include "BulletDynamics/MLCPSolvers/btMLCPSolver.h"
76 corner1 (-worldSize,-worldSize, -worldSize),
77 corner2 (worldSize, worldSize, worldSize),
78 dispatcher(&collisionConfiguration),
81 #if (1) // More acc broadphase - remeber the comma (consider doing ifndef)
82 broadphase(corner1, corner2, 16384)
85 broadphase(corner1, corner2, 16384),
90 broadphase.getOverlappingPairCache()->setInternalGhostPairCallback(&ghostCallback);
92 const btVector3 corner1;
93 const btVector3 corner2;
94 btSoftBodyRigidBodyCollisionConfiguration collisionConfiguration;
95 btCollisionDispatcher dispatcher;
96 btGhostPairCallback ghostCallback;
97 #if (0) // Default broadphase
98 btDbvtBroadphase broadphase;
101 btAxisSweep3 broadphase;
106 btSolveProjectedGaussSeidel mlcp;
109 btSequentialImpulseConstraintSolver solver;
118 m_pDynamicsWorld(createDynamicsWorld())
122 const btVector3 gravityVector(0, -config.
gravity, 0);
123 m_pDynamicsWorld->setGravity(gravityVector);
125 if (!tgCast::cast<tgBulletGround, tgEmptyGround>(ground) && ground != NULL)
136 m_pDynamicsWorld->getSolverInfo().m_splitImpulse =
true;
137 m_pDynamicsWorld->getSolverInfo().m_splitImpulsePenetrationThreshold = -0.02;
141 m_pDynamicsWorld->getSolverInfo().m_numIterations = 20;
152 const size_t nco = m_pDynamicsWorld->getNumCollisionObjects();
153 btCollisionObjectArray& oa = m_pDynamicsWorld->getCollisionObjectArray();
154 for (
int i = nco - 1; i >= 0; --i)
156 btCollisionObject *
const pCollisionObject = oa[i];
159 const btRigidBody*
const pRigidBody =
160 btRigidBody::upcast(pCollisionObject);
163 delete pRigidBody->getMotionState();
167 m_pDynamicsWorld->removeCollisionObject(pCollisionObject);
169 delete pCollisionObject;
172 assert(m_pDynamicsWorld->getNumCollisionObjects() == 0);
175 const size_t ncs = m_collisionShapes.size();
177 for (
size_t i = 0; i < ncs; ++i) {
delete m_collisionShapes[i]; }
179 delete m_pDynamicsWorld;
182 delete m_pIntermediateBuildProducts;
189 btDynamicsWorld* tgWorldBulletPhysicsImpl::createDynamicsWorld()
const
191 btSoftRigidDynamicsWorld*
const result =
192 new btSoftRigidDynamicsWorld(&m_pIntermediateBuildProducts->dispatcher,
193 &m_pIntermediateBuildProducts->broadphase,
194 &m_pIntermediateBuildProducts->solver,
195 &m_pIntermediateBuildProducts->collisionConfiguration);
197 result ->getSolverInfo().m_minimumSolverBatchSize = 1;
207 const btScalar timeStep = dt;
208 const int maxSubSteps = 1;
209 const btScalar fixedTimeStep = dt;
210 m_pDynamicsWorld->stepSimulation(timeStep, maxSubSteps, fixedTimeStep);
218 #ifndef BT_NO_PROFILE
219 BT_PROFILE(
"addCollisionShape");
220 #endif //BT_NO_PROFILE
224 m_collisionShapes.push_back(pShape);
233 #ifndef BT_NO_PROFILE
234 BT_PROFILE(
"deleteCollisionShape");
235 #endif //BT_NO_PROFILE
239 btCompoundShape* cShape = tgCast::cast<btCollisionShape, btCompoundShape>(pShape);
242 std::size_t n = cShape->getNumChildShapes();
243 for( std::size_t i = 0; i < n; i++)
248 m_collisionShapes.remove(pShape);
256 bool tgWorldBulletPhysicsImpl::invariant()
const
258 return (m_pDynamicsWorld != 0);
~tgWorldBulletPhysicsImpl()
Contains the definition of class tgBulletGround.
Contains the definition of class tgWorldBulletPhysicsImpl.
Utility class for class casting and filtering collections by type.
tgWorldBulletPhysicsImpl(const tgWorld::Config &config, tgBulletGround *ground)
virtual btRigidBody * getGroundRigidBody() const =0
Contains the definition of class tgWorld $Id$.
virtual void step(double dt)
void addCollisionShape(btCollisionShape *pShape)
void deleteCollisionShape(btCollisionShape *pShape)
Contains the definition of class tgEmptyGround.