btCompoundShape.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 COMPOUND_SHAPE_H
00017 #define COMPOUND_SHAPE_H
00018 
00019 #include "btCollisionShape.h"
00020 
00021 #include "LinearMath/btVector3.h"
00022 #include "LinearMath/btTransform.h"
00023 #include "LinearMath/btMatrix3x3.h"
00024 #include "btCollisionMargin.h"
00025 #include "LinearMath/btAlignedObjectArray.h"
00026 
00027 //class btOptimizedBvh;
00028 struct btDbvt;
00029 
00030 struct btCompoundShapeChild
00031 {
00032         BT_DECLARE_ALIGNED_ALLOCATOR();
00033 
00034         btTransform                     m_transform;
00035         btCollisionShape*       m_childShape;
00036         int                                     m_childShapeType;
00037         btScalar                        m_childMargin;
00038         struct btDbvtNode*      m_node;
00039 };
00040 
00041 SIMD_FORCE_INLINE bool operator==(const btCompoundShapeChild& c1, const btCompoundShapeChild& c2)
00042 {
00043         return  ( c1.m_transform      == c2.m_transform &&
00044                 c1.m_childShape     == c2.m_childShape &&
00045                 c1.m_childShapeType == c2.m_childShapeType &&
00046                 c1.m_childMargin    == c2.m_childMargin );
00047 }
00048 
00054 class btCompoundShape   : public btCollisionShape
00055 {
00056         btAlignedObjectArray<btCompoundShapeChild> m_children;
00057         btVector3                                               m_localAabbMin;
00058         btVector3                                               m_localAabbMax;
00059 
00060         btDbvt*                                                 m_dynamicAabbTree;
00061 
00063         int                                                             m_updateRevision;
00064 
00065         btScalar        m_collisionMargin;
00066 
00067 protected:
00068         btVector3       m_localScaling;
00069 
00070 public:
00071         BT_DECLARE_ALIGNED_ALLOCATOR();
00072 
00073         btCompoundShape(bool enableDynamicAabbTree = true);
00074 
00075         virtual ~btCompoundShape();
00076 
00077         void    addChildShape(const btTransform& localTransform,btCollisionShape* shape);
00078 
00080         virtual void removeChildShape(btCollisionShape* shape);
00081 
00082         void removeChildShapeByIndex(int childShapeindex);
00083 
00084 
00085         int             getNumChildShapes() const
00086         {
00087                 return int (m_children.size());
00088         }
00089 
00090         btCollisionShape* getChildShape(int index)
00091         {
00092                 return m_children[index].m_childShape;
00093         }
00094         const btCollisionShape* getChildShape(int index) const
00095         {
00096                 return m_children[index].m_childShape;
00097         }
00098 
00099         btTransform&    getChildTransform(int index)
00100         {
00101                 return m_children[index].m_transform;
00102         }
00103         const btTransform&      getChildTransform(int index) const
00104         {
00105                 return m_children[index].m_transform;
00106         }
00107 
00109         void    updateChildTransform(int childIndex, const btTransform& newChildTransform);
00110 
00111 
00112         btCompoundShapeChild* getChildList()
00113         {
00114                 return &m_children[0];
00115         }
00116 
00118         virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
00119 
00122         virtual void recalculateLocalAabb(); 
00123 
00124         virtual void    setLocalScaling(const btVector3& scaling);
00125 
00126         virtual const btVector3& getLocalScaling() const 
00127         {
00128                 return m_localScaling;
00129         }
00130 
00131         virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) const;
00132 
00133         virtual void    setMargin(btScalar margin)
00134         {
00135                 m_collisionMargin = margin;
00136         }
00137         virtual btScalar        getMargin() const
00138         {
00139                 return m_collisionMargin;
00140         }
00141         virtual const char*     getName()const
00142         {
00143                 return "Compound";
00144         }
00145 
00146 
00147         btDbvt*                                                 getDynamicAabbTree()
00148         {
00149                 return m_dynamicAabbTree;
00150         }
00151 
00157         void calculatePrincipalAxisTransform(btScalar* masses, btTransform& principal, btVector3& inertia) const;
00158 
00159         int     getUpdateRevision() const
00160         {
00161                 return m_updateRevision;
00162         }
00163 
00164         virtual int     calculateSerializeBufferSize() const;
00165 
00167         virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
00168 
00169 
00170 };
00171 
00173 struct btCompoundShapeChildData
00174 {
00175         btTransformFloatData    m_transform;
00176         btCollisionShapeData    *m_childShape;
00177         int                                             m_childShapeType;
00178         float                                   m_childMargin;
00179 };
00180 
00182 struct  btCompoundShapeData
00183 {
00184         btCollisionShapeData            m_collisionShapeData;
00185 
00186         btCompoundShapeChildData        *m_childShapePtr;
00187 
00188         int                                                     m_numChildShapes;
00189 
00190         float   m_collisionMargin;
00191 
00192 };
00193 
00194 
00195 SIMD_FORCE_INLINE       int     btCompoundShape::calculateSerializeBufferSize() const
00196 {
00197         return sizeof(btCompoundShapeData);
00198 }
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206 #endif //COMPOUND_SHAPE_H

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