Ray.h 1.8 KB

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