Bullet Collision Detection & Physics Library
btTypedConstraint.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2010 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 #ifndef BT_TYPED_CONSTRAINT_H
17 #define BT_TYPED_CONSTRAINT_H
18 
19 
20 #include "LinearMath/btScalar.h"
21 #include "btSolverConstraint.h"
23 
24 #ifdef BT_USE_DOUBLE_PRECISION
25 #define btTypedConstraintData2 btTypedConstraintDoubleData
26 #define btTypedConstraintDataName "btTypedConstraintDoubleData"
27 #else
28 #define btTypedConstraintData2 btTypedConstraintFloatData
29 #define btTypedConstraintDataName "btTypedConstraintFloatData"
30 #endif //BT_USE_DOUBLE_PRECISION
31 
32 
33 class btSerializer;
34 
35 //Don't change any of the existing enum values, so add enum types at the end for serialization compatibility
37 {
49 };
50 
51 
53 {
58 };
59 
60 #if 1
61  #define btAssertConstrParams(_par) btAssert(_par)
62 #else
63  #define btAssertConstrParams(_par)
64 #endif
65 
66 
68 {
74 };
75 
76 
79 {
81 
82  union
83  {
86  };
87 
92 
93 
95  {
96  btAssert(0);
97  (void) other;
98  return *this;
99  }
100 
101 protected:
107 
109  btScalar getMotorFactor(btScalar pos, btScalar lowLim, btScalar uppLim, btScalar vel, btScalar timeFact);
110 
111 
112 public:
113 
115 
116  virtual ~btTypedConstraint() {};
119 
121  int m_numConstraintRows,nub;
122  };
123 
124  static btRigidBody& getFixedBody();
125 
127  // integrator parameters: frames per second (1/stepsize), default error
128  // reduction parameter (0..1).
130 
131  // for the first and second body, pointers to two (linear and angular)
132  // n*3 jacobian sub matrices, stored by rows. these matrices will have
133  // been initialized to 0 on entry. if the second body is zero then the
134  // J2xx pointers may be 0.
135  btScalar *m_J1linearAxis,*m_J1angularAxis,*m_J2linearAxis,*m_J2angularAxis;
136 
137  // elements to jump from one row to the next in J's
138  int rowskip;
139 
140  // right hand sides of the equation J*v = c + cfm * lambda. cfm is the
141  // "constraint force mixing" vector. c is set to zero on entry, cfm is
142  // set to a constant value (typically very small or zero) value on entry.
144 
145  // lo and hi limits for variables (set to -/+ infinity on entry).
146  btScalar *m_lowerLimit,*m_upperLimit;
147 
148  // findex vector for variables. see the LCP solver interface for a
149  // description of what this does. this is set to -1 on entry.
150  // note that the returned indexes are relative to the first index of
151  // the constraint.
152  int *findex;
153  // number of solver iterations
155 
156  //damping of the velocity
158  };
159 
161  {
162  return m_overrideNumSolverIterations;
163  }
164 
167  void setOverrideNumSolverIterations(int overideNumIterations)
168  {
169  m_overrideNumSolverIterations = overideNumIterations;
170  }
171 
173  virtual void buildJacobian() {};
174 
176  virtual void setupSolverConstraint(btConstraintArray& ca, int solverBodyA,int solverBodyB, btScalar timeStep)
177  {
178  (void)ca;
179  (void)solverBodyA;
180  (void)solverBodyB;
181  (void)timeStep;
182  }
183 
185  virtual void getInfo1 (btConstraintInfo1* info)=0;
186 
188  virtual void getInfo2 (btConstraintInfo2* info)=0;
189 
191  void internalSetAppliedImpulse(btScalar appliedImpulse)
192  {
193  m_appliedImpulse = appliedImpulse;
194  }
197  {
198  return m_appliedImpulse;
199  }
200 
201 
203  {
204  return m_breakingImpulseThreshold;
205  }
206 
208  {
209  m_breakingImpulseThreshold = threshold;
210  }
211 
212  bool isEnabled() const
213  {
214  return m_isEnabled;
215  }
216 
217  void setEnabled(bool enabled)
218  {
219  m_isEnabled=enabled;
220  }
221 
222 
224  virtual void solveConstraintObsolete(btSolverBody& /*bodyA*/,btSolverBody& /*bodyB*/,btScalar /*timeStep*/) {};
225 
226 
227  const btRigidBody& getRigidBodyA() const
228  {
229  return m_rbA;
230  }
231  const btRigidBody& getRigidBodyB() const
232  {
233  return m_rbB;
234  }
235 
237  {
238  return m_rbA;
239  }
241  {
242  return m_rbB;
243  }
244 
246  {
247  return m_userConstraintType ;
248  }
249 
250  void setUserConstraintType(int userConstraintType)
251  {
252  m_userConstraintType = userConstraintType;
253  };
254 
255  void setUserConstraintId(int uid)
256  {
257  m_userConstraintId = uid;
258  }
259 
261  {
262  return m_userConstraintId;
263  }
264 
265  void setUserConstraintPtr(void* ptr)
266  {
267  m_userConstraintPtr = ptr;
268  }
269 
271  {
272  return m_userConstraintPtr;
273  }
274 
275  void setJointFeedback(btJointFeedback* jointFeedback)
276  {
277  m_jointFeedback = jointFeedback;
278  }
279 
281  {
282  return m_jointFeedback;
283  }
284 
286  {
287  return m_jointFeedback;
288  }
289 
290 
291  int getUid() const
292  {
293  return m_userConstraintId;
294  }
295 
296  bool needsFeedback() const
297  {
298  return m_needsFeedback;
299  }
300 
303  void enableFeedback(bool needsFeedback)
304  {
305  m_needsFeedback = needsFeedback;
306  }
307 
311  {
312  btAssert(m_needsFeedback);
313  return m_appliedImpulse;
314  }
315 
317  {
318  return btTypedConstraintType(m_objectType);
319  }
320 
321  void setDbgDrawSize(btScalar dbgDrawSize)
322  {
323  m_dbgDrawSize = dbgDrawSize;
324  }
326  {
327  return m_dbgDrawSize;
328  }
329 
332  virtual void setParam(int num, btScalar value, int axis = -1) = 0;
333 
335  virtual btScalar getParam(int num, int axis = -1) const = 0;
336 
337  virtual int calculateSerializeBufferSize() const;
338 
340  virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
341 
342 };
343 
344 // returns angle in range [-SIMD_2_PI, SIMD_2_PI], closest to one of the limits
345 // all arguments should be normalized angles (i.e. in range [-SIMD_PI, SIMD_PI])
346 SIMD_FORCE_INLINE btScalar btAdjustAngleToLimits(btScalar angleInRadians, btScalar angleLowerLimitInRadians, btScalar angleUpperLimitInRadians)
347 {
348  if(angleLowerLimitInRadians >= angleUpperLimitInRadians)
349  {
350  return angleInRadians;
351  }
352  else if(angleInRadians < angleLowerLimitInRadians)
353  {
354  btScalar diffLo = btFabs(btNormalizeAngle(angleLowerLimitInRadians - angleInRadians));
355  btScalar diffHi = btFabs(btNormalizeAngle(angleUpperLimitInRadians - angleInRadians));
356  return (diffLo < diffHi) ? angleInRadians : (angleInRadians + SIMD_2_PI);
357  }
358  else if(angleInRadians > angleUpperLimitInRadians)
359  {
360  btScalar diffHi = btFabs(btNormalizeAngle(angleInRadians - angleUpperLimitInRadians));
361  btScalar diffLo = btFabs(btNormalizeAngle(angleInRadians - angleLowerLimitInRadians));
362  return (diffLo < diffHi) ? (angleInRadians - SIMD_2_PI) : angleInRadians;
363  }
364  else
365  {
366  return angleInRadians;
367  }
368 }
369 
372 {
375  char *m_name;
376 
381 
384 
387 
390 
391 };
392 
394 
395 #define BT_BACKWARDS_COMPATIBLE_SERIALIZATION
396 #ifdef BT_BACKWARDS_COMPATIBLE_SERIALIZATION
399 {
402  char *m_name;
403 
408 
411 
414 
417 
418 };
419 #endif //BACKWARDS_COMPATIBLE
420 
422 {
425  char *m_name;
426 
431 
434 
437 
440  char padding[4];
441 
442 };
443 
444 
446 {
447  return sizeof(btTypedConstraintData2);
448 }
449 
450 
451 
453 {
454 private:
455  btScalar
456  m_center,
457  m_halfRange,
458  m_softness,
459  m_biasFactor,
460  m_relaxationFactor,
461  m_correction,
462  m_sign;
463 
464  bool
466 
467 public:
470  :m_center(0.0f),
471  m_halfRange(-1.0f),
472  m_softness(0.9f),
473  m_biasFactor(0.3f),
474  m_relaxationFactor(1.0f),
475  m_correction(0.0f),
476  m_sign(0.0f),
477  m_solveLimit(false)
478  {}
479 
483  void set(btScalar low, btScalar high, btScalar _softness = 0.9f, btScalar _biasFactor = 0.3f, btScalar _relaxationFactor = 1.0f);
484 
487  void test(const btScalar angle);
488 
490  inline btScalar getSoftness() const
491  {
492  return m_softness;
493  }
494 
496  inline btScalar getBiasFactor() const
497  {
498  return m_biasFactor;
499  }
500 
503  {
504  return m_relaxationFactor;
505  }
506 
508  inline btScalar getCorrection() const
509  {
510  return m_correction;
511  }
512 
514  inline btScalar getSign() const
515  {
516  return m_sign;
517  }
518 
520  inline btScalar getHalfRange() const
521  {
522  return m_halfRange;
523  }
524 
526  inline bool isLimit() const
527  {
528  return m_solveLimit;
529  }
530 
533  void fit(btScalar& angle) const;
534 
536  btScalar getError() const;
537 
538  btScalar getLow() const;
539 
540  btScalar getHigh() const;
541 
542 };
543 
544 
545 
546 #endif //BT_TYPED_CONSTRAINT_H
void enableFeedback(bool needsFeedback)
enableFeedback will allow to read the applied linear and angular impulse use getAppliedImpulse, getAppliedLinearImpulse and getAppliedAngularImpulse to read feedback information
btRigidBodyFloatData * m_rbB
btRigidBodyData * m_rbB
int getUserConstraintType() const
btTypedConstraintType getConstraintType() const
void setUserConstraintPtr(void *ptr)
void setJointFeedback(btJointFeedback *jointFeedback)
bool isLimit() const
Returns true when the last test() invocation recognized limit violation.
#define btAssert(x)
Definition: btScalar.h:113
btRigidBodyData * m_rbA
btScalar getBreakingImpulseThreshold() const
#define SIMD_FORCE_INLINE
Definition: btScalar.h:63
void setUserConstraintId(int uid)
#define btRigidBodyData
Definition: btRigidBody.h:36
btJointFeedback * m_jointFeedback
int getUserConstraintId() const
btVector3 m_appliedForceBodyB
const btJointFeedback * getJointFeedback() const
void setBreakingImpulseThreshold(btScalar threshold)
btScalar m_breakingImpulseThreshold
void setDbgDrawSize(btScalar dbgDrawSize)
btTypedConstraint & operator=(btTypedConstraint &other)
btScalar getHalfRange() const
Gives half of the distance between min and max limit angle.
#define SIMD_2_PI
Definition: btScalar.h:477
bool needsFeedback() const
btVector3 m_appliedForceBodyA
btScalar getSign() const
Returns sign value evaluated when test() was invoked.
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
Definition: btRigidBody.h:587
btScalar getSoftness() const
Returns limit&#39;s softness.
void setOverrideNumSolverIterations(int overideNumIterations)
override the number of constraint solver iterations used to solve this constraint -1 will use the def...
btScalar getBiasFactor() const
Returns limit&#39;s bias factor.
virtual ~btTypedConstraint()
#define btTypedConstraintData2
The btRigidBody is the main class for rigid body objects.
Definition: btRigidBody.h:62
btTypedConstraintType
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
Definition: btRigidBody.h:561
this structure is not used, except for loading pre-2.82 .bullet files
bool isEnabled() const
btScalar btAdjustAngleToLimits(btScalar angleInRadians, btScalar angleLowerLimitInRadians, btScalar angleUpperLimitInRadians)
btRigidBodyDoubleData * m_rbA
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:64
void setUserConstraintType(int userConstraintType)
btScalar btNormalizeAngle(btScalar angleInRadians)
Definition: btScalar.h:724
virtual void solveConstraintObsolete(btSolverBody &, btSolverBody &, btScalar)
internal method used by the constraint solver, don&#39;t use them directly
rudimentary class to provide type info
Definition: btScalar.h:744
btVector3 m_appliedTorqueBodyB
The btSolverBody is an internal datastructure for the constraint solver. Only necessary data is packe...
Definition: btSolverBody.h:108
btScalar getRelaxationFactor() const
Returns limit&#39;s relaxation factor.
virtual void setupSolverConstraint(btConstraintArray &ca, int solverBodyA, int solverBodyB, btScalar timeStep)
internal method used by the constraint solver, don&#39;t use them directly
TypedConstraint is the baseclass for Bullet constraints and vehicles.
btScalar internalGetAppliedImpulse()
internal method used by the constraint solver, don&#39;t use them directly
const btRigidBody & getRigidBodyA() const
void setEnabled(bool enabled)
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:388
virtual int calculateSerializeBufferSize() const
btRigidBody & getRigidBodyB()
btVector3 m_appliedTorqueBodyA
btScalar getCorrection() const
Returns correction value evaluated when test() was invoked.
btRigidBodyFloatData * m_rbA
btAngularLimit()
Default constructor initializes limit as inactive, allowing free constraint movement.
btScalar getAppliedImpulse() const
getAppliedImpulse is an estimated total applied impulse.
btConstraintParams
void internalSetAppliedImpulse(btScalar appliedImpulse)
internal method used by the constraint solver, don&#39;t use them directly
btRigidBody & getRigidBodyA()
const btRigidBody & getRigidBodyB() const
int getOverrideNumSolverIterations() const
virtual void buildJacobian()
internal method used by the constraint solver, don&#39;t use them directly
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:278
btRigidBodyDoubleData * m_rbB
btJointFeedback * getJointFeedback()
btScalar btFabs(btScalar x)
Definition: btScalar.h:449