LineSegment.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #ifndef ANKI_COLLISION_LINE_SEGMENT_H
  2. #define ANKI_COLLISION_LINE_SEGMENT_H
  3. #include "anki/collision/CollisionShape.h"
  4. #include "anki/math/Vec3.h"
  5. namespace anki {
  6. /// @addtogroup Collision
  7. /// @{
  8. /// Line segment. Line from a point to a point. P0 = origin and
  9. /// P1 = direction + origin
  10. class LineSegment: public CollisionShape
  11. {
  12. public:
  13. /// @name Constructors
  14. /// @{
  15. LineSegment()
  16. : CollisionShape(CST_LINE_SEG)
  17. {}
  18. LineSegment(const Vec3& origin_, const Vec3& direction)
  19. : CollisionShape(CST_LINE_SEG), origin(origin_), dir(direction)
  20. {}
  21. LineSegment(const LineSegment& b)
  22. : CollisionShape(CST_LINE_SEG), origin(b.origin), dir(b.dir)
  23. {}
  24. /// @}
  25. /// @name Accessors
  26. /// @{
  27. const Vec3& getOrigin() const
  28. {
  29. return origin;
  30. }
  31. Vec3& getOrigin()
  32. {
  33. return origin;
  34. }
  35. void setOrigin(const Vec3& x)
  36. {
  37. origin = x;
  38. }
  39. const Vec3& getDirection() const
  40. {
  41. return dir;
  42. }
  43. Vec3& getDirection()
  44. {
  45. return dir;
  46. }
  47. void setDirection(const Vec3& x)
  48. {
  49. dir = x;
  50. }
  51. /// @}
  52. /// @name Operators
  53. /// @{
  54. LineSegment& operator=(const LineSegment& b)
  55. {
  56. origin = b.origin;
  57. dir = b.dir;
  58. return *this;
  59. }
  60. /// @}
  61. /// Check for collision
  62. template<typename T>
  63. Bool collide(const T& x) const
  64. {
  65. return detail::collide(*this, x);
  66. }
  67. /// Implements CollisionShape::accept
  68. void accept(MutableVisitor& v)
  69. {
  70. v.visit(*this);
  71. }
  72. /// Implements CollisionShape::accept
  73. void accept(ConstVisitor& v) const
  74. {
  75. v.visit(*this);
  76. }
  77. /// Implements CollisionShape::testPlane
  78. F32 testPlane(const Plane& p) const;
  79. /// Implements CollisionShape::transform
  80. void transform(const Transform& trf)
  81. {
  82. *this = getTransformed(trf);
  83. }
  84. /// Implements CollisionShape::toAabb
  85. void toAabb(Aabb& b) const;
  86. LineSegment getTransformed(const Transform& transform) const;
  87. private:
  88. /// @name Data
  89. /// @{
  90. Vec3 origin; ///< P0
  91. Vec3 dir; ///< P1 = origin+dir so dir = P1-origin
  92. /// @}
  93. };
  94. /// @}
  95. } // end namespace
  96. #endif