Blender V2.61 - r43446

btCollisionShape.cpp

Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
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 #include "BulletCollision/CollisionShapes/btCollisionShape.h"
00016 #include "LinearMath/btSerializer.h"
00017 
00018 /*
00019   Make sure this dummy function never changes so that it
00020   can be used by probes that are checking whether the
00021   library is actually installed.
00022 */
00023 extern "C" 
00024 {
00025 void btBulletCollisionProbe ();
00026 
00027 void btBulletCollisionProbe () {}
00028 }
00029 
00030 
00031 
00032 void    btCollisionShape::getBoundingSphere(btVector3& center,btScalar& radius) const
00033 {
00034     btTransform tr;
00035     tr.setIdentity();
00036     btVector3 aabbMin,aabbMax;
00037 
00038     getAabb(tr,aabbMin,aabbMax);
00039 
00040     radius = (aabbMax-aabbMin).length()*btScalar(0.5);
00041     center = (aabbMin+aabbMax)*btScalar(0.5);
00042 }
00043 
00044 
00045 btScalar    btCollisionShape::getContactBreakingThreshold(btScalar defaultContactThreshold) const
00046 {
00047     return getAngularMotionDisc() * defaultContactThreshold;
00048 }
00049 
00050 btScalar    btCollisionShape::getAngularMotionDisc() const
00051 {
00053     btVector3   center;
00054     btScalar disc;
00055     getBoundingSphere(center,disc);
00056     disc += (center).length();
00057     return disc;
00058 }
00059 
00060 void btCollisionShape::calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const
00061 {
00062     //start with static aabb
00063     getAabb(curTrans,temporalAabbMin,temporalAabbMax);
00064 
00065     btScalar temporalAabbMaxx = temporalAabbMax.getX();
00066     btScalar temporalAabbMaxy = temporalAabbMax.getY();
00067     btScalar temporalAabbMaxz = temporalAabbMax.getZ();
00068     btScalar temporalAabbMinx = temporalAabbMin.getX();
00069     btScalar temporalAabbMiny = temporalAabbMin.getY();
00070     btScalar temporalAabbMinz = temporalAabbMin.getZ();
00071 
00072     // add linear motion
00073     btVector3 linMotion = linvel*timeStep;
00075     if (linMotion.x() > btScalar(0.))
00076         temporalAabbMaxx += linMotion.x(); 
00077     else
00078         temporalAabbMinx += linMotion.x();
00079     if (linMotion.y() > btScalar(0.))
00080         temporalAabbMaxy += linMotion.y(); 
00081     else
00082         temporalAabbMiny += linMotion.y();
00083     if (linMotion.z() > btScalar(0.))
00084         temporalAabbMaxz += linMotion.z(); 
00085     else
00086         temporalAabbMinz += linMotion.z();
00087 
00088     //add conservative angular motion
00089     btScalar angularMotion = angvel.length() * getAngularMotionDisc() * timeStep;
00090     btVector3 angularMotion3d(angularMotion,angularMotion,angularMotion);
00091     temporalAabbMin = btVector3(temporalAabbMinx,temporalAabbMiny,temporalAabbMinz);
00092     temporalAabbMax = btVector3(temporalAabbMaxx,temporalAabbMaxy,temporalAabbMaxz);
00093 
00094     temporalAabbMin -= angularMotion3d;
00095     temporalAabbMax += angularMotion3d;
00096 }
00097 
00099 const char* btCollisionShape::serialize(void* dataBuffer, btSerializer* serializer) const
00100 {
00101     btCollisionShapeData* shapeData = (btCollisionShapeData*) dataBuffer;
00102     char* name = (char*) serializer->findNameForPointer(this);
00103     shapeData->m_name = (char*)serializer->getUniquePointer(name);
00104     if (shapeData->m_name)
00105     {
00106         serializer->serializeName(name);
00107     }
00108     shapeData->m_shapeType = m_shapeType;
00109     //shapeData->m_padding//??
00110     return "btCollisionShapeData";
00111 }
00112 
00113 void    btCollisionShape::serializeSingleShape(btSerializer* serializer) const
00114 {
00115     int len = calculateSerializeBufferSize();
00116     btChunk* chunk = serializer->allocate(len,1);
00117     const char* structType = serialize(chunk->m_oldPtr, serializer);
00118     serializer->finalizeChunk(chunk,structType,BT_SHAPE_CODE,(void*)this);
00119 }