btCollisionShape.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_COLLISION_SHAPE_H
00017 #define BT_COLLISION_SHAPE_H
00018 
00019 #include "LinearMath/btTransform.h"
00020 #include "LinearMath/btVector3.h"
00021 #include "LinearMath/btMatrix3x3.h"
00022 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" //for the shape types
00023 class btSerializer;
00024 
00025 
00027 ATTRIBUTE_ALIGNED16(class) btCollisionShape
00028 {
00029 protected:
00030         int m_shapeType;
00031         void* m_userPointer;
00032 
00033 public:
00034 
00035         BT_DECLARE_ALIGNED_ALLOCATOR();
00036 
00037         btCollisionShape() : m_shapeType (INVALID_SHAPE_PROXYTYPE), m_userPointer(0)
00038         {
00039         }
00040 
00041         virtual ~btCollisionShape()
00042         {
00043         }
00044 
00046         virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const =0;
00047 
00048         virtual void    getBoundingSphere(btVector3& center,btScalar& radius) const;
00049 
00051         virtual btScalar        getAngularMotionDisc() const;
00052 
00053         virtual btScalar        getContactBreakingThreshold(btScalar defaultContactThresholdFactor) const;
00054 
00055 
00058         void calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const;
00059 
00060 
00061 
00062         SIMD_FORCE_INLINE bool  isPolyhedral() const
00063         {
00064                 return btBroadphaseProxy::isPolyhedral(getShapeType());
00065         }
00066 
00067         SIMD_FORCE_INLINE bool  isConvex2d() const
00068         {
00069                 return btBroadphaseProxy::isConvex2d(getShapeType());
00070         }
00071 
00072         SIMD_FORCE_INLINE bool  isConvex() const
00073         {
00074                 return btBroadphaseProxy::isConvex(getShapeType());
00075         }
00076         SIMD_FORCE_INLINE bool  isNonMoving() const
00077         {
00078                 return btBroadphaseProxy::isNonMoving(getShapeType());
00079         }
00080         SIMD_FORCE_INLINE bool  isConcave() const
00081         {
00082                 return btBroadphaseProxy::isConcave(getShapeType());
00083         }
00084         SIMD_FORCE_INLINE bool  isCompound() const
00085         {
00086                 return btBroadphaseProxy::isCompound(getShapeType());
00087         }
00088 
00089         SIMD_FORCE_INLINE bool  isSoftBody() const
00090         {
00091                 return btBroadphaseProxy::isSoftBody(getShapeType());
00092         }
00093 
00095         SIMD_FORCE_INLINE bool isInfinite() const
00096         {
00097                 return btBroadphaseProxy::isInfinite(getShapeType());
00098         }
00099 
00100 #ifndef __SPU__
00101         virtual void    setLocalScaling(const btVector3& scaling) =0;
00102         virtual const btVector3& getLocalScaling() const =0;
00103         virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) const = 0;
00104 
00105 
00106 //debugging support
00107         virtual const char*     getName()const =0 ;
00108 #endif //__SPU__
00109 
00110         
00111         int             getShapeType() const { return m_shapeType; }
00112 
00115         virtual btVector3       getAnisotropicRollingFrictionDirection() const
00116         {
00117                 return btVector3(1,1,1);
00118         }
00119         virtual void    setMargin(btScalar margin) = 0;
00120         virtual btScalar        getMargin() const = 0;
00121 
00122         
00124         void    setUserPointer(void*  userPtr)
00125         {
00126                 m_userPointer = userPtr;
00127         }
00128 
00129         void*   getUserPointer() const
00130         {
00131                 return m_userPointer;
00132         }
00133 
00134         virtual int     calculateSerializeBufferSize() const;
00135 
00137         virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
00138 
00139         virtual void    serializeSingleShape(btSerializer* serializer) const;
00140 
00141 };      
00142 
00144 struct  btCollisionShapeData
00145 {
00146         char    *m_name;
00147         int             m_shapeType;
00148         char    m_padding[4];
00149 };
00150 
00151 SIMD_FORCE_INLINE       int     btCollisionShape::calculateSerializeBufferSize() const
00152 {
00153         return sizeof(btCollisionShapeData);
00154 }
00155 
00156 
00157 
00158 #endif //BT_COLLISION_SHAPE_H
00159