Blender  V3.3
btMultiBodyConstraint.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2013 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 #ifndef BT_MULTIBODY_CONSTRAINT_H
17 #define BT_MULTIBODY_CONSTRAINT_H
18 
19 #include "LinearMath/btScalar.h"
21 #include "btMultiBody.h"
22 
23 
24 //Don't change any of the existing enum values, so add enum types at the end for serialization compatibility
26 {
34 
36 };
37 
38 class btMultiBody;
39 struct btSolverInfo;
40 
42 
44 {
46  btAlignedObjectArray<btScalar> m_deltaVelocitiesUnitImpulse; //holds the joint-space response of the corresp. tree to the test impulse in each constraint space dimension
47  btAlignedObjectArray<btScalar> m_deltaVelocities; //holds joint-space vectors of all the constrained trees accumulating the effect of corrective impulses applied in SI
53 };
54 
57 {
58 protected:
59  btMultiBody* m_bodyA;
61  int m_linkA;
62  int m_linkB;
63 
64  int m_type; //btTypedMultiBodyConstraintType
65 
66  int m_numRows;
70 
74 
75  // warning: the data block lay out is not consistent for all constraints
76  // data block laid out as follows:
77  // cached impulses. (one per row.)
78  // jacobians. (interleaved, row1 body1 then row1 body2 then row2 body 1 etc)
79  // positions. (one per row.)
81 
82  void applyDeltaVee(btMultiBodyJacobianData & data, btScalar * delta_vee, btScalar impulse, int velocityIndex, int ndof);
83 
86  btScalar * jacOrgA, btScalar * jacOrgB,
87  const btVector3& constraintNormalAng,
88 
89  const btVector3& constraintNormalLin,
90  const btVector3& posAworld, const btVector3& posBworld,
91  btScalar posError,
93  btScalar lowerLimit, btScalar upperLimit,
94  bool angConstraint = false,
95 
96  btScalar relaxation = 1.f,
97  bool isFriction = false, btScalar desiredVelocity = 0, btScalar cfmSlip = 0);
98 
99 public:
101 
102  btMultiBodyConstraint(btMultiBody * bodyA, btMultiBody * bodyB, int linkA, int linkB, int numRows, bool isUnilateral, int type);
103  virtual ~btMultiBodyConstraint();
104 
105  void updateJacobianSizes();
107 
108  int getConstraintType() const
109  {
110  return m_type;
111  }
112  //many constraints have setFrameInB/setPivotInB. Will use 'getConstraintType' later.
113  virtual void setFrameInB(const btMatrix3x3& frameInB) {}
114  virtual void setPivotInB(const btVector3& pivotInB) {}
115 
116  virtual void finalizeMultiDof() = 0;
117 
118  virtual int getIslandIdA() const = 0;
119  virtual int getIslandIdB() const = 0;
120 
121  virtual void createConstraintRows(btMultiBodyConstraintArray & constraintRows,
123  const btContactSolverInfo& infoGlobal) = 0;
124 
125  int getNumRows() const
126  {
127  return m_numRows;
128  }
129 
131  {
132  return m_bodyA;
133  }
135  {
136  return m_bodyB;
137  }
138 
139  int getLinkA() const
140  {
141  return m_linkA;
142  }
143  int getLinkB() const
144  {
145  return m_linkB;
146  }
147  void internalSetAppliedImpulse(int dof, btScalar appliedImpulse)
148  {
149  btAssert(dof >= 0);
150  btAssert(dof < getNumRows());
151  m_data[dof] = appliedImpulse;
152  }
153 
155  {
156  btAssert(dof >= 0);
157  btAssert(dof < getNumRows());
158  return m_data[dof];
159  }
160  // current constraint position
161  // constraint is pos >= 0 for unilateral, or pos = 0 for bilateral
162  // NOTE: ignored position for friction rows.
163  btScalar getPosition(int row) const
164  {
165  return m_data[m_posOffset + row];
166  }
167 
168  void setPosition(int row, btScalar pos)
169  {
170  m_data[m_posOffset + row] = pos;
171  }
172 
173  bool isUnilateral() const
174  {
175  return m_isUnilateral;
176  }
177 
178  // jacobian blocks.
179  // each of size 6 + num_links. (jacobian2 is null if no body2.)
180  // format: 3 'omega' coefficients, 3 'v' coefficients, then the 'qdot' coefficients.
181  btScalar* jacobianA(int row)
182  {
183  return &m_data[m_numRows + row * m_jacSizeBoth];
184  }
185  const btScalar* jacobianA(int row) const
186  {
187  return &m_data[m_numRows + (row * m_jacSizeBoth)];
188  }
189  btScalar* jacobianB(int row)
190  {
191  return &m_data[m_numRows + (row * m_jacSizeBoth) + m_jacSizeA];
192  }
193  const btScalar* jacobianB(int row) const
194  {
195  return &m_data[m_numRows + (row * m_jacSizeBoth) + m_jacSizeA];
196  }
197 
199  {
200  return m_maxAppliedImpulse;
201  }
203  {
204  m_maxAppliedImpulse = maxImp;
205  }
206 
207  virtual void debugDraw(class btIDebugDraw * drawer) = 0;
208 
209  virtual void setGearRatio(btScalar ratio) {}
210  virtual void setGearAuxLink(int gearAuxLink) {}
211  virtual void setRelativePositionTarget(btScalar relPosTarget) {}
212  virtual void setErp(btScalar erp) {}
213 };
214 
215 #endif //BT_MULTIBODY_CONSTRAINT_H
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
btFixedConstraint btRigidBody const btTransform const btTransform & frameInB
btMatrix3x3
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition: btMatrix3x3.h:50
btScalar getMaxAppliedImpulse() const
btTypedMultiBodyConstraintType
@ MAX_MULTIBODY_CONSTRAINT_TYPE
@ MULTIBODY_CONSTRAINT_LIMIT
@ MULTIBODY_CONSTRAINT_SLIDER
@ MULTIBODY_CONSTRAINT_FIXED
@ MULTIBODY_CONSTRAINT_POINT_TO_POINT
@ MULTIBODY_CONSTRAINT_GEAR
@ MULTIBODY_CONSTRAINT_1DOF_JOINT_MOTOR
@ MULTIBODY_CONSTRAINT_SPHERICAL_MOTOR
virtual void createConstraintRows(btMultiBodyConstraintArray &constraintRows, btMultiBodyJacobianData &data, const btContactSolverInfo &infoGlobal)=0
BT_DECLARE_ALIGNED_ALLOCATOR()
int getLinkB() const
int m_numDofsFinalized
void setMaxAppliedImpulse(btScalar maxImp)
int m_linkB
virtual void setRelativePositionTarget(btScalar relPosTarget)
btScalar getPosition(int row) const
int m_jacSizeA
virtual void finalizeMultiDof()=0
void updateJacobianSizes()
virtual void setGearAuxLink(int gearAuxLink)
int m_posOffset
bool m_isUnilateral
virtual void setErp(btScalar erp)
void applyDeltaVee(btMultiBodyJacobianData &data, btScalar *delta_vee, btScalar impulse, int velocityIndex, int ndof)
void setPosition(int row, btScalar pos)
virtual void setFrameInB(const btMatrix3x3 &frameInB)
btScalar getAppliedImpulse(int dof)
virtual void setGearRatio(btScalar ratio)
btScalar * jacobianB(int row)
btAlignedObjectArray< btScalar > m_data
virtual int getIslandIdA() const =0
btMultiBody * getMultiBodyB()
int m_type
btMultiBody * m_bodyB
bool isUnilateral() const
int m_linkA
virtual int getIslandIdB() const =0
void allocateJacobiansMultiDof()
virtual ~btMultiBodyConstraint()
int m_jacSizeBoth
int m_numRows
btScalar fillMultiBodyConstraint(btMultiBodySolverConstraint &solverConstraint, btMultiBodyJacobianData &data, btScalar *jacOrgA, btScalar *jacOrgB, const btVector3 &constraintNormalAng, const btVector3 &constraintNormalLin, const btVector3 &posAworld, const btVector3 &posBworld, btScalar posError, const btContactSolverInfo &infoGlobal, btScalar lowerLimit, btScalar upperLimit, bool angConstraint=false, btScalar relaxation=1.f, bool isFriction=false, btScalar desiredVelocity=0, btScalar cfmSlip=0)
virtual void debugDraw(class btIDebugDraw *drawer)=0
void internalSetAppliedImpulse(int dof, btScalar appliedImpulse)
btScalar m_maxAppliedImpulse
btScalar * jacobianA(int row)
btMultiBodyConstraint
virtual void setPivotInB(const btVector3 &pivotInB)
btMultiBody * getMultiBodyA()
int getLinkA() const
int getConstraintType() const
int getNumRows() const
btMultiBodySolverConstraint
1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and fr...
btMultiBody
Definition: btMultiBody.h:51
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
#define btAssert(x)
Definition: btScalar.h:295
btSequentialImpulseConstraintSolverMt int btPersistentManifold int btTypedConstraint int const btContactSolverInfo & infoGlobal
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
uint pos
btAlignedObjectArray< btScalar > m_deltaVelocitiesUnitImpulse
btAlignedObjectArray< btScalar > m_deltaVelocities
btAlignedObjectArray< btScalar > m_jacobians
btAlignedObjectArray< btSolverBody > * m_solverBodyPool
btAlignedObjectArray< btScalar > scratch_r
btAlignedObjectArray< btMatrix3x3 > scratch_m
btAlignedObjectArray< btVector3 > scratch_v