2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2013 Erwin Coumans http://bulletphysics.org
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:
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.
16 #ifndef BT_MULTIBODY_CONSTRAINT_H
17 #define BT_MULTIBODY_CONSTRAINT_H
19 #include "LinearMath/btScalar.h"
20 #include "LinearMath/btAlignedObjectArray.h"
21 #include "btMultiBody.h"
24 //Don't change any of the existing enum values, so add enum types at the end for serialization compatibility
25 enum btTypedMultiBodyConstraintType
27 MULTIBODY_CONSTRAINT_LIMIT=3,
28 MULTIBODY_CONSTRAINT_1DOF_JOINT_MOTOR,
29 MULTIBODY_CONSTRAINT_GEAR,
30 MULTIBODY_CONSTRAINT_POINT_TO_POINT,
31 MULTIBODY_CONSTRAINT_SLIDER,
32 MULTIBODY_CONSTRAINT_SPHERICAL_MOTOR,
33 MULTIBODY_CONSTRAINT_FIXED,
34 MULTIBODY_CONSTRAINT_SPHERICAL_LIMIT,
35 MAX_MULTIBODY_CONSTRAINT_TYPE,
41 #include "btMultiBodySolverConstraint.h"
43 struct btMultiBodyJacobianData
45 btAlignedObjectArray<btScalar> m_jacobians;
46 btAlignedObjectArray<btScalar> m_deltaVelocitiesUnitImpulse; //holds the joint-space response of the corresp. tree to the test impulse in each constraint space dimension
47 btAlignedObjectArray<btScalar> m_deltaVelocities; //holds joint-space vectors of all the constrained trees accumulating the effect of corrective impulses applied in SI
48 btAlignedObjectArray<btScalar> scratch_r;
49 btAlignedObjectArray<btVector3> scratch_v;
50 btAlignedObjectArray<btMatrix3x3> scratch_m;
51 btAlignedObjectArray<btSolverBody>* m_solverBodyPool;
55 ATTRIBUTE_ALIGNED16(class)
64 int m_type; //btTypedMultiBodyConstraintType
72 int m_numDofsFinalized;
73 btScalar m_maxAppliedImpulse;
75 // warning: the data block lay out is not consistent for all constraints
76 // data block laid out as follows:
77 // cached impulses. (one per row.)
78 // jacobians. (interleaved, row1 body1 then row1 body2 then row2 body 1 etc)
79 // positions. (one per row.)
80 btAlignedObjectArray<btScalar> m_data;
82 void applyDeltaVee(btMultiBodyJacobianData & data, btScalar * delta_vee, btScalar impulse, int velocityIndex, int ndof);
84 btScalar fillMultiBodyConstraint(btMultiBodySolverConstraint & solverConstraint,
85 btMultiBodyJacobianData & data,
86 btScalar * jacOrgA, btScalar * jacOrgB,
87 const btVector3& constraintNormalAng,
89 const btVector3& constraintNormalLin,
90 const btVector3& posAworld, const btVector3& posBworld,
92 const btContactSolverInfo& infoGlobal,
93 btScalar lowerLimit, btScalar upperLimit,
94 bool angConstraint = false,
96 btScalar relaxation = 1.f,
97 bool isFriction = false, btScalar desiredVelocity = 0, btScalar cfmSlip = 0, btScalar damping = 1.0);
100 BT_DECLARE_ALIGNED_ALLOCATOR();
102 btMultiBodyConstraint(btMultiBody * bodyA, btMultiBody * bodyB, int linkA, int linkB, int numRows, bool isUnilateral, int type);
103 virtual ~btMultiBodyConstraint();
105 void updateJacobianSizes();
106 void allocateJacobiansMultiDof();
108 int getConstraintType() const
112 //many constraints have setFrameInB/setPivotInB. Will use 'getConstraintType' later.
113 virtual void setFrameInB(const btMatrix3x3& frameInB) {}
114 virtual void setPivotInB(const btVector3& pivotInB) {}
116 virtual void finalizeMultiDof() = 0;
118 virtual int getIslandIdA() const = 0;
119 virtual int getIslandIdB() const = 0;
121 virtual void createConstraintRows(btMultiBodyConstraintArray & constraintRows,
122 btMultiBodyJacobianData & data,
123 const btContactSolverInfo& infoGlobal) = 0;
125 int getNumRows() const
130 btMultiBody* getMultiBodyA()
134 btMultiBody* getMultiBodyB()
147 void internalSetAppliedImpulse(int dof, btScalar appliedImpulse)
150 btAssert(dof < getNumRows());
151 m_data[dof] = appliedImpulse;
154 btScalar getAppliedImpulse(int dof)
157 btAssert(dof < getNumRows());
160 // current constraint position
161 // constraint is pos >= 0 for unilateral, or pos = 0 for bilateral
162 // NOTE: ignored position for friction rows.
163 btScalar getPosition(int row) const
165 return m_data[m_posOffset + row];
168 void setPosition(int row, btScalar pos)
170 m_data[m_posOffset + row] = pos;
173 bool isUnilateral() const
175 return m_isUnilateral;
179 // each of size 6 + num_links. (jacobian2 is null if no body2.)
180 // format: 3 'omega' coefficients, 3 'v' coefficients, then the 'qdot' coefficients.
181 btScalar* jacobianA(int row)
183 return &m_data[m_numRows + row * m_jacSizeBoth];
185 const btScalar* jacobianA(int row) const
187 return &m_data[m_numRows + (row * m_jacSizeBoth)];
189 btScalar* jacobianB(int row)
191 return &m_data[m_numRows + (row * m_jacSizeBoth) + m_jacSizeA];
193 const btScalar* jacobianB(int row) const
195 return &m_data[m_numRows + (row * m_jacSizeBoth) + m_jacSizeA];
198 btScalar getMaxAppliedImpulse() const
200 return m_maxAppliedImpulse;
202 void setMaxAppliedImpulse(btScalar maxImp)
204 m_maxAppliedImpulse = maxImp;
207 virtual void debugDraw(class btIDebugDraw * drawer) = 0;
209 virtual void setGearRatio(btScalar ratio) {}
210 virtual void setGearAuxLink(int gearAuxLink) {}
211 virtual void setRelativePositionTarget(btScalar relPosTarget) {}
212 virtual void setErp(btScalar erp) {}
215 #endif //BT_MULTIBODY_CONSTRAINT_H