btCollisionObject.cpp

Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 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.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 
00017 #include "btCollisionObject.h"
00018 #include "LinearMath/btSerializer.h"
00019 
00020 btCollisionObject::btCollisionObject()
00021         :       m_anisotropicFriction(1.f,1.f,1.f),
00022         m_hasAnisotropicFriction(false),
00023         m_contactProcessingThreshold(BT_LARGE_FLOAT),
00024                 m_broadphaseHandle(0),
00025                 m_collisionShape(0),
00026                 m_extensionPointer(0),
00027                 m_rootCollisionShape(0),
00028                 m_collisionFlags(btCollisionObject::CF_STATIC_OBJECT),
00029                 m_islandTag1(-1),
00030                 m_companionId(-1),
00031                 m_activationState1(1),
00032                 m_deactivationTime(btScalar(0.)),
00033                 m_friction(btScalar(0.5)),
00034                 m_rollingFriction(0.0f),
00035                 m_restitution(btScalar(0.)),
00036                 m_internalType(CO_COLLISION_OBJECT),
00037                 m_userObjectPointer(0),
00038                 m_hitFraction(btScalar(1.)),
00039                 m_ccdSweptSphereRadius(btScalar(0.)),
00040                 m_ccdMotionThreshold(btScalar(0.)),
00041                 m_checkCollideWith(false)
00042 {
00043         m_worldTransform.setIdentity();
00044 }
00045 
00046 btCollisionObject::~btCollisionObject()
00047 {
00048 }
00049 
00050 void btCollisionObject::setActivationState(int newState) const
00051 { 
00052         if ( (m_activationState1 != DISABLE_DEACTIVATION) && (m_activationState1 != DISABLE_SIMULATION))
00053                 m_activationState1 = newState;
00054 }
00055 
00056 void btCollisionObject::forceActivationState(int newState) const
00057 {
00058         m_activationState1 = newState;
00059 }
00060 
00061 void btCollisionObject::activate(bool forceActivation) const
00062 {
00063         if (forceActivation || !(m_collisionFlags & (CF_STATIC_OBJECT|CF_KINEMATIC_OBJECT)))
00064         {
00065                 setActivationState(ACTIVE_TAG);
00066                 m_deactivationTime = btScalar(0.);
00067         }
00068 }
00069 
00070 const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* serializer) const
00071 {
00072 
00073         btCollisionObjectData* dataOut = (btCollisionObjectData*)dataBuffer;
00074 
00075         m_worldTransform.serialize(dataOut->m_worldTransform);
00076         m_interpolationWorldTransform.serialize(dataOut->m_interpolationWorldTransform);
00077         m_interpolationLinearVelocity.serialize(dataOut->m_interpolationLinearVelocity);
00078         m_interpolationAngularVelocity.serialize(dataOut->m_interpolationAngularVelocity);
00079         m_anisotropicFriction.serialize(dataOut->m_anisotropicFriction);
00080         dataOut->m_hasAnisotropicFriction = m_hasAnisotropicFriction;
00081         dataOut->m_contactProcessingThreshold = m_contactProcessingThreshold;
00082         dataOut->m_broadphaseHandle = 0;
00083         dataOut->m_collisionShape = serializer->getUniquePointer(m_collisionShape);
00084         dataOut->m_rootCollisionShape = 0;//@todo
00085         dataOut->m_collisionFlags = m_collisionFlags;
00086         dataOut->m_islandTag1 = m_islandTag1;
00087         dataOut->m_companionId = m_companionId;
00088         dataOut->m_activationState1 = m_activationState1;
00089         dataOut->m_deactivationTime = m_deactivationTime;
00090         dataOut->m_friction = m_friction;
00091         dataOut->m_rollingFriction = m_rollingFriction;
00092         dataOut->m_restitution = m_restitution;
00093         dataOut->m_internalType = m_internalType;
00094         
00095         char* name = (char*) serializer->findNameForPointer(this);
00096         dataOut->m_name = (char*)serializer->getUniquePointer(name);
00097         if (dataOut->m_name)
00098         {
00099                 serializer->serializeName(name);
00100         }
00101         dataOut->m_hitFraction = m_hitFraction;
00102         dataOut->m_ccdSweptSphereRadius = m_ccdSweptSphereRadius;
00103         dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold;
00104         dataOut->m_checkCollideWith = m_checkCollideWith;
00105 
00106         return btCollisionObjectDataName;
00107 }
00108 
00109 
00110 void btCollisionObject::serializeSingleObject(class btSerializer* serializer) const
00111 {
00112         int len = calculateSerializeBufferSize();
00113         btChunk* chunk = serializer->allocate(len,1);
00114         const char* structType = serialize(chunk->m_oldPtr, serializer);
00115         serializer->finalizeChunk(chunk,structType,BT_COLLISIONOBJECT_CODE,(void*)this);
00116 }