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 
17 #include "btCollisionObject.h"
19 
21  : m_anisotropicFriction(1.f,1.f,1.f),
22  m_hasAnisotropicFriction(false),
23  m_contactProcessingThreshold(BT_LARGE_FLOAT),
24  m_broadphaseHandle(0),
25  m_collisionShape(0),
26  m_extensionPointer(0),
27  m_rootCollisionShape(0),
28  m_collisionFlags(btCollisionObject::CF_STATIC_OBJECT),
29  m_islandTag1(-1),
30  m_companionId(-1),
31  m_activationState1(1),
32  m_deactivationTime(btScalar(0.)),
33  m_friction(btScalar(0.5)),
34  m_restitution(btScalar(0.)),
35  m_rollingFriction(0.0f),
36  m_internalType(CO_COLLISION_OBJECT),
37  m_userObjectPointer(0),
38  m_userIndex(-1),
39  m_hitFraction(btScalar(1.)),
40  m_ccdSweptSphereRadius(btScalar(0.)),
41  m_ccdMotionThreshold(btScalar(0.)),
42  m_checkCollideWith(false),
43  m_updateRevision(0)
44 {
46 }
47 
49 {
50 }
51 
52 void btCollisionObject::setActivationState(int newState) const
53 {
55  m_activationState1 = newState;
56 }
57 
59 {
60  m_activationState1 = newState;
61 }
62 
63 void btCollisionObject::activate(bool forceActivation) const
64 {
65  if (forceActivation || !(m_collisionFlags & (CF_STATIC_OBJECT|CF_KINEMATIC_OBJECT)))
66  {
69  }
70 }
71 
72 const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* serializer) const
73 {
74 
75  btCollisionObjectData* dataOut = (btCollisionObjectData*)dataBuffer;
76 
77  m_worldTransform.serialize(dataOut->m_worldTransform);
78  m_interpolationWorldTransform.serialize(dataOut->m_interpolationWorldTransform);
79  m_interpolationLinearVelocity.serialize(dataOut->m_interpolationLinearVelocity);
80  m_interpolationAngularVelocity.serialize(dataOut->m_interpolationAngularVelocity);
81  m_anisotropicFriction.serialize(dataOut->m_anisotropicFriction);
82  dataOut->m_hasAnisotropicFriction = m_hasAnisotropicFriction;
83  dataOut->m_contactProcessingThreshold = m_contactProcessingThreshold;
84  dataOut->m_broadphaseHandle = 0;
85  dataOut->m_collisionShape = serializer->getUniquePointer(m_collisionShape);
86  dataOut->m_rootCollisionShape = 0;//@todo
87  dataOut->m_collisionFlags = m_collisionFlags;
88  dataOut->m_islandTag1 = m_islandTag1;
89  dataOut->m_companionId = m_companionId;
90  dataOut->m_activationState1 = m_activationState1;
91  dataOut->m_deactivationTime = m_deactivationTime;
92  dataOut->m_friction = m_friction;
93  dataOut->m_rollingFriction = m_rollingFriction;
94  dataOut->m_restitution = m_restitution;
95  dataOut->m_internalType = m_internalType;
96 
97  char* name = (char*) serializer->findNameForPointer(this);
98  dataOut->m_name = (char*)serializer->getUniquePointer(name);
99  if (dataOut->m_name)
100  {
101  serializer->serializeName(name);
102  }
103  dataOut->m_hitFraction = m_hitFraction;
104  dataOut->m_ccdSweptSphereRadius = m_ccdSweptSphereRadius;
105  dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold;
106  dataOut->m_checkCollideWith = m_checkCollideWith;
107 
109 }
110 
111 
113 {
114  int len = calculateSerializeBufferSize();
115  btChunk* chunk = serializer->allocate(len,1);
116  const char* structType = serialize(chunk->m_oldPtr, serializer);
117  serializer->finalizeChunk(chunk,structType,BT_COLLISIONOBJECT_CODE,(void*)this);
118 }
#define ACTIVE_TAG
#define BT_LARGE_FLOAT
Definition: btScalar.h:280
btScalar m_ccdMotionThreshold
Don't do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold...
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::
virtual int calculateSerializeBufferSize() const
virtual void * getUniquePointer(void *oldPtr)=0
void setIdentity()
Set this transformation to the identity.
Definition: btTransform.h:172
btScalar m_hitFraction
time of impact calculation
#define btCollisionObjectData
btTransform m_worldTransform
btCollisionShape * m_collisionShape
void forceActivationState(int newState) const
btVector3 m_anisotropicFriction
virtual const char * serialize(void *dataBuffer, class btSerializer *serializer) const
fills the dataBuffer and returns the struct name (and 0 on failure)
void setActivationState(int newState) const
#define btCollisionObjectDataName
int m_internalType
m_internalType is reserved to distinguish Bullet's btCollisionObject, btRigidBody, btSoftBody, btGhostObject etc.
void serialize(struct btVector3Data &dataOut) const
Definition: btVector3.h:1340
btCollisionObject can be used to manage collision detection objects.
#define DISABLE_SIMULATION
btScalar m_contactProcessingThreshold
#define BT_COLLISIONOBJECT_CODE
Definition: btSerializer.h:119
void activate(bool forceActivation=false) const
virtual void finalizeChunk(btChunk *chunk, const char *structType, int chunkCode, void *oldPtr)=0
virtual void serializeName(const char *ptr)=0
btVector3 m_interpolationAngularVelocity
int m_checkCollideWith
If some object should have elaborate collision filtering by sub-classes.
#define DISABLE_DEACTIVATION
virtual void serializeSingleObject(class btSerializer *serializer) const
virtual const char * findNameForPointer(const void *ptr) const =0
void serialize(struct btTransformData &dataOut) const
Definition: btTransform.h:267
btVector3 m_interpolationLinearVelocity
void * m_oldPtr
Definition: btSerializer.h:56
virtual btChunk * allocate(size_t size, int numElements)=0
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:278