Bullet Collision Detection & Physics Library
btSliderConstraint.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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 /*
17 Added by Roman Ponomarev (rponom@gmail.com)
18 April 04, 2008
19 
20 TODO:
21  - add clamping od accumulated impulse to improve stability
22  - add conversion for ODE constraint solver
23 */
24 
25 #ifndef BT_SLIDER_CONSTRAINT_H
26 #define BT_SLIDER_CONSTRAINT_H
27 
28 #ifdef BT_USE_DOUBLE_PRECISION
29 #define btSliderConstraintData2 btSliderConstraintDoubleData
30 #define btSliderConstraintDataName "btSliderConstraintDoubleData"
31 #else
32 #define btSliderConstraintData2 btSliderConstraintData
33 #define btSliderConstraintDataName "btSliderConstraintData"
34 #endif //BT_USE_DOUBLE_PRECISION
35 
36 #include "LinearMath/btVector3.h"
37 #include "btJacobianEntry.h"
38 #include "btTypedConstraint.h"
39 
40 
41 
42 class btRigidBody;
43 
44 
45 
46 #define SLIDER_CONSTRAINT_DEF_SOFTNESS (btScalar(1.0))
47 #define SLIDER_CONSTRAINT_DEF_DAMPING (btScalar(1.0))
48 #define SLIDER_CONSTRAINT_DEF_RESTITUTION (btScalar(0.7))
49 #define SLIDER_CONSTRAINT_DEF_CFM (btScalar(0.f))
50 
51 
53 {
66 };
67 
68 
70 {
71 protected:
77  // use frameA fo define limits, if true
79  // linear limits
82  // angular limits
85  // softness, restitution and damping for different cases
86  // DirLin - moving inside linear limits
87  // LimLin - hitting linear limit
88  // DirAng - moving inside angular limits
89  // LimAng - hitting angular limit
90  // OrthoLin, OrthoAng - against constraint axis
95 
100 
105 
110 
115 
120 
121  // for interlal use
124 
125  int m_flags;
126 
127  btJacobianEntry m_jacLin[3];
128  btScalar m_jacLinDiagABInv[3];
129 
130  btJacobianEntry m_jacAng[3];
131 
135 
144 
147 
150 
155 
160 
161  //------------------------
162  void initParams();
163 public:
165 
166  // constructors
167  btSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA);
168  btSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA);
169 
170  // overrides
171 
172  virtual void getInfo1 (btConstraintInfo1* info);
173 
174  void getInfo1NonVirtual(btConstraintInfo1* info);
175 
176  virtual void getInfo2 (btConstraintInfo2* info);
177 
178  void getInfo2NonVirtual(btConstraintInfo2* info, const btTransform& transA, const btTransform& transB,const btVector3& linVelA,const btVector3& linVelB, btScalar rbAinvMass,btScalar rbBinvMass);
179 
180 
181  // access
182  const btRigidBody& getRigidBodyA() const { return m_rbA; }
183  const btRigidBody& getRigidBodyB() const { return m_rbB; }
184  const btTransform & getCalculatedTransformA() const { return m_calculatedTransformA; }
185  const btTransform & getCalculatedTransformB() const { return m_calculatedTransformB; }
186  const btTransform & getFrameOffsetA() const { return m_frameInA; }
187  const btTransform & getFrameOffsetB() const { return m_frameInB; }
188  btTransform & getFrameOffsetA() { return m_frameInA; }
189  btTransform & getFrameOffsetB() { return m_frameInB; }
190  btScalar getLowerLinLimit() { return m_lowerLinLimit; }
191  void setLowerLinLimit(btScalar lowerLimit) { m_lowerLinLimit = lowerLimit; }
192  btScalar getUpperLinLimit() { return m_upperLinLimit; }
193  void setUpperLinLimit(btScalar upperLimit) { m_upperLinLimit = upperLimit; }
194  btScalar getLowerAngLimit() { return m_lowerAngLimit; }
195  void setLowerAngLimit(btScalar lowerLimit) { m_lowerAngLimit = btNormalizeAngle(lowerLimit); }
196  btScalar getUpperAngLimit() { return m_upperAngLimit; }
197  void setUpperAngLimit(btScalar upperLimit) { m_upperAngLimit = btNormalizeAngle(upperLimit); }
198  bool getUseLinearReferenceFrameA() { return m_useLinearReferenceFrameA; }
199  btScalar getSoftnessDirLin() { return m_softnessDirLin; }
200  btScalar getRestitutionDirLin() { return m_restitutionDirLin; }
201  btScalar getDampingDirLin() { return m_dampingDirLin ; }
202  btScalar getSoftnessDirAng() { return m_softnessDirAng; }
203  btScalar getRestitutionDirAng() { return m_restitutionDirAng; }
204  btScalar getDampingDirAng() { return m_dampingDirAng; }
205  btScalar getSoftnessLimLin() { return m_softnessLimLin; }
206  btScalar getRestitutionLimLin() { return m_restitutionLimLin; }
207  btScalar getDampingLimLin() { return m_dampingLimLin; }
208  btScalar getSoftnessLimAng() { return m_softnessLimAng; }
209  btScalar getRestitutionLimAng() { return m_restitutionLimAng; }
210  btScalar getDampingLimAng() { return m_dampingLimAng; }
211  btScalar getSoftnessOrthoLin() { return m_softnessOrthoLin; }
212  btScalar getRestitutionOrthoLin() { return m_restitutionOrthoLin; }
213  btScalar getDampingOrthoLin() { return m_dampingOrthoLin; }
214  btScalar getSoftnessOrthoAng() { return m_softnessOrthoAng; }
215  btScalar getRestitutionOrthoAng() { return m_restitutionOrthoAng; }
216  btScalar getDampingOrthoAng() { return m_dampingOrthoAng; }
217  void setSoftnessDirLin(btScalar softnessDirLin) { m_softnessDirLin = softnessDirLin; }
218  void setRestitutionDirLin(btScalar restitutionDirLin) { m_restitutionDirLin = restitutionDirLin; }
219  void setDampingDirLin(btScalar dampingDirLin) { m_dampingDirLin = dampingDirLin; }
220  void setSoftnessDirAng(btScalar softnessDirAng) { m_softnessDirAng = softnessDirAng; }
221  void setRestitutionDirAng(btScalar restitutionDirAng) { m_restitutionDirAng = restitutionDirAng; }
222  void setDampingDirAng(btScalar dampingDirAng) { m_dampingDirAng = dampingDirAng; }
223  void setSoftnessLimLin(btScalar softnessLimLin) { m_softnessLimLin = softnessLimLin; }
224  void setRestitutionLimLin(btScalar restitutionLimLin) { m_restitutionLimLin = restitutionLimLin; }
225  void setDampingLimLin(btScalar dampingLimLin) { m_dampingLimLin = dampingLimLin; }
226  void setSoftnessLimAng(btScalar softnessLimAng) { m_softnessLimAng = softnessLimAng; }
227  void setRestitutionLimAng(btScalar restitutionLimAng) { m_restitutionLimAng = restitutionLimAng; }
228  void setDampingLimAng(btScalar dampingLimAng) { m_dampingLimAng = dampingLimAng; }
229  void setSoftnessOrthoLin(btScalar softnessOrthoLin) { m_softnessOrthoLin = softnessOrthoLin; }
230  void setRestitutionOrthoLin(btScalar restitutionOrthoLin) { m_restitutionOrthoLin = restitutionOrthoLin; }
231  void setDampingOrthoLin(btScalar dampingOrthoLin) { m_dampingOrthoLin = dampingOrthoLin; }
232  void setSoftnessOrthoAng(btScalar softnessOrthoAng) { m_softnessOrthoAng = softnessOrthoAng; }
233  void setRestitutionOrthoAng(btScalar restitutionOrthoAng) { m_restitutionOrthoAng = restitutionOrthoAng; }
234  void setDampingOrthoAng(btScalar dampingOrthoAng) { m_dampingOrthoAng = dampingOrthoAng; }
235  void setPoweredLinMotor(bool onOff) { m_poweredLinMotor = onOff; }
236  bool getPoweredLinMotor() { return m_poweredLinMotor; }
237  void setTargetLinMotorVelocity(btScalar targetLinMotorVelocity) { m_targetLinMotorVelocity = targetLinMotorVelocity; }
238  btScalar getTargetLinMotorVelocity() { return m_targetLinMotorVelocity; }
239  void setMaxLinMotorForce(btScalar maxLinMotorForce) { m_maxLinMotorForce = maxLinMotorForce; }
240  btScalar getMaxLinMotorForce() { return m_maxLinMotorForce; }
241  void setPoweredAngMotor(bool onOff) { m_poweredAngMotor = onOff; }
242  bool getPoweredAngMotor() { return m_poweredAngMotor; }
243  void setTargetAngMotorVelocity(btScalar targetAngMotorVelocity) { m_targetAngMotorVelocity = targetAngMotorVelocity; }
244  btScalar getTargetAngMotorVelocity() { return m_targetAngMotorVelocity; }
245  void setMaxAngMotorForce(btScalar maxAngMotorForce) { m_maxAngMotorForce = maxAngMotorForce; }
246  btScalar getMaxAngMotorForce() { return m_maxAngMotorForce; }
247 
248  btScalar getLinearPos() const { return m_linPos; }
249  btScalar getAngularPos() const { return m_angPos; }
250 
251 
252 
253  // access for ODE solver
254  bool getSolveLinLimit() { return m_solveLinLim; }
255  btScalar getLinDepth() { return m_depth[0]; }
256  bool getSolveAngLimit() { return m_solveAngLim; }
257  btScalar getAngDepth() { return m_angDepth; }
258  // shared code used by ODE solver
259  void calculateTransforms(const btTransform& transA,const btTransform& transB);
260  void testLinLimits();
261  void testAngLimits();
262  // access for PE Solver
263  btVector3 getAncorInA();
264  btVector3 getAncorInB();
265  // access for UseFrameOffset
266  bool getUseFrameOffset() { return m_useOffsetForConstraintFrame; }
267  void setUseFrameOffset(bool frameOffsetOnOff) { m_useOffsetForConstraintFrame = frameOffsetOnOff; }
268 
269  void setFrames(const btTransform& frameA, const btTransform& frameB)
270  {
271  m_frameInA=frameA;
272  m_frameInB=frameB;
273  calculateTransforms(m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform());
274  buildJacobian();
275  }
276 
277 
280  virtual void setParam(int num, btScalar value, int axis = -1);
282  virtual btScalar getParam(int num, int axis = -1) const;
283 
284  virtual int calculateSerializeBufferSize() const;
285 
287  virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
288 
289 
290 };
291 
292 
294 
295 
297 {
299  btTransformFloatData m_rbAFrame; // constraint axii. Assumes z is hinge axis.
301 
304 
307 
310 
311 };
312 
313 
315 {
317  btTransformDoubleData m_rbAFrame; // constraint axii. Assumes z is hinge axis.
319 
322 
325 
328 
329 };
330 
332 {
333  return sizeof(btSliderConstraintData2);
334 }
335 
337 SIMD_FORCE_INLINE const char* btSliderConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
338 {
339 
340  btSliderConstraintData2* sliderData = (btSliderConstraintData2*) dataBuffer;
341  btTypedConstraint::serialize(&sliderData->m_typeConstraintData,serializer);
342 
343  m_frameInA.serialize(sliderData->m_rbAFrame);
344  m_frameInB.serialize(sliderData->m_rbBFrame);
345 
346  sliderData->m_linearUpperLimit = m_upperLinLimit;
347  sliderData->m_linearLowerLimit = m_lowerLinLimit;
348 
349  sliderData->m_angularUpperLimit = m_upperAngLimit;
350  sliderData->m_angularLowerLimit = m_lowerAngLimit;
351 
352  sliderData->m_useLinearReferenceFrameA = m_useLinearReferenceFrameA;
353  sliderData->m_useOffsetForConstraintFrame = m_useOffsetForConstraintFrame;
354 
356 }
357 
358 
359 
360 #endif //BT_SLIDER_CONSTRAINT_H
361 
void setMaxLinMotorForce(btScalar maxLinMotorForce)
void setDampingDirLin(btScalar dampingDirLin)
const btRigidBody & getRigidBodyB() const
void setUpperLinLimit(btScalar upperLimit)
void setRestitutionOrthoLin(btScalar restitutionOrthoLin)
btScalar getMaxAngMotorForce()
const btTransform & getCalculatedTransformA() const
const btTransform & getCalculatedTransformB() const
void setFrames(const btTransform &frameA, const btTransform &frameB)
void setLowerLinLimit(btScalar lowerLimit)
btTypedConstraintData m_typeConstraintData
btScalar getRestitutionDirAng()
void setRestitutionLimAng(btScalar restitutionLimAng)
Jacobian entry is an abstraction that allows to describe constraints it can be used in combination wi...
void setLowerAngLimit(btScalar lowerLimit)
void setDampingLimAng(btScalar dampingLimAng)
const btTransform & getFrameOffsetA() const
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
btScalar getRestitutionLimAng()
btScalar m_accumulatedAngMotorImpulse
void setSoftnessLimLin(btScalar softnessLimLin)
btScalar m_accumulatedLinMotorImpulse
void setPoweredAngMotor(bool onOff)
#define SIMD_FORCE_INLINE
Definition: btScalar.h:58
btTransform m_calculatedTransformB
void setRestitutionLimLin(btScalar restitutionLimLin)
void setUseFrameOffset(bool frameOffsetOnOff)
btScalar getLinearPos() const
void setTargetAngMotorVelocity(btScalar targetAngMotorVelocity)
void setRestitutionDirLin(btScalar restitutionDirLin)
btScalar getAngularPos() const
btTransformFloatData m_rbBFrame
void setPoweredLinMotor(bool onOff)
void setDampingLimLin(btScalar dampingLimLin)
btScalar getMaxLinMotorForce()
virtual int calculateSerializeBufferSize() const
void setDampingDirAng(btScalar dampingDirAng)
void setSoftnessDirAng(btScalar softnessDirAng)
void setSoftnessOrthoAng(btScalar softnessOrthoAng)
void setTargetLinMotorVelocity(btScalar targetLinMotorVelocity)
void setSoftnessLimAng(btScalar softnessLimAng)
void setDampingOrthoLin(btScalar dampingOrthoLin)
#define btSliderConstraintData2
void setUpperAngLimit(btScalar upperLimit)
btScalar getRestitutionDirLin()
const btRigidBody & getRigidBodyA() const
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:59
virtual const char * serialize(void *dataBuffer, btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
this structure is not used, except for loading pre-2.82 .bullet files
virtual int calculateSerializeBufferSize() const
btScalar getTargetLinMotorVelocity()
void setSoftnessOrthoLin(btScalar softnessOrthoLin)
const btTransform & getFrameOffsetB() const
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:59
btScalar getRestitutionOrthoAng()
btScalar getSoftnessOrthoLin()
btScalar btNormalizeAngle(btScalar angleInRadians)
Definition: btScalar.h:674
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
void setDampingOrthoAng(btScalar dampingOrthoAng)
#define btSliderConstraintDataName
btScalar getTargetAngMotorVelocity()
btTransform m_calculatedTransformA
TypedConstraint is the baseclass for Bullet constraints and vehicles.
void setRestitutionDirAng(btScalar restitutionDirAng)
btTransformFloatData m_rbAFrame
for serialization
Definition: btTransform.h:253
void setSoftnessDirLin(btScalar softnessDirLin)
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:357
virtual const char * serialize(void *dataBuffer, class btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
virtual const char * serialize(void *dataBuffer, btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
btTypedConstraintDoubleData m_typeConstraintData
bool m_useSolveConstraintObsolete
for backwards compatibility during the transition to 'getInfo/getInfo2'
btTransformDoubleData m_rbBFrame
void setMaxAngMotorForce(btScalar maxAngMotorForce)
void setRestitutionOrthoAng(btScalar restitutionOrthoAng)
btScalar getRestitutionOrthoLin()
void serialize(struct btTransformData &dataOut) const
Definition: btTransform.h:267
btScalar getSoftnessOrthoAng()
btTransformDoubleData m_rbAFrame
btTransform & getFrameOffsetB()
btScalar getRestitutionLimLin()
btTransform & getFrameOffsetA()
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:266
btSliderFlags