Bullet Collision Detection & Physics Library
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 
45 
50 {
51 
52 protected:
53 
55 
59  //those two are experimental: just added for bullet time effect, so you can still apply impulses (directly modifying velocities)
60  //without destroying the continuous interpolated motion (which uses this interpolation velocities)
63 
67 
72 
77 
79 
82  int m_worldArrayIndex; // index of object in world's collisionObjects array
83 
84  mutable int m_activationState1;
86 
89  btScalar m_rollingFriction;//torsional friction orthogonal to contact normal (useful to stop spheres rolling forever)
90  btScalar m_spinningFriction; // torsional friction around the contact normal (useful for grasping)
93 
94 
95 
99 
101 
103 
105 
107 
110 
113 
116 
119 
121 
124 
126 
127 public:
128 
130 
132  {
133  CF_STATIC_OBJECT= 1,
134  CF_KINEMATIC_OBJECT= 2,
135  CF_NO_CONTACT_RESPONSE = 4,
136  CF_CUSTOM_MATERIAL_CALLBACK = 8,//this allows per-triangle material (friction/restitution)
137  CF_CHARACTER_OBJECT = 16,
138  CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
139  CF_DISABLE_SPU_COLLISION_PROCESSING = 64,//disable parallel/SPU processing
140  CF_HAS_CONTACT_STIFFNESS_DAMPING = 128,
141  CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR = 256,
142  CF_HAS_FRICTION_ANCHOR = 512,
143  CF_HAS_COLLISION_SOUND_TRIGGER = 1024
144  };
145 
147  {
148  CO_COLLISION_OBJECT =1,
149  CO_RIGID_BODY=2,
152  CO_GHOST_OBJECT=4,
153  CO_SOFT_BODY=8,
154  CO_HF_FLUID=16,
155  CO_USER_TYPE=32,
156  CO_FEATHERSTONE_LINK=64
157  };
158 
160  {
161  CF_ANISOTROPIC_FRICTION_DISABLED=0,
162  CF_ANISOTROPIC_FRICTION = 1,
163  CF_ANISOTROPIC_ROLLING_FRICTION = 2
164  };
165 
167  {
169  return ((m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT | CF_NO_CONTACT_RESPONSE) )==0);
170  }
171 
173  {
174  return m_anisotropicFriction;
175  }
176  void setAnisotropicFriction(const btVector3& anisotropicFriction, int frictionMode = CF_ANISOTROPIC_FRICTION)
177  {
178  m_anisotropicFriction = anisotropicFriction;
179  bool isUnity = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
180  m_hasAnisotropicFriction = isUnity?frictionMode : 0;
181  }
182  bool hasAnisotropicFriction(int frictionMode = CF_ANISOTROPIC_FRICTION) const
183  {
184  return (m_hasAnisotropicFriction&frictionMode)!=0;
185  }
186 
189  void setContactProcessingThreshold( btScalar contactProcessingThreshold)
190  {
191  m_contactProcessingThreshold = contactProcessingThreshold;
192  }
194  {
195  return m_contactProcessingThreshold;
196  }
197 
199  return (m_collisionFlags & CF_STATIC_OBJECT) != 0;
200  }
201 
203  {
204  return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
205  }
206 
208  {
209  return (m_collisionFlags & (CF_KINEMATIC_OBJECT | CF_STATIC_OBJECT)) != 0 ;
210  }
211 
213  return (m_collisionFlags & CF_NO_CONTACT_RESPONSE)==0;
214  }
215 
216 
218 
219  virtual ~btCollisionObject();
220 
221  virtual void setCollisionShape(btCollisionShape* collisionShape)
222  {
223  m_updateRevision++;
224  m_collisionShape = collisionShape;
225  m_rootCollisionShape = collisionShape;
226  }
227 
229  {
230  return m_collisionShape;
231  }
232 
234  {
235  return m_collisionShape;
236  }
237 
238  void setIgnoreCollisionCheck(const btCollisionObject* co, bool ignoreCollisionCheck)
239  {
240  if (ignoreCollisionCheck)
241  {
242  //We don't check for duplicates. Is it ok to leave that up to the user of this API?
243  //int index = m_objectsWithoutCollisionCheck.findLinearSearch(co);
244  //if (index == m_objectsWithoutCollisionCheck.size())
245  //{
246  m_objectsWithoutCollisionCheck.push_back(co);
247  //}
248  }
249  else
250  {
251  m_objectsWithoutCollisionCheck.remove(co);
252  }
253  m_checkCollideWith = m_objectsWithoutCollisionCheck.size() > 0;
254  }
255 
256  virtual bool checkCollideWithOverride(const btCollisionObject* co) const
257  {
258  int index = m_objectsWithoutCollisionCheck.findLinearSearch(co);
259  if (index < m_objectsWithoutCollisionCheck.size())
260  {
261  return false;
262  }
263  return true;
264  }
265 
266 
267 
268 
272  {
273  return m_extensionPointer;
274  }
277  void internalSetExtensionPointer(void* pointer)
278  {
279  m_extensionPointer = pointer;
280  }
281 
282  SIMD_FORCE_INLINE int getActivationState() const { return m_activationState1;}
283 
284  void setActivationState(int newState) const;
285 
287  {
288  m_deactivationTime = time;
289  }
291  {
292  return m_deactivationTime;
293  }
294 
295  void forceActivationState(int newState) const;
296 
297  void activate(bool forceActivation = false) const;
298 
300  {
301  return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
302  }
303 
305  {
306  m_updateRevision++;
307  m_restitution = rest;
308  }
310  {
311  return m_restitution;
312  }
313  void setFriction(btScalar frict)
314  {
315  m_updateRevision++;
316  m_friction = frict;
317  }
319  {
320  return m_friction;
321  }
322 
324  {
325  m_updateRevision++;
326  m_rollingFriction = frict;
327  }
329  {
330  return m_rollingFriction;
331  }
333  {
334  m_updateRevision++;
335  m_spinningFriction = frict;
336  }
338  {
339  return m_spinningFriction;
340  }
342  {
343  m_updateRevision++;
344  m_contactStiffness = stiffness;
345  m_contactDamping = damping;
346 
347  m_collisionFlags |=CF_HAS_CONTACT_STIFFNESS_DAMPING;
348 
349  //avoid divisions by zero...
350  if (m_contactStiffness< SIMD_EPSILON)
351  {
352  m_contactStiffness = SIMD_EPSILON;
353  }
354  }
355 
357  {
358  return m_contactStiffness;
359  }
360 
362  {
363  return m_contactDamping;
364  }
365 
367  int getInternalType() const
368  {
369  return m_internalType;
370  }
371 
373  {
374  return m_worldTransform;
375  }
376 
378  {
379  return m_worldTransform;
380  }
381 
382  void setWorldTransform(const btTransform& worldTrans)
383  {
384  m_updateRevision++;
385  m_worldTransform = worldTrans;
386  }
387 
388 
390  {
391  return m_broadphaseHandle;
392  }
393 
395  {
396  return m_broadphaseHandle;
397  }
398 
400  {
401  m_broadphaseHandle = handle;
402  }
403 
404 
406  {
407  return m_interpolationWorldTransform;
408  }
409 
411  {
412  return m_interpolationWorldTransform;
413  }
414 
416  {
417  m_updateRevision++;
418  m_interpolationWorldTransform = trans;
419  }
420 
422  {
423  m_updateRevision++;
424  m_interpolationLinearVelocity = linvel;
425  }
426 
428  {
429  m_updateRevision++;
430  m_interpolationAngularVelocity = angvel;
431  }
432 
434  {
435  return m_interpolationLinearVelocity;
436  }
437 
439  {
440  return m_interpolationAngularVelocity;
441  }
442 
444  {
445  return m_islandTag1;
446  }
447 
448  void setIslandTag(int tag)
449  {
450  m_islandTag1 = tag;
451  }
452 
454  {
455  return m_companionId;
456  }
457 
458  void setCompanionId(int id)
459  {
460  m_companionId = id;
461  }
462 
464  {
465  return m_worldArrayIndex;
466  }
467 
468  // only should be called by CollisionWorld
469  void setWorldArrayIndex(int ix)
470  {
471  m_worldArrayIndex = ix;
472  }
473 
475  {
476  return m_hitFraction;
477  }
478 
479  void setHitFraction(btScalar hitFraction)
480  {
481  m_hitFraction = hitFraction;
482  }
483 
484 
486  {
487  return m_collisionFlags;
488  }
489 
490  void setCollisionFlags(int flags)
491  {
492  m_collisionFlags = flags;
493  }
494 
497  {
498  return m_ccdSweptSphereRadius;
499  }
500 
503  {
504  m_ccdSweptSphereRadius = radius;
505  }
506 
508  {
509  return m_ccdMotionThreshold;
510  }
511 
513  {
514  return m_ccdMotionThreshold*m_ccdMotionThreshold;
515  }
516 
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 
542  void setUserPointer(void* userPointer)
543  {
544  m_userObjectPointer = userPointer;
545  }
546 
548  void setUserIndex(int index)
549  {
550  m_userIndex = index;
551  }
552 
553  void setUserIndex2(int index)
554  {
555  m_userIndex2 = index;
556  }
557 
559  {
560  return m_updateRevision;
561  }
562 
563  void setCustomDebugColor(const btVector3& colorRGB)
564  {
565  m_customDebugColorRGB = colorRGB;
566  m_collisionFlags |= CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR;
567  }
568 
570  {
571  m_collisionFlags &= ~CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR;
572  }
573 
574  bool getCustomDebugColor(btVector3& colorRGB) const
575  {
576  bool hasCustomColor = (0!=(m_collisionFlags&CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR));
577  if (hasCustomColor)
578  {
579  colorRGB = m_customDebugColorRGB;
580  }
581  return hasCustomColor;
582  }
583 
584  inline bool checkCollideWith(const btCollisionObject* co) const
585  {
586  if (m_checkCollideWith)
587  return checkCollideWithOverride(co);
588 
589  return true;
590  }
591 
592  virtual int calculateSerializeBufferSize() const;
593 
595  virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
596 
597  virtual void serializeSingleObject(class btSerializer* serializer) const;
598 
599 };
600 
603 {
607  char *m_name;
608 
616  double m_friction;
621  double m_hitFraction;
633  int m_uniqueId;//m_uniqueId is introduced for paircache. could get rid of this, by calculating the address offset etc.
634 };
635 
638 {
642  char *m_name;
643 
651  float m_friction;
669 };
670 
671 
672 
674 {
675  return sizeof(btCollisionObjectData);
676 }
677 
678 
679 
680 #endif //BT_COLLISION_OBJECT_H
btTransformFloatData m_worldTransform
int getUpdateRevisionInternal() const
btScalar getDeactivationTime() const
void setUserIndex2(int index)
btScalar getCcdMotionThreshold() const
#define SIMD_EPSILON
Definition: btScalar.h:521
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
void setContactStiffnessAndDamping(btScalar stiffness, btScalar damping)
void push_back(const T &_Val)
btScalar getCcdSweptSphereRadius() const
Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
btVector3FloatData m_anisotropicFriction
btScalar m_ccdMotionThreshold
Don&#39;t do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold...
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
btTransform m_interpolationWorldTransform
m_interpolationWorldTransform is used for CCD and interpolation it can be either previous or future (...
btScalar m_ccdSweptSphereRadius
Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
int getInternalType() const
reserved for Bullet internal usage
const btVector3 & getInterpolationAngularVelocity() const
virtual int calculateSerializeBufferSize() const
btTransformFloatData m_interpolationWorldTransform
bool mergesSimulationIslands() const
void setCcdMotionThreshold(btScalar ccdMotionThreshold)
Don&#39;t do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold...
btAlignedObjectArray< const btCollisionObject * > m_objectsWithoutCollisionCheck
btScalar m_hitFraction
time of impact calculation
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
void setHitFraction(btScalar hitFraction)
void setWorldArrayIndex(int ix)
#define SIMD_FORCE_INLINE
Definition: btScalar.h:81
btScalar getContactProcessingThreshold() const
int getUserIndex() const
int getCollisionFlags() const
#define btCollisionObjectData
btTransform m_worldTransform
#define ISLAND_SLEEPING
void setCustomDebugColor(const btVector3 &colorRGB)
btVector3DoubleData m_anisotropicFriction
const btVector3 & getInterpolationLinearVelocity() const
btCollisionShape * m_collisionShape
btCollisionShapeData * m_rootCollisionShape
bool hasContactResponse() const
void setIgnoreCollisionCheck(const btCollisionObject *co, bool ignoreCollisionCheck)
void setRestitution(btScalar rest)
btScalar getSpinningFriction() const
const btVector3 & getAnisotropicFriction() const
btVector3DoubleData m_interpolationAngularVelocity
btCollisionShapeData * m_rootCollisionShape
btScalar getCcdSquareMotionThreshold() const
const btTransform & getInterpolationWorldTransform() const
btVector3 m_anisotropicFriction
virtual void setCollisionShape(btCollisionShape *collisionShape)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
int getWorldArrayIndex() const
btTransform & getWorldTransform()
int m_internalType
m_internalType is reserved to distinguish Bullet&#39;s btCollisionObject, btRigidBody, btSoftBody, btGhostObject etc.
int size() const
return the number of elements in the array
btBroadphaseProxy * getBroadphaseHandle()
void * getUserPointer() const
users can point to their objects, userPointer is not used by Bullet
void setFriction(btScalar frict)
bool isKinematicObject() const
bool isStaticObject() const
void setCcdSweptSphereRadius(btScalar radius)
Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
btCollisionShape * m_rootCollisionShape
m_rootCollisionShape is temporarily used to store the original collision shape The m_collisionShape m...
void setSpinningFriction(btScalar frict)
btVector3FloatData m_interpolationLinearVelocity
btAlignedObjectArray< class btCollisionObject * > btCollisionObjectArray
btTransform & getInterpolationWorldTransform()
bool isStaticOrKinematicObject() const
btScalar getContactDamping() const
bool checkCollideWith(const btCollisionObject *co) const
btCollisionObject can be used to manage collision detection objects.
void setUserPointer(void *userPointer)
users can point to their objects, userPointer is not used by Bullet
#define DISABLE_SIMULATION
void setUserIndex(int index)
users can point to their objects, userPointer is not used by Bullet
void * m_extensionPointer
m_extensionPointer is used by some internal low-level Bullet extensions.
btVector3 m_customDebugColorRGB
btScalar m_contactProcessingThreshold
btScalar getRestitution() const
void setDeactivationTime(btScalar time)
void setWorldTransform(const btTransform &worldTrans)
void setCompanionId(int id)
int m_updateRevision
internal update revision number. It will be increased when the object changes. This allows some subsy...
void setInterpolationWorldTransform(const btTransform &trans)
The btBroadphaseProxy is the main class that can be used with the Bullet broadphases.
int getUserIndex2() const
btScalar getHitFraction() const
void setInterpolationAngularVelocity(const btVector3 &angvel)
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:82
const btBroadphaseProxy * getBroadphaseHandle() const
int getCompanionId() const
void setAnisotropicFriction(const btVector3 &anisotropicFriction, int frictionMode=CF_ANISOTROPIC_FRICTION)
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
btCollisionShape * getCollisionShape()
virtual bool checkCollideWithOverride(const btCollisionObject *co) const
void setCollisionFlags(int flags)
int getIslandTag() const
void setBroadphaseHandle(btBroadphaseProxy *handle)
void remove(const T &key)
bool hasAnisotropicFriction(int frictionMode=CF_ANISOTROPIC_FRICTION) const
btTransformDoubleData m_worldTransform
btTransformDoubleData m_interpolationWorldTransform
btVector3 m_interpolationAngularVelocity
for serialization
Definition: btTransform.h:253
btScalar getRollingFriction() const
int findLinearSearch(const T &key) const
void setIslandTag(int tag)
void setRollingFriction(btScalar frict)
btScalar getFriction() const
const btTransform & getWorldTransform() const
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:403
btVector3DoubleData m_interpolationLinearVelocity
int m_checkCollideWith
If some object should have elaborate collision filtering by sub-classes.
void internalSetExtensionPointer(void *pointer)
Avoid using this internal API call, the extension pointer is used by some Bullet extensions If you ne...
void * m_userObjectPointer
users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPoin...
void * internalGetExtensionPointer() const
Avoid using this internal API call, the extension pointer is used by some Bullet extensions.
void setInterpolationLinearVelocity(const btVector3 &linvel)
btBroadphaseProxy * m_broadphaseHandle
btVector3 m_interpolationLinearVelocity
void setContactProcessingThreshold(btScalar contactProcessingThreshold)
the constraint solver can discard solving contacts, if the distance is above this threshold...
const btCollisionShape * getCollisionShape() const
bool getCustomDebugColor(btVector3 &colorRGB) const
int getActivationState() const
btVector3FloatData m_interpolationAngularVelocity
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:292
bool isActive() const
btScalar getContactStiffness() const