Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / GIMPACTUtils / btGImpactConvexDecompositionShape.h
1 /*! \file btGImpactConvexDecompositionShape.h
2 \author Francisco León Nájera
3 */
4 /*
5 This source file is part of GIMPACT Library.
6
7 For the latest info, see http://gimpact.sourceforge.net/
8
9 Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
10 email: projectileman@yahoo.com
11
12
13 This software is provided 'as-is', without any express or implied warranty.
14 In no event will the authors be held liable for any damages arising from the use of this software.
15 Permission is granted to anyone to use this software for any purpose,
16 including commercial applications, and to alter it and redistribute it freely,
17 subject to the following restrictions:
18
19 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.
20 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
21 3. This notice may not be removed or altered from any source distribution.
22 */
23
24 #ifndef GIMPACT_CONVEX_DECOMPOSITION_SHAPE_H
25 #define GIMPACT_CONVEX_DECOMPOSITION_SHAPE_H
26
27
28 #include "BulletCollision/Gimpact/btGImpactShape.h" // box tree class
29
30
31
32 //! This class creates a decomposition from a trimesh.
33 /*!
34
35 */
36 class btGImpactConvexDecompositionShape : public btGImpactCompoundShape
37 {
38 protected:
39         btAlignedObjectArray<btGImpactMeshShapePart::TrimeshPrimitiveManager> m_trimeshInterfaces;
40
41         class GIM_ConvexDecomposition*  m_decomposition;
42
43         void buildConvexDecomposition(bool transformSubShapes);
44 public:
45
46         btGImpactConvexDecompositionShape(
47                         btStridingMeshInterface * meshInterface,
48                         const btVector3 & mesh_scale,
49                         btScalar margin = btScalar(0.01),bool children_has_transform = true)
50                         :btGImpactCompoundShape(children_has_transform)
51         {
52
53                 m_collisionMargin = margin;
54
55                 btGImpactMeshShapePart::TrimeshPrimitiveManager triInterface;
56                 triInterface.m_meshInterface = meshInterface;
57                 triInterface.m_scale = mesh_scale;
58                 triInterface.m_margin = btScalar(1.0);
59
60                 //add parts
61                 int part_count = meshInterface->getNumSubParts();
62                 for (int i=0;i< part_count;i++ )
63                 {
64                         triInterface.m_part = i;
65                         m_trimeshInterfaces.push_back(triInterface);
66                 }
67
68                 m_decomposition = 0;
69
70                 buildConvexDecomposition(children_has_transform);
71         }
72
73         virtual ~btGImpactConvexDecompositionShape();
74
75         SIMD_FORCE_INLINE btGImpactMeshShapePart::TrimeshPrimitiveManager * getTrimeshInterface(int part)
76         {
77                 return &m_trimeshInterfaces[part];
78         }
79
80         virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
81
82 };
83
84
85
86
87 #endif //GIMPACT_MESH_SHAPE_H