2
Bullet Continuous Collision Detection and Physics Library
3
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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:
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.
16
#ifndef BT_COLLISION_OBJECT_H
17
#define BT_COLLISION_OBJECT_H
19
#include "LinearMath/btTransform.h"
21
//island management, m_activationState1
23
#define ISLAND_SLEEPING 2
24
#define WANTS_DEACTIVATION 3
25
#define DISABLE_DEACTIVATION 4
26
#define DISABLE_SIMULATION 5
28
struct btBroadphaseProxy;
29
class btCollisionShape;
30
struct btCollisionShapeData;
31
#include "LinearMath/btMotionState.h"
32
#include "LinearMath/btAlignedAllocator.h"
33
#include "LinearMath/btAlignedObjectArray.h"
35
typedef btAlignedObjectArray<class btCollisionObject*> btCollisionObjectArray;
37
#ifdef BT_USE_DOUBLE_PRECISION
38
#define btCollisionObjectData btCollisionObjectDoubleData
39
#define btCollisionObjectDataName "btCollisionObjectDoubleData"
41
#define btCollisionObjectData btCollisionObjectFloatData
42
#define btCollisionObjectDataName "btCollisionObjectFloatData"
46
/// btCollisionObject can be used to manage collision detection objects.
47
/// btCollisionObject maintains all information that is needed for a collision detection: Shape, Transform and AABB proxy.
48
/// They can be added to the btCollisionWorld.
49
ATTRIBUTE_ALIGNED16(class) btCollisionObject
54
btTransform m_worldTransform;
56
///m_interpolationWorldTransform is used for CCD and interpolation
57
///it can be either previous or future (predicted) transform
58
btTransform m_interpolationWorldTransform;
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)
61
btVector3 m_interpolationLinearVelocity;
62
btVector3 m_interpolationAngularVelocity;
64
btVector3 m_anisotropicFriction;
65
int m_hasAnisotropicFriction;
66
btScalar m_contactProcessingThreshold;
68
btBroadphaseProxy* m_broadphaseHandle;
69
btCollisionShape* m_collisionShape;
70
///m_extensionPointer is used by some internal low-level Bullet extensions.
71
void* m_extensionPointer;
73
///m_rootCollisionShape is temporarily used to store the original collision shape
74
///The m_collisionShape might be temporarily replaced by a child collision shape during collision detection purposes
75
///If it is NULL, the m_collisionShape is not temporarily replaced.
76
btCollisionShape* m_rootCollisionShape;
83
int m_activationState1;
84
btScalar m_deactivationTime;
87
btScalar m_restitution;
89
///m_internalType is reserved to distinguish Bullet's btCollisionObject, btRigidBody, btSoftBody, btGhostObject etc.
90
///do not assign your own m_internalType unless you write a new dynamics object class.
93
///users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPointer
94
void* m_userObjectPointer;
96
///time of impact calculation
97
btScalar m_hitFraction;
99
///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
100
btScalar m_ccdSweptSphereRadius;
102
/// Don't do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold
103
btScalar m_ccdMotionThreshold;
105
/// If some object should have elaborate collision filtering by sub-classes
106
int m_checkCollideWith;
108
virtual bool checkCollideWithOverride(btCollisionObject* /* co */)
115
BT_DECLARE_ALIGNED_ALLOCATOR();
120
CF_KINEMATIC_OBJECT= 2,
121
CF_NO_CONTACT_RESPONSE = 4,
122
CF_CUSTOM_MATERIAL_CALLBACK = 8,//this allows per-triangle material (friction/restitution)
123
CF_CHARACTER_OBJECT = 16,
124
CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
125
CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing
128
enum CollisionObjectTypes
130
CO_COLLISION_OBJECT =1,
132
///CO_GHOST_OBJECT keeps track of all objects overlapping its AABB and that pass its collision filter
133
///It is useful for collision sensors, explosion objects, character controller etc.
140
SIMD_FORCE_INLINE bool mergesSimulationIslands() const
142
///static objects, kinematic and object without contact response don't merge islands
143
return ((m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT | CF_NO_CONTACT_RESPONSE) )==0);
146
const btVector3& getAnisotropicFriction() const
148
return m_anisotropicFriction;
150
void setAnisotropicFriction(const btVector3& anisotropicFriction)
152
m_anisotropicFriction = anisotropicFriction;
153
m_hasAnisotropicFriction = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
155
bool hasAnisotropicFriction() const
157
return m_hasAnisotropicFriction!=0;
160
///the constraint solver can discard solving contacts, if the distance is above this threshold. 0 by default.
161
///Note that using contacts with positive distance can improve stability. It increases, however, the chance of colliding with degerate contacts, such as 'interior' triangle edges
162
void setContactProcessingThreshold( btScalar contactProcessingThreshold)
164
m_contactProcessingThreshold = contactProcessingThreshold;
166
btScalar getContactProcessingThreshold() const
168
return m_contactProcessingThreshold;
171
SIMD_FORCE_INLINE bool isStaticObject() const {
172
return (m_collisionFlags & CF_STATIC_OBJECT) != 0;
175
SIMD_FORCE_INLINE bool isKinematicObject() const
177
return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
180
SIMD_FORCE_INLINE bool isStaticOrKinematicObject() const
182
return (m_collisionFlags & (CF_KINEMATIC_OBJECT | CF_STATIC_OBJECT)) != 0 ;
185
SIMD_FORCE_INLINE bool hasContactResponse() const {
186
return (m_collisionFlags & CF_NO_CONTACT_RESPONSE)==0;
192
virtual ~btCollisionObject();
194
virtual void setCollisionShape(btCollisionShape* collisionShape)
196
m_collisionShape = collisionShape;
197
m_rootCollisionShape = collisionShape;
200
SIMD_FORCE_INLINE const btCollisionShape* getCollisionShape() const
202
return m_collisionShape;
205
SIMD_FORCE_INLINE btCollisionShape* getCollisionShape()
207
return m_collisionShape;
210
SIMD_FORCE_INLINE const btCollisionShape* getRootCollisionShape() const
212
return m_rootCollisionShape;
215
SIMD_FORCE_INLINE btCollisionShape* getRootCollisionShape()
217
return m_rootCollisionShape;
220
///Avoid using this internal API call
221
///internalSetTemporaryCollisionShape is used to temporary replace the actual collision shape by a child collision shape.
222
void internalSetTemporaryCollisionShape(btCollisionShape* collisionShape)
224
m_collisionShape = collisionShape;
227
///Avoid using this internal API call, the extension pointer is used by some Bullet extensions.
228
///If you need to store your own user pointer, use 'setUserPointer/getUserPointer' instead.
229
void* internalGetExtensionPointer() const
231
return m_extensionPointer;
233
///Avoid using this internal API call, the extension pointer is used by some Bullet extensions
234
///If you need to store your own user pointer, use 'setUserPointer/getUserPointer' instead.
235
void internalSetExtensionPointer(void* pointer)
237
m_extensionPointer = pointer;
240
SIMD_FORCE_INLINE int getActivationState() const { return m_activationState1;}
242
void setActivationState(int newState);
244
void setDeactivationTime(btScalar time)
246
m_deactivationTime = time;
248
btScalar getDeactivationTime() const
250
return m_deactivationTime;
253
void forceActivationState(int newState);
255
void activate(bool forceActivation = false);
257
SIMD_FORCE_INLINE bool isActive() const
259
return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
262
void setRestitution(btScalar rest)
264
m_restitution = rest;
266
btScalar getRestitution() const
268
return m_restitution;
270
void setFriction(btScalar frict)
274
btScalar getFriction() const
279
///reserved for Bullet internal usage
280
int getInternalType() const
282
return m_internalType;
285
btTransform& getWorldTransform()
287
return m_worldTransform;
290
const btTransform& getWorldTransform() const
292
return m_worldTransform;
295
void setWorldTransform(const btTransform& worldTrans)
297
m_worldTransform = worldTrans;
301
SIMD_FORCE_INLINE btBroadphaseProxy* getBroadphaseHandle()
303
return m_broadphaseHandle;
306
SIMD_FORCE_INLINE const btBroadphaseProxy* getBroadphaseHandle() const
308
return m_broadphaseHandle;
311
void setBroadphaseHandle(btBroadphaseProxy* handle)
313
m_broadphaseHandle = handle;
317
const btTransform& getInterpolationWorldTransform() const
319
return m_interpolationWorldTransform;
322
btTransform& getInterpolationWorldTransform()
324
return m_interpolationWorldTransform;
327
void setInterpolationWorldTransform(const btTransform& trans)
329
m_interpolationWorldTransform = trans;
332
void setInterpolationLinearVelocity(const btVector3& linvel)
334
m_interpolationLinearVelocity = linvel;
337
void setInterpolationAngularVelocity(const btVector3& angvel)
339
m_interpolationAngularVelocity = angvel;
342
const btVector3& getInterpolationLinearVelocity() const
344
return m_interpolationLinearVelocity;
347
const btVector3& getInterpolationAngularVelocity() const
349
return m_interpolationAngularVelocity;
352
SIMD_FORCE_INLINE int getIslandTag() const
357
void setIslandTag(int tag)
362
SIMD_FORCE_INLINE int getCompanionId() const
364
return m_companionId;
367
void setCompanionId(int id)
372
SIMD_FORCE_INLINE btScalar getHitFraction() const
374
return m_hitFraction;
377
void setHitFraction(btScalar hitFraction)
379
m_hitFraction = hitFraction;
383
SIMD_FORCE_INLINE int getCollisionFlags() const
385
return m_collisionFlags;
388
void setCollisionFlags(int flags)
390
m_collisionFlags = flags;
393
///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
394
btScalar getCcdSweptSphereRadius() const
396
return m_ccdSweptSphereRadius;
399
///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
400
void setCcdSweptSphereRadius(btScalar radius)
402
m_ccdSweptSphereRadius = radius;
405
btScalar getCcdMotionThreshold() const
407
return m_ccdMotionThreshold;
410
btScalar getCcdSquareMotionThreshold() const
412
return m_ccdMotionThreshold*m_ccdMotionThreshold;
417
/// Don't do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold
418
void setCcdMotionThreshold(btScalar ccdMotionThreshold)
420
m_ccdMotionThreshold = ccdMotionThreshold;
423
///users can point to their objects, userPointer is not used by Bullet
424
void* getUserPointer() const
426
return m_userObjectPointer;
429
///users can point to their objects, userPointer is not used by Bullet
430
void setUserPointer(void* userPointer)
432
m_userObjectPointer = userPointer;
436
inline bool checkCollideWith(btCollisionObject* co)
438
if (m_checkCollideWith)
439
return checkCollideWithOverride(co);
444
virtual int calculateSerializeBufferSize() const;
446
///fills the dataBuffer and returns the struct name (and 0 on failure)
447
virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
449
virtual void serializeSingleObject(class btSerializer* serializer) const;
453
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
454
struct btCollisionObjectDoubleData
456
void *m_broadphaseHandle;
457
void *m_collisionShape;
458
btCollisionShapeData *m_rootCollisionShape;
461
btTransformDoubleData m_worldTransform;
462
btTransformDoubleData m_interpolationWorldTransform;
463
btVector3DoubleData m_interpolationLinearVelocity;
464
btVector3DoubleData m_interpolationAngularVelocity;
465
btVector3DoubleData m_anisotropicFriction;
466
double m_contactProcessingThreshold;
467
double m_deactivationTime;
469
double m_restitution;
470
double m_hitFraction;
471
double m_ccdSweptSphereRadius;
472
double m_ccdMotionThreshold;
474
int m_hasAnisotropicFriction;
475
int m_collisionFlags;
478
int m_activationState1;
480
int m_checkCollideWith;
485
///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
486
struct btCollisionObjectFloatData
488
void *m_broadphaseHandle;
489
void *m_collisionShape;
490
btCollisionShapeData *m_rootCollisionShape;
493
btTransformFloatData m_worldTransform;
494
btTransformFloatData m_interpolationWorldTransform;
495
btVector3FloatData m_interpolationLinearVelocity;
496
btVector3FloatData m_interpolationAngularVelocity;
497
btVector3FloatData m_anisotropicFriction;
498
float m_contactProcessingThreshold;
499
float m_deactivationTime;
503
float m_ccdSweptSphereRadius;
504
float m_ccdMotionThreshold;
506
int m_hasAnisotropicFriction;
507
int m_collisionFlags;
510
int m_activationState1;
512
int m_checkCollideWith;
517
SIMD_FORCE_INLINE int btCollisionObject::calculateSerializeBufferSize() const
519
return sizeof(btCollisionObjectData);
524
#endif //BT_COLLISION_OBJECT_H