btCylinderShape.h

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 
00016 #ifndef CYLINDER_MINKOWSKI_H
00017 #define CYLINDER_MINKOWSKI_H
00018 
00019 #include "btBoxShape.h"
00020 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
00021 #include "LinearMath/btVector3.h"
00022 
00024 class btCylinderShape : public btConvexInternalShape
00025 
00026 {
00027 
00028 protected:
00029 
00030         int     m_upAxis;
00031 
00032 public:
00033 
00034         btVector3 getHalfExtentsWithMargin() const
00035         {
00036                 btVector3 halfExtents = getHalfExtentsWithoutMargin();
00037                 btVector3 margin(getMargin(),getMargin(),getMargin());
00038                 halfExtents += margin;
00039                 return halfExtents;
00040         }
00041         
00042         const btVector3& getHalfExtentsWithoutMargin() const
00043         {
00044                 return m_implicitShapeDimensions;//changed in Bullet 2.63: assume the scaling and margin are included
00045         }
00046 
00047         btCylinderShape (const btVector3& halfExtents);
00048         
00049         void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
00050 
00051         virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) const;
00052 
00053         virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
00054 
00055         virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
00056 
00057         virtual void setMargin(btScalar collisionMargin)
00058         {
00059                 //correct the m_implicitShapeDimensions for the margin
00060                 btVector3 oldMargin(getMargin(),getMargin(),getMargin());
00061                 btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
00062                 
00063                 btConvexInternalShape::setMargin(collisionMargin);
00064                 btVector3 newMargin(getMargin(),getMargin(),getMargin());
00065                 m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin;
00066 
00067         }
00068 
00069         virtual btVector3       localGetSupportingVertex(const btVector3& vec) const
00070         {
00071 
00072                 btVector3 supVertex;
00073                 supVertex = localGetSupportingVertexWithoutMargin(vec);
00074                 
00075                 if ( getMargin()!=btScalar(0.) )
00076                 {
00077                         btVector3 vecnorm = vec;
00078                         if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
00079                         {
00080                                 vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
00081                         } 
00082                         vecnorm.normalize();
00083                         supVertex+= getMargin() * vecnorm;
00084                 }
00085                 return supVertex;
00086         }
00087 
00088 
00089         //use box inertia
00090         //      virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) const;
00091 
00092 
00093         int     getUpAxis() const
00094         {
00095                 return m_upAxis;
00096         }
00097 
00098         virtual btScalar getRadius() const
00099         {
00100                 return getHalfExtentsWithMargin().getX();
00101         }
00102 
00103         //debugging
00104         virtual const char*     getName()const
00105         {
00106                 return "CylinderY";
00107         }
00108 
00109         virtual int     calculateSerializeBufferSize() const;
00110 
00112         virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
00113 
00114 };
00115 
00116 class btCylinderShapeX : public btCylinderShape
00117 {
00118 public:
00119         btCylinderShapeX (const btVector3& halfExtents);
00120 
00121         virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
00122         virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
00123         
00124                 //debugging
00125         virtual const char*     getName()const
00126         {
00127                 return "CylinderX";
00128         }
00129 
00130         virtual btScalar getRadius() const
00131         {
00132                 return getHalfExtentsWithMargin().getY();
00133         }
00134 
00135 };
00136 
00137 class btCylinderShapeZ : public btCylinderShape
00138 {
00139 public:
00140         btCylinderShapeZ (const btVector3& halfExtents);
00141 
00142         virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
00143         virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
00144 
00145         virtual int     getUpAxis() const
00146         {
00147                 return 2;
00148         }
00149                 //debugging
00150         virtual const char*     getName()const
00151         {
00152                 return "CylinderZ";
00153         }
00154 
00155         virtual btScalar getRadius() const
00156         {
00157                 return getHalfExtentsWithMargin().getX();
00158         }
00159 
00160 };
00161 
00163 struct  btCylinderShapeData
00164 {
00165         btConvexInternalShapeData       m_convexInternalShapeData;
00166 
00167         int     m_upAxis;
00168 
00169         char    m_padding[4];
00170 };
00171 
00172 SIMD_FORCE_INLINE       int     btCylinderShape::calculateSerializeBufferSize() const
00173 {
00174         return sizeof(btCylinderShapeData);
00175 }
00176 
00178 SIMD_FORCE_INLINE       const char*     btCylinderShape::serialize(void* dataBuffer, btSerializer* serializer) const
00179 {
00180         btCylinderShapeData* shapeData = (btCylinderShapeData*) dataBuffer;
00181         
00182         btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData,serializer);
00183 
00184         shapeData->m_upAxis = m_upAxis;
00185         
00186         return "btCylinderShapeData";
00187 }
00188 
00189 
00190 
00191 #endif //CYLINDER_MINKOWSKI_H
00192 

Generated on Mon Feb 15 22:17:03 2010 for Bullet Collision Detection & Physics Library by  doxygen 1.6.1