Back to index

supertuxkart  0.5+dfsg1
btCompoundShape.h
Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
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 
00029 ATTRIBUTE_ALIGNED16(struct) btCompoundShapeChild
00030 {
00031        BT_DECLARE_ALIGNED_ALLOCATOR();
00032 
00033        btTransform                 m_transform;
00034        btCollisionShape*    m_childShape;
00035        int                                m_childShapeType;
00036        btScalar                    m_childMargin;
00037 };
00038        
00041 ATTRIBUTE_ALIGNED16(class) btCompoundShape       : public btCollisionShape
00042 {
00043        //btAlignedObjectArray<btTransform>              m_childTransforms;
00044        //btAlignedObjectArray<btCollisionShape*> m_childShapes;
00045        btAlignedObjectArray<btCompoundShapeChild> m_children;
00046        btVector3                                        m_localAabbMin;
00047        btVector3                                        m_localAabbMax;
00048 
00049        btOptimizedBvh*                                  m_aabbTree;
00050 
00051 public:
00052        BT_DECLARE_ALIGNED_ALLOCATOR();
00053 
00054        btCompoundShape();
00055 
00056        virtual ~btCompoundShape();
00057 
00058        void   addChildShape(const btTransform& localTransform,btCollisionShape* shape);
00059 
00060        int           getNumChildShapes() const
00061        {
00062               return int (m_children.size());
00063        }
00064 
00065        btCollisionShape* getChildShape(int index)
00066        {
00067               return m_children[index].m_childShape;
00068        }
00069        const btCollisionShape* getChildShape(int index) const
00070        {
00071               return m_children[index].m_childShape;
00072        }
00073 
00074        btTransform   getChildTransform(int index)
00075        {
00076               return m_children[index].m_transform;
00077        }
00078        const btTransform    getChildTransform(int index) const
00079        {
00080               return m_children[index].m_transform;
00081        }
00082 
00083 
00084        btCompoundShapeChild* getChildList()
00085        {
00086               return &m_children[0];
00087        }
00088 
00090        void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
00091 
00092 
00093        virtual void  setLocalScaling(const btVector3& scaling)
00094        {
00095               m_localScaling = scaling;
00096        }
00097        virtual const btVector3& getLocalScaling() const 
00098        {
00099               return m_localScaling;
00100        }
00101 
00102        virtual void  calculateLocalInertia(btScalar mass,btVector3& inertia) const;
00103        
00104        virtual int   getShapeType() const { return COMPOUND_SHAPE_PROXYTYPE;}
00105 
00106        virtual void  setMargin(btScalar margin)
00107        {
00108               m_collisionMargin = margin;
00109        }
00110        virtual btScalar     getMargin() const
00111        {
00112               return m_collisionMargin;
00113        }
00114        virtual const char*  getName()const
00115        {
00116               return "Compound";
00117        }
00118 
00119        //this is optional, but should make collision queries faster, by culling non-overlapping nodes
00120        void   createAabbTreeFromChildren();
00121 
00122        const btOptimizedBvh*                                   getAabbTree() const
00123        {
00124               return m_aabbTree;
00125        }
00126 
00127 private:
00128        btScalar      m_collisionMargin;
00129 protected:
00130        btVector3     m_localScaling;
00131 
00132 };
00133 
00134 
00135 
00136 #endif //COMPOUND_SHAPE_H