Bullet Collision Detection & Physics Library
btMultiBodySliderConstraint.cpp
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
17
23
24#define BTMBSLIDERCONSTRAINT_DIM 5
25#define EPSILON 0.000001
26
29 m_rigidBodyA(0),
30 m_rigidBodyB(bodyB),
31 m_pivotInA(pivotInA),
32 m_pivotInB(pivotInB),
33 m_frameInA(frameInA),
34 m_frameInB(frameInB),
35 m_jointAxis(jointAxis)
36{
37 m_data.resize(BTMBSLIDERCONSTRAINT_DIM); //at least store the applied impulses
38}
39
42 m_rigidBodyA(0),
43 m_rigidBodyB(0),
44 m_pivotInA(pivotInA),
45 m_pivotInB(pivotInB),
46 m_frameInA(frameInA),
47 m_frameInB(frameInB),
48 m_jointAxis(jointAxis)
49{
50 m_data.resize(BTMBSLIDERCONSTRAINT_DIM); //at least store the applied impulses
51}
52
54{
55 //not implemented yet
56 btAssert(0);
57}
58
60{
61}
62
64{
65 if (m_rigidBodyA)
66 return m_rigidBodyA->getIslandTag();
67
68 if (m_bodyA)
69 {
70 if (m_linkA < 0)
71 {
73 if (col)
74 return col->getIslandTag();
75 }
76 else
77 {
80 }
81 }
82 return -1;
83}
84
86{
87 if (m_rigidBodyB)
88 return m_rigidBodyB->getIslandTag();
89 if (m_bodyB)
90 {
91 if (m_linkB < 0)
92 {
94 if (col)
95 return col->getIslandTag();
96 }
97 else
98 {
101 }
102 }
103 return -1;
104}
106{
107 // Convert local points back to world
111 if (m_rigidBodyA)
112 {
116 }
117 else if (m_bodyA)
118 {
122 }
125 if (m_rigidBodyB)
126 {
129 }
130 else if (m_bodyB)
131 {
134 }
135
137 for (int i = 0; i < 3; ++i)
138 {
139 constraintAxis[0] = frameAworld.getColumn(i).cross(jointAxis);
140 if (constraintAxis[0].safeNorm() > EPSILON)
141 {
145 break;
146 }
147 }
148
152
154 for (int i = 0; i < numDim; i++)
155 {
158 constraintRow.m_orgDofIndex = i;
159 constraintRow.m_relpos1CrossNormal.setValue(0, 0, 0);
160 constraintRow.m_contactNormal1.setValue(0, 0, 0);
161 constraintRow.m_relpos2CrossNormal.setValue(0, 0, 0);
162 constraintRow.m_contactNormal2.setValue(0, 0, 0);
163 constraintRow.m_angularComponentA.setValue(0, 0, 0);
164 constraintRow.m_angularComponentB.setValue(0, 0, 0);
165
166 constraintRow.m_solverBodyIdA = data.m_fixedBodyId;
167 constraintRow.m_solverBodyIdB = data.m_fixedBodyId;
168
169 if (m_rigidBodyA)
170 {
171 constraintRow.m_solverBodyIdA = m_rigidBodyA->getCompanionId();
172 }
173 if (m_rigidBodyB)
174 {
175 constraintRow.m_solverBodyIdB = m_rigidBodyB->getCompanionId();
176 }
177
180 btScalar posError = 0.0;
181 if (i < 2)
182 {
187 posError,
190 }
191 else
192 { //i>=2
193 constraintNormalAng = frameAworld.getColumn(i % 3);
194 posError = angleDiff[i % 3];
197 posError,
200 }
201 }
202}
203
205{
207 tr.setIdentity();
208
209 if (m_rigidBodyA)
210 {
212 tr.setOrigin(pivot);
213 drawer->drawTransform(tr, 0.1);
214 }
215 if (m_bodyA)
216 {
218 tr.setOrigin(pivotAworld);
219 drawer->drawTransform(tr, 0.1);
220 }
221 if (m_rigidBodyB)
222 {
223 // that ideally should draw the same frame
225 tr.setOrigin(pivot);
226 drawer->drawTransform(tr, 0.1);
227 }
228 if (m_bodyB)
229 {
231 tr.setOrigin(pivotBworld);
232 drawer->drawTransform(tr, 0.1);
233 }
234}
#define EPSILON
const T & btMax(const T &a, const T &b)
Definition btMinMax.h:27
@ MULTIBODY_CONSTRAINT_SLIDER
#define BTMBSLIDERCONSTRAINT_DIM
This file was written by Erwin Coumans.
btScalar dot(const btQuaternion &q1, const btQuaternion &q2)
Calculate the dot product between two quaternions.
btVector3 quatRotate(const btQuaternion &rotation, const btVector3 &v)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
#define btAssert(x)
Definition btScalar.h:153
void resize(int newsize, const T &fillData=T())
static bool matrixToEulerXYZ(const btMatrix3x3 &mat, btVector3 &xyz)
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
Definition btMatrix3x3.h:50
btMatrix3x3 inverse() const
Return the inverse of the matrix.
btMatrix3x3 transpose() const
Return the transpose of the matrix.
btAlignedObjectArray< btScalar > m_data
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, btScalar damping=1.0)
virtual void createConstraintRows(btMultiBodyConstraintArray &constraintRows, btMultiBodyJacobianData &data, const btContactSolverInfo &infoGlobal)
virtual void debugDraw(class btIDebugDraw *drawer)
btMultiBodySliderConstraint(btMultiBody *body, int link, btRigidBody *bodyB, const btVector3 &pivotInA, const btVector3 &pivotInB, const btMatrix3x3 &frameInA, const btMatrix3x3 &frameInB, const btVector3 &jointAxis)
btMatrix3x3 localFrameToWorld(int i, const btMatrix3x3 &local_frame) const
const btMultibodyLink & getLink(int index) const
const btMultiBodyLinkCollider * getBaseCollider() const
btVector3 localPosToWorld(int i, const btVector3 &local_pos) const
btVector3 localDirToWorld(int i, const btVector3 &local_dir) const
The btRigidBody is the main class for rigid body objects.
Definition btRigidBody.h:60
btQuaternion getOrientation() const
const btTransform & getCenterOfMassTransform() const
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition btTransform.h:30
void setIdentity()
Set this transformation to the identity.
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
btVector3 cross(const btVector3 &v) const
Return the cross product between this and another vector.
Definition btVector3.h:380
btVector3 normalized() const
Return a normalized version of this vector.
Definition btVector3.h:949
1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and fr...