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 {
38 
39 };
40 
41 
43 {
44 protected:
45 
48  int m_linkA;
49  int m_linkB;
50 
55 
57 
59 
60 
61  // data block laid out as follows:
62  // cached impulses. (one per row.)
63  // jacobians. (interleaved, row1 body1 then row1 body2 then row2 body 1 etc)
64  // positions. (one per row.)
66 
67  void applyDeltaVee(btMultiBodyJacobianData& data, btScalar* delta_vee, btScalar impulse, int velocityIndex, int ndof);
68 
71  const btVector3& contactNormalOnB,
72  const btVector3& posAworld, const btVector3& posBworld,
73  btScalar position,
74  const btContactSolverInfo& infoGlobal,
75  btScalar& relaxation,
76  bool isFriction, btScalar desiredVelocity=0, btScalar cfmSlip=0);
77 
80  btScalar* jacOrgA,btScalar* jacOrgB,
81  const btContactSolverInfo& infoGlobal,
82  btScalar desiredVelocity,
83  btScalar lowerLimit,
84  btScalar upperLimit);
85 
86 public:
87 
88  btMultiBodyConstraint(btMultiBody* bodyA,btMultiBody* bodyB,int linkA, int linkB, int numRows, bool isUnilateral);
89  virtual ~btMultiBodyConstraint();
90 
91 
92 
93  virtual int getIslandIdA() const =0;
94  virtual int getIslandIdB() const =0;
95 
96  virtual void createConstraintRows(btMultiBodyConstraintArray& constraintRows,
98  const btContactSolverInfo& infoGlobal)=0;
99 
100  int getNumRows() const
101  {
102  return m_num_rows;
103  }
104 
106  {
107  return m_bodyA;
108  }
110  {
111  return m_bodyB;
112  }
113 
114  // current constraint position
115  // constraint is pos >= 0 for unilateral, or pos = 0 for bilateral
116  // NOTE: ignored position for friction rows.
117  btScalar getPosition(int row) const
118  {
119  return m_data[m_pos_offset + row];
120  }
121 
122  void setPosition(int row, btScalar pos)
123  {
124  m_data[m_pos_offset + row] = pos;
125  }
126 
127 
128  bool isUnilateral() const
129  {
130  return m_isUnilateral;
131  }
132 
133  // jacobian blocks.
134  // each of size 6 + num_links. (jacobian2 is null if no body2.)
135  // format: 3 'omega' coefficients, 3 'v' coefficients, then the 'qdot' coefficients.
136  btScalar* jacobianA(int row)
137  {
138  return &m_data[m_num_rows + row * m_jac_size_both];
139  }
140  const btScalar* jacobianA(int row) const
141  {
142  return &m_data[m_num_rows + (row * m_jac_size_both)];
143  }
144  btScalar* jacobianB(int row)
145  {
146  return &m_data[m_num_rows + (row * m_jac_size_both) + m_jac_size_A];
147  }
148  const btScalar* jacobianB(int row) const
149  {
150  return &m_data[m_num_rows + (row * m_jac_size_both) + m_jac_size_A];
151  }
152 
154  {
155  return m_maxAppliedImpulse;
156  }
158  {
159  m_maxAppliedImpulse = maxImp;
160  }
161 
162 
163 };
164 
165 #endif //BT_MULTIBODY_CONSTRAINT_H
166 
btScalar getMaxAppliedImpulse() const
void fillMultiBodyConstraintMixed(btMultiBodySolverConstraint &solverConstraint, btMultiBodyJacobianData &data, const btVector3 &contactNormalOnB, const btVector3 &posAworld, const btVector3 &posBworld, btScalar position, const btContactSolverInfo &infoGlobal, btScalar &relaxation, bool isFriction, btScalar desiredVelocity=0, btScalar cfmSlip=0)
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
virtual void createConstraintRows(btMultiBodyConstraintArray &constraintRows, btMultiBodyJacobianData &data, const btContactSolverInfo &infoGlobal)=0
btAlignedObjectArray< btSolverBody > * m_solverBodyPool
btScalar * jacobianA(int row)
btAlignedObjectArray< btMatrix3x3 > scratch_m
virtual int getIslandIdB() const =0
btAlignedObjectArray< btScalar > m_deltaVelocitiesUnitImpulse
btScalar getPosition(int row) const
btAlignedObjectArray< btScalar > m_data
btAlignedObjectArray< btScalar > m_jacobians
virtual int getIslandIdA() const =0
const btScalar * jacobianA(int row) const
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btScalar fillConstraintRowMultiBodyMultiBody(btMultiBodySolverConstraint &constraintRow, btMultiBodyJacobianData &data, btScalar *jacOrgA, btScalar *jacOrgB, const btContactSolverInfo &infoGlobal, btScalar desiredVelocity, btScalar lowerLimit, btScalar upperLimit)
btAlignedObjectArray< btVector3 > scratch_v
void setPosition(int row, btScalar pos)
void setMaxAppliedImpulse(btScalar maxImp)
btMultiBodyConstraint(btMultiBody *bodyA, btMultiBody *bodyB, int linkA, int linkB, int numRows, bool isUnilateral)
const btScalar * jacobianB(int row) const
void applyDeltaVee(btMultiBodyJacobianData &data, btScalar *delta_vee, btScalar impulse, int velocityIndex, int ndof)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:266