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  union
96  {
99  };
100 
103 
106 
109 
112 
115 
116  virtual bool checkCollideWithOverride(const btCollisionObject* /* co */) const
117  {
118  return true;
119  }
120 
121 public:
122 
124 
126  {
127  CF_STATIC_OBJECT= 1,
128  CF_KINEMATIC_OBJECT= 2,
129  CF_NO_CONTACT_RESPONSE = 4,
130  CF_CUSTOM_MATERIAL_CALLBACK = 8,//this allows per-triangle material (friction/restitution)
131  CF_CHARACTER_OBJECT = 16,
132  CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
133  CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing
134  };
135 
137  {
138  CO_COLLISION_OBJECT =1,
139  CO_RIGID_BODY=2,
142  CO_GHOST_OBJECT=4,
143  CO_SOFT_BODY=8,
144  CO_HF_FLUID=16,
145  CO_USER_TYPE=32,
146  CO_FEATHERSTONE_LINK=64
147  };
148 
150  {
151  CF_ANISOTROPIC_FRICTION_DISABLED=0,
152  CF_ANISOTROPIC_FRICTION = 1,
153  CF_ANISOTROPIC_ROLLING_FRICTION = 2
154  };
155 
157  {
159  return ((m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT | CF_NO_CONTACT_RESPONSE) )==0);
160  }
161 
163  {
164  return m_anisotropicFriction;
165  }
166  void setAnisotropicFriction(const btVector3& anisotropicFriction, int frictionMode = CF_ANISOTROPIC_FRICTION)
167  {
168  m_anisotropicFriction = anisotropicFriction;
169  bool isUnity = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
170  m_hasAnisotropicFriction = isUnity?frictionMode : 0;
171  }
172  bool hasAnisotropicFriction(int frictionMode = CF_ANISOTROPIC_FRICTION) const
173  {
174  return (m_hasAnisotropicFriction&frictionMode)!=0;
175  }
176 
179  void setContactProcessingThreshold( btScalar contactProcessingThreshold)
180  {
181  m_contactProcessingThreshold = contactProcessingThreshold;
182  }
184  {
185  return m_contactProcessingThreshold;
186  }
187 
189  return (m_collisionFlags & CF_STATIC_OBJECT) != 0;
190  }
191 
193  {
194  return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
195  }
196 
198  {
199  return (m_collisionFlags & (CF_KINEMATIC_OBJECT | CF_STATIC_OBJECT)) != 0 ;
200  }
201 
203  return (m_collisionFlags & CF_NO_CONTACT_RESPONSE)==0;
204  }
205 
206 
208 
209  virtual ~btCollisionObject();
210 
211  virtual void setCollisionShape(btCollisionShape* collisionShape)
212  {
213  m_updateRevision++;
214  m_collisionShape = collisionShape;
215  m_rootCollisionShape = collisionShape;
216  }
217 
219  {
220  return m_collisionShape;
221  }
222 
224  {
225  return m_collisionShape;
226  }
227 
228 
229 
230 
231 
235  {
236  return m_extensionPointer;
237  }
240  void internalSetExtensionPointer(void* pointer)
241  {
242  m_extensionPointer = pointer;
243  }
244 
245  SIMD_FORCE_INLINE int getActivationState() const { return m_activationState1;}
246 
247  void setActivationState(int newState) const;
248 
250  {
251  m_deactivationTime = time;
252  }
254  {
255  return m_deactivationTime;
256  }
257 
258  void forceActivationState(int newState) const;
259 
260  void activate(bool forceActivation = false) const;
261 
263  {
264  return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
265  }
266 
268  {
269  m_updateRevision++;
270  m_restitution = rest;
271  }
273  {
274  return m_restitution;
275  }
276  void setFriction(btScalar frict)
277  {
278  m_updateRevision++;
279  m_friction = frict;
280  }
282  {
283  return m_friction;
284  }
285 
287  {
288  m_updateRevision++;
289  m_rollingFriction = frict;
290  }
292  {
293  return m_rollingFriction;
294  }
295 
296 
298  int getInternalType() const
299  {
300  return m_internalType;
301  }
302 
304  {
305  return m_worldTransform;
306  }
307 
309  {
310  return m_worldTransform;
311  }
312 
313  void setWorldTransform(const btTransform& worldTrans)
314  {
315  m_updateRevision++;
316  m_worldTransform = worldTrans;
317  }
318 
319 
321  {
322  return m_broadphaseHandle;
323  }
324 
326  {
327  return m_broadphaseHandle;
328  }
329 
331  {
332  m_broadphaseHandle = handle;
333  }
334 
335 
337  {
338  return m_interpolationWorldTransform;
339  }
340 
342  {
343  return m_interpolationWorldTransform;
344  }
345 
347  {
348  m_updateRevision++;
349  m_interpolationWorldTransform = trans;
350  }
351 
353  {
354  m_updateRevision++;
355  m_interpolationLinearVelocity = linvel;
356  }
357 
359  {
360  m_updateRevision++;
361  m_interpolationAngularVelocity = angvel;
362  }
363 
365  {
366  return m_interpolationLinearVelocity;
367  }
368 
370  {
371  return m_interpolationAngularVelocity;
372  }
373 
375  {
376  return m_islandTag1;
377  }
378 
379  void setIslandTag(int tag)
380  {
381  m_islandTag1 = tag;
382  }
383 
385  {
386  return m_companionId;
387  }
388 
389  void setCompanionId(int id)
390  {
391  m_companionId = id;
392  }
393 
395  {
396  return m_hitFraction;
397  }
398 
399  void setHitFraction(btScalar hitFraction)
400  {
401  m_hitFraction = hitFraction;
402  }
403 
404 
406  {
407  return m_collisionFlags;
408  }
409 
410  void setCollisionFlags(int flags)
411  {
412  m_collisionFlags = flags;
413  }
414 
417  {
418  return m_ccdSweptSphereRadius;
419  }
420 
423  {
424  m_ccdSweptSphereRadius = radius;
425  }
426 
428  {
429  return m_ccdMotionThreshold;
430  }
431 
433  {
434  return m_ccdMotionThreshold*m_ccdMotionThreshold;
435  }
436 
437 
438 
440  void setCcdMotionThreshold(btScalar ccdMotionThreshold)
441  {
442  m_ccdMotionThreshold = ccdMotionThreshold;
443  }
444 
446  void* getUserPointer() const
447  {
448  return m_userObjectPointer;
449  }
450 
451  int getUserIndex() const
452  {
453  return m_userIndex;
454  }
456  void setUserPointer(void* userPointer)
457  {
458  m_userObjectPointer = userPointer;
459  }
460 
462  void setUserIndex(int index)
463  {
464  m_userIndex = index;
465  }
466 
468  {
469  return m_updateRevision;
470  }
471 
472 
473  inline bool checkCollideWith(const btCollisionObject* co) const
474  {
475  if (m_checkCollideWith)
476  return checkCollideWithOverride(co);
477 
478  return true;
479  }
480 
481  virtual int calculateSerializeBufferSize() const;
482 
484  virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
485 
486  virtual void serializeSingleObject(class btSerializer* serializer) const;
487 
488 };
489 
492 {
496  char *m_name;
497 
505  double m_friction;
508  double m_hitFraction;
511 
519 
520  char m_padding[4];
521 };
522 
525 {
529  char *m_name;
530 
538  float m_friction;
540 
545 
553  char m_padding[4];
554 };
555 
556 
557 
559 {
560  return sizeof(btCollisionObjectData);
561 }
562 
563 
564 
565 #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 ...
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...
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:58
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 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.
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:59
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()
void setCollisionFlags(int flags)
int getIslandTag() const
void setBroadphaseHandle(btBroadphaseProxy *handle)
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
void setIslandTag(int tag)
void setRollingFriction(btScalar frict)
btScalar getFriction() const
const btTransform & getWorldTransform() const
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:357
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...
virtual bool checkCollideWithOverride(const btCollisionObject *) const
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:266
bool isActive() const