LineSegment.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright (C) 2009-present, 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/Math.h>
  8. namespace anki {
  9. /// @addtogroup collision
  10. /// @{
  11. /// Line segment. Line from a point to a point. P0 = origin and P1 = direction + origin
  12. class LineSegment
  13. {
  14. public:
  15. static constexpr CollisionShapeType kClassType = CollisionShapeType::kLineSegment;
  16. /// Will not initialize any memory, nothing.
  17. LineSegment()
  18. {
  19. }
  20. LineSegment(const Vec4& origin, const Vec4& direction)
  21. : m_origin(origin)
  22. , m_dir(direction)
  23. {
  24. check();
  25. }
  26. LineSegment(const LineSegment& b)
  27. {
  28. operator=(b);
  29. }
  30. LineSegment& operator=(const LineSegment& b)
  31. {
  32. b.check();
  33. m_origin = b.m_origin;
  34. m_dir = b.m_dir;
  35. return *this;
  36. }
  37. const Vec4& getOrigin() const
  38. {
  39. check();
  40. return m_origin;
  41. }
  42. void setOrigin(const Vec4& origin)
  43. {
  44. m_origin = origin;
  45. }
  46. const Vec4& getDirection() const
  47. {
  48. check();
  49. return m_dir;
  50. }
  51. void setDirection(const Vec4& dir)
  52. {
  53. m_dir = dir;
  54. }
  55. LineSegment getTransformed(const Transform& trf) const
  56. {
  57. check();
  58. LineSegment out;
  59. out.m_origin = trf.transform(m_origin);
  60. out.m_dir = Vec4(trf.getRotation() * (m_dir * trf.getScale()), 0.0f);
  61. return out;
  62. }
  63. private:
  64. Vec4 m_origin ///< P0
  65. #if ANKI_ASSERTIONS_ENABLED
  66. = Vec4(kMaxF32)
  67. #endif
  68. ;
  69. Vec4 m_dir ///< P1 = origin+dir so dir = P1-origin
  70. #if ANKI_ASSERTIONS_ENABLED
  71. = Vec4(kMaxF32)
  72. #endif
  73. ;
  74. void check() const
  75. {
  76. ANKI_ASSERT(m_origin.w != 0.0f && m_dir.w != 0.0f);
  77. }
  78. };
  79. /// @}
  80. } // end namespace anki