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 
89 
93 
95 
97 
99 
102 
105 
108 
111 
113 
116 
117 
118 public:
119 
121 
123  {
124  CF_STATIC_OBJECT= 1,
125  CF_KINEMATIC_OBJECT= 2,
126  CF_NO_CONTACT_RESPONSE = 4,
127  CF_CUSTOM_MATERIAL_CALLBACK = 8,//this allows per-triangle material (friction/restitution)
128  CF_CHARACTER_OBJECT = 16,
129  CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
130  CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing
131  };
132 
134  {
135  CO_COLLISION_OBJECT =1,
136  CO_RIGID_BODY=2,
139  CO_GHOST_OBJECT=4,
140  CO_SOFT_BODY=8,
141  CO_HF_FLUID=16,
142  CO_USER_TYPE=32,
143  CO_FEATHERSTONE_LINK=64
144  };
145 
147  {
148  CF_ANISOTROPIC_FRICTION_DISABLED=0,
149  CF_ANISOTROPIC_FRICTION = 1,
150  CF_ANISOTROPIC_ROLLING_FRICTION = 2
151  };
152 
154  {
156  return ((m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT | CF_NO_CONTACT_RESPONSE) )==0);
157  }
158 
160  {
161  return m_anisotropicFriction;
162  }
163  void setAnisotropicFriction(const btVector3& anisotropicFriction, int frictionMode = CF_ANISOTROPIC_FRICTION)
164  {
165  m_anisotropicFriction = anisotropicFriction;
166  bool isUnity = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
167  m_hasAnisotropicFriction = isUnity?frictionMode : 0;
168  }
169  bool hasAnisotropicFriction(int frictionMode = CF_ANISOTROPIC_FRICTION) const
170  {
171  return (m_hasAnisotropicFriction&frictionMode)!=0;
172  }
173 
176  void setContactProcessingThreshold( btScalar contactProcessingThreshold)
177  {
178  m_contactProcessingThreshold = contactProcessingThreshold;
179  }
181  {
182  return m_contactProcessingThreshold;
183  }
184 
186  return (m_collisionFlags & CF_STATIC_OBJECT) != 0;
187  }
188 
190  {
191  return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
192  }
193 
195  {
196  return (m_collisionFlags & (CF_KINEMATIC_OBJECT | CF_STATIC_OBJECT)) != 0 ;
197  }
198 
200  return (m_collisionFlags & CF_NO_CONTACT_RESPONSE)==0;
201  }
202 
203 
205 
206  virtual ~btCollisionObject();
207 
208  virtual void setCollisionShape(btCollisionShape* collisionShape)
209  {
210  m_updateRevision++;
211  m_collisionShape = collisionShape;
212  m_rootCollisionShape = collisionShape;
213  }
214 
216  {
217  return m_collisionShape;
218  }
219 
221  {
222  return m_collisionShape;
223  }
224 
225  void setIgnoreCollisionCheck(const btCollisionObject* co, bool ignoreCollisionCheck)
226  {
227  if (ignoreCollisionCheck)
228  {
229  //We don't check for duplicates. Is it ok to leave that up to the user of this API?
230  //int index = m_objectsWithoutCollisionCheck.findLinearSearch(co);
231  //if (index == m_objectsWithoutCollisionCheck.size())
232  //{
233  m_objectsWithoutCollisionCheck.push_back(co);
234  //}
235  }
236  else
237  {
238  m_objectsWithoutCollisionCheck.remove(co);
239  }
240  m_checkCollideWith = m_objectsWithoutCollisionCheck.size() > 0;
241  }
242 
243  virtual bool checkCollideWithOverride(const btCollisionObject* co) const
244  {
245  int index = m_objectsWithoutCollisionCheck.findLinearSearch(co);
246  if (index < m_objectsWithoutCollisionCheck.size())
247  {
248  return false;
249  }
250  return true;
251  }
252 
253 
254 
255 
259  {
260  return m_extensionPointer;
261  }
264  void internalSetExtensionPointer(void* pointer)
265  {
266  m_extensionPointer = pointer;
267  }
268 
269  SIMD_FORCE_INLINE int getActivationState() const { return m_activationState1;}
270 
271  void setActivationState(int newState) const;
272 
274  {
275  m_deactivationTime = time;
276  }
278  {
279  return m_deactivationTime;
280  }
281 
282  void forceActivationState(int newState) const;
283 
284  void activate(bool forceActivation = false) const;
285 
287  {
288  return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
289  }
290 
292  {
293  m_updateRevision++;
294  m_restitution = rest;
295  }
297  {
298  return m_restitution;
299  }
300  void setFriction(btScalar frict)
301  {
302  m_updateRevision++;
303  m_friction = frict;
304  }
306  {
307  return m_friction;
308  }
309 
311  {
312  m_updateRevision++;
313  m_rollingFriction = frict;
314  }
316  {
317  return m_rollingFriction;
318  }
319 
320 
322  int getInternalType() const
323  {
324  return m_internalType;
325  }
326 
328  {
329  return m_worldTransform;
330  }
331 
333  {
334  return m_worldTransform;
335  }
336 
337  void setWorldTransform(const btTransform& worldTrans)
338  {
339  m_updateRevision++;
340  m_worldTransform = worldTrans;
341  }
342 
343 
345  {
346  return m_broadphaseHandle;
347  }
348 
350  {
351  return m_broadphaseHandle;
352  }
353 
355  {
356  m_broadphaseHandle = handle;
357  }
358 
359 
361  {
362  return m_interpolationWorldTransform;
363  }
364 
366  {
367  return m_interpolationWorldTransform;
368  }
369 
371  {
372  m_updateRevision++;
373  m_interpolationWorldTransform = trans;
374  }
375 
377  {
378  m_updateRevision++;
379  m_interpolationLinearVelocity = linvel;
380  }
381 
383  {
384  m_updateRevision++;
385  m_interpolationAngularVelocity = angvel;
386  }
387 
389  {
390  return m_interpolationLinearVelocity;
391  }
392 
394  {
395  return m_interpolationAngularVelocity;
396  }
397 
399  {
400  return m_islandTag1;
401  }
402 
403  void setIslandTag(int tag)
404  {
405  m_islandTag1 = tag;
406  }
407 
409  {
410  return m_companionId;
411  }
412 
413  void setCompanionId(int id)
414  {
415  m_companionId = id;
416  }
417 
419  {
420  return m_hitFraction;
421  }
422 
423  void setHitFraction(btScalar hitFraction)
424  {
425  m_hitFraction = hitFraction;
426  }
427 
428 
430  {
431  return m_collisionFlags;
432  }
433 
434  void setCollisionFlags(int flags)
435  {
436  m_collisionFlags = flags;
437  }
438 
441  {
442  return m_ccdSweptSphereRadius;
443  }
444 
447  {
448  m_ccdSweptSphereRadius = radius;
449  }
450 
452  {
453  return m_ccdMotionThreshold;
454  }
455 
457  {
458  return m_ccdMotionThreshold*m_ccdMotionThreshold;
459  }
460 
461 
462 
464  void setCcdMotionThreshold(btScalar ccdMotionThreshold)
465  {
466  m_ccdMotionThreshold = ccdMotionThreshold;
467  }
468 
470  void* getUserPointer() const
471  {
472  return m_userObjectPointer;
473  }
474 
475  int getUserIndex() const
476  {
477  return m_userIndex;
478  }
480  void setUserPointer(void* userPointer)
481  {
482  m_userObjectPointer = userPointer;
483  }
484 
486  void setUserIndex(int index)
487  {
488  m_userIndex = index;
489  }
490 
492  {
493  return m_updateRevision;
494  }
495 
496 
497  inline bool checkCollideWith(const btCollisionObject* co) const
498  {
499  if (m_checkCollideWith)
500  return checkCollideWithOverride(co);
501 
502  return true;
503  }
504 
505  virtual int calculateSerializeBufferSize() const;
506 
508  virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
509 
510  virtual void serializeSingleObject(class btSerializer* serializer) const;
511 
512 };
513 
516 {
520  char *m_name;
521 
529  double m_friction;
532  double m_hitFraction;
535 
543 
544  char m_padding[4];
545 };
546 
549 {
553  char *m_name;
554 
562  float m_friction;
564 
569 
577  char m_padding[4];
578 };
579 
580 
581 
583 {
584  return sizeof(btCollisionObjectData);
585 }
586 
587 
588 
589 #endif //BT_COLLISION_OBJECT_H
btTransformFloatData m_worldTransform
int getUpdateRevisionInternal() const
btScalar getDeactivationTime() const
btScalar getCcdMotionThreshold() const
do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 ...
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'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'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)
#define SIMD_FORCE_INLINE
Definition: btScalar.h:63
btScalar getContactProcessingThreshold() const
int getUserIndex() const
int getCollisionFlags() const
#define btCollisionObjectData
btTransform m_worldTransform
#define ISLAND_SLEEPING
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)
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 ...
btTransform & getWorldTransform()
int m_internalType
m_internalType is reserved to distinguish Bullet'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...
btVector3FloatData m_interpolationLinearVelocity
btAlignedObjectArray< class btCollisionObject * > btCollisionObjectArray
btTransform & getInterpolationWorldTransform()
bool isStaticOrKinematicObject() 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.
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.
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:64
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:388
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
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:278
bool isActive() const