Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.h @ 1963

Last change on this file since 1963 was 1963, checked in by rgrieder, 16 years ago

Added Bullet physics engine.

  • Property svn:eol-style set to native
File size: 5.0 KB
Line 
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#ifndef COMPOUND_SHAPE_H
17#define COMPOUND_SHAPE_H
18
19#include "btCollisionShape.h"
20
21#include "LinearMath/btVector3.h"
22#include "LinearMath/btTransform.h"
23#include "LinearMath/btMatrix3x3.h"
24#include "btCollisionMargin.h"
25#include "LinearMath/btAlignedObjectArray.h"
26
27//class btOptimizedBvh;
28struct btDbvt;
29
30ATTRIBUTE_ALIGNED16(struct) btCompoundShapeChild
31{
32        BT_DECLARE_ALIGNED_ALLOCATOR();
33
34        btTransform                     m_transform;
35        btCollisionShape*       m_childShape;
36        int                                     m_childShapeType;
37        btScalar                        m_childMargin;
38        struct btDbvtNode*      m_node;
39};
40
41SIMD_FORCE_INLINE bool operator==(const btCompoundShapeChild& c1, const btCompoundShapeChild& c2)
42{
43        return  ( c1.m_transform      == c2.m_transform &&
44                c1.m_childShape     == c2.m_childShape &&
45                c1.m_childShapeType == c2.m_childShapeType &&
46                c1.m_childMargin    == c2.m_childMargin );
47}
48
49/// btCompoundShape allows to store multiple other btCollisionShapes
50/// This allows for moving concave collision objects. This is more general then the static concave btBvhTriangleMeshShape.
51ATTRIBUTE_ALIGNED16(class) btCompoundShape      : public btCollisionShape
52{
53        //btAlignedObjectArray<btTransform>             m_childTransforms;
54        //btAlignedObjectArray<btCollisionShape*>       m_childShapes;
55        btAlignedObjectArray<btCompoundShapeChild> m_children;
56        btVector3                                               m_localAabbMin;
57        btVector3                                               m_localAabbMax;
58
59        //btOptimizedBvh*                                       m_aabbTree;
60        btDbvt*                                                 m_dynamicAabbTree;
61
62public:
63        BT_DECLARE_ALIGNED_ALLOCATOR();
64
65        btCompoundShape();
66
67        virtual ~btCompoundShape();
68
69        void    addChildShape(const btTransform& localTransform,btCollisionShape* shape);
70
71        /// Remove all children shapes that contain the specified shape
72        virtual void removeChildShape(btCollisionShape* shape);
73
74        void removeChildShapeByIndex(int childShapeindex);
75
76
77        int             getNumChildShapes() const
78        {
79                return int (m_children.size());
80        }
81
82        btCollisionShape* getChildShape(int index)
83        {
84                return m_children[index].m_childShape;
85        }
86        const btCollisionShape* getChildShape(int index) const
87        {
88                return m_children[index].m_childShape;
89        }
90
91        btTransform     getChildTransform(int index)
92        {
93                return m_children[index].m_transform;
94        }
95        const btTransform       getChildTransform(int index) const
96        {
97                return m_children[index].m_transform;
98        }
99
100
101        btCompoundShapeChild* getChildList()
102        {
103                return &m_children[0];
104        }
105
106        ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
107        virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
108
109        /** Re-calculate the local Aabb. Is called at the end of removeChildShapes.
110        Use this yourself if you modify the children or their transforms. */
111        virtual void recalculateLocalAabb(); 
112
113        virtual void    setLocalScaling(const btVector3& scaling)
114        {
115                m_localScaling = scaling;
116        }
117        virtual const btVector3& getLocalScaling() const 
118        {
119                return m_localScaling;
120        }
121
122        virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) const;
123
124        virtual void    setMargin(btScalar margin)
125        {
126                m_collisionMargin = margin;
127        }
128        virtual btScalar        getMargin() const
129        {
130                return m_collisionMargin;
131        }
132        virtual const char*     getName()const
133        {
134                return "Compound";
135        }
136
137        //this is optional, but should make collision queries faster, by culling non-overlapping nodes
138        void    createAabbTreeFromChildren();
139
140        btDbvt*                                                 getDynamicAabbTree()
141        {
142                return m_dynamicAabbTree;
143        }
144
145        ///computes the exact moment of inertia and the transform from the coordinate system defined by the principal axes of the moment of inertia
146        ///and the center of mass to the current coordinate system. "masses" points to an array of masses of the children. The resulting transform
147        ///"principal" has to be applied inversely to all children transforms in order for the local coordinate system of the compound
148        ///shape to be centered at the center of mass and to coincide with the principal axes. This also necessitates a correction of the world transform
149        ///of the collision object by the principal transform.
150        void calculatePrincipalAxisTransform(btScalar* masses, btTransform& principal, btVector3& inertia) const;
151
152
153private:
154        btScalar        m_collisionMargin;
155protected:
156        btVector3       m_localScaling;
157
158};
159
160
161
162#endif //COMPOUND_SHAPE_H
Note: See TracBrowser for help on using the repository browser.