Blender  V3.3
btCollisionObject.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 #ifndef BT_COLLISION_OBJECT_H
17 #define BT_COLLISION_OBJECT_H
18 
19 #include "LinearMath/btTransform.h"
20 
21 //island management, m_activationState1
22 #define ACTIVE_TAG 1
23 #define ISLAND_SLEEPING 2
24 #define WANTS_DEACTIVATION 3
25 #define DISABLE_DEACTIVATION 4
26 #define DISABLE_SIMULATION 5
27 
28 struct btBroadphaseProxy;
29 class btCollisionShape;
34 
36 
37 #ifdef BT_USE_DOUBLE_PRECISION
38 #define btCollisionObjectData btCollisionObjectDoubleData
39 #define btCollisionObjectDataName "btCollisionObjectDoubleData"
40 #else
41 #define btCollisionObjectData btCollisionObjectFloatData
42 #define btCollisionObjectDataName "btCollisionObjectFloatData"
43 #endif
44 
50 {
51 protected:
53 
57  //those two are experimental: just added for bullet time effect, so you can still apply impulses (directly modifying velocities)
58  //without destroying the continuous interpolated motion (which uses this interpolation velocities)
61 
65 
70 
75 
77 
80  int m_worldArrayIndex; // index of object in world's collisionObjects array
81 
82  mutable int m_activationState1;
84 
87  btScalar m_rollingFriction; //torsional friction orthogonal to contact normal (useful to stop spheres rolling forever)
88  btScalar m_spinningFriction; // torsional friction around the contact normal (useful for grasping)
91 
95 
97 
99 
101 
103 
105 
108 
111 
114 
117 
119 
122 
124 
125 public:
127 
129  {
133  CF_CUSTOM_MATERIAL_CALLBACK = 8, //this allows per-triangle material (friction/restitution)
135  CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
136  CF_DISABLE_SPU_COLLISION_PROCESSING = 64, //disable parallel/SPU processing
141  };
142 
144  {
154  };
155 
157  {
161  };
162 
164  {
167  }
168 
170  {
171  return m_anisotropicFriction;
172  }
173  void setAnisotropicFriction(const btVector3& anisotropicFriction, int frictionMode = CF_ANISOTROPIC_FRICTION)
174  {
175  m_anisotropicFriction = anisotropicFriction;
176  bool isUnity = (anisotropicFriction[0] != 1.f) || (anisotropicFriction[1] != 1.f) || (anisotropicFriction[2] != 1.f);
177  m_hasAnisotropicFriction = isUnity ? frictionMode : 0;
178  }
179  bool hasAnisotropicFriction(int frictionMode = CF_ANISOTROPIC_FRICTION) const
180  {
181  return (m_hasAnisotropicFriction & frictionMode) != 0;
182  }
183 
186  void setContactProcessingThreshold(btScalar contactProcessingThreshold)
187  {
188  m_contactProcessingThreshold = contactProcessingThreshold;
189  }
191  {
193  }
194 
196  {
197  return (m_collisionFlags & CF_STATIC_OBJECT) != 0;
198  }
199 
201  {
202  return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
203  }
204 
206  {
208  }
209 
211  {
213  }
214 
216 
217  virtual ~btCollisionObject();
218 
219  virtual void setCollisionShape(btCollisionShape * collisionShape)
220  {
222  m_collisionShape = collisionShape;
223  m_rootCollisionShape = collisionShape;
224  }
225 
227  {
228  return m_collisionShape;
229  }
230 
232  {
233  return m_collisionShape;
234  }
235 
236  void setIgnoreCollisionCheck(const btCollisionObject* co, bool ignoreCollisionCheck)
237  {
238  if (ignoreCollisionCheck)
239  {
240  //We don't check for duplicates. Is it ok to leave that up to the user of this API?
241  //int index = m_objectsWithoutCollisionCheck.findLinearSearch(co);
242  //if (index == m_objectsWithoutCollisionCheck.size())
243  //{
245  //}
246  }
247  else
248  {
250  }
252  }
253 
255  {
257  }
258 
260  {
261  return m_objectsWithoutCollisionCheck[index];
262  }
263 
264  virtual bool checkCollideWithOverride(const btCollisionObject* co) const
265  {
267  if (index < m_objectsWithoutCollisionCheck.size())
268  {
269  return false;
270  }
271  return true;
272  }
273 
277  {
278  return m_extensionPointer;
279  }
282  void internalSetExtensionPointer(void* pointer)
283  {
284  m_extensionPointer = pointer;
285  }
286 
288 
289  void setActivationState(int newState) const;
290 
292  {
294  }
296  {
297  return m_deactivationTime;
298  }
299 
300  void forceActivationState(int newState) const;
301 
302  void activate(bool forceActivation = false) const;
303 
305  {
307  }
308 
310  {
312  m_restitution = rest;
313  }
315  {
316  return m_restitution;
317  }
318  void setFriction(btScalar frict)
319  {
321  m_friction = frict;
322  }
324  {
325  return m_friction;
326  }
327 
329  {
331  m_rollingFriction = frict;
332  }
334  {
335  return m_rollingFriction;
336  }
338  {
340  m_spinningFriction = frict;
341  }
343  {
344  return m_spinningFriction;
345  }
347  {
349  m_contactStiffness = stiffness;
350  m_contactDamping = damping;
351 
353 
354  //avoid divisions by zero...
356  {
358  }
359  }
360 
362  {
363  return m_contactStiffness;
364  }
365 
367  {
368  return m_contactDamping;
369  }
370 
372  int getInternalType() const
373  {
374  return m_internalType;
375  }
376 
378  {
379  return m_worldTransform;
380  }
381 
382  const btTransform& getWorldTransform() const
383  {
384  return m_worldTransform;
385  }
386 
387  void setWorldTransform(const btTransform& worldTrans)
388  {
390  m_worldTransform = worldTrans;
391  }
392 
394  {
395  return m_broadphaseHandle;
396  }
397 
399  {
400  return m_broadphaseHandle;
401  }
402 
404  {
405  m_broadphaseHandle = handle;
406  }
407 
409  {
411  }
412 
414  {
416  }
417 
419  {
422  }
423 
425  {
428  }
429 
431  {
434  }
435 
437  {
439  }
440 
442  {
444  }
445 
447  {
448  return m_islandTag1;
449  }
450 
451  void setIslandTag(int tag)
452  {
453  m_islandTag1 = tag;
454  }
455 
457  {
458  return m_companionId;
459  }
460 
461  void setCompanionId(int id)
462  {
463  m_companionId = id;
464  }
465 
467  {
468  return m_worldArrayIndex;
469  }
470 
471  // only should be called by CollisionWorld
472  void setWorldArrayIndex(int ix)
473  {
474  m_worldArrayIndex = ix;
475  }
476 
478  {
479  return m_hitFraction;
480  }
481 
482  void setHitFraction(btScalar hitFraction)
483  {
484  m_hitFraction = hitFraction;
485  }
486 
488  {
489  return m_collisionFlags;
490  }
491 
492  void setCollisionFlags(int flags)
493  {
494  m_collisionFlags = flags;
495  }
496 
499  {
500  return m_ccdSweptSphereRadius;
501  }
502 
505  {
506  m_ccdSweptSphereRadius = radius;
507  }
508 
510  {
511  return m_ccdMotionThreshold;
512  }
513 
515  {
517  }
518 
520  void setCcdMotionThreshold(btScalar ccdMotionThreshold)
521  {
522  m_ccdMotionThreshold = ccdMotionThreshold;
523  }
524 
526  void* getUserPointer() const
527  {
528  return m_userObjectPointer;
529  }
530 
531  int getUserIndex() const
532  {
533  return m_userIndex;
534  }
535 
536  int getUserIndex2() const
537  {
538  return m_userIndex2;
539  }
540 
541  int getUserIndex3() const
542  {
543  return m_userIndex3;
544  }
545 
547  void setUserPointer(void* userPointer)
548  {
549  m_userObjectPointer = userPointer;
550  }
551 
553  void setUserIndex(int index)
554  {
555  m_userIndex = index;
556  }
557 
558  void setUserIndex2(int index)
559  {
560  m_userIndex2 = index;
561  }
562 
563  void setUserIndex3(int index)
564  {
565  m_userIndex3 = index;
566  }
567 
569  {
570  return m_updateRevision;
571  }
572 
573  void setCustomDebugColor(const btVector3& colorRGB)
574  {
575  m_customDebugColorRGB = colorRGB;
577  }
578 
580  {
582  }
583 
584  bool getCustomDebugColor(btVector3 & colorRGB) const
585  {
586  bool hasCustomColor = (0 != (m_collisionFlags & CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR));
587  if (hasCustomColor)
588  {
589  colorRGB = m_customDebugColorRGB;
590  }
591  return hasCustomColor;
592  }
593 
594  inline bool checkCollideWith(const btCollisionObject* co) const
595  {
596  if (m_checkCollideWith)
597  return checkCollideWithOverride(co);
598 
599  return true;
600  }
601 
602  virtual int calculateSerializeBufferSize() const;
603 
605  virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
606 
607  virtual void serializeSingleObject(class btSerializer * serializer) const;
608 };
609 
610 // clang-format off
611 
614 {
618  char *m_name;
619 
627  double m_friction;
632  double m_hitFraction;
644  int m_uniqueId;//m_uniqueId is introduced for paircache. could get rid of this, by calculating the address offset etc.
645 };
646 
649 {
653  char *m_name;
654 
662  float m_friction;
680 };
681 // clang-format on
682 
684 {
685  return sizeof(btCollisionObjectData);
686 }
687 
688 #endif //BT_COLLISION_OBJECT_H
btBroadphaseProxy
void internalSetExtensionPointer(void *pointer)
void removeCustomDebugColor()
btScalar m_contactStiffness
btVector3 m_interpolationAngularVelocity
BT_DECLARE_ALIGNED_ALLOCATOR()
void setUserPointer(void *userPointer)
users can point to their objects, userPointer is not used by Bullet
btScalar getDeactivationTime() const
int m_islandTag1
btScalar getFriction() const
const btVector3 & getInterpolationAngularVelocity() const
void setWorldArrayIndex(int ix)
SIMD_FORCE_INLINE int getWorldArrayIndex() const
SIMD_FORCE_INLINE int getCompanionId() const
SIMD_FORCE_INLINE bool isStaticOrKinematicObject() const
btCollisionObject
btVector3 m_anisotropicFriction
SIMD_FORCE_INLINE btBroadphaseProxy * getBroadphaseHandle()
virtual const char * serialize(void *dataBuffer, class btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
#define btCollisionObjectData
void setWorldTransform(const btTransform &worldTrans)
btScalar getContactStiffness() const
virtual int calculateSerializeBufferSize() const
void * m_extensionPointer
m_extensionPointer is used by some internal low-level Bullet extensions.
int m_hasAnisotropicFriction
void activate(bool forceActivation=false) const
SIMD_FORCE_INLINE int getCollisionFlags() const
btScalar m_ccdMotionThreshold
Don't do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold...
void setCcdSweptSphereRadius(btScalar radius)
Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
void setRestitution(btScalar rest)
void setHitFraction(btScalar hitFraction)
void setUserIndex3(int index)
void setCcdMotionThreshold(btScalar ccdMotionThreshold)
Don't do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold...
void setIslandTag(int tag)
btScalar m_deactivationTime
void setAnisotropicFriction(const btVector3 &anisotropicFriction, int frictionMode=CF_ANISOTROPIC_FRICTION)
CollisionFlags
@ CF_HAS_COLLISION_SOUND_TRIGGER
@ CF_CHARACTER_OBJECT
@ CF_HAS_CONTACT_STIFFNESS_DAMPING
@ CF_HAS_FRICTION_ANCHOR
@ CF_DISABLE_VISUALIZE_OBJECT
@ CF_KINEMATIC_OBJECT
@ CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR
@ CF_STATIC_OBJECT
@ CF_DISABLE_SPU_COLLISION_PROCESSING
@ CF_NO_CONTACT_RESPONSE
@ CF_CUSTOM_MATERIAL_CALLBACK
btTransform m_interpolationWorldTransform
void setActivationState(int newState) const
const btVector3 & getAnisotropicFriction() const
void setDeactivationTime(btScalar time)
btScalar m_contactProcessingThreshold
void * m_userObjectPointer
users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPoin...
void setContactProcessingThreshold(btScalar contactProcessingThreshold)
btScalar m_restitution
int m_checkCollideWith
If some object should have elaborate collision filtering by sub-classes.
CollisionObjectTypes
@ CO_GHOST_OBJECT
@ CO_HF_FLUID
@ CO_USER_TYPE
@ CO_FEATHERSTONE_LINK
@ CO_RIGID_BODY
@ CO_SOFT_BODY
@ CO_COLLISION_OBJECT
const btCollisionObject * getObjectWithoutCollision(int index)
virtual bool checkCollideWithOverride(const btCollisionObject *co) const
void setInterpolationLinearVelocity(const btVector3 &linvel)
int getUserIndex3() const
btScalar m_hitFraction
time of impact calculation
btScalar m_rollingFriction
btVector3 m_customDebugColorRGB
void setCustomDebugColor(const btVector3 &colorRGB)
int m_userIndex
int m_companionId
btAlignedObjectArray< class btCollisionObject * > btCollisionObjectArray
void setInterpolationAngularVelocity(const btVector3 &angvel)
void setContactStiffnessAndDamping(btScalar stiffness, btScalar damping)
btScalar m_friction
int getUserIndex() const
int getNumObjectsWithoutCollision() const
void setUserIndex(int index)
users can point to their objects, userPointer is not used by Bullet
btScalar m_spinningFriction
void setRollingFriction(btScalar frict)
SIMD_FORCE_INLINE int getActivationState() const
int m_userIndex3
bool checkCollideWith(const btCollisionObject *co) const
void forceActivationState(int newState) const
int getInternalType() const
reserved for Bullet internal usage
bool getCustomDebugColor(btVector3 &colorRGB) const
virtual ~btCollisionObject()
void * getUserPointer() const
users can point to their objects, userPointer is not used by Bullet
btCollisionShape * m_rootCollisionShape
void setUserIndex2(int index)
void setFriction(btScalar frict)
int m_worldArrayIndex
int m_collisionFlags
void setCompanionId(int id)
SIMD_FORCE_INLINE bool isKinematicObject() const
AnisotropicFrictionFlags
@ CF_ANISOTROPIC_FRICTION
@ CF_ANISOTROPIC_ROLLING_FRICTION
@ CF_ANISOTROPIC_FRICTION_DISABLED
virtual void setCollisionShape(btCollisionShape *collisionShape)
bool hasAnisotropicFriction(int frictionMode=CF_ANISOTROPIC_FRICTION) const
void setCollisionFlags(int flags)
SIMD_FORCE_INLINE bool isActive() const
btScalar getContactDamping() const
btScalar getRollingFriction() const
SIMD_FORCE_INLINE bool mergesSimulationIslands() const
btScalar m_ccdSweptSphereRadius
Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
void * internalGetExtensionPointer() const
SIMD_FORCE_INLINE bool hasContactResponse() const
SIMD_FORCE_INLINE int getIslandTag() const
int getUpdateRevisionInternal() const
btVector3 m_interpolationLinearVelocity
SIMD_FORCE_INLINE btScalar getHitFraction() const
btScalar getCcdMotionThreshold() const
const btVector3 & getInterpolationLinearVelocity() const
const btTransform & getInterpolationWorldTransform() const
btScalar getSpinningFriction() const
btScalar getRestitution() const
btScalar getCcdSquareMotionThreshold() const
#define ISLAND_SLEEPING
SIMD_FORCE_INLINE const btCollisionShape * getCollisionShape() const
btTransform & getWorldTransform()
int m_userIndex2
void setInterpolationWorldTransform(const btTransform &trans)
#define DISABLE_SIMULATION
btScalar getContactProcessingThreshold() const
void setIgnoreCollisionCheck(const btCollisionObject *co, bool ignoreCollisionCheck)
void setSpinningFriction(btScalar frict)
btScalar getCcdSweptSphereRadius() const
Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
virtual void serializeSingleObject(class btSerializer *serializer) const
btScalar m_contactDamping
void setBroadphaseHandle(btBroadphaseProxy *handle)
int m_internalType
btAlignedObjectArray< const btCollisionObject * > m_objectsWithoutCollisionCheck
int m_updateRevision
internal update revision number. It will be increased when the object changes. This allows some subsy...
int m_activationState1
SIMD_FORCE_INLINE bool isStaticObject() const
int getUserIndex2() const
btCollisionShape * m_collisionShape
btBroadphaseProxy * m_broadphaseHandle
btCollisionShape
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
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
#define SIMD_FORCE_INLINE
Definition: btScalar.h:280
#define SIMD_EPSILON
Definition: btScalar.h:543
btTransform m_worldTransform
Definition: btSolverBody.h:107
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
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
int findLinearSearch(const T &key) const
SIMD_FORCE_INLINE int size() const
return the number of elements in the array
void remove(const T &key)
SIMD_FORCE_INLINE void push_back(const T &_Val)
double time
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btVector3DoubleData m_anisotropicFriction
btVector3DoubleData m_interpolationLinearVelocity
btTransformDoubleData m_interpolationWorldTransform
btTransformDoubleData m_worldTransform
btVector3DoubleData m_interpolationAngularVelocity
btCollisionShapeData * m_rootCollisionShape
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
btVector3FloatData m_interpolationLinearVelocity
btVector3FloatData m_anisotropicFriction
btTransformFloatData m_interpolationWorldTransform
btVector3FloatData m_interpolationAngularVelocity
btTransformFloatData m_worldTransform
btCollisionShapeData * m_rootCollisionShape
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
for serialization
Definition: btTransform.h:245