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 BT_CONVEX_HULL_COMPUTER_H |
16 | #define BT_CONVEX_HULL_COMPUTER_H |
17 | |
18 | #include "btAlignedObjectArray.h" |
19 | #include "btVector3.h" |
20 | |
21 | // -- GODOT start -- |
22 | namespace VHACD { |
23 | // -- GODOT end -- |
24 | |
25 | /// Convex hull implementation based on Preparata and Hong |
26 | /// See http://code.google.com/p/bullet/issues/detail?id=275 |
27 | /// Ole Kniemeyer, MAXON Computer GmbH |
28 | class btConvexHullComputer { |
29 | private: |
30 | btScalar compute(const void* coords, bool doubleCoords, int32_t stride, int32_t count, btScalar shrink, btScalar shrinkClamp); |
31 | |
32 | public: |
33 | class Edge { |
34 | private: |
35 | int32_t next; |
36 | int32_t reverse; |
37 | int32_t targetVertex; |
38 | |
39 | friend class btConvexHullComputer; |
40 | |
41 | public: |
42 | int32_t getSourceVertex() const |
43 | { |
44 | return (this + reverse)->targetVertex; |
45 | } |
46 | |
47 | int32_t getTargetVertex() const |
48 | { |
49 | return targetVertex; |
50 | } |
51 | |
52 | const Edge* getNextEdgeOfVertex() const // clockwise list of all edges of a vertex |
53 | { |
54 | return this + next; |
55 | } |
56 | |
57 | const Edge* getNextEdgeOfFace() const // counter-clockwise list of all edges of a face |
58 | { |
59 | return (this + reverse)->getNextEdgeOfVertex(); |
60 | } |
61 | |
62 | const Edge* getReverseEdge() const |
63 | { |
64 | return this + reverse; |
65 | } |
66 | }; |
67 | |
68 | // Vertices of the output hull |
69 | btAlignedObjectArray<btVector3> vertices; |
70 | |
71 | // Edges of the output hull |
72 | btAlignedObjectArray<Edge> edges; |
73 | |
74 | // 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 |
75 | btAlignedObjectArray<int32_t> faces; |
76 | |
77 | /* |
78 | Compute convex hull of "count" vertices stored in "coords". "stride" is the difference in bytes |
79 | between the addresses of consecutive vertices. If "shrink" is positive, the convex hull is shrunken |
80 | by that amount (each face is moved by "shrink" length units towards the center along its normal). |
81 | If "shrinkClamp" is positive, "shrink" is clamped to not exceed "shrinkClamp * innerRadius", where "innerRadius" |
82 | is the minimum distance of a face to the center of the convex hull. |
83 | |
84 | The returned value is the amount by which the hull has been shrunken. If it is negative, the amount was so large |
85 | that the resulting convex hull is empty. |
86 | |
87 | The output convex hull can be found in the member variables "vertices", "edges", "faces". |
88 | */ |
89 | btScalar compute(const float* coords, int32_t stride, int32_t count, btScalar shrink, btScalar shrinkClamp) |
90 | { |
91 | return compute(coords, false, stride, count, shrink, shrinkClamp); |
92 | } |
93 | |
94 | // same as above, but double precision |
95 | btScalar compute(const double* coords, int32_t stride, int32_t count, btScalar shrink, btScalar shrinkClamp) |
96 | { |
97 | return compute(coords, true, stride, count, shrink, shrinkClamp); |
98 | } |
99 | }; |
100 | |
101 | // -- GODOT start -- |
102 | }; // namespace VHACD |
103 | // -- GODOT end -- |
104 | |
105 | #endif //BT_CONVEX_HULL_COMPUTER_H |
106 | |