ray.hh 2.14 KB
Newer Older
1
2
3
4
5
6
7
#ifndef RADIX_RADIXMATH_RAY_HH_
#define RADIX_RADIXMATH_RAY_HH_
#include <string>
#include "radixmath/constants.hh"
#include "radixmath/point3d.hh"
#include "radixmath/vector3d.hh"

8
#include "radixcore/visibility.hh"
9

10
11
12
13
namespace radix
{
class RADIX_PUBLIC Ray
{
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  // public member variables
 public:
  /**
   * @brief the origin of the ray
   */
  Point3D o;
  /**
   * @brief the direction of the ray
   */
  Vector3D d;
  // constructor/deconstructor
 public:
  Ray(void);
  Ray(const Point3D &origin, const Vector3D &dir);
  Ray(const Ray &ray);
  ~Ray(void);
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  // operators
 public:
  /**
   * operator=
   * @param rhs
   * @return this
   */
  Ray &operator=(const Ray &rhs);
  bool operator==(const Ray &rhs) const;
  bool operator!=(const Ray &rhs) const;
  /**
   * Move the ray position by {@code tmin}
   * @param tmin
   * @return this updated
   */
  Ray &operator+=(const Real t);
  Ray &operator-=(const Real t);
48
49
  void move(Real t)
  {
50
51
52
53
    this->o.x += d.x * t;
    this->o.y += d.y * t;
    this->o.z += d.z * t;
  }
54
55
  void backup(Real t)
  {
56
57
58
59
    this->o.x -= d.x * t;
    this->o.y -= d.y * t;
    this->o.z -= d.z * t;
  }
60

61
62
63
64
  // public methods
 public:
  inline Point3D getIntersection(const Real &t) const;
  std::string toString() const;
65
66
};

67
68
inline Point3D Ray::getIntersection(const Real &t) const
{
69
  return Point3D(o.x + d.x * t, o.y + d.y * t, o.z + d.z * t);
70
71
}

72
73
inline Ray &Ray::operator+=(const Real t)
{
74
75
76
77
78
  this->o.x += d.x * t;
  this->o.y += d.y * t;
  this->o.z += d.z * t;
  return *this;
}  // operator+
79
80
inline Ray &Ray::operator-=(const Real t)
{
81
82
83
84
85
  this->o.x -= d.x * t;
  this->o.y -= d.y * t;
  this->o.z -= d.z * t;
  return *this;
}  // operator+
86
87
inline bool Ray::operator==(const Ray &rhs) const
{
88
89
  if (o == rhs.o && d == rhs.d) return true;
  return false;
90
}
91
92
inline bool Ray::operator!=(const Ray &rhs) const
{
93
94
  if (o == rhs.o && d == rhs.d) return false;
  return true;
95
96
97
98
99
100
101
}
/**
 * Allow for printing a Ray to stream
 * @param os - the stream to receive the string representation of the ray
 * @param r - the ray to be stringified
 * @return the stream
 */
102
103
RADIX_PUBLIC std::ostream &operator<<(std::ostream &os, const Ray &r);
}  // namespace radix
104
#endif