Bullet Collision Detection & Physics Library
btMultiBodyConstraint.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2013 Erwin Coumans http://bulletphysics.org
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_MULTIBODY_CONSTRAINT_H
17#define BT_MULTIBODY_CONSTRAINT_H
18
19#include "LinearMath/btScalar.h"
21#include "btMultiBody.h"
22
23class btMultiBody;
24struct 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
42{
43protected:
48
53
57
58 // warning: the data block lay out is not consistent for all constraints
59 // data block laid out as follows:
60 // cached impulses. (one per row.)
61 // jacobians. (interleaved, row1 body1 then row1 body2 then row2 body 1 etc)
62 // positions. (one per row.)
64
65 void applyDeltaVee(btMultiBodyJacobianData & data, btScalar * delta_vee, btScalar impulse, int velocityIndex, int ndof);
66
67 btScalar fillMultiBodyConstraint(btMultiBodySolverConstraint & solverConstraint,
69 btScalar * jacOrgA, btScalar * jacOrgB,
70 const btVector3& constraintNormalAng,
71
72 const btVector3& constraintNormalLin,
73 const btVector3& posAworld, const btVector3& posBworld,
74 btScalar posError,
75 const btContactSolverInfo& infoGlobal,
76 btScalar lowerLimit, btScalar upperLimit,
77 bool angConstraint = false,
78
79 btScalar relaxation = 1.f,
80 bool isFriction = false, btScalar desiredVelocity = 0, btScalar cfmSlip = 0);
81
82public:
84
85 btMultiBodyConstraint(btMultiBody * bodyA, btMultiBody * bodyB, int linkA, int linkB, int numRows, bool isUnilateral);
86 virtual ~btMultiBodyConstraint();
87
88 void updateJacobianSizes();
89 void allocateJacobiansMultiDof();
90
91 //many constraints have setFrameInB/setPivotInB. Will use 'getConstraintType' later.
92 virtual void setFrameInB(const btMatrix3x3& frameInB) {}
93 virtual void setPivotInB(const btVector3& pivotInB) {}
94
95 virtual void finalizeMultiDof() = 0;
96
97 virtual int getIslandIdA() const = 0;
98 virtual int getIslandIdB() const = 0;
99
102 const btContactSolverInfo& infoGlobal) = 0;
103
104 int getNumRows() const
105 {
106 return m_numRows;
107 }
108
110 {
111 return m_bodyA;
112 }
114 {
115 return m_bodyB;
116 }
117
118 int getLinkA() const
119 {
120 return m_linkA;
121 }
122 int getLinkB() const
123 {
124 return m_linkB;
125 }
126 void internalSetAppliedImpulse(int dof, btScalar appliedImpulse)
127 {
128 btAssert(dof >= 0);
129 btAssert(dof < getNumRows());
130 m_data[dof] = appliedImpulse;
131 }
132
134 {
135 btAssert(dof >= 0);
136 btAssert(dof < getNumRows());
137 return m_data[dof];
138 }
139 // current constraint position
140 // constraint is pos >= 0 for unilateral, or pos = 0 for bilateral
141 // NOTE: ignored position for friction rows.
142 btScalar getPosition(int row) const
143 {
144 return m_data[m_posOffset + row];
145 }
146
147 void setPosition(int row, btScalar pos)
148 {
149 m_data[m_posOffset + row] = pos;
150 }
151
152 bool isUnilateral() const
153 {
154 return m_isUnilateral;
155 }
156
157 // jacobian blocks.
158 // each of size 6 + num_links. (jacobian2 is null if no body2.)
159 // format: 3 'omega' coefficients, 3 'v' coefficients, then the 'qdot' coefficients.
161 {
162 return &m_data[m_numRows + row * m_jacSizeBoth];
163 }
164 const btScalar* jacobianA(int row) const
165 {
166 return &m_data[m_numRows + (row * m_jacSizeBoth)];
167 }
169 {
170 return &m_data[m_numRows + (row * m_jacSizeBoth) + m_jacSizeA];
171 }
172 const btScalar* jacobianB(int row) const
173 {
174 return &m_data[m_numRows + (row * m_jacSizeBoth) + m_jacSizeA];
175 }
176
178 {
179 return m_maxAppliedImpulse;
180 }
182 {
183 m_maxAppliedImpulse = maxImp;
184 }
185
186 virtual void debugDraw(class btIDebugDraw * drawer) = 0;
187
188 virtual void setGearRatio(btScalar ratio) {}
189 virtual void setGearAuxLink(int gearAuxLink) {}
190 virtual void setRelativePositionTarget(btScalar relPosTarget) {}
191 virtual void setErp(btScalar erp) {}
192};
193
194#endif //BT_MULTIBODY_CONSTRAINT_H
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:99
#define btAssert(x)
Definition: btScalar.h:153
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
Definition: btIDebugDraw.h:27
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition: btMatrix3x3.h:48
virtual void setGearRatio(btScalar ratio)
virtual void setRelativePositionTarget(btScalar relPosTarget)
btScalar getPosition(int row) const
const btScalar * jacobianA(int row) const
virtual int getIslandIdA() const =0
btAlignedObjectArray< btScalar > m_data
btScalar * jacobianA(int row)
void setPosition(int row, btScalar pos)
virtual void debugDraw(class btIDebugDraw *drawer)=0
btScalar * jacobianB(int row)
virtual void createConstraintRows(btMultiBodyConstraintArray &constraintRows, btMultiBodyJacobianData &data, const btContactSolverInfo &infoGlobal)=0
virtual void setPivotInB(const btVector3 &pivotInB)
void setMaxAppliedImpulse(btScalar maxImp)
btScalar getAppliedImpulse(int dof)
virtual int getIslandIdB() const =0
virtual void setErp(btScalar erp)
btScalar getMaxAppliedImpulse() const
const btScalar * jacobianB(int row) const
void internalSetAppliedImpulse(int dof, btScalar appliedImpulse)
virtual void setGearAuxLink(int gearAuxLink)
virtual void setFrameInB(const btMatrix3x3 &frameInB)
virtual void finalizeMultiDof()=0
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:82
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
1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and fr...