Bullet Collision Detection & Physics Library: btMultiBodyConstraint.h Source File

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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"
20 #include "LinearMath/btAlignedObjectArray.h"
21 #include "btMultiBody.h"
22
23 class btMultiBody;
24 struct btSolverInfo;
25
26 #include "btMultiBodySolverConstraint.h"
27
28 struct btMultiBodyJacobianData
29 {
30 btAlignedObjectArray<btScalar> m_jacobians;
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
33 btAlignedObjectArray<btScalar> scratch_r;
34 btAlignedObjectArray<btVector3> scratch_v;
35 btAlignedObjectArray<btMatrix3x3> scratch_m;
36 btAlignedObjectArray<btSolverBody>* m_solverBodyPool;
37 int m_fixedBodyId;
38
39 };
40
41
42 class btMultiBodyConstraint
43 {
44 protected:
45
46 btMultiBody* m_bodyA;
47 btMultiBody* m_bodyB;
48 int m_linkA;
49 int m_linkB;
50
51 int m_numRows;
52 int m_jacSizeA;
53 int m_jacSizeBoth;
54 int m_posOffset;
55
56 bool m_isUnilateral;
57
58 btScalar m_maxAppliedImpulse;
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.)
65 btAlignedObjectArray<btScalar> m_data;
66
67 void applyDeltaVee(btMultiBodyJacobianData& data, btScalar* delta_vee, btScalar impulse, int velocityIndex, int ndof);
68
69 btScalar fillMultiBodyConstraint(btMultiBodySolverConstraint& solverConstraint,
70 btMultiBodyJacobianData& data,
71 btScalar* jacOrgA, btScalar* jacOrgB,
72 const btVector3& contactNormalOnB,
73 const btVector3& posAworld, const btVector3& posBworld,
74 btScalar posError,
75 const btContactSolverInfo& infoGlobal,
76 btScalar lowerLimit, btScalar upperLimit,
77 btScalar relaxation = 1.f,
78 bool isFriction = false, btScalar desiredVelocity=0, btScalar cfmSlip=0);
79
80 public:
81
82 btMultiBodyConstraint(btMultiBody* bodyA,btMultiBody* bodyB,int linkA, int linkB, int numRows, bool isUnilateral);
83 virtual ~btMultiBodyConstraint();
84
85 void finalizeMultiDof();
86
87 virtual int getIslandIdA() const =0;
88 virtual int getIslandIdB() const =0;
89
90 virtual void createConstraintRows(btMultiBodyConstraintArray& constraintRows,
91 btMultiBodyJacobianData& data,
92 const btContactSolverInfo& infoGlobal)=0;
93
94 int getNumRows() const
95 {
96 return m_numRows;
97 }
98
99 btMultiBody* getMultiBodyA()
100 {
101 return m_bodyA;
102 }
103 btMultiBody* getMultiBodyB()
104 {
105 return m_bodyB;
106 }
107
108 // current constraint position
109 // constraint is pos >= 0 for unilateral, or pos = 0 for bilateral
110 // NOTE: ignored position for friction rows.
111 btScalar getPosition(int row) const
112 {
113 return m_data[m_posOffset + row];
114 }
115
116 void setPosition(int row, btScalar pos)
117 {
118 m_data[m_posOffset + row] = pos;
119 }
120
121
122 bool isUnilateral() const
123 {
124 return m_isUnilateral;
125 }
126
127 // jacobian blocks.
128 // each of size 6 + num_links. (jacobian2 is null if no body2.)
129 // format: 3 'omega' coefficients, 3 'v' coefficients, then the 'qdot' coefficients.
130 btScalar* jacobianA(int row)
131 {
132 return &m_data[m_numRows + row * m_jacSizeBoth];
133 }
134 const btScalar* jacobianA(int row) const
135 {
136 return &m_data[m_numRows + (row * m_jacSizeBoth)];
137 }
138 btScalar* jacobianB(int row)
139 {
140 return &m_data[m_numRows + (row * m_jacSizeBoth) + m_jacSizeA];
141 }
142 const btScalar* jacobianB(int row) const
143 {
144 return &m_data[m_numRows + (row * m_jacSizeBoth) + m_jacSizeA];
145 }
146
147 btScalar getMaxAppliedImpulse() const
148 {
149 return m_maxAppliedImpulse;
150 }
151 void setMaxAppliedImpulse(btScalar maxImp)
152 {
153 m_maxAppliedImpulse = maxImp;
154 }
155
156 virtual void debugDraw(class btIDebugDraw* drawer)=0;
157
158 };
159
160 #endif //BT_MULTIBODY_CONSTRAINT_H
161
btMultiBodyConstraint::fillMultiBodyConstraint
btScalar fillMultiBodyConstraint(btMultiBodySolverConstraint &solverConstraint, btMultiBodyJacobianData &data, btScalar *jacOrgA, btScalar *jacOrgB, const btVector3 &contactNormalOnB, const btVector3 &posAworld, const btVector3 &posBworld, btScalar posError, const btContactSolverInfo &infoGlobal, btScalar lowerLimit, btScalar upperLimit, btScalar relaxation=1.f, bool isFriction=false, btScalar desiredVelocity=0, btScalar cfmSlip=0)
Definition: btMultiBodyConstraint.cpp:55
btMultiBodyConstraint::getMaxAppliedImpulse
btScalar getMaxAppliedImpulse() const
Definition: btMultiBodyConstraint.h:147
btMultiBodyConstraint::jacobianB
btScalar * jacobianB(int row)
Definition: btMultiBodyConstraint.h:138
btMultiBodyConstraint::getMultiBodyA
btMultiBody * getMultiBodyA()
Definition: btMultiBodyConstraint.h:99
btMultiBodySolverConstraint
1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and fr...
Definition: btMultiBodySolverConstraint.h:27
btMultiBodyJacobianData::scratch_r
btAlignedObjectArray< btScalar > scratch_r
Definition: btMultiBodyConstraint.h:33
btMultiBodyJacobianData::m_deltaVelocities
btAlignedObjectArray< btScalar > m_deltaVelocities
Definition: btMultiBodyConstraint.h:32
btMultiBodyConstraint::createConstraintRows
virtual void createConstraintRows(btMultiBodyConstraintArray &constraintRows, btMultiBodyJacobianData &data, const btContactSolverInfo &infoGlobal)=0
btAlignedObjectArray< btScalar >
btMultiBodyJacobianData::m_solverBodyPool
btAlignedObjectArray< btSolverBody > * m_solverBodyPool
Definition: btMultiBodyConstraint.h:36
btMultiBodyConstraint::m_maxAppliedImpulse
btScalar m_maxAppliedImpulse
Definition: btMultiBodyConstraint.h:58
btMultiBodySolverConstraint.h
btMultiBodyConstraint::m_bodyB
btMultiBody * m_bodyB
Definition: btMultiBodyConstraint.h:47
btMultiBodyConstraint::jacobianA
btScalar * jacobianA(int row)
Definition: btMultiBodyConstraint.h:130
btMultiBodyConstraint::~btMultiBodyConstraint
virtual ~btMultiBodyConstraint()
Definition: btMultiBodyConstraint.cpp:45
btMultiBodyConstraint::m_posOffset
int m_posOffset
Definition: btMultiBodyConstraint.h:54
btMultiBody
Definition: btMultiBody.h:37
btMultiBodyConstraint::debugDraw
virtual void debugDraw(class btIDebugDraw *drawer)=0
btMultiBodyJacobianData::scratch_m
btAlignedObjectArray< btMatrix3x3 > scratch_m
Definition: btMultiBodyConstraint.h:35
btMultiBodyConstraint
Definition: btMultiBodyConstraint.h:42
btMultiBodyConstraint::getNumRows
int getNumRows() const
Definition: btMultiBodyConstraint.h:94
btMultiBodyConstraint::getIslandIdB
virtual int getIslandIdB() const =0
btMultiBodyJacobianData::m_deltaVelocitiesUnitImpulse
btAlignedObjectArray< btScalar > m_deltaVelocitiesUnitImpulse
Definition: btMultiBodyConstraint.h:31
btMultiBodyConstraint::isUnilateral
bool isUnilateral() const
Definition: btMultiBodyConstraint.h:122
btMultiBodyJacobianData::m_fixedBodyId
int m_fixedBodyId
Definition: btMultiBodyConstraint.h:37
btMultiBodyConstraint::getPosition
btScalar getPosition(int row) const
Definition: btMultiBodyConstraint.h:111
btMultiBodyConstraint::m_jacSizeA
int m_jacSizeA
Definition: btMultiBodyConstraint.h:52
btMultiBodyConstraint::m_jacSizeBoth
int m_jacSizeBoth
Definition: btMultiBodyConstraint.h:53
btMultiBodyConstraint::finalizeMultiDof
void finalizeMultiDof()
Definition: btMultiBodyConstraint.cpp:21
btIDebugDraw
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations...
Definition: btIDebugDraw.h:28
btMultiBodyJacobianData
Definition: btMultiBodyConstraint.h:28
btMultiBodyConstraint::m_data
btAlignedObjectArray< btScalar > m_data
Definition: btMultiBodyConstraint.h:65
btMultiBodyJacobianData::m_jacobians
btAlignedObjectArray< btScalar > m_jacobians
Definition: btMultiBodyConstraint.h:30
btMultiBodyConstraint::getIslandIdA
virtual int getIslandIdA() const =0
btMultiBodyConstraint::jacobianA
const btScalar * jacobianA(int row) const
Definition: btMultiBodyConstraint.h:134
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btMultiBodyJacobianData::scratch_v
btAlignedObjectArray< btVector3 > scratch_v
Definition: btMultiBodyConstraint.h:34
btMultiBody.h
btContactSolverInfo
Definition: btContactSolverInfo.h:65
btMultiBodyConstraint::m_numRows
int m_numRows
Definition: btMultiBodyConstraint.h:51
btMultiBodyConstraint::setPosition
void setPosition(int row, btScalar pos)
Definition: btMultiBodyConstraint.h:116
btMultiBodyConstraint::setMaxAppliedImpulse
void setMaxAppliedImpulse(btScalar maxImp)
Definition: btMultiBodyConstraint.h:151
btMultiBodyConstraint::m_bodyA
btMultiBody * m_bodyA
Definition: btMultiBodyConstraint.h:46
btAlignedObjectArray.h
btMultiBodyConstraint::m_isUnilateral
bool m_isUnilateral
Definition: btMultiBodyConstraint.h:56
btMultiBodyConstraint::btMultiBodyConstraint
btMultiBodyConstraint(btMultiBody *bodyA, btMultiBody *bodyB, int linkA, int linkB, int numRows, bool isUnilateral)
Definition: btMultiBodyConstraint.cpp:7
btMultiBodyConstraint::jacobianB
const btScalar * jacobianB(int row) const
Definition: btMultiBodyConstraint.h:142
btMultiBodyConstraint::getMultiBodyB
btMultiBody * getMultiBodyB()
Definition: btMultiBodyConstraint.h:103
btMultiBodyConstraint::applyDeltaVee
void applyDeltaVee(btMultiBodyJacobianData &data, btScalar *delta_vee, btScalar impulse, int velocityIndex, int ndof)
Definition: btMultiBodyConstraint.cpp:49
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:278
btMultiBodyConstraint::m_linkB
int m_linkB
Definition: btMultiBodyConstraint.h:49
btScalar.h
btMultiBodyConstraint::m_linkA
int m_linkA
Definition: btMultiBodyConstraint.h:48