Bullet Collision Detection & Physics Library: btCollisionObject.cpp Source File

Bullet Collision Detection & Physics Library

btCollisionObject.cpp
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 #include "btCollisionObject.h"
17 #include "LinearMath/btSerializer.h"
18 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
19
20 btCollisionObject::btCollisionObject()
21 : m_interpolationLinearVelocity(0.f, 0.f, 0.f),
22 m_interpolationAngularVelocity(0.f, 0.f, 0.f),
23 m_anisotropicFriction(1.f, 1.f, 1.f),
24 m_hasAnisotropicFriction(false),
25 m_contactProcessingThreshold(BT_LARGE_FLOAT),
26 m_broadphaseHandle(0),
27 m_collisionShape(0),
28 m_extensionPointer(0),
29 m_rootCollisionShape(0),
30 m_collisionFlags(btCollisionObject::CF_STATIC_OBJECT),
31 m_islandTag1(-1),
32 m_companionId(-1),
33 m_worldArrayIndex(-1),
34 m_activationState1(1),
35 m_deactivationTime(btScalar(0.)),
36 m_friction(btScalar(0.5)),
37 m_restitution(btScalar(0.)),
38 m_rollingFriction(0.0f),
39 m_spinningFriction(0.f),
40 m_contactDamping(.1),
41 m_contactStiffness(BT_LARGE_FLOAT),
42 m_internalType(CO_COLLISION_OBJECT),
43 m_userObjectPointer(0),
44 m_userIndex2(-1),
45 m_userIndex(-1),
46 m_userIndex3(-1),
47 m_hitFraction(btScalar(1.)),
48 m_ccdSweptSphereRadius(btScalar(0.)),
49 m_ccdMotionThreshold(btScalar(0.)),
50 m_checkCollideWith(false),
51 m_updateRevision(0)
52 {
53 m_worldTransform.setIdentity();
54 m_interpolationWorldTransform.setIdentity();
55 }
56
57 btCollisionObject::~btCollisionObject()
58 {
59 }
60
61 void btCollisionObject::setActivationState(int newState) const
62 {
63 if ((m_activationState1 != DISABLE_DEACTIVATION) && (m_activationState1 != DISABLE_SIMULATION))
64 m_activationState1 = newState;
65 }
66
67 void btCollisionObject::forceActivationState(int newState) const
68 {
69 m_activationState1 = newState;
70 }
71
72 void btCollisionObject::activate(bool forceActivation) const
73 {
74 if (forceActivation || !(m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT)))
75 {
76 setActivationState(ACTIVE_TAG);
77 m_deactivationTime = btScalar(0.);
78 }
79 }
80
81 const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* serializer) const
82 {
83 btCollisionObjectData* dataOut = (btCollisionObjectData*)dataBuffer;
84
85 m_worldTransform.serialize(dataOut->m_worldTransform);
86 m_interpolationWorldTransform.serialize(dataOut->m_interpolationWorldTransform);
87 m_interpolationLinearVelocity.serialize(dataOut->m_interpolationLinearVelocity);
88 m_interpolationAngularVelocity.serialize(dataOut->m_interpolationAngularVelocity);
89 m_anisotropicFriction.serialize(dataOut->m_anisotropicFriction);
90 dataOut->m_hasAnisotropicFriction = m_hasAnisotropicFriction;
91 dataOut->m_contactProcessingThreshold = m_contactProcessingThreshold;
92 dataOut->m_broadphaseHandle = 0;
93 dataOut->m_collisionShape = serializer->getUniquePointer(m_collisionShape);
94 dataOut->m_rootCollisionShape = 0; //@todo
95 dataOut->m_collisionFlags = m_collisionFlags;
96 dataOut->m_islandTag1 = m_islandTag1;
97 dataOut->m_companionId = m_companionId;
98 dataOut->m_activationState1 = m_activationState1;
99 dataOut->m_deactivationTime = m_deactivationTime;
100 dataOut->m_friction = m_friction;
101 dataOut->m_rollingFriction = m_rollingFriction;
102 dataOut->m_contactDamping = m_contactDamping;
103 dataOut->m_contactStiffness = m_contactStiffness;
104 dataOut->m_restitution = m_restitution;
105 dataOut->m_internalType = m_internalType;
106
107 char* name = (char*)serializer->findNameForPointer(this);
108 dataOut->m_name = (char*)serializer->getUniquePointer(name);
109 if (dataOut->m_name)
110 {
111 serializer->serializeName(name);
112 }
113 dataOut->m_hitFraction = m_hitFraction;
114 dataOut->m_ccdSweptSphereRadius = m_ccdSweptSphereRadius;
115 dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold;
116 dataOut->m_checkCollideWith = m_checkCollideWith;
117 if (m_broadphaseHandle)
118 {
119 dataOut->m_collisionFilterGroup = m_broadphaseHandle->m_collisionFilterGroup;
120 dataOut->m_collisionFilterMask = m_broadphaseHandle->m_collisionFilterMask;
121 dataOut->m_uniqueId = m_broadphaseHandle->m_uniqueId;
122 }
123 else
124 {
125 dataOut->m_collisionFilterGroup = 0;
126 dataOut->m_collisionFilterMask = 0;
127 dataOut->m_uniqueId = -1;
128 }
129 return btCollisionObjectDataName;
130 }
131
132 void btCollisionObject::serializeSingleObject(class btSerializer* serializer) const
133 {
134 int len = calculateSerializeBufferSize();
135 btChunk* chunk = serializer->allocate(len, 1);
136 const char* structType = serialize(chunk->m_oldPtr, serializer);
137 serializer->finalizeChunk(chunk, structType, BT_COLLISIONOBJECT_CODE, (void*)this);
138 }
btBroadphaseProxy.h
btCollisionObject.h
ACTIVE_TAG
#define ACTIVE_TAG
Definition: btCollisionObject.h:22
btCollisionObjectData
#define btCollisionObjectData
Definition: btCollisionObject.h:42
DISABLE_DEACTIVATION
#define DISABLE_DEACTIVATION
Definition: btCollisionObject.h:25
btCollisionObjectDataName
#define btCollisionObjectDataName
Definition: btCollisionObject.h:43
DISABLE_SIMULATION
#define DISABLE_SIMULATION
Definition: btCollisionObject.h:26
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
BT_LARGE_FLOAT
#define BT_LARGE_FLOAT
Definition: btScalar.h:316
btSerializer.h
BT_COLLISIONOBJECT_CODE
#define BT_COLLISIONOBJECT_CODE
Definition: btSerializer.h:111
btChunk
Definition: btSerializer.h:48
btChunk::m_oldPtr
void * m_oldPtr
Definition: btSerializer.h:52
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:51
btCollisionObject::CF_STATIC_OBJECT
@ CF_STATIC_OBJECT
Definition: btCollisionObject.h:132
btCollisionObject::CF_KINEMATIC_OBJECT
@ CF_KINEMATIC_OBJECT
Definition: btCollisionObject.h:133
btCollisionObject::serialize
virtual const char * serialize(void *dataBuffer, class btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
Definition: btCollisionObject.cpp:81
btCollisionObject::m_checkCollideWith
int m_checkCollideWith
If some object should have elaborate collision filtering by sub-classes.
Definition: btCollisionObject.h:117
btCollisionObject::m_worldTransform
btTransform m_worldTransform
Definition: btCollisionObject.h:53
btCollisionObject::m_collisionShape
btCollisionShape * m_collisionShape
Definition: btCollisionObject.h:68
btCollisionObject::serializeSingleObject
virtual void serializeSingleObject(class btSerializer *serializer) const
Definition: btCollisionObject.cpp:132
btCollisionObject::m_friction
btScalar m_friction
Definition: btCollisionObject.h:86
btCollisionObject::m_interpolationLinearVelocity
btVector3 m_interpolationLinearVelocity
Definition: btCollisionObject.h:60
btCollisionObject::activate
void activate(bool forceActivation=false) const
Definition: btCollisionObject.cpp:72
btCollisionObject::setActivationState
void setActivationState(int newState) const
Definition: btCollisionObject.cpp:61
btCollisionObject::m_interpolationAngularVelocity
btVector3 m_interpolationAngularVelocity
Definition: btCollisionObject.h:61
btCollisionObject::m_internalType
int m_internalType
m_internalType is reserved to distinguish Bullet's btCollisionObject, btRigidBody,...
Definition: btCollisionObject.h:95
btCollisionObject::m_anisotropicFriction
btVector3 m_anisotropicFriction
Definition: btCollisionObject.h:63
btCollisionObject::m_activationState1
int m_activationState1
Definition: btCollisionObject.h:83
btCollisionObject::m_ccdSweptSphereRadius
btScalar m_ccdSweptSphereRadius
Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
Definition: btCollisionObject.h:111
btCollisionObject::calculateSerializeBufferSize
virtual int calculateSerializeBufferSize() const
Definition: btCollisionObject.h:685
btCollisionObject::m_interpolationWorldTransform
btTransform m_interpolationWorldTransform
m_interpolationWorldTransform is used for CCD and interpolation it can be either previous or future (...
Definition: btCollisionObject.h:57
btCollisionObject::forceActivationState
void forceActivationState(int newState) const
Definition: btCollisionObject.cpp:67
btCollisionObject::m_deactivationTime
btScalar m_deactivationTime
Definition: btCollisionObject.h:84
btCollisionObject::~btCollisionObject
virtual ~btCollisionObject()
Definition: btCollisionObject.cpp:57
btCollisionObject::m_companionId
int m_companionId
Definition: btCollisionObject.h:80
btCollisionObject::btCollisionObject
btCollisionObject()
Definition: btCollisionObject.cpp:20
btCollisionObject::m_ccdMotionThreshold
btScalar m_ccdMotionThreshold
Don't do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold...
Definition: btCollisionObject.h:114
btCollisionObject::m_contactProcessingThreshold
btScalar m_contactProcessingThreshold
Definition: btCollisionObject.h:65
btCollisionObject::m_contactDamping
btScalar m_contactDamping
Definition: btCollisionObject.h:90
btCollisionObject::m_collisionFlags
int m_collisionFlags
Definition: btCollisionObject.h:77
btCollisionObject::m_broadphaseHandle
btBroadphaseProxy * m_broadphaseHandle
Definition: btCollisionObject.h:67
btCollisionObject::m_hasAnisotropicFriction
int m_hasAnisotropicFriction
Definition: btCollisionObject.h:64
btCollisionObject::m_rollingFriction
btScalar m_rollingFriction
Definition: btCollisionObject.h:88
btCollisionObject::m_islandTag1
int m_islandTag1
Definition: btCollisionObject.h:79
btCollisionObject::m_hitFraction
btScalar m_hitFraction
time of impact calculation
Definition: btCollisionObject.h:108
btCollisionObject::m_restitution
btScalar m_restitution
Definition: btCollisionObject.h:87
btCollisionObject::m_contactStiffness
btScalar m_contactStiffness
Definition: btCollisionObject.h:91
btSerializer
Definition: btSerializer.h:66
btSerializer::allocate
virtual btChunk * allocate(size_t size, int numElements)=0
btSerializer::findNameForPointer
virtual const char * findNameForPointer(const void *ptr) const =0
btSerializer::serializeName
virtual void serializeName(const char *ptr)=0
btSerializer::getUniquePointer
virtual void * getUniquePointer(void *oldPtr)=0
btSerializer::finalizeChunk
virtual void finalizeChunk(btChunk *chunk, const char *structType, int chunkCode, void *oldPtr)=0
btTransform::serialize
void serialize(struct btTransformData &dataOut) const
Definition: btTransform.h:256
btTransform::setIdentity
void setIdentity()
Set this transformation to the identity.
Definition: btTransform.h:166
btVector3::serialize
void serialize(struct btVector3Data &dataOut) const
Definition: btVector3.h:1317
btBroadphaseProxy::m_collisionFilterMask
int m_collisionFilterMask
Definition: btBroadphaseProxy.h:104
btBroadphaseProxy::m_collisionFilterGroup
int m_collisionFilterGroup
Definition: btBroadphaseProxy.h:103
btBroadphaseProxy::m_uniqueId
int m_uniqueId
Definition: btBroadphaseProxy.h:106