Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "BulletCollision/CollisionShapes/btCollisionShape.h"
00016 #include "LinearMath/btSerializer.h"
00017
00018
00019
00020
00021
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
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
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
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
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 }