ConvexHullShape.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Collision/Common.h>
  7. #include <AnKi/Util/WeakArray.h>
  8. namespace anki
  9. {
  10. /// @addtogroup collision
  11. /// @{
  12. /// Convex hull collision shape
  13. class ConvexHullShape
  14. {
  15. public:
  16. static constexpr CollisionShapeType CLASS_TYPE = CollisionShapeType::CONVEX_HULL;
  17. /// Will not initialize any memory, nothing.
  18. ConvexHullShape()
  19. {
  20. }
  21. ConvexHullShape(const ConvexHullShape& other)
  22. {
  23. operator=(other);
  24. }
  25. /// In initializes the storage that holds the point cloud using a predefined buffer. The convex hull is not the
  26. /// owner of the storage.
  27. /// @param points The base of the storage buffer. Size should be @a pointCount * sizeof(Vec4)
  28. /// @param pointCount The number of points
  29. ConvexHullShape(const Vec4* points, U32 pointCount)
  30. : m_trf(Transform::getIdentity())
  31. , m_invTrf(Transform::getIdentity())
  32. , m_points(points)
  33. , m_pointCount(pointCount)
  34. , m_trfIdentity(true)
  35. {
  36. check();
  37. }
  38. ConvexHullShape& operator=(const ConvexHullShape& b)
  39. {
  40. b.check();
  41. m_trf = b.m_trf;
  42. m_invTrf = b.m_invTrf;
  43. m_points = b.m_points;
  44. m_pointCount = b.m_pointCount;
  45. m_trfIdentity = b.m_trfIdentity;
  46. return *this;
  47. }
  48. /// Get points in local space.
  49. ConstWeakArray<Vec4> getPoints() const
  50. {
  51. check();
  52. return ConstWeakArray<Vec4>(m_points, m_pointCount);
  53. }
  54. /// Get current transform.
  55. const Transform& getTransform() const
  56. {
  57. check();
  58. return m_trf;
  59. }
  60. const Transform& getInvertTransform() const
  61. {
  62. check();
  63. return m_invTrf;
  64. }
  65. Bool isTransformIdentity() const
  66. {
  67. return m_trfIdentity;
  68. }
  69. void setTransform(const Transform& trf);
  70. /// Get a transformed.
  71. ANKI_USE_RESULT ConvexHullShape getTransformed(const Transform& trf) const;
  72. /// Compute the GJK support.
  73. ANKI_USE_RESULT Vec4 computeSupport(const Vec4& dir) const;
  74. private:
  75. Transform m_trf;
  76. Transform m_invTrf;
  77. const Vec4* m_points
  78. #if ANKI_ENABLE_ASSERTIONS
  79. = nullptr
  80. #endif
  81. ;
  82. U32 m_pointCount
  83. #if ANKI_ENABLE_ASSERTIONS
  84. = 0
  85. #endif
  86. ;
  87. Bool m_trfIdentity; ///< Optimization.
  88. void check() const
  89. {
  90. ANKI_ASSERT(m_points && m_pointCount > 0);
  91. }
  92. };
  93. /// @}
  94. } // end namespace anki