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;
105 btDantzigSolver 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;
144 m_pDynamicsWorld->getSolverInfo().m_erp = 0.8;
158 const size_t nco = m_pDynamicsWorld->getNumCollisionObjects();
159 btCollisionObjectArray& oa = m_pDynamicsWorld->getCollisionObjectArray();
160 for (
int i = nco - 1; i >= 0; --i)
162 btCollisionObject *
const pCollisionObject = oa[i];
165 const btRigidBody*
const pRigidBody =
166 btRigidBody::upcast(pCollisionObject);
169 delete pRigidBody->getMotionState();
173 m_pDynamicsWorld->removeCollisionObject(pCollisionObject);
175 delete pCollisionObject;
178 assert(m_pDynamicsWorld->getNumCollisionObjects() == 0);
181 const size_t ncs = m_collisionShapes.size();
183 for (
size_t i = 0; i < ncs; ++i) {
delete m_collisionShapes[i]; }
185 delete m_pDynamicsWorld;
188 delete m_pIntermediateBuildProducts;
195 btDynamicsWorld* tgWorldBulletPhysicsImpl::createDynamicsWorld()
const
198 btSoftRigidDynamicsWorld*
const result =
199 new btSoftRigidDynamicsWorld(&m_pIntermediateBuildProducts->dispatcher,
200 &m_pIntermediateBuildProducts->broadphase,
201 &m_pIntermediateBuildProducts->solver,
202 &m_pIntermediateBuildProducts->collisionConfiguration);
204 result ->getSolverInfo().m_minimumSolverBatchSize = 1;
214 const btScalar timeStep = dt;
215 const int maxSubSteps = 1;
216 const btScalar fixedTimeStep = dt;
217 m_pDynamicsWorld->stepSimulation(timeStep, maxSubSteps, fixedTimeStep);
225 #ifndef BT_NO_PROFILE
226 BT_PROFILE(
"addCollisionShape");
227 #endif //BT_NO_PROFILE
231 m_collisionShapes.push_back(pShape);
240 #ifndef BT_NO_PROFILE
241 BT_PROFILE(
"deleteCollisionShape");
242 #endif //BT_NO_PROFILE
246 btCompoundShape* cShape = tgCast::cast<btCollisionShape, btCompoundShape>(pShape);
249 std::size_t n = cShape->getNumChildShapes();
250 for( std::size_t i = 0; i < n; i++)
255 m_collisionShapes.remove(pShape);
263 bool tgWorldBulletPhysicsImpl::invariant()
const
265 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.