Bullet Collision Detection & Physics Library: btDiscreteDynamicsWorldMt.cpp Source File

Bullet Collision Detection & Physics Library

btDiscreteDynamicsWorldMt.cpp
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
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
17 #include "btDiscreteDynamicsWorldMt.h"
18
19 //collision detection
20 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
21 #include "BulletCollision/BroadphaseCollision/btSimpleBroadphase.h"
22 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
23 #include "BulletCollision/CollisionShapes/btCollisionShape.h"
24 #include "btSimulationIslandManagerMt.h"
25 #include "LinearMath/btTransformUtil.h"
26 #include "LinearMath/btQuickprof.h"
27
28 //rigidbody & constraints
29 #include "BulletDynamics/Dynamics/btRigidBody.h"
30 #include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h"
31 #include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h"
32 #include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
33 #include "BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h"
34 #include "BulletDynamics/ConstraintSolver/btHingeConstraint.h"
35 #include "BulletDynamics/ConstraintSolver/btConeTwistConstraint.h"
36 #include "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h"
37 #include "BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.h"
38 #include "BulletDynamics/ConstraintSolver/btSliderConstraint.h"
39 #include "BulletDynamics/ConstraintSolver/btContactConstraint.h"
40
41
42 #include "LinearMath/btIDebugDraw.h"
43 #include "BulletCollision/CollisionShapes/btSphereShape.h"
44
45
46 #include "BulletDynamics/Dynamics/btActionInterface.h"
47 #include "LinearMath/btQuickprof.h"
48 #include "LinearMath/btMotionState.h"
49
50 #include "LinearMath/btSerializer.h"
51
52
53 struct InplaceSolverIslandCallbackMt : public btSimulationIslandManagerMt::IslandCallback
54 {
55 btContactSolverInfo* m_solverInfo;
56 btConstraintSolver* m_solver;
57 btIDebugDraw* m_debugDrawer;
58 btDispatcher* m_dispatcher;
59
60 InplaceSolverIslandCallbackMt(
61 btConstraintSolver* solver,
62 btStackAlloc* stackAlloc,
63 btDispatcher* dispatcher)
64 :m_solverInfo(NULL),
65 m_solver(solver),
66 m_debugDrawer(NULL),
67 m_dispatcher(dispatcher)
68 {
69
70 }
71
72 InplaceSolverIslandCallbackMt& operator=(InplaceSolverIslandCallbackMt& other)
73 {
74 btAssert(0);
75 (void)other;
76 return *this;
77 }
78
79 SIMD_FORCE_INLINE void setup ( btContactSolverInfo* solverInfo, btIDebugDraw* debugDrawer)
80 {
81 btAssert(solverInfo);
82 m_solverInfo = solverInfo;
83 m_debugDrawer = debugDrawer;
84 }
85
86
87 virtual void processIsland( btCollisionObject** bodies,
88 int numBodies,
89 btPersistentManifold** manifolds,
90 int numManifolds,
91 btTypedConstraint** constraints,
92 int numConstraints,
93 int islandId
94 )
95 {
96 m_solver->solveGroup( bodies,
97 numBodies,
98 manifolds,
99 numManifolds,
100 constraints,
101 numConstraints,
102 *m_solverInfo,
103 m_debugDrawer,
104 m_dispatcher
105 );
106 }
107
108 };
109
110
111
112 btDiscreteDynamicsWorldMt::btDiscreteDynamicsWorldMt(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver, btCollisionConfiguration* collisionConfiguration)
113 : btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration)
114 {
115 if (m_ownsIslandManager)
116 {
117 m_islandManager->~btSimulationIslandManager();
118 btAlignedFree( m_islandManager);
119 }
120 {
121 void* mem = btAlignedAlloc(sizeof(InplaceSolverIslandCallbackMt),16);
122 m_solverIslandCallbackMt = new (mem) InplaceSolverIslandCallbackMt (m_constraintSolver, 0, dispatcher);
123 }
124 {
125 void* mem = btAlignedAlloc(sizeof(btSimulationIslandManagerMt),16);
126 btSimulationIslandManagerMt* im = new (mem) btSimulationIslandManagerMt();
127 m_islandManager = im;
128 im->setMinimumSolverBatchSize( m_solverInfo.m_minimumSolverBatchSize );
129 }
130 }
131
132
133 btDiscreteDynamicsWorldMt::~btDiscreteDynamicsWorldMt()
134 {
135 if (m_solverIslandCallbackMt)
136 {
137 m_solverIslandCallbackMt->~InplaceSolverIslandCallbackMt();
138 btAlignedFree(m_solverIslandCallbackMt);
139 }
140 if (m_ownsConstraintSolver)
141 {
142 m_constraintSolver->~btConstraintSolver();
143 btAlignedFree(m_constraintSolver);
144 }
145 }
146
147
148 void btDiscreteDynamicsWorldMt::solveConstraints(btContactSolverInfo& solverInfo)
149 {
150 BT_PROFILE("solveConstraints");
151
152 m_solverIslandCallbackMt->setup(&solverInfo, getDebugDrawer());
153 m_constraintSolver->prepareSolve(getCollisionWorld()->getNumCollisionObjects(), getCollisionWorld()->getDispatcher()->getNumManifolds());
154
156 btSimulationIslandManagerMt* im = static_cast<btSimulationIslandManagerMt*>(m_islandManager);
157 im->buildAndProcessIslands( getCollisionWorld()->getDispatcher(), getCollisionWorld(), m_constraints, m_solverIslandCallbackMt );
158
159 m_constraintSolver->allSolved(solverInfo, m_debugDrawer);
160 }
161
162
btTransformUtil.h
btPersistentManifold
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
Definition: btPersistentManifold.h:55
btDiscreteDynamicsWorldMt::btDiscreteDynamicsWorldMt
btDiscreteDynamicsWorldMt(btDispatcher *dispatcher, btBroadphaseInterface *pairCache, btConstraintSolver *constraintSolver, btCollisionConfiguration *collisionConfiguration)
Definition: btDiscreteDynamicsWorldMt.cpp:112
btDiscreteDynamicsWorld::m_islandManager
btSimulationIslandManager * m_islandManager
Definition: btDiscreteDynamicsWorld.h:47
btSimulationIslandManagerMt::buildAndProcessIslands
virtual void buildAndProcessIslands(btDispatcher *dispatcher, btCollisionWorld *collisionWorld, btAlignedObjectArray< btTypedConstraint *> &constraints, IslandCallback *callback)
Definition: btSimulationIslandManagerMt.cpp:569
btDiscreteDynamicsWorld
btDiscreteDynamicsWorld provides discrete rigid body simulation those classes replace the obsolete Cc...
Definition: btDiscreteDynamicsWorld.h:38
btAssert
#define btAssert(x)
Definition: btScalar.h:114
btSequentialImpulseConstraintSolver.h
btCollisionConfiguration
btCollisionConfiguration allows to configure Bullet collision detection stack allocator size...
Definition: btCollisionConfiguration.h:26
btDiscreteDynamicsWorldMt::solveConstraints
virtual void solveConstraints(btContactSolverInfo &solverInfo)
Definition: btDiscreteDynamicsWorldMt.cpp:148
btActionInterface.h
btContactConstraint.h
btConstraintSolver::solveGroup
virtual btScalar solveGroup(btCollisionObject **bodies, int numBodies, btPersistentManifold **manifold, int numManifolds, btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &info, class btIDebugDraw *debugDrawer, btDispatcher *dispatcher)=0
solve a group of constraints
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition: btScalar.h:64
btDiscreteDynamicsWorld::m_ownsConstraintSolver
bool m_ownsConstraintSolver
Definition: btDiscreteDynamicsWorld.h:61
InplaceSolverIslandCallbackMt::m_solverInfo
btContactSolverInfo * m_solverInfo
Definition: btDiscreteDynamicsWorldMt.cpp:55
InplaceSolverIslandCallbackMt::InplaceSolverIslandCallbackMt
InplaceSolverIslandCallbackMt(btConstraintSolver *solver, btStackAlloc *stackAlloc, btDispatcher *dispatcher)
Definition: btDiscreteDynamicsWorldMt.cpp:60
btRigidBody.h
btSimulationIslandManagerMt.h
btStackAlloc
The StackAlloc class provides some fast stack-based memory allocator (LIFO last-in first-out) ...
Definition: btStackAlloc.h:34
btDynamicsWorld::m_solverInfo
btContactSolverInfo m_solverInfo
Definition: btDynamicsWorld.h:50
btCollisionWorld::getNumCollisionObjects
int getNumCollisionObjects() const
Definition: btCollisionWorld.h:440
btTypedConstraint.h
btDiscreteDynamicsWorld::getCollisionWorld
btCollisionWorld * getCollisionWorld()
Definition: btDiscreteDynamicsWorld.h:138
btPoint2PointConstraint.h
InplaceSolverIslandCallbackMt::m_dispatcher
btDispatcher * m_dispatcher
Definition: btDiscreteDynamicsWorldMt.cpp:58
btSimpleBroadphase.h
btCollisionWorld::m_debugDrawer
btIDebugDraw * m_debugDrawer
Definition: btCollisionWorld.h:102
btCollisionWorld::getDebugDrawer
virtual btIDebugDraw * getDebugDrawer()
Definition: btCollisionWorld.h:162
InplaceSolverIslandCallbackMt::m_debugDrawer
btIDebugDraw * m_debugDrawer
Definition: btDiscreteDynamicsWorldMt.cpp:57
btAlignedFree
#define btAlignedFree(ptr)
Definition: btAlignedAllocator.h:48
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:49
btIDebugDraw
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations...
Definition: btIDebugDraw.h:29
btConeTwistConstraint.h
InplaceSolverIslandCallbackMt::setup
void setup(btContactSolverInfo *solverInfo, btIDebugDraw *debugDrawer)
Definition: btDiscreteDynamicsWorldMt.cpp:79
btBroadphaseInterface
The btBroadphaseInterface class provides an interface to detect aabb-overlapping object pairs...
Definition: btBroadphaseInterface.h:51
btHingeConstraint.h
btCollisionWorld::getDispatcher
btDispatcher * getDispatcher()
Definition: btCollisionWorld.h:138
btCollisionShape.h
BT_PROFILE
#define BT_PROFILE(name)
Definition: btQuickprof.h:213
btMotionState.h
btSimulationIslandManagerMt::IslandCallback
Definition: btSimulationIslandManagerMt.h:48
btContactSolverInfo
Definition: btContactSolverInfo.h:65
InplaceSolverIslandCallbackMt
Definition: btDiscreteDynamicsWorldMt.cpp:53
btConstraintSolver::allSolved
virtual void allSolved(const btContactSolverInfo &, class btIDebugDraw *)
Definition: btConstraintSolver.h:52
btContactSolverInfoData::m_minimumSolverBatchSize
int m_minimumSolverBatchSize
Definition: btContactSolverInfo.h:58
btIDebugDraw.h
btCollisionDispatcher.h
btConstraintSolver::prepareSolve
virtual void prepareSolve(int, int)
Definition: btConstraintSolver.h:47
btTypedConstraint
TypedConstraint is the baseclass for Bullet constraints and vehicles.
Definition: btTypedConstraint.h:78
btQuickprof.h
btSimulationIslandManagerMt::setMinimumSolverBatchSize
void setMinimumSolverBatchSize(int sz)
Definition: btSimulationIslandManagerMt.h:93
btGeneric6DofSpring2Constraint.h
btSliderConstraint.h
btAlignedAlloc
#define btAlignedAlloc(size, alignment)
Definition: btAlignedAllocator.h:47
btDiscreteDynamicsWorld::m_constraintSolver
btConstraintSolver * m_constraintSolver
Definition: btDiscreteDynamicsWorld.h:45
btDiscreteDynamicsWorld::m_ownsIslandManager
bool m_ownsIslandManager
Definition: btDiscreteDynamicsWorld.h:60
InplaceSolverIslandCallbackMt::processIsland
virtual void processIsland(btCollisionObject **bodies, int numBodies, btPersistentManifold **manifolds, int numManifolds, btTypedConstraint **constraints, int numConstraints, int islandId)
Definition: btDiscreteDynamicsWorldMt.cpp:87
InplaceSolverIslandCallbackMt::operator=
InplaceSolverIslandCallbackMt & operator=(InplaceSolverIslandCallbackMt &other)
Definition: btDiscreteDynamicsWorldMt.cpp:72
InplaceSolverIslandCallbackMt::m_solver
btConstraintSolver * m_solver
Definition: btDiscreteDynamicsWorldMt.cpp:56
btDiscreteDynamicsWorldMt::~btDiscreteDynamicsWorldMt
virtual ~btDiscreteDynamicsWorldMt()
Definition: btDiscreteDynamicsWorldMt.cpp:133
btSphereShape.h
btDispatcher
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:75
btGeneric6DofConstraint.h
btDiscreteDynamicsWorldMt::m_solverIslandCallbackMt
InplaceSolverIslandCallbackMt * m_solverIslandCallbackMt
Definition: btDiscreteDynamicsWorldMt.h:31
btDiscreteDynamicsWorldMt.h
btSimulationIslandManagerMt
SimulationIslandManagerMt – Multithread capable version of SimulationIslandManager Splits the world...
Definition: btSimulationIslandManagerMt.h:33
btSimulationIslandManager::~btSimulationIslandManager
virtual ~btSimulationIslandManager()
Definition: btSimulationIslandManager.cpp:33
btCollisionAlgorithm.h
btContactSolverInfo.h
btConstraintSolver::~btConstraintSolver
virtual ~btConstraintSolver()
Definition: btConstraintSolver.h:45
btSerializer.h
btDiscreteDynamicsWorld::m_constraints
btAlignedObjectArray< btTypedConstraint * > m_constraints
Definition: btDiscreteDynamicsWorld.h:49
btConstraintSolver
Definition: btConstraintSolver.h:40