Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/ggz2/src/external/bullet/BulletCollision/CollisionShapes/btCompoundShape.h @ 12373

Last change on this file since 12373 was 5738, checked in by landauf, 15 years ago

merged libraries2 back to trunk

  • Property svn:eol-style set to native
File size: 5.6 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/// The btCompoundShape allows to store multiple other btCollisionShapes
50/// This allows for moving concave collision objects. This is more general then the static concave btBvhTriangleMeshShape.
51/// It has an (optional) dynamic aabb tree to accelerate early rejection tests.
52/// @todo: This aabb tree can also be use to speed up ray tests on btCompoundShape, see http://code.google.com/p/bullet/issues/detail?id=25
53/// Currently, removal of child shapes is only supported when disabling the aabb tree (pass 'false' in the constructor of btCompoundShape)
54ATTRIBUTE_ALIGNED16(class) btCompoundShape      : public btCollisionShape
55{
56        btAlignedObjectArray<btCompoundShapeChild> m_children;
57        btVector3                                               m_localAabbMin;
58        btVector3                                               m_localAabbMax;
59
60        btDbvt*                                                 m_dynamicAabbTree;
61
62        ///increment m_updateRevision when adding/removing/replacing child shapes, so that some caches can be updated
63        int                                                             m_updateRevision;
64
65public:
66        BT_DECLARE_ALIGNED_ALLOCATOR();
67
68        btCompoundShape(bool enableDynamicAabbTree = true);
69
70        virtual ~btCompoundShape();
71
72        void    addChildShape(const btTransform& localTransform,btCollisionShape* shape);
73
74        /// Remove all children shapes that contain the specified shape
75        virtual void removeChildShape(btCollisionShape* shape);
76
77        void removeChildShapeByIndex(int childShapeindex);
78
79
80        int             getNumChildShapes() const
81        {
82                return int (m_children.size());
83        }
84
85        btCollisionShape* getChildShape(int index)
86        {
87                return m_children[index].m_childShape;
88        }
89        const btCollisionShape* getChildShape(int index) const
90        {
91                return m_children[index].m_childShape;
92        }
93
94        btTransform&    getChildTransform(int index)
95        {
96                return m_children[index].m_transform;
97        }
98        const btTransform&      getChildTransform(int index) const
99        {
100                return m_children[index].m_transform;
101        }
102
103        ///set a new transform for a child, and update internal data structures (local aabb and dynamic tree)
104        void    updateChildTransform(int childIndex, const btTransform& newChildTransform);
105
106
107        btCompoundShapeChild* getChildList()
108        {
109                return &m_children[0];
110        }
111
112        ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
113        virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
114
115        /** Re-calculate the local Aabb. Is called at the end of removeChildShapes.
116        Use this yourself if you modify the children or their transforms. */
117        virtual void recalculateLocalAabb(); 
118
119        virtual void    setLocalScaling(const btVector3& scaling)
120        {
121                m_localScaling = scaling;
122        }
123        virtual const btVector3& getLocalScaling() const 
124        {
125                return m_localScaling;
126        }
127
128        virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) const;
129
130        virtual void    setMargin(btScalar margin)
131        {
132                m_collisionMargin = margin;
133        }
134        virtual btScalar        getMargin() const
135        {
136                return m_collisionMargin;
137        }
138        virtual const char*     getName()const
139        {
140                return "Compound";
141        }
142
143        //this is optional, but should make collision queries faster, by culling non-overlapping nodes
144        void    createAabbTreeFromChildren();
145
146        btDbvt*                                                 getDynamicAabbTree()
147        {
148                return m_dynamicAabbTree;
149        }
150
151        ///computes the exact moment of inertia and the transform from the coordinate system defined by the principal axes of the moment of inertia
152        ///and the center of mass to the current coordinate system. "masses" points to an array of masses of the children. The resulting transform
153        ///"principal" has to be applied inversely to all children transforms in order for the local coordinate system of the compound
154        ///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
155        ///of the collision object by the principal transform.
156        void calculatePrincipalAxisTransform(btScalar* masses, btTransform& principal, btVector3& inertia) const;
157
158        int     getUpdateRevision() const
159        {
160                return m_updateRevision;
161        }
162
163private:
164        btScalar        m_collisionMargin;
165protected:
166        btVector3       m_localScaling;
167
168};
169
170
171
172#endif //COMPOUND_SHAPE_H
Note: See TracBrowser for help on using the repository browser.