Blender V2.61 - r43446
|
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_restitution(btScalar(0.)), 00035 m_internalType(CO_COLLISION_OBJECT), 00036 m_userObjectPointer(0), 00037 m_hitFraction(btScalar(1.)), 00038 m_ccdSweptSphereRadius(btScalar(0.)), 00039 m_ccdMotionThreshold(btScalar(0.)), 00040 m_checkCollideWith(false) 00041 { 00042 m_worldTransform.setIdentity(); 00043 } 00044 00045 btCollisionObject::~btCollisionObject() 00046 { 00047 } 00048 00049 void btCollisionObject::setActivationState(int newState) 00050 { 00051 if ( (m_activationState1 != DISABLE_DEACTIVATION) && (m_activationState1 != DISABLE_SIMULATION)) 00052 m_activationState1 = newState; 00053 } 00054 00055 void btCollisionObject::forceActivationState(int newState) 00056 { 00057 m_activationState1 = newState; 00058 } 00059 00060 void btCollisionObject::activate(bool forceActivation) 00061 { 00062 if (forceActivation || !(m_collisionFlags & (CF_STATIC_OBJECT|CF_KINEMATIC_OBJECT))) 00063 { 00064 setActivationState(ACTIVE_TAG); 00065 m_deactivationTime = btScalar(0.); 00066 } 00067 } 00068 00069 const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* serializer) const 00070 { 00071 00072 btCollisionObjectData* dataOut = (btCollisionObjectData*)dataBuffer; 00073 00074 m_worldTransform.serialize(dataOut->m_worldTransform); 00075 m_interpolationWorldTransform.serialize(dataOut->m_interpolationWorldTransform); 00076 m_interpolationLinearVelocity.serialize(dataOut->m_interpolationLinearVelocity); 00077 m_interpolationAngularVelocity.serialize(dataOut->m_interpolationAngularVelocity); 00078 m_anisotropicFriction.serialize(dataOut->m_anisotropicFriction); 00079 dataOut->m_hasAnisotropicFriction = m_hasAnisotropicFriction; 00080 dataOut->m_contactProcessingThreshold = m_contactProcessingThreshold; 00081 dataOut->m_broadphaseHandle = 0; 00082 dataOut->m_collisionShape = serializer->getUniquePointer(m_collisionShape); 00083 dataOut->m_rootCollisionShape = 0;//@todo 00084 dataOut->m_collisionFlags = m_collisionFlags; 00085 dataOut->m_islandTag1 = m_islandTag1; 00086 dataOut->m_companionId = m_companionId; 00087 dataOut->m_activationState1 = m_activationState1; 00088 dataOut->m_activationState1 = m_activationState1; 00089 dataOut->m_deactivationTime = m_deactivationTime; 00090 dataOut->m_friction = m_friction; 00091 dataOut->m_restitution = m_restitution; 00092 dataOut->m_internalType = m_internalType; 00093 00094 char* name = (char*) serializer->findNameForPointer(this); 00095 dataOut->m_name = (char*)serializer->getUniquePointer(name); 00096 if (dataOut->m_name) 00097 { 00098 serializer->serializeName(name); 00099 } 00100 dataOut->m_hitFraction = m_hitFraction; 00101 dataOut->m_ccdSweptSphereRadius = m_ccdSweptSphereRadius; 00102 dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold; 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 }