[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / bullet3 / src / Bullet3Geometry / b3ConvexHullComputer.h
1 /*
2 Copyright (c) 2011 Ole Kniemeyer, MAXON, www.maxon.net
3
4 This software is provided 'as-is', without any express or implied warranty.
5 In no event will the authors be held liable for any damages arising from the use of this software.
6 Permission is granted to anyone to use this software for any purpose, 
7 including commercial applications, and to alter it and redistribute it freely, 
8 subject to the following restrictions:
9
10 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.
11 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
12 3. This notice may not be removed or altered from any source distribution.
13 */
14
15 #ifndef B3_CONVEX_HULL_COMPUTER_H
16 #define B3_CONVEX_HULL_COMPUTER_H
17
18 #include "Bullet3Common/b3Vector3.h"
19 #include "Bullet3Common/b3AlignedObjectArray.h"
20
21 /// Convex hull implementation based on Preparata and Hong
22 /// See http://code.google.com/p/bullet/issues/detail?id=275
23 /// Ole Kniemeyer, MAXON Computer GmbH
24 class b3ConvexHullComputer
25 {
26 private:
27         b3Scalar compute(const void* coords, bool doubleCoords, int stride, int count, b3Scalar shrink, b3Scalar shrinkClamp);
28
29 public:
30         class Edge
31         {
32         private:
33                 int next;
34                 int reverse;
35                 int targetVertex;
36
37                 friend class b3ConvexHullComputer;
38
39         public:
40                 int getSourceVertex() const
41                 {
42                         return (this + reverse)->targetVertex;
43                 }
44
45                 int getTargetVertex() const
46                 {
47                         return targetVertex;
48                 }
49
50                 const Edge* getNextEdgeOfVertex() const  // clockwise list of all edges of a vertex
51                 {
52                         return this + next;
53                 }
54
55                 const Edge* getNextEdgeOfFace() const  // counter-clockwise list of all edges of a face
56                 {
57                         return (this + reverse)->getNextEdgeOfVertex();
58                 }
59
60                 const Edge* getReverseEdge() const
61                 {
62                         return this + reverse;
63                 }
64         };
65
66         // Vertices of the output hull
67         b3AlignedObjectArray<b3Vector3> vertices;
68
69         // Edges of the output hull
70         b3AlignedObjectArray<Edge> edges;
71
72         // Faces of the convex hull. Each entry is an index into the "edges" array pointing to an edge of the face. Faces are planar n-gons
73         b3AlignedObjectArray<int> faces;
74
75         /*
76                 Compute convex hull of "count" vertices stored in "coords". "stride" is the difference in bytes
77                 between the addresses of consecutive vertices. If "shrink" is positive, the convex hull is shrunken
78                 by that amount (each face is moved by "shrink" length units towards the center along its normal).
79                 If "shrinkClamp" is positive, "shrink" is clamped to not exceed "shrinkClamp * innerRadius", where "innerRadius"
80                 is the minimum distance of a face to the center of the convex hull.
81
82                 The returned value is the amount by which the hull has been shrunken. If it is negative, the amount was so large
83                 that the resulting convex hull is empty.
84
85                 The output convex hull can be found in the member variables "vertices", "edges", "faces".
86                 */
87         b3Scalar compute(const float* coords, int stride, int count, b3Scalar shrink, b3Scalar shrinkClamp)
88         {
89                 return compute(coords, false, stride, count, shrink, shrinkClamp);
90         }
91
92         // same as above, but double precision
93         b3Scalar compute(const double* coords, int stride, int count, b3Scalar shrink, b3Scalar shrinkClamp)
94         {
95                 return compute(coords, true, stride, count, shrink, shrinkClamp);
96         }
97 };
98
99 #endif  //B3_CONVEX_HULL_COMPUTER_H