Bullet Collision Detection & Physics Library: btSequentialImpulseConstraintSolver.h Source File

Bullet Collision Detection & Physics Library

btSequentialImpulseConstraintSolver.h
Go to the documentation of this file.
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_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H
17 #define BT_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H
18
19 class btIDebugDraw;
20 class btPersistentManifold;
21 class btDispatcher;
22 class btCollisionObject;
23 #include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
24 #include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h"
25 #include "BulletDynamics/ConstraintSolver/btSolverBody.h"
26 #include "BulletDynamics/ConstraintSolver/btSolverConstraint.h"
27 #include "BulletCollision/NarrowPhaseCollision/btManifoldPoint.h"
28 #include "BulletDynamics/ConstraintSolver/btConstraintSolver.h"
29
30 typedef btScalar (*btSingleConstraintRowSolver)(btSolverBody&, btSolverBody&, const btSolverConstraint&);
31
33 ATTRIBUTE_ALIGNED16(class)
34 btSequentialImpulseConstraintSolver : public btConstraintSolver
35 {
36 protected:
37 btAlignedObjectArray<btSolverBody> m_tmpSolverBodyPool;
38 btConstraintArray m_tmpSolverContactConstraintPool;
39 btConstraintArray m_tmpSolverNonContactConstraintPool;
40 btConstraintArray m_tmpSolverContactFrictionConstraintPool;
41 btConstraintArray m_tmpSolverContactRollingFrictionConstraintPool;
42
43 btAlignedObjectArray<int> m_orderTmpConstraintPool;
44 btAlignedObjectArray<int> m_orderNonContactConstraintPool;
45 btAlignedObjectArray<int> m_orderFrictionConstraintPool;
46 btAlignedObjectArray<btTypedConstraint::btConstraintInfo1> m_tmpConstraintSizesPool;
47 int m_maxOverrideNumSolverIterations;
48 int m_fixedBodyId;
49 // When running solvers on multiple threads, a race condition exists for Kinematic objects that
50 // participate in more than one solver.
51 // The getOrInitSolverBody() function writes the companionId of each body (storing the index of the solver body
52 // for the current solver). For normal dynamic bodies it isn't an issue because they can only be in one island
53 // (and therefore one thread) at a time. But kinematic bodies can be in multiple islands at once.
54 // To avoid this race condition, this solver does not write the companionId, instead it stores the solver body
55 // index in this solver-local table, indexed by the uniqueId of the body.
56 btAlignedObjectArray<int> m_kinematicBodyUniqueIdToSolverBodyTable; // only used for multithreading
57
58 btSingleConstraintRowSolver m_resolveSingleConstraintRowGeneric;
59 btSingleConstraintRowSolver m_resolveSingleConstraintRowLowerLimit;
60 btSingleConstraintRowSolver m_resolveSplitPenetrationImpulse;
61 int m_cachedSolverMode; // used to check if SOLVER_SIMD flag has been changed
62 void setupSolverFunctions(bool useSimd);
63
64 btScalar m_leastSquaresResidual;
65
66 void setupFrictionConstraint(btSolverConstraint & solverConstraint, const btVector3& normalAxis, int solverBodyIdA, int solverBodyIdB,
67 btManifoldPoint& cp, const btVector3& rel_pos1, const btVector3& rel_pos2,
68 btCollisionObject* colObj0, btCollisionObject* colObj1, btScalar relaxation,
69 const btContactSolverInfo& infoGlobal,
70 btScalar desiredVelocity = 0., btScalar cfmSlip = 0.);
71
72 void setupTorsionalFrictionConstraint(btSolverConstraint & solverConstraint, const btVector3& normalAxis, int solverBodyIdA, int solverBodyIdB,
73 btManifoldPoint& cp, btScalar combinedTorsionalFriction, const btVector3& rel_pos1, const btVector3& rel_pos2,
74 btCollisionObject* colObj0, btCollisionObject* colObj1, btScalar relaxation,
75 btScalar desiredVelocity = 0., btScalar cfmSlip = 0.);
76
77 btSolverConstraint& addFrictionConstraint(const btVector3& normalAxis, int solverBodyIdA, int solverBodyIdB, int frictionIndex, btManifoldPoint& cp, const btVector3& rel_pos1, const btVector3& rel_pos2, btCollisionObject* colObj0, btCollisionObject* colObj1, btScalar relaxation, const btContactSolverInfo& infoGlobal, btScalar desiredVelocity = 0., btScalar cfmSlip = 0.);
78 btSolverConstraint& addTorsionalFrictionConstraint(const btVector3& normalAxis, int solverBodyIdA, int solverBodyIdB, int frictionIndex, btManifoldPoint& cp, btScalar torsionalFriction, const btVector3& rel_pos1, const btVector3& rel_pos2, btCollisionObject* colObj0, btCollisionObject* colObj1, btScalar relaxation, btScalar desiredVelocity = 0, btScalar cfmSlip = 0.f);
79
80 void setupContactConstraint(btSolverConstraint & solverConstraint, int solverBodyIdA, int solverBodyIdB, btManifoldPoint& cp,
81 const btContactSolverInfo& infoGlobal, btScalar& relaxation, const btVector3& rel_pos1, const btVector3& rel_pos2);
82
83 static void applyAnisotropicFriction(btCollisionObject * colObj, btVector3 & frictionDirection, int frictionMode);
84
85 void setFrictionConstraintImpulse(btSolverConstraint & solverConstraint, int solverBodyIdA, int solverBodyIdB,
86 btManifoldPoint& cp, const btContactSolverInfo& infoGlobal);
87
89 unsigned long m_btSeed2;
90
91 btScalar restitutionCurve(btScalar rel_vel, btScalar restitution, btScalar velocityThreshold);
92
93 virtual void convertContacts(btPersistentManifold * *manifoldPtr, int numManifolds, const btContactSolverInfo& infoGlobal);
94
95 void convertContact(btPersistentManifold * manifold, const btContactSolverInfo& infoGlobal);
96
97 virtual void convertJoints(btTypedConstraint * *constraints, int numConstraints, const btContactSolverInfo& infoGlobal);
98 void convertJoint(btSolverConstraint * currentConstraintRow, btTypedConstraint * constraint, const btTypedConstraint::btConstraintInfo1& info1, int solverBodyIdA, int solverBodyIdB, const btContactSolverInfo& infoGlobal);
99
100 virtual void convertBodies(btCollisionObject * *bodies, int numBodies, const btContactSolverInfo& infoGlobal);
101
102 btScalar resolveSplitPenetrationSIMD(btSolverBody & bodyA, btSolverBody & bodyB, const btSolverConstraint& contactConstraint)
103 {
104 return m_resolveSplitPenetrationImpulse(bodyA, bodyB, contactConstraint);
105 }
106
107 btScalar resolveSplitPenetrationImpulseCacheFriendly(btSolverBody & bodyA, btSolverBody & bodyB, const btSolverConstraint& contactConstraint)
108 {
109 return m_resolveSplitPenetrationImpulse(bodyA, bodyB, contactConstraint);
110 }
111
112 //internal method
113 int getOrInitSolverBody(btCollisionObject & body, btScalar timeStep);
114 void initSolverBody(btSolverBody * solverBody, btCollisionObject * collisionObject, btScalar timeStep);
115
116 btScalar resolveSingleConstraintRowGeneric(btSolverBody & bodyA, btSolverBody & bodyB, const btSolverConstraint& contactConstraint);
117 btScalar resolveSingleConstraintRowGenericSIMD(btSolverBody & bodyA, btSolverBody & bodyB, const btSolverConstraint& contactConstraint);
118 btScalar resolveSingleConstraintRowLowerLimit(btSolverBody & bodyA, btSolverBody & bodyB, const btSolverConstraint& contactConstraint);
119 btScalar resolveSingleConstraintRowLowerLimitSIMD(btSolverBody & bodyA, btSolverBody & bodyB, const btSolverConstraint& contactConstraint);
120 btScalar resolveSplitPenetrationImpulse(btSolverBody & bodyA, btSolverBody & bodyB, const btSolverConstraint& contactConstraint)
121 {
122 return m_resolveSplitPenetrationImpulse(bodyA, bodyB, contactConstraint);
123 }
124
125 protected:
126 void writeBackContacts(int iBegin, int iEnd, const btContactSolverInfo& infoGlobal);
127 void writeBackJoints(int iBegin, int iEnd, const btContactSolverInfo& infoGlobal);
128 void writeBackBodies(int iBegin, int iEnd, const btContactSolverInfo& infoGlobal);
129 virtual void solveGroupCacheFriendlySplitImpulseIterations(btCollisionObject * *bodies, int numBodies, btPersistentManifold** manifoldPtr, int numManifolds, btTypedConstraint** constraints, int numConstraints, const btContactSolverInfo& infoGlobal, btIDebugDraw* debugDrawer);
130 virtual btScalar solveGroupCacheFriendlyFinish(btCollisionObject * *bodies, int numBodies, const btContactSolverInfo& infoGlobal);
131 virtual btScalar solveSingleIteration(int iteration, btCollisionObject** bodies, int numBodies, btPersistentManifold** manifoldPtr, int numManifolds, btTypedConstraint** constraints, int numConstraints, const btContactSolverInfo& infoGlobal, btIDebugDraw* debugDrawer);
132
133 virtual btScalar solveGroupCacheFriendlySetup(btCollisionObject * *bodies, int numBodies, btPersistentManifold** manifoldPtr, int numManifolds, btTypedConstraint** constraints, int numConstraints, const btContactSolverInfo& infoGlobal, btIDebugDraw* debugDrawer);
134 virtual btScalar solveGroupCacheFriendlyIterations(btCollisionObject * *bodies, int numBodies, btPersistentManifold** manifoldPtr, int numManifolds, btTypedConstraint** constraints, int numConstraints, const btContactSolverInfo& infoGlobal, btIDebugDraw* debugDrawer);
135
136 public:
137 BT_DECLARE_ALIGNED_ALLOCATOR();
138
139 btSequentialImpulseConstraintSolver();
140 virtual ~btSequentialImpulseConstraintSolver();
141
142 virtual btScalar solveGroup(btCollisionObject * *bodies, int numBodies, btPersistentManifold** manifold, int numManifolds, btTypedConstraint** constraints, int numConstraints, const btContactSolverInfo& info, btIDebugDraw* debugDrawer, btDispatcher* dispatcher);
143
145 virtual void reset();
146
147 unsigned long btRand2();
148
149 int btRandInt2(int n);
150
151 void setRandSeed(unsigned long seed)
152 {
153 m_btSeed2 = seed;
154 }
155 unsigned long getRandSeed() const
156 {
157 return m_btSeed2;
158 }
159
160 virtual btConstraintSolverType getSolverType() const
161 {
162 return BT_SEQUENTIAL_IMPULSE_SOLVER;
163 }
164
165 btSingleConstraintRowSolver getActiveConstraintRowSolverGeneric()
166 {
167 return m_resolveSingleConstraintRowGeneric;
168 }
169 void setConstraintRowSolverGeneric(btSingleConstraintRowSolver rowSolver)
170 {
171 m_resolveSingleConstraintRowGeneric = rowSolver;
172 }
173 btSingleConstraintRowSolver getActiveConstraintRowSolverLowerLimit()
174 {
175 return m_resolveSingleConstraintRowLowerLimit;
176 }
177 void setConstraintRowSolverLowerLimit(btSingleConstraintRowSolver rowSolver)
178 {
179 m_resolveSingleConstraintRowLowerLimit = rowSolver;
180 }
181
183 btSingleConstraintRowSolver getScalarConstraintRowSolverGeneric();
184 btSingleConstraintRowSolver getSSE2ConstraintRowSolverGeneric();
185 btSingleConstraintRowSolver getSSE4_1ConstraintRowSolverGeneric();
186
188 btSingleConstraintRowSolver getScalarConstraintRowSolverLowerLimit();
189 btSingleConstraintRowSolver getSSE2ConstraintRowSolverLowerLimit();
190 btSingleConstraintRowSolver getSSE4_1ConstraintRowSolverLowerLimit();
191 };
192
193 #endif //BT_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H
btSequentialImpulseConstraintSolver::m_cachedSolverMode
int m_cachedSolverMode
Definition: btSequentialImpulseConstraintSolver.h:61
btSequentialImpulseConstraintSolver::m_fixedBodyId
int m_fixedBodyId
Definition: btSequentialImpulseConstraintSolver.h:48
btSequentialImpulseConstraintSolver::getRandSeed
unsigned long getRandSeed() const
Definition: btSequentialImpulseConstraintSolver.h:155
btPersistentManifold
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
Definition: btPersistentManifold.h:63
btSequentialImpulseConstraintSolver::m_tmpSolverContactFrictionConstraintPool
btConstraintArray m_tmpSolverContactFrictionConstraintPool
Definition: btSequentialImpulseConstraintSolver.h:40
btSequentialImpulseConstraintSolver::m_tmpSolverContactRollingFrictionConstraintPool
btConstraintArray m_tmpSolverContactRollingFrictionConstraintPool
Definition: btSequentialImpulseConstraintSolver.h:41
btAlignedObjectArray< btSolverBody >
btConstraintSolverType
btConstraintSolverType
btConstraintSolver provides solver interface
Definition: btConstraintSolver.h:32
btSequentialImpulseConstraintSolver::setConstraintRowSolverGeneric
void setConstraintRowSolverGeneric(btSingleConstraintRowSolver rowSolver)
Definition: btSequentialImpulseConstraintSolver.h:169
btSolverConstraint
1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and fr...
Definition: btSolverConstraint.h:29
btSequentialImpulseConstraintSolver::m_resolveSingleConstraintRowGeneric
btSingleConstraintRowSolver m_resolveSingleConstraintRowGeneric
Definition: btSequentialImpulseConstraintSolver.h:58
BT_SEQUENTIAL_IMPULSE_SOLVER
Definition: btConstraintSolver.h:34
btManifoldPoint
ManifoldContactPoint collects and maintains persistent contactpoints.
Definition: btManifoldPoint.h:51
btSequentialImpulseConstraintSolver::m_orderTmpConstraintPool
btAlignedObjectArray< int > m_orderTmpConstraintPool
Definition: btSequentialImpulseConstraintSolver.h:43
btSequentialImpulseConstraintSolver::getActiveConstraintRowSolverLowerLimit
btSingleConstraintRowSolver getActiveConstraintRowSolverLowerLimit()
Definition: btSequentialImpulseConstraintSolver.h:173
btSequentialImpulseConstraintSolver::getSolverType
virtual btConstraintSolverType getSolverType() const
Definition: btSequentialImpulseConstraintSolver.h:160
btTypedConstraint.h
btSequentialImpulseConstraintSolver::m_tmpSolverBodyPool
btAlignedObjectArray< btSolverBody > m_tmpSolverBodyPool
Definition: btSequentialImpulseConstraintSolver.h:37
btSingleConstraintRowSolver
btScalar(* btSingleConstraintRowSolver)(btSolverBody &, btSolverBody &, const btSolverConstraint &)
Definition: btSequentialImpulseConstraintSolver.h:30
btSequentialImpulseConstraintSolver::resolveSplitPenetrationSIMD
btScalar resolveSplitPenetrationSIMD(btSolverBody &bodyA, btSolverBody &bodyB, const btSolverConstraint &contactConstraint)
Definition: btSequentialImpulseConstraintSolver.h:102
btSequentialImpulseConstraintSolver::m_tmpSolverContactConstraintPool
btConstraintArray m_tmpSolverContactConstraintPool
Definition: btSequentialImpulseConstraintSolver.h:38
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:48
btIDebugDraw
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations...
Definition: btIDebugDraw.h:26
btSequentialImpulseConstraintSolver::m_maxOverrideNumSolverIterations
int m_maxOverrideNumSolverIterations
Definition: btSequentialImpulseConstraintSolver.h:47
btSolverConstraint.h
btSequentialImpulseConstraintSolver
The btSequentialImpulseConstraintSolver is a fast SIMD implementation of the Projected Gauss Seidel (...
Definition: btSequentialImpulseConstraintSolver.h:33
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:80
ATTRIBUTE_ALIGNED16
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:84
btSequentialImpulseConstraintSolver::resolveSplitPenetrationImpulse
btScalar resolveSplitPenetrationImpulse(btSolverBody &bodyA, btSolverBody &bodyB, const btSolverConstraint &contactConstraint)
Definition: btSequentialImpulseConstraintSolver.h:120
btContactSolverInfo
Definition: btContactSolverInfo.h:69
btConstraintSolver.h
btSolverBody
The btSolverBody is an internal datastructure for the constraint solver. Only necessary data is packe...
Definition: btSolverBody.h:103
btSequentialImpulseConstraintSolver::m_tmpConstraintSizesPool
btAlignedObjectArray< btTypedConstraint::btConstraintInfo1 > m_tmpConstraintSizesPool
Definition: btSequentialImpulseConstraintSolver.h:46
btTypedConstraint
TypedConstraint is the baseclass for Bullet constraints and vehicles.
Definition: btTypedConstraint.h:74
BT_DECLARE_ALIGNED_ALLOCATOR
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:405
btSequentialImpulseConstraintSolver::m_orderFrictionConstraintPool
btAlignedObjectArray< int > m_orderFrictionConstraintPool
Definition: btSequentialImpulseConstraintSolver.h:45
btSequentialImpulseConstraintSolver::m_orderNonContactConstraintPool
btAlignedObjectArray< int > m_orderNonContactConstraintPool
Definition: btSequentialImpulseConstraintSolver.h:44
btSequentialImpulseConstraintSolver::m_btSeed2
unsigned long m_btSeed2
m_btSeed2 is used for re-arranging the constraint rows. improves convergence/quality of friction ...
Definition: btSequentialImpulseConstraintSolver.h:89
btSequentialImpulseConstraintSolver::resolveSplitPenetrationImpulseCacheFriendly
btScalar resolveSplitPenetrationImpulseCacheFriendly(btSolverBody &bodyA, btSolverBody &bodyB, const btSolverConstraint &contactConstraint)
Definition: btSequentialImpulseConstraintSolver.h:107
btSolverBody.h
btDispatcher
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:76
btTypedConstraint::btConstraintInfo1
Definition: btTypedConstraint.h:113
btManifoldPoint.h
btSequentialImpulseConstraintSolver::getActiveConstraintRowSolverGeneric
btSingleConstraintRowSolver getActiveConstraintRowSolverGeneric()
Definition: btSequentialImpulseConstraintSolver.h:165
btSequentialImpulseConstraintSolver::m_resolveSingleConstraintRowLowerLimit
btSingleConstraintRowSolver m_resolveSingleConstraintRowLowerLimit
Definition: btSequentialImpulseConstraintSolver.h:59
btSequentialImpulseConstraintSolver::m_tmpSolverNonContactConstraintPool
btConstraintArray m_tmpSolverNonContactConstraintPool
Definition: btSequentialImpulseConstraintSolver.h:39
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:294
btSequentialImpulseConstraintSolver::setConstraintRowSolverLowerLimit
void setConstraintRowSolverLowerLimit(btSingleConstraintRowSolver rowSolver)
Definition: btSequentialImpulseConstraintSolver.h:177
btSequentialImpulseConstraintSolver::m_kinematicBodyUniqueIdToSolverBodyTable
btAlignedObjectArray< int > m_kinematicBodyUniqueIdToSolverBodyTable
Definition: btSequentialImpulseConstraintSolver.h:56
btSequentialImpulseConstraintSolver::setRandSeed
void setRandSeed(unsigned long seed)
Definition: btSequentialImpulseConstraintSolver.h:151
btContactSolverInfo.h
btConstraintSolver
Definition: btConstraintSolver.h:40
btSequentialImpulseConstraintSolver::m_resolveSplitPenetrationImpulse
btSingleConstraintRowSolver m_resolveSplitPenetrationImpulse
Definition: btSequentialImpulseConstraintSolver.h:60
btSequentialImpulseConstraintSolver::m_leastSquaresResidual
btScalar m_leastSquaresResidual
Definition: btSequentialImpulseConstraintSolver.h:64