btConvexHullComputer.h 3.7 KB

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