Bullet Collision Detection & Physics Library
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 class btMultiBody;
24 struct btSolverInfo;
25 
27 
29 {
31  btAlignedObjectArray<btScalar> m_deltaVelocitiesUnitImpulse; //holds the joint-space response of the corresp. tree to the test impulse in each constraint space dimension
32  btAlignedObjectArray<btScalar> m_deltaVelocities; //holds joint-space vectors of all the constrained trees accumulating the effect of corrective impulses applied in SI
38 
39 };
40 
41 
43 {
44 protected:
45 
48  int m_linkA;
49  int m_linkB;
50 
51  int m_numRows;
55 
59 
60 
61  // warning: the data block lay out is not consistent for all constraints
62  // data block laid out as follows:
63  // cached impulses. (one per row.)
64  // jacobians. (interleaved, row1 body1 then row1 body2 then row2 body 1 etc)
65  // positions. (one per row.)
67 
68  void applyDeltaVee(btMultiBodyJacobianData& data, btScalar* delta_vee, btScalar impulse, int velocityIndex, int ndof);
69 
70  btScalar fillMultiBodyConstraint(btMultiBodySolverConstraint& solverConstraint,
72  btScalar* jacOrgA, btScalar* jacOrgB,
73  const btVector3& constraintNormalAng,
74 
75  const btVector3& constraintNormalLin,
76  const btVector3& posAworld, const btVector3& posBworld,
77  btScalar posError,
78  const btContactSolverInfo& infoGlobal,
79  btScalar lowerLimit, btScalar upperLimit,
80  bool angConstraint = false,
81 
82  btScalar relaxation = 1.f,
83  bool isFriction = false, btScalar desiredVelocity=0, btScalar cfmSlip=0);
84 
85 public:
86 
87  btMultiBodyConstraint(btMultiBody* bodyA,btMultiBody* bodyB,int linkA, int linkB, int numRows, bool isUnilateral);
88  virtual ~btMultiBodyConstraint();
89 
90  void updateJacobianSizes();
91  void allocateJacobiansMultiDof();
92 
93  virtual void finalizeMultiDof()=0;
94 
95  virtual int getIslandIdA() const =0;
96  virtual int getIslandIdB() const =0;
97 
98  virtual void createConstraintRows(btMultiBodyConstraintArray& constraintRows,
100  const btContactSolverInfo& infoGlobal)=0;
101 
102  int getNumRows() const
103  {
104  return m_numRows;
105  }
106 
108  {
109  return m_bodyA;
110  }
112  {
113  return m_bodyB;
114  }
115 
116  void internalSetAppliedImpulse(int dof, btScalar appliedImpulse)
117  {
118  btAssert(dof>=0);
119  btAssert(dof < getNumRows());
120  m_data[dof] = appliedImpulse;
121 
122  }
123 
125  {
126  btAssert(dof>=0);
127  btAssert(dof < getNumRows());
128  return m_data[dof];
129  }
130  // current constraint position
131  // constraint is pos >= 0 for unilateral, or pos = 0 for bilateral
132  // NOTE: ignored position for friction rows.
133  btScalar getPosition(int row) const
134  {
135  return m_data[m_posOffset + row];
136  }
137 
138  void setPosition(int row, btScalar pos)
139  {
140  m_data[m_posOffset + row] = pos;
141  }
142 
143 
144  bool isUnilateral() const
145  {
146  return m_isUnilateral;
147  }
148 
149  // jacobian blocks.
150  // each of size 6 + num_links. (jacobian2 is null if no body2.)
151  // format: 3 'omega' coefficients, 3 'v' coefficients, then the 'qdot' coefficients.
152  btScalar* jacobianA(int row)
153  {
154  return &m_data[m_numRows + row * m_jacSizeBoth];
155  }
156  const btScalar* jacobianA(int row) const
157  {
158  return &m_data[m_numRows + (row * m_jacSizeBoth)];
159  }
160  btScalar* jacobianB(int row)
161  {
162  return &m_data[m_numRows + (row * m_jacSizeBoth) + m_jacSizeA];
163  }
164  const btScalar* jacobianB(int row) const
165  {
166  return &m_data[m_numRows + (row * m_jacSizeBoth) + m_jacSizeA];
167  }
168 
170  {
171  return m_maxAppliedImpulse;
172  }
174  {
175  m_maxAppliedImpulse = maxImp;
176  }
177 
178  virtual void debugDraw(class btIDebugDraw* drawer)=0;
179 
180 };
181 
182 #endif //BT_MULTIBODY_CONSTRAINT_H
183 
const btScalar * jacobianA(int row) const
btScalar * jacobianB(int row)
1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and fr...
btAlignedObjectArray< btScalar > scratch_r
btAlignedObjectArray< btScalar > m_deltaVelocities
btAlignedObjectArray< btSolverBody > * m_solverBodyPool
btScalar getAppliedImpulse(int dof)
void internalSetAppliedImpulse(int dof, btScalar appliedImpulse)
#define btAssert(x)
Definition: btScalar.h:114
btScalar * jacobianA(int row)
btScalar getPosition(int row) const
btAlignedObjectArray< btMatrix3x3 > scratch_m
btAlignedObjectArray< btScalar > m_deltaVelocitiesUnitImpulse
const btScalar * jacobianB(int row) const
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations...
Definition: btIDebugDraw.h:29
btAlignedObjectArray< btScalar > m_data
btAlignedObjectArray< btScalar > m_jacobians
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btAlignedObjectArray< btVector3 > scratch_v
void setPosition(int row, btScalar pos)
void setMaxAppliedImpulse(btScalar maxImp)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:279
btScalar getMaxAppliedImpulse() const