ray.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include "types.h"
  25. #include "vector3.h"
  26. namespace crown
  27. {
  28. /// 3D Ray.
  29. ///
  30. /// Defined by the origin and the unit-length direction vector.
  31. struct Ray
  32. {
  33. public:
  34. /// Does nothing for efficiency.
  35. Ray();
  36. /// Constructs from @a origin and @a direction
  37. Ray(const Vector3& origin, const Vector3& direction);
  38. Ray(const Ray& ray);
  39. const Vector3& origin() const;
  40. const Vector3& direction() const;
  41. void set_origin(const Vector3& origin);
  42. void set_direction(const Vector3& direction);
  43. private:
  44. Vector3 m_origin;
  45. Vector3 m_direction;
  46. };
  47. //-----------------------------------------------------------------------------
  48. inline Ray::Ray()
  49. {
  50. }
  51. //-----------------------------------------------------------------------------
  52. inline Ray::Ray(const Vector3& origin, const Vector3& direction) : m_origin(origin), m_direction(direction)
  53. {
  54. }
  55. //-----------------------------------------------------------------------------
  56. inline Ray::Ray(const Ray& ray) : m_origin(ray.m_origin), m_direction(ray.m_direction)
  57. {
  58. }
  59. //-----------------------------------------------------------------------------
  60. inline const Vector3& Ray::origin() const
  61. {
  62. return m_origin;
  63. }
  64. //-----------------------------------------------------------------------------
  65. inline const Vector3& Ray::direction() const
  66. {
  67. return m_direction;
  68. }
  69. //-----------------------------------------------------------------------------
  70. inline void Ray::set_origin(const Vector3& origin)
  71. {
  72. m_origin = origin;
  73. }
  74. //-----------------------------------------------------------------------------
  75. inline void Ray::set_direction(const Vector3& direction)
  76. {
  77. m_direction = direction;
  78. }
  79. } // namespace crown