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 
83  mutable int m_activationState1;
85 
88  btScalar m_rollingFriction;//torsional friction orthogonal to contact normal (useful to stop spheres rolling forever)
89  btScalar m_spinningFriction; // torsional friction around the contact normal (useful for grasping)
92 
93 
94 
98 
100 
102 
104 
106 
109 
112 
115 
118 
120 
123 
124 
125 public:
126 
128 
130  {
131  CF_STATIC_OBJECT= 1,
132  CF_KINEMATIC_OBJECT= 2,
133  CF_NO_CONTACT_RESPONSE = 4,
134  CF_CUSTOM_MATERIAL_CALLBACK = 8,//this allows per-triangle material (friction/restitution)
135  CF_CHARACTER_OBJECT = 16,
136  CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
137  CF_DISABLE_SPU_COLLISION_PROCESSING = 64,//disable parallel/SPU processing
138  CF_HAS_CONTACT_STIFFNESS_DAMPING = 128
139  };
140 
142  {
143  CO_COLLISION_OBJECT =1,
144  CO_RIGID_BODY=2,
147  CO_GHOST_OBJECT=4,
148  CO_SOFT_BODY=8,
149  CO_HF_FLUID=16,
150  CO_USER_TYPE=32,
151  CO_FEATHERSTONE_LINK=64
152  };
153 
155  {
156  CF_ANISOTROPIC_FRICTION_DISABLED=0,
157  CF_ANISOTROPIC_FRICTION = 1,
158  CF_ANISOTROPIC_ROLLING_FRICTION = 2
159  };
160 
162  {
164  return ((m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT | CF_NO_CONTACT_RESPONSE) )==0);
165  }
166 
168  {
169  return m_anisotropicFriction;
170  }
171  void setAnisotropicFriction(const btVector3& anisotropicFriction, int frictionMode = CF_ANISOTROPIC_FRICTION)
172  {
173  m_anisotropicFriction = anisotropicFriction;
174  bool isUnity = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
175  m_hasAnisotropicFriction = isUnity?frictionMode : 0;
176  }
177  bool hasAnisotropicFriction(int frictionMode = CF_ANISOTROPIC_FRICTION) const
178  {
179  return (m_hasAnisotropicFriction&frictionMode)!=0;
180  }
181 
184  void setContactProcessingThreshold( btScalar contactProcessingThreshold)
185  {
186  m_contactProcessingThreshold = contactProcessingThreshold;
187  }
189  {
190  return m_contactProcessingThreshold;
191  }
192 
194  return (m_collisionFlags & CF_STATIC_OBJECT) != 0;
195  }
196 
198  {
199  return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
200  }
201 
203  {
204  return (m_collisionFlags & (CF_KINEMATIC_OBJECT | CF_STATIC_OBJECT)) != 0 ;
205  }
206 
208  return (m_collisionFlags & CF_NO_CONTACT_RESPONSE)==0;
209  }
210 
211 
213 
214  virtual ~btCollisionObject();
215 
216  virtual void setCollisionShape(btCollisionShape* collisionShape)
217  {
218  m_updateRevision++;
219  m_collisionShape = collisionShape;
220  m_rootCollisionShape = collisionShape;
221  }
222 
224  {
225  return m_collisionShape;
226  }
227 
229  {
230  return m_collisionShape;
231  }
232 
233  void setIgnoreCollisionCheck(const btCollisionObject* co, bool ignoreCollisionCheck)
234  {
235  if (ignoreCollisionCheck)
236  {
237  //We don't check for duplicates. Is it ok to leave that up to the user of this API?
238  //int index = m_objectsWithoutCollisionCheck.findLinearSearch(co);
239  //if (index == m_objectsWithoutCollisionCheck.size())
240  //{
241  m_objectsWithoutCollisionCheck.push_back(co);
242  //}
243  }
244  else
245  {
246  m_objectsWithoutCollisionCheck.remove(co);
247  }
248  m_checkCollideWith = m_objectsWithoutCollisionCheck.size() > 0;
249  }
250 
251  virtual bool checkCollideWithOverride(const btCollisionObject* co) const
252  {
253  int index = m_objectsWithoutCollisionCheck.findLinearSearch(co);
254  if (index < m_objectsWithoutCollisionCheck.size())
255  {
256  return false;
257  }
258  return true;
259  }
260 
261 
262 
263 
267  {
268  return m_extensionPointer;
269  }
272  void internalSetExtensionPointer(void* pointer)
273  {
274  m_extensionPointer = pointer;
275  }
276 
277  SIMD_FORCE_INLINE int getActivationState() const { return m_activationState1;}
278 
279  void setActivationState(int newState) const;
280 
282  {
283  m_deactivationTime = time;
284  }
286  {
287  return m_deactivationTime;
288  }
289 
290  void forceActivationState(int newState) const;
291 
292  void activate(bool forceActivation = false) const;
293 
295  {
296  return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
297  }
298 
300  {
301  m_updateRevision++;
302  m_restitution = rest;
303  }
305  {
306  return m_restitution;
307  }
308  void setFriction(btScalar frict)
309  {
310  m_updateRevision++;
311  m_friction = frict;
312  }
314  {
315  return m_friction;
316  }
317 
319  {
320  m_updateRevision++;
321  m_rollingFriction = frict;
322  }
324  {
325  return m_rollingFriction;
326  }
328  {
329  m_updateRevision++;
330  m_spinningFriction = frict;
331  }
333  {
334  return m_spinningFriction;
335  }
337  {
338  m_updateRevision++;
339  m_contactStiffness = stiffness;
340  m_contactDamping = damping;
341 
342  m_collisionFlags |=CF_HAS_CONTACT_STIFFNESS_DAMPING;
343 
344  //avoid divisions by zero...
345  if (m_contactStiffness< SIMD_EPSILON)
346  {
347  m_contactStiffness = SIMD_EPSILON;
348  }
349  }
350 
352  {
353  return m_contactStiffness;
354  }
355 
357  {
358  return m_contactDamping;
359  }
360 
362  int getInternalType() const
363  {
364  return m_internalType;
365  }
366 
368  {
369  return m_worldTransform;
370  }
371 
373  {
374  return m_worldTransform;
375  }
376 
377  void setWorldTransform(const btTransform& worldTrans)
378  {
379  m_updateRevision++;
380  m_worldTransform = worldTrans;
381  }
382 
383 
385  {
386  return m_broadphaseHandle;
387  }
388 
390  {
391  return m_broadphaseHandle;
392  }
393 
395  {
396  m_broadphaseHandle = handle;
397  }
398 
399 
401  {
402  return m_interpolationWorldTransform;
403  }
404 
406  {
407  return m_interpolationWorldTransform;
408  }
409 
411  {
412  m_updateRevision++;
413  m_interpolationWorldTransform = trans;
414  }
415 
417  {
418  m_updateRevision++;
419  m_interpolationLinearVelocity = linvel;
420  }
421 
423  {
424  m_updateRevision++;
425  m_interpolationAngularVelocity = angvel;
426  }
427 
429  {
430  return m_interpolationLinearVelocity;
431  }
432 
434  {
435  return m_interpolationAngularVelocity;
436  }
437 
439  {
440  return m_islandTag1;
441  }
442 
443  void setIslandTag(int tag)
444  {
445  m_islandTag1 = tag;
446  }
447 
449  {
450  return m_companionId;
451  }
452 
453  void setCompanionId(int id)
454  {
455  m_companionId = id;
456  }
457 
459  {
460  return m_hitFraction;
461  }
462 
463  void setHitFraction(btScalar hitFraction)
464  {
465  m_hitFraction = hitFraction;
466  }
467 
468 
470  {
471  return m_collisionFlags;
472  }
473 
474  void setCollisionFlags(int flags)
475  {
476  m_collisionFlags = flags;
477  }
478 
481  {
482  return m_ccdSweptSphereRadius;
483  }
484 
487  {
488  m_ccdSweptSphereRadius = radius;
489  }
490 
492  {
493  return m_ccdMotionThreshold;
494  }
495 
497  {
498  return m_ccdMotionThreshold*m_ccdMotionThreshold;
499  }
500 
501 
502 
504  void setCcdMotionThreshold(btScalar ccdMotionThreshold)
505  {
506  m_ccdMotionThreshold = ccdMotionThreshold;
507  }
508 
510  void* getUserPointer() const
511  {
512  return m_userObjectPointer;
513  }
514 
515  int getUserIndex() const
516  {
517  return m_userIndex;
518  }
519 
520  int getUserIndex2() const
521  {
522  return m_userIndex2;
523  }
524 
526  void setUserPointer(void* userPointer)
527  {
528  m_userObjectPointer = userPointer;
529  }
530 
532  void setUserIndex(int index)
533  {
534  m_userIndex = index;
535  }
536 
537  void setUserIndex2(int index)
538  {
539  m_userIndex2 = index;
540  }
541 
543  {
544  return m_updateRevision;
545  }
546 
547 
548  inline bool checkCollideWith(const btCollisionObject* co) const
549  {
550  if (m_checkCollideWith)
551  return checkCollideWithOverride(co);
552 
553  return true;
554  }
555 
556  virtual int calculateSerializeBufferSize() const;
557 
559  virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
560 
561  virtual void serializeSingleObject(class btSerializer* serializer) const;
562 
563 };
564 
567 {
571  char *m_name;
572 
580  double m_friction;
585  double m_hitFraction;
588 
596 
597  char m_padding[4];
598 };
599 
602 {
606  char *m_name;
607 
615  float m_friction;
623 
631  char m_padding[4];
632 };
633 
634 
635 
637 {
638  return sizeof(btCollisionObjectData);
639 }
640 
641 
642 
643 #endif //BT_COLLISION_OBJECT_H
btTransformFloatData m_worldTransform
void setUserIndex2(int index)
#define SIMD_EPSILON
Definition: btScalar.h:495
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
const btVector3 & getInterpolationAngularVelocity() const
void setContactStiffnessAndDamping(btScalar stiffness, btScalar damping)
void push_back(const T &_Val)
int getUserIndex2() const
btVector3FloatData m_anisotropicFriction
btScalar getContactDamping() const
bool mergesSimulationIslands() const
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...
int findLinearSearch(const T &key) const
const btBroadphaseProxy * getBroadphaseHandle() const
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::
btTransformFloatData m_interpolationWorldTransform
void setCcdMotionThreshold(btScalar ccdMotionThreshold)
Don&#39;t do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold...
btScalar getContactStiffness() const
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)
bool isKinematicObject() const
const btTransform & getWorldTransform() const
#define SIMD_FORCE_INLINE
Definition: btScalar.h:64
int getActivationState() const
#define btCollisionObjectData
btTransform m_worldTransform
#define ISLAND_SLEEPING
bool isStaticOrKinematicObject() const
btVector3DoubleData m_anisotropicFriction
btCollisionShape * m_collisionShape
btCollisionShapeData * m_rootCollisionShape
void setIgnoreCollisionCheck(const btCollisionObject *co, bool ignoreCollisionCheck)
void setRestitution(btScalar rest)
bool checkCollideWith(const btCollisionObject *co) const
btVector3DoubleData m_interpolationAngularVelocity
btCollisionShapeData * m_rootCollisionShape
const btVector3 & getInterpolationLinearVelocity() const
btVector3 m_anisotropicFriction
virtual void setCollisionShape(btCollisionShape *collisionShape)
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
btTransform & getWorldTransform()
int m_internalType
m_internalType is reserved to distinguish Bullet&#39;s btCollisionObject, btRigidBody, btSoftBody, btGhostObject etc.
btBroadphaseProxy * getBroadphaseHandle()
const btVector3 & getAnisotropicFriction() const
void setFriction(btScalar frict)
btScalar getCcdSquareMotionThreshold() 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
btScalar getRestitution() const
btTransform & getInterpolationWorldTransform()
btScalar getDeactivationTime() 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
bool hasContactResponse() const
const btTransform & getInterpolationWorldTransform() const
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.
btScalar m_contactProcessingThreshold
virtual int calculateSerializeBufferSize() 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...
btScalar getRollingFriction() const
int getUserIndex() const
void setInterpolationWorldTransform(const btTransform &trans)
int getCollisionFlags() const
The btBroadphaseProxy is the main class that can be used with the Bullet broadphases.
btScalar getContactProcessingThreshold() const
void * internalGetExtensionPointer() const
Avoid using this internal API call, the extension pointer is used by some Bullet extensions.
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:65
int size() const
return the number of elements in the array
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
btScalar getCcdMotionThreshold() const
btCollisionShape * getCollisionShape()
int getIslandTag() const
void setCollisionFlags(int flags)
void setBroadphaseHandle(btBroadphaseProxy *handle)
btScalar getSpinningFriction() const
btScalar getHitFraction() const
void remove(const T &key)
btTransformDoubleData m_worldTransform
btTransformDoubleData m_interpolationWorldTransform
btVector3 m_interpolationAngularVelocity
for serialization
Definition: btTransform.h:253
void setIslandTag(int tag)
int getInternalType() const
reserved for Bullet internal usage
void setRollingFriction(btScalar frict)
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:389
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 setInterpolationLinearVelocity(const btVector3 &linvel)
bool hasAnisotropicFriction(int frictionMode=CF_ANISOTROPIC_FRICTION) const
btBroadphaseProxy * m_broadphaseHandle
btScalar getCcdSweptSphereRadius() const
Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
btVector3 m_interpolationLinearVelocity
void setContactProcessingThreshold(btScalar contactProcessingThreshold)
the constraint solver can discard solving contacts, if the distance is above this threshold...
btScalar getFriction() const
btVector3FloatData m_interpolationAngularVelocity
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
int getCompanionId() const
virtual bool checkCollideWithOverride(const btCollisionObject *co) const
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:279
const btCollisionShape * getCollisionShape() const
void * getUserPointer() const
users can point to their objects, userPointer is not used by Bullet
int getUpdateRevisionInternal() const