btCapsuleShape.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 BT_CAPSULE_SHAPE_H
00017 #define BT_CAPSULE_SHAPE_H
00018 
00019 #include "btConvexInternalShape.h"
00020 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
00021 
00022 
00026 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         btCapsuleShape(btScalar radius,btScalar height);
00037 
00039         virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) const;
00040 
00042         virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
00043 
00044         virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
00045         
00046         virtual void getAabb (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
00047         {
00048                         btVector3 halfExtents(getRadius(),getRadius(),getRadius());
00049                         halfExtents[m_upAxis] = getRadius() + getHalfHeight();
00050                         halfExtents += btVector3(getMargin(),getMargin(),getMargin());
00051                         btMatrix3x3 abs_b = t.getBasis().absolute();  
00052                         btVector3 center = t.getOrigin();
00053                         btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents));              
00054                         
00055                         aabbMin = center - extent;
00056                         aabbMax = center + extent;
00057         }
00058 
00059         virtual const char*     getName()const 
00060         {
00061                 return "CapsuleShape";
00062         }
00063 
00064         int     getUpAxis() const
00065         {
00066                 return m_upAxis;
00067         }
00068 
00069         btScalar        getRadius() const
00070         {
00071                 int radiusAxis = (m_upAxis+2)%3;
00072                 return m_implicitShapeDimensions[radiusAxis];
00073         }
00074 
00075         btScalar        getHalfHeight() const
00076         {
00077                 return m_implicitShapeDimensions[m_upAxis];
00078         }
00079 
00080         virtual void    setLocalScaling(const btVector3& scaling)
00081         {
00082                 btVector3 oldMargin(getMargin(),getMargin(),getMargin());
00083                 btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
00084                 btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling;
00085 
00086                 btConvexInternalShape::setLocalScaling(scaling);
00087 
00088                 m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin;
00089 
00090         }
00091 
00092         virtual int     calculateSerializeBufferSize() const;
00093 
00095         virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
00096 
00097 
00098 };
00099 
00102 class btCapsuleShapeX : public btCapsuleShape
00103 {
00104 public:
00105 
00106         btCapsuleShapeX(btScalar radius,btScalar height);
00107                 
00108         //debugging
00109         virtual const char*     getName()const
00110         {
00111                 return "CapsuleX";
00112         }
00113 
00114         
00115 
00116 };
00117 
00120 class btCapsuleShapeZ : public btCapsuleShape
00121 {
00122 public:
00123         btCapsuleShapeZ(btScalar radius,btScalar height);
00124 
00125                 //debugging
00126         virtual const char*     getName()const
00127         {
00128                 return "CapsuleZ";
00129         }
00130 
00131         
00132 };
00133 
00135 struct  btCapsuleShapeData
00136 {
00137         btConvexInternalShapeData       m_convexInternalShapeData;
00138 
00139         int     m_upAxis;
00140 
00141         char    m_padding[4];
00142 };
00143 
00144 SIMD_FORCE_INLINE       int     btCapsuleShape::calculateSerializeBufferSize() const
00145 {
00146         return sizeof(btCapsuleShapeData);
00147 }
00148 
00150 SIMD_FORCE_INLINE       const char*     btCapsuleShape::serialize(void* dataBuffer, btSerializer* serializer) const
00151 {
00152         btCapsuleShapeData* shapeData = (btCapsuleShapeData*) dataBuffer;
00153         
00154         btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData,serializer);
00155 
00156         shapeData->m_upAxis = m_upAxis;
00157         
00158         return "btCapsuleShapeData";
00159 }
00160 
00161 #endif //BT_CAPSULE_SHAPE_H

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