Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef BT_CAPSULE_SHAPE_H
00017 #define BT_CAPSULE_SHAPE_H
00018
00019 #include "btConvexInternalShape.h"
00020 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
00021
00022
00026 ATTRIBUTE_ALIGNED16(class) btCapsuleShape : public btConvexInternalShape
00027 {
00028 protected:
00029 int m_upAxis;
00030
00031 protected:
00033 btCapsuleShape() : btConvexInternalShape() {m_shapeType = CAPSULE_SHAPE_PROXYTYPE;};
00034
00035 public:
00036
00037 BT_DECLARE_ALIGNED_ALLOCATOR();
00038
00039 btCapsuleShape(btScalar radius,btScalar height);
00040
00042 virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
00043
00045 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
00046
00047 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
00048
00049 virtual void setMargin(btScalar collisionMargin)
00050 {
00051
00052 btVector3 oldMargin(getMargin(),getMargin(),getMargin());
00053 btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
00054
00055 btConvexInternalShape::setMargin(collisionMargin);
00056 btVector3 newMargin(getMargin(),getMargin(),getMargin());
00057 m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin;
00058
00059 }
00060
00061 virtual void getAabb (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
00062 {
00063 btVector3 halfExtents(getRadius(),getRadius(),getRadius());
00064 halfExtents[m_upAxis] = getRadius() + getHalfHeight();
00065 halfExtents += btVector3(getMargin(),getMargin(),getMargin());
00066 btMatrix3x3 abs_b = t.getBasis().absolute();
00067 btVector3 center = t.getOrigin();
00068 btVector3 extent = halfExtents.dot3(abs_b[0], abs_b[1], abs_b[2]);
00069
00070 aabbMin = center - extent;
00071 aabbMax = center + extent;
00072 }
00073
00074 virtual const char* getName()const
00075 {
00076 return "CapsuleShape";
00077 }
00078
00079 int getUpAxis() const
00080 {
00081 return m_upAxis;
00082 }
00083
00084 btScalar getRadius() const
00085 {
00086 int radiusAxis = (m_upAxis+2)%3;
00087 return m_implicitShapeDimensions[radiusAxis];
00088 }
00089
00090 btScalar getHalfHeight() const
00091 {
00092 return m_implicitShapeDimensions[m_upAxis];
00093 }
00094
00095 virtual void setLocalScaling(const btVector3& scaling)
00096 {
00097 btVector3 oldMargin(getMargin(),getMargin(),getMargin());
00098 btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
00099 btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling;
00100
00101 btConvexInternalShape::setLocalScaling(scaling);
00102
00103 m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin;
00104
00105 }
00106
00107 virtual btVector3 getAnisotropicRollingFrictionDirection() const
00108 {
00109 btVector3 aniDir(0,0,0);
00110 aniDir[getUpAxis()]=1;
00111 return aniDir;
00112 }
00113
00114
00115 virtual int calculateSerializeBufferSize() const;
00116
00118 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
00119
00120
00121 };
00122
00125 class btCapsuleShapeX : public btCapsuleShape
00126 {
00127 public:
00128
00129 btCapsuleShapeX(btScalar radius,btScalar height);
00130
00131
00132 virtual const char* getName()const
00133 {
00134 return "CapsuleX";
00135 }
00136
00137
00138
00139 };
00140
00143 class btCapsuleShapeZ : public btCapsuleShape
00144 {
00145 public:
00146 btCapsuleShapeZ(btScalar radius,btScalar height);
00147
00148
00149 virtual const char* getName()const
00150 {
00151 return "CapsuleZ";
00152 }
00153
00154
00155 };
00156
00158 struct btCapsuleShapeData
00159 {
00160 btConvexInternalShapeData m_convexInternalShapeData;
00161
00162 int m_upAxis;
00163
00164 char m_padding[4];
00165 };
00166
00167 SIMD_FORCE_INLINE int btCapsuleShape::calculateSerializeBufferSize() const
00168 {
00169 return sizeof(btCapsuleShapeData);
00170 }
00171
00173 SIMD_FORCE_INLINE const char* btCapsuleShape::serialize(void* dataBuffer, btSerializer* serializer) const
00174 {
00175 btCapsuleShapeData* shapeData = (btCapsuleShapeData*) dataBuffer;
00176
00177 btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData,serializer);
00178
00179 shapeData->m_upAxis = m_upAxis;
00180
00181 return "btCapsuleShapeData";
00182 }
00183
00184 #endif //BT_CAPSULE_SHAPE_H