Blender  V3.3
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;
21 class btDispatcher;
22 class btCollisionObject;
29 
31 
33 {
35  {
36  m_numSolverCalls = 0;
39  m_islandId = -2;
40  }
47 };
48 
52 {
53 
54 
55 protected:
56  btAlignedObjectArray<btSolverBody> m_tmpSolverBodyPool;
61 
68  // When running solvers on multiple threads, a race condition exists for Kinematic objects that
69  // participate in more than one solver.
70  // The getOrInitSolverBody() function writes the companionId of each body (storing the index of the solver body
71  // for the current solver). For normal dynamic bodies it isn't an issue because they can only be in one island
72  // (and therefore one thread) at a time. But kinematic bodies can be in multiple islands at once.
73  // To avoid this race condition, this solver does not write the companionId, instead it stores the solver body
74  // index in this solver-local table, indexed by the uniqueId of the body.
76 
80  int m_cachedSolverMode; // used to check if SOLVER_SIMD flag has been changed
81  void setupSolverFunctions(bool useSimd);
82 
84 
85  void setupFrictionConstraint(btSolverConstraint & solverConstraint, const btVector3& normalAxis, int solverBodyIdA, int solverBodyIdB,
86  btManifoldPoint& cp, const btVector3& rel_pos1, const btVector3& rel_pos2,
87  btCollisionObject* colObj0, btCollisionObject* colObj1, btScalar relaxation,
89  btScalar desiredVelocity = 0., btScalar cfmSlip = 0.);
90 
91  void setupTorsionalFrictionConstraint(btSolverConstraint & solverConstraint, const btVector3& normalAxis, int solverBodyIdA, int solverBodyIdB,
92  btManifoldPoint& cp, btScalar combinedTorsionalFriction, const btVector3& rel_pos1, const btVector3& rel_pos2,
93  btCollisionObject* colObj0, btCollisionObject* colObj1, btScalar relaxation,
94  btScalar desiredVelocity = 0., btScalar cfmSlip = 0.);
95 
96  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.);
97  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);
98 
99  void setupContactConstraint(btSolverConstraint & solverConstraint, int solverBodyIdA, int solverBodyIdB, btManifoldPoint& cp,
100  const btContactSolverInfo& infoGlobal, btScalar& relaxation, const btVector3& rel_pos1, const btVector3& rel_pos2);
101 
102  static void applyAnisotropicFriction(btCollisionObject * colObj, btVector3 & frictionDirection, int frictionMode);
103 
104  void setFrictionConstraintImpulse(btSolverConstraint & solverConstraint, int solverBodyIdA, int solverBodyIdB,
106 
108  unsigned long m_btSeed2;
109 
110  btScalar restitutionCurve(btScalar rel_vel, btScalar restitution, btScalar velocityThreshold);
111 
113 
115 
117  void convertJoint(btSolverConstraint * currentConstraintRow, btTypedConstraint * constraint, const btTypedConstraint::btConstraintInfo1& info1, int solverBodyIdA, int solverBodyIdB, const btContactSolverInfo& infoGlobal);
118 
119  virtual void convertBodies(btCollisionObject * *bodies, int numBodies, const btContactSolverInfo& infoGlobal);
120 
122  {
123  return m_resolveSplitPenetrationImpulse(bodyA, bodyB, contactConstraint);
124  }
125 
127  {
128  return m_resolveSplitPenetrationImpulse(bodyA, bodyB, contactConstraint);
129  }
130 
131  //internal method
132  int getOrInitSolverBody(btCollisionObject & body, btScalar timeStep);
133  void initSolverBody(btSolverBody * solverBody, btCollisionObject * collisionObject, btScalar timeStep);
134 
135  btScalar resolveSingleConstraintRowGeneric(btSolverBody & bodyA, btSolverBody & bodyB, const btSolverConstraint& contactConstraint);
140  {
141  return m_resolveSplitPenetrationImpulse(bodyA, bodyB, contactConstraint);
142  }
143 
144 protected:
145  void writeBackContacts(int iBegin, int iEnd, const btContactSolverInfo& infoGlobal);
146  void writeBackJoints(int iBegin, int iEnd, const btContactSolverInfo& infoGlobal);
147  void writeBackBodies(int iBegin, int iEnd, const btContactSolverInfo& infoGlobal);
151 
154 
155 public:
157 
160 
162 
164  virtual void reset();
165 
166  unsigned long btRand2();
167 
168  int btRandInt2(int n);
169 
170  void setRandSeed(unsigned long seed)
171  {
172  m_btSeed2 = seed;
173  }
174  unsigned long getRandSeed() const
175  {
176  return m_btSeed2;
177  }
178 
180  {
182  }
183 
185  {
187  }
189  {
191  }
193  {
195  }
197  {
199  }
200 
201 
202 
207 
213 };
214 
215 #endif //BT_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H
btCollisionObject
btConstraintSolverType
btConstraintSolver provides solver interface
@ BT_SEQUENTIAL_IMPULSE_SOLVER
btPersistentManifold()
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:285
btSequentialImpulseConstraintSolverMt int btPersistentManifold int btTypedConstraint ** constraints
btSequentialImpulseConstraintSolverMt int btPersistentManifold ** manifoldPtr
btSequentialImpulseConstraintSolverMt int btPersistentManifold int btTypedConstraint int numConstraints
btSequentialImpulseConstraintSolverMt int numBodies
btSequentialImpulseConstraintSolverMt int btPersistentManifold int btTypedConstraint int const btContactSolverInfo & infoGlobal
btSequentialImpulseConstraintSolverMt int btPersistentManifold int numManifolds
btSingleConstraintRowSolver getScalarConstraintRowSolverLowerLimit()
Various implementations of solving a single constraint row using an inequality (lower limit) constrai...
BT_DECLARE_ALIGNED_ALLOCATOR()
void initSolverBody(btSolverBody *solverBody, btCollisionObject *collisionObject, btScalar timeStep)
virtual void convertJoints(btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &infoGlobal)
btSingleConstraintRowSolver getSSE4_1ConstraintRowSolverGeneric()
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.)
void writeBackJoints(int iBegin, int iEnd, const btContactSolverInfo &infoGlobal)
btConstraintArray m_tmpSolverContactRollingFrictionConstraintPool
void setRandSeed(unsigned long seed)
btAlignedObjectArray< int > m_orderTmpConstraintPool
btScalar(* btSingleConstraintRowSolver)(btSolverBody &, btSolverBody &, const btSolverConstraint &)
btAlignedObjectArray< int > m_orderNonContactConstraintPool
void setConstraintRowSolverLowerLimit(btSingleConstraintRowSolver rowSolver)
int m_maxOverrideNumSolverIterations
unsigned long getRandSeed() const
virtual btScalar solveGroupCacheFriendlySetup(btCollisionObject **bodies, int numBodies, btPersistentManifold **manifoldPtr, int numManifolds, btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &infoGlobal, btIDebugDraw *debugDrawer)
virtual btScalar solveGroupCacheFriendlyFinish(btCollisionObject **bodies, int numBodies, const btContactSolverInfo &infoGlobal)
virtual void solveGroupCacheFriendlySplitImpulseIterations(btCollisionObject **bodies, int numBodies, btPersistentManifold **manifoldPtr, int numManifolds, btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &infoGlobal, btIDebugDraw *debugDrawer)
virtual void convertContacts(btPersistentManifold **manifoldPtr, int numManifolds, const btContactSolverInfo &infoGlobal)
virtual ~btSequentialImpulseConstraintSolver()
void convertJoint(btSolverConstraint *currentConstraintRow, btTypedConstraint *constraint, const btTypedConstraint::btConstraintInfo1 &info1, int solverBodyIdA, int solverBodyIdB, const btContactSolverInfo &infoGlobal)
btAlignedObjectArray< int > m_kinematicBodyUniqueIdToSolverBodyTable
virtual btScalar solveGroup(btCollisionObject **bodies, int numBodies, btPersistentManifold **manifold, int numManifolds, btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &info, btIDebugDraw *debugDrawer, btDispatcher *dispatcher)
btSolverAnalyticsData m_analyticsData
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)
btScalar m_leastSquaresResidual
btSingleConstraintRowSolver getSSE4_1ConstraintRowSolverLowerLimit()
void setConstraintRowSolverGeneric(btSingleConstraintRowSolver rowSolver)
btSingleConstraintRowSolver m_resolveSplitPenetrationImpulse
virtual btConstraintSolverType getSolverType() const
btSingleConstraintRowSolver getSSE2ConstraintRowSolverLowerLimit()
btScalar resolveSingleConstraintRowLowerLimit(btSolverBody &bodyA, btSolverBody &bodyB, const btSolverConstraint &contactConstraint)
virtual void reset()
clear internal cached data and reset random seed
virtual btScalar solveGroupCacheFriendlyIterations(btCollisionObject **bodies, int numBodies, btPersistentManifold **manifoldPtr, int numManifolds, btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &infoGlobal, btIDebugDraw *debugDrawer)
void setupSolverFunctions(bool useSimd)
unsigned long m_btSeed2
m_btSeed2 is used for re-arranging the constraint rows. improves convergence/quality of friction
static void applyAnisotropicFriction(btCollisionObject *colObj, btVector3 &frictionDirection, int frictionMode)
btSingleConstraintRowSolver m_resolveSingleConstraintRowGeneric
btScalar resolveSingleConstraintRowGeneric(btSolverBody &bodyA, btSolverBody &bodyB, const btSolverConstraint &contactConstraint)
void setupTorsionalFrictionConstraint(btSolverConstraint &solverConstraint, const btVector3 &normalAxis, int solverBodyIdA, int solverBodyIdB, btManifoldPoint &cp, btScalar combinedTorsionalFriction, const btVector3 &rel_pos1, const btVector3 &rel_pos2, btCollisionObject *colObj0, btCollisionObject *colObj1, btScalar relaxation, btScalar desiredVelocity=0., btScalar cfmSlip=0.)
btSingleConstraintRowSolver getActiveConstraintRowSolverLowerLimit()
void convertContact(btPersistentManifold *manifold, const btContactSolverInfo &infoGlobal)
btScalar resolveSplitPenetrationImpulseCacheFriendly(btSolverBody &bodyA, btSolverBody &bodyB, const btSolverConstraint &contactConstraint)
virtual btScalar solveSingleIteration(int iteration, btCollisionObject **bodies, int numBodies, btPersistentManifold **manifoldPtr, int numManifolds, btTypedConstraint **constraints, int numConstraints, const btContactSolverInfo &infoGlobal, btIDebugDraw *debugDrawer)
btScalar resolveSplitPenetrationImpulse(btSolverBody &bodyA, btSolverBody &bodyB, const btSolverConstraint &contactConstraint)
btSingleConstraintRowSolver getScalarConstraintRowSolverGeneric()
Various implementations of solving a single constraint row using a generic equality constraint,...
btSingleConstraintRowSolver getSSE2ConstraintRowSolverGeneric()
btAlignedObjectArray< int > m_orderFrictionConstraintPool
unsigned long btRand2()
void writeBackBodies(int iBegin, int iEnd, const btContactSolverInfo &infoGlobal)
void setupFrictionConstraint(btSolverConstraint &solverConstraint, const btVector3 &normalAxis, int solverBodyIdA, int solverBodyIdB, 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.)
btConstraintArray m_tmpSolverContactFrictionConstraintPool
btConstraintArray m_tmpSolverContactConstraintPool
btSingleConstraintRowSolver getActiveConstraintRowSolverGeneric()
btSingleConstraintRowSolver m_resolveSingleConstraintRowLowerLimit
virtual void convertBodies(btCollisionObject **bodies, int numBodies, const btContactSolverInfo &infoGlobal)
btScalar resolveSplitPenetrationSIMD(btSolverBody &bodyA, btSolverBody &bodyB, const btSolverConstraint &contactConstraint)
void setFrictionConstraintImpulse(btSolverConstraint &solverConstraint, int solverBodyIdA, int solverBodyIdB, btManifoldPoint &cp, const btContactSolverInfo &infoGlobal)
btScalar resolveSingleConstraintRowLowerLimitSIMD(btSolverBody &bodyA, btSolverBody &bodyB, const btSolverConstraint &contactConstraint)
int getOrInitSolverBody(btCollisionObject &body, btScalar timeStep)
btScalar restitutionCurve(btScalar rel_vel, btScalar restitution, btScalar velocityThreshold)
btScalar resolveSingleConstraintRowGenericSIMD(btSolverBody &bodyA, btSolverBody &bodyB, const btSolverConstraint &contactConstraint)
void writeBackContacts(int iBegin, int iEnd, const btContactSolverInfo &infoGlobal)
btConstraintArray m_tmpSolverNonContactConstraintPool
void setupContactConstraint(btSolverConstraint &solverConstraint, int solverBodyIdA, int solverBodyIdB, btManifoldPoint &cp, const btContactSolverInfo &infoGlobal, btScalar &relaxation, const btVector3 &rel_pos1, const btVector3 &rel_pos2)
btAlignedObjectArray< btTypedConstraint::btConstraintInfo1 > m_tmpConstraintSizesPool
static unsigned long seed
Definition: btSoftBody.h:39
btSolverBody
The btSolverBody is an internal datastructure for the constraint solver. Only necessary data is packe...
Definition: btSolverBody.h:105
btSolverConstraint
1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and fr...
btTypedConstraint(btTypedConstraintType type, btRigidBody &rbA)
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
Definition: btVector3.h:82