Plane.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. namespace anki
  8. {
  9. /// @addtogroup collision
  10. /// @{
  11. /// Plane collision shape
  12. class Plane
  13. {
  14. public:
  15. static constexpr CollisionShapeType CLASS_TYPE = CollisionShapeType::PLANE;
  16. /// Will not initialize any memory, nothing.
  17. Plane()
  18. {
  19. }
  20. /// Copy constructor
  21. Plane(const Plane& b)
  22. {
  23. operator=(b);
  24. }
  25. /// Constructor
  26. Plane(const Vec4& normal, F32 offset)
  27. : m_normal(normal)
  28. , m_offset(offset)
  29. {
  30. check();
  31. }
  32. /// @see setFrom3Points
  33. Plane(const Vec4& p0, const Vec4& p1, const Vec4& p2)
  34. {
  35. setFrom3Points(p0, p1, p2);
  36. }
  37. /// @see setFromPlaneEquation
  38. Plane(F32 a, F32 b, F32 c, F32 d)
  39. {
  40. setFromPlaneEquation(a, b, c, d);
  41. }
  42. Plane& operator=(const Plane& b)
  43. {
  44. b.check();
  45. m_normal = b.m_normal;
  46. m_offset = b.m_offset;
  47. return *this;
  48. }
  49. const Vec4& getNormal() const
  50. {
  51. check();
  52. return m_normal;
  53. }
  54. void setNormal(const Vec4& x)
  55. {
  56. m_normal = x;
  57. }
  58. F32 getOffset() const
  59. {
  60. check();
  61. return m_offset;
  62. }
  63. void setOffset(const F32 x)
  64. {
  65. m_offset = x;
  66. }
  67. /// Set the plane from 3 points
  68. void setFrom3Points(const Vec4& p0, const Vec4& p1, const Vec4& p2);
  69. /// Set from plane equation is ax+by+cz+d
  70. void setFromPlaneEquation(F32 a, F32 b, F32 c, F32 d);
  71. /// Return the transformed
  72. Plane getTransformed(const Transform& trf) const;
  73. private:
  74. Vec4 m_normal
  75. #if ANKI_ENABLE_ASSERTIONS
  76. = Vec4(MAX_F32)
  77. #endif
  78. ;
  79. F32 m_offset
  80. #if ANKI_ENABLE_ASSERTIONS
  81. = MAX_F32
  82. #endif
  83. ;
  84. void check() const
  85. {
  86. ANKI_ASSERT(m_normal.w() == 0.0f);
  87. ANKI_ASSERT(m_offset != MAX_F32);
  88. }
  89. };
  90. /// @}
  91. } // end namespace anki