Bullet Collision Detection & Physics Library
btSequentialImpulseConstraintSolver.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. 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
19class btIDebugDraw;
21class btDispatcher;
29
31
34{
35protected:
41
48 // When running solvers on multiple threads, a race condition exists for Kinematic objects that
49 // participate in more than one solver.
50 // The getOrInitSolverBody() function writes the companionId of each body (storing the index of the solver body
51 // for the current solver). For normal dynamic bodies it isn't an issue because they can only be in one island
52 // (and therefore one thread) at a time. But kinematic bodies can be in multiple islands at once.
53 // To avoid this race condition, this solver does not write the companionId, instead it stores the solver body
54 // index in this solver-local table, indexed by the uniqueId of the body.
56
60 int m_cachedSolverMode; // used to check if SOLVER_SIMD flag has been changed
61 void setupSolverFunctions( bool useSimd );
62
64
65 void setupFrictionConstraint( btSolverConstraint& solverConstraint, const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,
66 btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,
67 btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation,
68 const btContactSolverInfo& infoGlobal,
69 btScalar desiredVelocity=0., btScalar cfmSlip=0.);
70
71 void setupTorsionalFrictionConstraint( btSolverConstraint& solverConstraint, const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,
72 btManifoldPoint& cp,btScalar combinedTorsionalFriction, const btVector3& rel_pos1,const btVector3& rel_pos2,
73 btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation,
74 btScalar desiredVelocity=0., btScalar cfmSlip=0.);
75
76 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.);
77 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);
78
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
92 btScalar restitutionCurve(btScalar rel_vel, btScalar restitution, btScalar velocityThreshold);
93
94 virtual void convertContacts(btPersistentManifold** manifoldPtr, int numManifolds, const btContactSolverInfo& infoGlobal);
95
96 void convertContact(btPersistentManifold* manifold,const btContactSolverInfo& infoGlobal);
97
98
100 {
101 return m_resolveSplitPenetrationImpulse( bodyA, bodyB, contactConstraint );
102 }
103
105 {
106 return m_resolveSplitPenetrationImpulse( bodyA, bodyB, contactConstraint );
107 }
108
109 //internal method
110 int getOrInitSolverBody(btCollisionObject& body,btScalar timeStep);
111 void initSolverBody(btSolverBody* solverBody, btCollisionObject* collisionObject, btScalar timeStep);
112
113 btSimdScalar resolveSingleConstraintRowGeneric(btSolverBody& bodyA,btSolverBody& bodyB,const btSolverConstraint& contactConstraint);
114 btSimdScalar resolveSingleConstraintRowGenericSIMD(btSolverBody& bodyA,btSolverBody& bodyB,const btSolverConstraint& contactConstraint);
115 btSimdScalar resolveSingleConstraintRowLowerLimit(btSolverBody& bodyA,btSolverBody& bodyB,const btSolverConstraint& contactConstraint);
116 btSimdScalar resolveSingleConstraintRowLowerLimitSIMD(btSolverBody& bodyA,btSolverBody& bodyB,const btSolverConstraint& contactConstraint);
118 {
119 return m_resolveSplitPenetrationImpulse( bodyA, bodyB, contactConstraint );
120 }
121
122protected:
123
124
125 virtual void solveGroupCacheFriendlySplitImpulseIterations(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer);
126 virtual btScalar solveGroupCacheFriendlyFinish(btCollisionObject** bodies,int numBodies,const btContactSolverInfo& infoGlobal);
127 virtual btScalar solveSingleIteration(int iteration, btCollisionObject** bodies ,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer);
128
129 virtual btScalar solveGroupCacheFriendlySetup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer);
130 virtual btScalar solveGroupCacheFriendlyIterations(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer);
131
132
133public:
134
136
139
140 virtual btScalar solveGroup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifold,int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& info, btIDebugDraw* debugDrawer,btDispatcher* dispatcher);
141
143 virtual void reset();
144
145 unsigned long btRand2();
146
147 int btRandInt2 (int n);
148
149 void setRandSeed(unsigned long seed)
150 {
151 m_btSeed2 = seed;
152 }
153 unsigned long getRandSeed() const
154 {
155 return m_btSeed2;
156 }
157
158
160 {
162 }
163
165 {
166 return m_resolveSingleConstraintRowGeneric;
167 }
169 {
170 m_resolveSingleConstraintRowGeneric = rowSolver;
171 }
173 {
174 return m_resolveSingleConstraintRowLowerLimit;
175 }
177 {
178 m_resolveSingleConstraintRowLowerLimit = rowSolver;
179 }
180
182 btSingleConstraintRowSolver getScalarConstraintRowSolverGeneric();
185
187 btSingleConstraintRowSolver getScalarConstraintRowSolverLowerLimit();
190};
191
192
193
194
195#endif //BT_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H
196
btConstraintSolverType
btConstraintSolver provides solver interface
@ BT_SEQUENTIAL_IMPULSE_SOLVER
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:82
btSimdScalar(* btSingleConstraintRowSolver)(btSolverBody &, btSolverBody &, const btSolverConstraint &)
#define btSimdScalar
Until we get other contributions, only use SIMD on Windows, when using Visual Studio 2008 or later,...
Definition: btSolverBody.h:104
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
btCollisionObject can be used to manage collision detection objects.
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:76
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
Definition: btIDebugDraw.h:30
ManifoldContactPoint collects and maintains persistent contactpoints.
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
The btSequentialImpulseConstraintSolver is a fast SIMD implementation of the Projected Gauss Seidel (...
btSimdScalar resolveSplitPenetrationImpulse(btSolverBody &bodyA, btSolverBody &bodyB, const btSolverConstraint &contactConstraint)
btSingleConstraintRowSolver getSSE2ConstraintRowSolverGeneric()
btSingleConstraintRowSolver getActiveConstraintRowSolverLowerLimit()
btSingleConstraintRowSolver getActiveConstraintRowSolverGeneric()
virtual btConstraintSolverType getSolverType() const
unsigned long m_btSeed2
m_btSeed2 is used for re-arranging the constraint rows. improves convergence/quality of friction
btSimdScalar resolveSplitPenetrationSIMD(btSolverBody &bodyA, btSolverBody &bodyB, const btSolverConstraint &contactConstraint)
btSingleConstraintRowSolver getSSE2ConstraintRowSolverLowerLimit()
btAlignedObjectArray< btSolverBody > m_tmpSolverBodyPool
btSingleConstraintRowSolver m_resolveSingleConstraintRowLowerLimit
btAlignedObjectArray< btTypedConstraint::btConstraintInfo1 > m_tmpConstraintSizesPool
btSingleConstraintRowSolver getSSE4_1ConstraintRowSolverGeneric()
void setConstraintRowSolverGeneric(btSingleConstraintRowSolver rowSolver)
btAlignedObjectArray< int > m_kinematicBodyUniqueIdToSolverBodyTable
btSingleConstraintRowSolver m_resolveSingleConstraintRowGeneric
btSimdScalar resolveSplitPenetrationImpulseCacheFriendly(btSolverBody &bodyA, btSolverBody &bodyB, const btSolverConstraint &contactConstraint)
void setConstraintRowSolverLowerLimit(btSingleConstraintRowSolver rowSolver)
btSingleConstraintRowSolver getSSE4_1ConstraintRowSolverLowerLimit()
TypedConstraint is the baseclass for Bullet constraints and vehicles.
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:84
The btSolverBody is an internal datastructure for the constraint solver. Only necessary data is packe...
Definition: btSolverBody.h:109
1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and fr...