Blender  V3.3
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 #include "LinearMath/btScalar.h"
20 #include "btSolverConstraint.h"
22 
23 #ifdef BT_USE_DOUBLE_PRECISION
24 #define btTypedConstraintData2 btTypedConstraintDoubleData
25 #define btTypedConstraintDataName "btTypedConstraintDoubleData"
26 #else
27 #define btTypedConstraintData2 btTypedConstraintFloatData
28 #define btTypedConstraintDataName "btTypedConstraintFloatData"
29 #endif //BT_USE_DOUBLE_PRECISION
30 
31 class btSerializer;
32 
33 //Don't change any of the existing enum values, so add enum types at the end for serialization compatibility
35 {
47 };
48 
50 {
55 };
56 
57 #if 1
58 #define btAssertConstrParams(_par) btAssert(_par)
59 #else
60 #define btAssertConstrParams(_par)
61 #endif
62 
63 ATTRIBUTE_ALIGNED16(struct)
65 {
71 };
72 
76 {
77  int m_userConstraintType;
78 
79  union {
82  };
83 
88 
90  {
91  btAssert(0);
92  (void)other;
93  return *this;
94  }
95 
96 protected:
102 
104  btScalar getMotorFactor(btScalar pos, btScalar lowLim, btScalar uppLim, btScalar vel, btScalar timeFact);
105 
106 public:
108 
109  virtual ~btTypedConstraint(){};
112 
114  {
116  };
117 
119 
121  {
122  // integrator parameters: frames per second (1/stepsize), default error
123  // reduction parameter (0..1).
125 
126  // for the first and second body, pointers to two (linear and angular)
127  // n*3 jacobian sub matrices, stored by rows. these matrices will have
128  // been initialized to 0 on entry. if the second body is zero then the
129  // J2xx pointers may be 0.
131 
132  // elements to jump from one row to the next in J's
133  int rowskip;
134 
135  // right hand sides of the equation J*v = c + cfm * lambda. cfm is the
136  // "constraint force mixing" vector. c is set to zero on entry, cfm is
137  // set to a constant value (typically very small or zero) value on entry.
139 
140  // lo and hi limits for variables (set to -/+ infinity on entry).
142 
143  // number of solver iterations
145 
146  //damping of the velocity
148  };
149 
151  {
153  }
154 
157  void setOverrideNumSolverIterations(int overideNumIterations)
158  {
159  m_overrideNumSolverIterations = overideNumIterations;
160  }
161 
163  virtual void buildJacobian(){};
164 
166  virtual void setupSolverConstraint(btConstraintArray & ca, int solverBodyA, int solverBodyB, btScalar timeStep)
167  {
168  (void)ca;
169  (void)solverBodyA;
170  (void)solverBodyB;
171  (void)timeStep;
172  }
173 
175  virtual void getInfo1(btConstraintInfo1 * info) = 0;
176 
178  virtual void getInfo2(btConstraintInfo2 * info) = 0;
179 
181  void internalSetAppliedImpulse(btScalar appliedImpulse)
182  {
183  m_appliedImpulse = appliedImpulse;
184  }
187  {
188  return m_appliedImpulse;
189  }
190 
192  {
194  }
195 
197  {
199  }
200 
201  bool isEnabled() const
202  {
203  return m_isEnabled;
204  }
205 
206  void setEnabled(bool enabled)
207  {
209  }
210 
212  virtual void solveConstraintObsolete(btSolverBody& /*bodyA*/, btSolverBody& /*bodyB*/, btScalar /*timeStep*/){};
213 
214  const btRigidBody& getRigidBodyA() const
215  {
216  return m_rbA;
217  }
218  const btRigidBody& getRigidBodyB() const
219  {
220  return m_rbB;
221  }
222 
224  {
225  return m_rbA;
226  }
228  {
229  return m_rbB;
230  }
231 
233  {
234  return m_userConstraintType;
235  }
236 
237  void setUserConstraintType(int userConstraintType)
238  {
239  m_userConstraintType = userConstraintType;
240  };
241 
242  void setUserConstraintId(int uid)
243  {
244  m_userConstraintId = uid;
245  }
246 
248  {
249  return m_userConstraintId;
250  }
251 
253  {
255  }
256 
258  {
259  return m_userConstraintPtr;
260  }
261 
262  void setJointFeedback(btJointFeedback * jointFeedback)
263  {
264  m_jointFeedback = jointFeedback;
265  }
266 
268  {
269  return m_jointFeedback;
270  }
271 
273  {
274  return m_jointFeedback;
275  }
276 
277  int getUid() const
278  {
279  return m_userConstraintId;
280  }
281 
282  bool needsFeedback() const
283  {
284  return m_needsFeedback;
285  }
286 
290  {
292  }
293 
297  {
299  return m_appliedImpulse;
300  }
301 
303  {
304  return btTypedConstraintType(m_objectType);
305  }
306 
307  void setDbgDrawSize(btScalar dbgDrawSize)
308  {
309  m_dbgDrawSize = dbgDrawSize;
310  }
312  {
313  return m_dbgDrawSize;
314  }
315 
318  virtual void setParam(int num, btScalar value, int axis = -1) = 0;
319 
321  virtual btScalar getParam(int num, int axis = -1) const = 0;
322 
323  virtual int calculateSerializeBufferSize() const;
324 
326  virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
327 };
328 
329 // returns angle in range [-SIMD_2_PI, SIMD_2_PI], closest to one of the limits
330 // all arguments should be normalized angles (i.e. in range [-SIMD_PI, SIMD_PI])
331 SIMD_FORCE_INLINE btScalar btAdjustAngleToLimits(btScalar angleInRadians, btScalar angleLowerLimitInRadians, btScalar angleUpperLimitInRadians)
332 {
333  if (angleLowerLimitInRadians >= angleUpperLimitInRadians)
334  {
335  return angleInRadians;
336  }
337  else if (angleInRadians < angleLowerLimitInRadians)
338  {
339  btScalar diffLo = btFabs(btNormalizeAngle(angleLowerLimitInRadians - angleInRadians));
340  btScalar diffHi = btFabs(btNormalizeAngle(angleUpperLimitInRadians - angleInRadians));
341  return (diffLo < diffHi) ? angleInRadians : (angleInRadians + SIMD_2_PI);
342  }
343  else if (angleInRadians > angleUpperLimitInRadians)
344  {
345  btScalar diffHi = btFabs(btNormalizeAngle(angleInRadians - angleUpperLimitInRadians));
346  btScalar diffLo = btFabs(btNormalizeAngle(angleInRadians - angleLowerLimitInRadians));
347  return (diffLo < diffHi) ? (angleInRadians - SIMD_2_PI) : angleInRadians;
348  }
349  else
350  {
351  return angleInRadians;
352  }
353 }
354 
355 // clang-format off
356 
359 {
362  char *m_name;
363 
368 
371 
374 
377 
378 };
379 
380 
381 
383 
384 #define BT_BACKWARDS_COMPATIBLE_SERIALIZATION
385 #ifdef BT_BACKWARDS_COMPATIBLE_SERIALIZATION
388 {
391  char *m_name;
392 
397 
400 
403 
406 
407 };
408 #endif //BACKWARDS_COMPATIBLE
409 
411 {
414  char *m_name;
415 
420 
423 
426 
429  char padding[4];
430 
431 };
432 
433 // clang-format on
434 
436 {
437  return sizeof(btTypedConstraintData2);
438 }
439 
441 {
442 private:
443  btScalar
444  m_center,
445  m_halfRange,
446  m_softness,
447  m_biasFactor,
448  m_relaxationFactor,
449  m_correction,
450  m_sign;
451 
452  bool
453  m_solveLimit;
454 
455 public:
458  : m_center(0.0f),
459  m_halfRange(-1.0f),
460  m_softness(0.9f),
461  m_biasFactor(0.3f),
462  m_relaxationFactor(1.0f),
463  m_correction(0.0f),
464  m_sign(0.0f),
465  m_solveLimit(false)
466  {
467  }
468 
472  void set(btScalar low, btScalar high, btScalar _softness = 0.9f, btScalar _biasFactor = 0.3f, btScalar _relaxationFactor = 1.0f);
473 
476  void test(const btScalar angle);
477 
479  inline btScalar getSoftness() const
480  {
481  return m_softness;
482  }
483 
485  inline btScalar getBiasFactor() const
486  {
487  return m_biasFactor;
488  }
489 
492  {
493  return m_relaxationFactor;
494  }
495 
497  inline btScalar getCorrection() const
498  {
499  return m_correction;
500  }
501 
503  inline btScalar getSign() const
504  {
505  return m_sign;
506  }
507 
509  inline btScalar getHalfRange() const
510  {
511  return m_halfRange;
512  }
513 
515  inline bool isLimit() const
516  {
517  return m_solveLimit;
518  }
519 
522  void fit(btScalar& angle) const;
523 
525  btScalar getError() const;
526 
527  btScalar getLow() const;
528 
529  btScalar getHigh() const;
530 };
531 
532 #endif //BT_TYPED_CONSTRAINT_H
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
__forceinline ssef low(const avxf &a)
Definition: avxf.h:264
__forceinline ssef high(const avxf &a)
Definition: avxf.h:268
btScalar m_biasFactor
btScalar m_relaxationFactor
btFixedConstraint btRigidBody & rbB
#define btRigidBodyData
Definition: btRigidBody.h:35
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:285
SIMD_FORCE_INLINE btScalar btNormalizeAngle(btScalar angleInRadians)
Definition: btScalar.h:781
SIMD_FORCE_INLINE btScalar btFabs(btScalar x)
Definition: btScalar.h:497
#define SIMD_FORCE_INLINE
Definition: btScalar.h:280
#define SIMD_2_PI
Definition: btScalar.h:527
#define btAssert(x)
Definition: btScalar.h:295
btSolverBody
The btSolverBody is an internal datastructure for the constraint solver. Only necessary data is packe...
Definition: btSolverBody.h:105
btVector3 m_appliedTorqueBodyA
btScalar m_breakingImpulseThreshold
BT_DECLARE_ALIGNED_ALLOCATOR()
bool needsFeedback() const
int m_userConstraintId
void setBreakingImpulseThreshold(btScalar threshold)
int getUid() const
btScalar m_dbgDrawSize
int getOverrideNumSolverIterations() const
btVector3 m_appliedForceBodyA
virtual int calculateSerializeBufferSize() const
void setEnabled(bool enabled)
#define btTypedConstraintData2
btScalar getMotorFactor(btScalar pos, btScalar lowLim, btScalar uppLim, btScalar vel, btScalar timeFact)
internal method used by the constraint solver, don't use them directly
void enableFeedback(bool needsFeedback)
bool m_isEnabled
virtual void setupSolverConstraint(btConstraintArray &ca, int solverBodyA, int solverBodyB, btScalar timeStep)
internal method used by the constraint solver, don't use them directly
void setJointFeedback(btJointFeedback *jointFeedback)
void * m_userConstraintPtr
const btRigidBody & getRigidBodyA() const
void setUserConstraintType(int userConstraintType)
const btJointFeedback * getJointFeedback() const
const btRigidBody & getRigidBodyB() const
btRigidBody & m_rbA
bool m_needsFeedback
void setUserConstraintPtr(void *ptr)
int m_overrideNumSolverIterations
btScalar getDbgDrawSize()
btScalar m_appliedImpulse
virtual void setParam(int num, btScalar value, int axis=-1)=0
btScalar getAppliedImpulse() const
virtual btScalar getParam(int num, int axis=-1) const =0
return the local value of parameter
SIMD_FORCE_INLINE btScalar btAdjustAngleToLimits(btScalar angleInRadians, btScalar angleLowerLimitInRadians, btScalar angleUpperLimitInRadians)
void internalSetAppliedImpulse(btScalar appliedImpulse)
internal method used by the constraint solver, don't use them directly
btTypedConstraint & operator=(btTypedConstraint &other)
btScalar getBreakingImpulseThreshold() const
btVector3 m_appliedTorqueBodyB
virtual void buildJacobian()
internal method used by the constraint solver, don't use them directly
bool isEnabled() const
btJointFeedback
int getUserConstraintType() const
virtual void getInfo1(btConstraintInfo1 *info)=0
internal method used by the constraint solver, don't use them directly
void * getUserConstraintPtr()
btVector3 m_appliedForceBodyB
btTypedConstraintType getConstraintType() const
btTypedConstraint(btTypedConstraintType type, btRigidBody &rbA)
int getUserConstraintId() const
void setUserConstraintId(int uid)
void setDbgDrawSize(btScalar dbgDrawSize)
btRigidBody & m_rbB
virtual void getInfo2(btConstraintInfo2 *info)=0
internal method used by the constraint solver, don't use them directly
static btRigidBody & getFixedBody()
btConstraintParams
@ BT_CONSTRAINT_CFM
@ BT_CONSTRAINT_ERP
@ BT_CONSTRAINT_STOP_CFM
@ BT_CONSTRAINT_STOP_ERP
virtual ~btTypedConstraint()
btJointFeedback * m_jointFeedback
void setOverrideNumSolverIterations(int overideNumIterations)
virtual void solveConstraintObsolete(btSolverBody &, btSolverBody &, btScalar)
internal method used by the constraint solver, don't use them directly
btTypedConstraintType
@ MAX_CONSTRAINT_TYPE
@ SLIDER_CONSTRAINT_TYPE
@ GEAR_CONSTRAINT_TYPE
@ CONETWIST_CONSTRAINT_TYPE
@ FIXED_CONSTRAINT_TYPE
@ POINT2POINT_CONSTRAINT_TYPE
@ D6_SPRING_2_CONSTRAINT_TYPE
@ HINGE_CONSTRAINT_TYPE
@ CONTACT_CONSTRAINT_TYPE
@ D6_SPRING_CONSTRAINT_TYPE
@ D6_CONSTRAINT_TYPE
virtual const char * serialize(void *dataBuffer, btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
btScalar internalGetAppliedImpulse()
internal method used by the constraint solver, don't use them directly
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
Definition: btVector3.h:82
bool isLimit() const
Returns true when the last test() invocation recognized limit violation.
btScalar getBiasFactor() const
Returns limit's bias factor.
btScalar getLow() const
btScalar getHigh() const
btScalar getSoftness() const
Returns limit's softness.
btScalar getCorrection() const
Returns correction value evaluated when test() was invoked.
btScalar getError() const
Returns correction value multiplied by sign value.
btScalar getSign() const
Returns sign value evaluated when test() was invoked.
void test(const btScalar angle)
void set(btScalar low, btScalar high, btScalar _softness=0.9f, btScalar _biasFactor=0.3f, btScalar _relaxationFactor=1.0f)
void fit(btScalar &angle) const
btAngularLimit()
Default constructor initializes limit as inactive, allowing free constraint movement.
btScalar getHalfRange() const
Gives half of the distance between min and max limit angle.
btScalar getRelaxationFactor() const
Returns limit's relaxation factor.
SyclQueue void void size_t num_bytes void
uint pos
bool enabled
ccl_gpu_kernel_postfix ccl_global float int int int int float threshold
btScalar * m_J2angularAxis
btScalar * m_J1angularAxis
btScalar * m_constraintError
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
Definition: btRigidBody.h:662
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
Definition: btRigidBody.h:636
this structure is not used, except for loading pre-2.82 .bullet files
btRigidBodyData * m_rbA
btRigidBodyData * m_rbB
btRigidBodyDoubleData * m_rbB
btRigidBodyDoubleData * m_rbA
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btRigidBodyFloatData * m_rbB
btRigidBodyFloatData * m_rbA
rudimentary class to provide type info
Definition: btScalar.h:800
PointerRNA * ptr
Definition: wm_files.c:3480