Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
Ray.h
Go to the documentation of this file.
1#pragma once
2
3#include "Math/TVector3.h"
6
7#include <Common/primitive_type.h>
8
9#include <limits>
10
11namespace ph
12{
13
20class Ray final
21{
22public:
23 class Differential;
24
25public:
28 Ray() = default;
29
34 Ray(const math::Vector3R& origin, const math::Vector3R& direction);
35
40 Ray(const math::Vector3R& origin, const math::Vector3R& direction, const Time& time);
41
47 Ray(const math::Vector3R& origin, const math::Vector3R& direction, real minT, real maxT);
48
53 Ray(const math::Vector3R& origin, const math::Vector3R& direction, real minT, real maxT, const Time& time);
54
59 Ray(const math::TLineSegment<real>& segment, const Time& time);
60
66 Ray& reverse();
67
70 void setMinT(real t);
71
74 void setMaxT(real t);
75
81 void setRange(real minT, real maxT);
82
85 void setOrigin(const math::Vector3R& pos);
86
91 void setDir(const math::Vector3R& dir);
92
93 void setSegment(const math::TLineSegment<real>& segment);
94
100 const math::Vector3R& getOrigin() const;
101 const math::Vector3R& getDir() const;
102 real getMinT() const;
103 real getMaxT() const;
105
108 math::Vector3R getTail() const;
109
112 math::Vector3R getHead() const;
114
117 void setTime(const Time& time);
118
121 const Time& getTime() const;
122
123private:
124 math::TLineSegment<real> m_segment;
125 Time m_time;
126};
127
128// In-header Implementations:
129
130inline Ray::Ray(const math::TLineSegment<real>& segment, const Time& time)
131 : m_segment(segment)
132 , m_time(time)
133{}
134
135inline Ray::Ray(
136 const math::Vector3R& origin,
137 const math::Vector3R& direction,
138 const real minT,
139 const real maxT,
140 const Time& time)
141
142 : Ray(math::TLineSegment<real>(origin, direction, minT, maxT), time)
143{}
144
145inline Ray::Ray(
146 const math::Vector3R& origin,
147 const math::Vector3R& direction,
148 const real minT,
149 const real maxT)
150
151 : Ray(origin, direction, minT, maxT, Time{})
152{}
153
154inline Ray::Ray(const math::Vector3R& origin, const math::Vector3R& direction)
155 : Ray(origin, direction, 0, std::numeric_limits<real>::max())
156{}
157
158inline Ray::Ray(const math::Vector3R& origin, const math::Vector3R& direction, const Time& time)
159 : Ray(origin, direction, 0, std::numeric_limits<real>::max(), time)
160{}
161
163{
164 m_segment.flip();
165
166 return *this;
167}
168
169inline void Ray::setMinT(const real t)
170{
171 m_segment.setMinT(t);
172}
173
174inline void Ray::setMaxT(const real t)
175{
176 m_segment.setMaxT(t);
177}
178
179inline void Ray::setRange(const real minT, const real maxT)
180{
181 m_segment.setRange(minT, maxT);
182}
183
184inline void Ray::setOrigin(const math::Vector3R& pos)
185{
186 m_segment.setOrigin(pos);
187}
188
189inline void Ray::setDir(const math::Vector3R& dir)
190{
191 m_segment.setDir(dir);
192}
193
194inline void Ray::setSegment(const math::TLineSegment<real>& segment)
195{
196 m_segment = segment;
197}
198
199inline void Ray::setTime(const Time& time)
200{
201 m_time = time;
202}
203
204inline const Time& Ray::getTime() const
205{
206 return m_time;
207}
208
209inline const math::Vector3R& Ray::getOrigin() const
210{
211 return m_segment.getOrigin();
212}
213
214inline const math::Vector3R& Ray::getDir() const
215{
216 return m_segment.getDir();
217}
218
219inline real Ray::getMinT() const
220{
221 return m_segment.getMinT();
222}
223
224inline real Ray::getMaxT() const
225{
226 return m_segment.getMaxT();
227}
228
230{
231 return m_segment;
232}
233
235{
236 return m_segment.getTail();
237}
238
240{
241 return m_segment.getHead();
242}
243
244}// end namespace ph
Represents a ray in space.
Definition Ray.h:21
const Time & getTime() const
Get the associated time of this ray.
Definition Ray.h:204
const math::Vector3R & getOrigin() const
Definition Ray.h:209
void setRange(real minT, real maxT)
Set the parametric range where the ray extends.
Definition Ray.h:179
void setMaxT(real t)
Set the parametric distance where the ray ends.
Definition Ray.h:174
void setOrigin(const math::Vector3R &pos)
Set the origin of the ray.
Definition Ray.h:184
const math::Vector3R & getDir() const
Definition Ray.h:214
void setSegment(const math::TLineSegment< real > &segment)
Definition Ray.h:194
void setMinT(real t)
Set the parametric distance where the ray starts.
Definition Ray.h:169
void setDir(const math::Vector3R &dir)
Set the direction vector of the ray.
Definition Ray.h:189
real getMinT() const
Definition Ray.h:219
math::Vector3R getHead() const
Get the coordinates on maximum parametric distance.
Definition Ray.h:239
void setTime(const Time &time)
Set the associated time of this ray.
Definition Ray.h:199
Ray & reverse()
Points this ray in opposite direction.
Definition Ray.h:162
Ray()=default
A ray with unspecified state.
const math::TLineSegment< real > & getSegment() const
Definition Ray.h:229
real getMaxT() const
Definition Ray.h:224
math::Vector3R getTail() const
Get the coordinates on minimum parametric distance.
Definition Ray.h:234
Definition Time.h:9
Represents a line segment in space.
Definition TLineSegment.h:25
void setMinT(T t)
Set the parametric distance where the segment starts.
Definition TLineSegment.ipp:43
TVector3< T > getHead() const
Get the coordinates on maximum parametric distance.
Definition TLineSegment.ipp:118
void setMaxT(T t)
Set the parametric distance where the segment ends.
Definition TLineSegment.ipp:49
T getMinT() const
Definition TLineSegment.ipp:94
void setOrigin(const TVector3< T > &pos)
Set the origin of the line.
Definition TLineSegment.ipp:70
const TVector3< T > & getOrigin() const
Definition TLineSegment.ipp:82
const TVector3< T > & getDir() const
Definition TLineSegment.ipp:88
void setDir(const TVector3< T > &dir)
Set the direction vector of the line.
Definition TLineSegment.ipp:76
T getMaxT() const
Definition TLineSegment.ipp:100
TVector3< T > getTail() const
Get the coordinates on minimum parametric distance.
Definition TLineSegment.ipp:112
void setRange(T minT, T maxT)
Set the parametric range where the segment extends. The range is [minT, maxT). This is equivalent to ...
Definition TLineSegment.ipp:55
TLineSegment & flip()
Point the line in opposite direction.
Definition TLineSegment.ipp:35
The root for all renderer implementations.
Definition EEngineProject.h:6
Definition TAABB2D.h:96