#pragma once
-#include <sstream>
#include "Vector.hxx"
template <typename MT>
// --- constructors and deconstructors ---
Ray()
- : _origin(0, 0, 0), _direction(0, 0, 0), _rgb(0, 0, 0), _min(5), _max(1000), _depth(10), _valid(false)
+ : _origin(0.0, 0.0, 0.0), _direction(0.0, 0.0, 0.0), _min(1.0), _max(1000.0), _depth(10)
{
}
- Ray(const Vector3<MT>& org, const Vector3<MT>& dir, const Vector3<MT>& rgb, const MT& min, const MT& max,
- const size_t& depth, const bool valid)
- : _origin(org), _direction(dir), _rgb(rgb), _min(min), _max(max), _depth(depth), _valid(valid)
+ Ray(const Vector3<MT>& org, const Vector3<MT>& dir, const MT& min, const MT& max, const size_t& depth)
+ : _origin(org), _direction(dir), _min(min), _max(max), _depth(depth)
{
}
Ray(const Ray& rhs)
- : _origin(rhs._origin), _direction(rhs._direction), _rgb(rhs._rgb), _min(rhs._min), _max(rhs._max),
- _depth(rhs._depth), _valid(rhs._valid)
+ : _origin(rhs._origin), _direction(rhs._direction), _min(rhs._min), _max(rhs._max), _depth(rhs._depth)
{
}
Ray(Ray&& rhs)
- : _origin(std::move(rhs._origin)), _direction(std::move(rhs._direction)), _rgb(std::move(rhs._rgb)),
- _min(std::move(rhs._min)), _max(std::move(rhs._max)), _depth(std::move(rhs._depth)), _valid(std::move(rhs._valid))
+ : _origin(std::move(rhs._origin)), _direction(std::move(rhs._direction)), _min(std::move(rhs._min)),
+ _max(std::move(rhs._max)), _depth(std::move(rhs._depth))
{
}
{
_origin = rhs._origin;
_direction = rhs._direction;
- _rgb = rhs._rgb;
_min = rhs._min;
_max = rhs._max;
_depth = rhs._depth;
- _valid = rhs._valid;
}
return *this;
{
_origin = std::move(rhs._origin);
_direction = std::move(rhs._direction);
- _rgb = std::move(rhs._rgb);
_min = std::move(rhs._min);
_max = std::move(rhs._max);
_depth = std::move(rhs._depth);
- _valid = std::move(rhs._valid);
}
return *this;
bool operator==(const Ray& rhs) const
{
- return _origin == rhs._origin && _direction == rhs._direction && _rgb == rhs._rgb && _min == rhs._min &&
- _max == rhs._max && _depth == rhs._depth && _valid == rhs._valid;
+ return _origin == rhs._origin &&
+ _direction == rhs._direction &&
+ _min == rhs._min &&
+ _max == rhs._max &&
+ _depth == rhs._depth;
}
bool operator!=(const Ray& rhs) const
// --- public methods ---
- void setOrigin(const Vector3<MT>& org)
- {
- _origin = org;
- }
-
- Vector3<MT> origin() const
- {
- return _origin;
- }
-
- void setDirection(const Vector3<MT>& dir)
+ size_t depth() const
{
- _direction = dir.normalized();
+ return _depth;
}
Vector3<MT> direction() const
return _direction;
}
- void setRgb(const Vector3<MT>& rgb)
- {
- _rgb = rgb;
- }
-
- Vector3<MT> rgb() const
- {
- return _rgb;
- }
-
- void setMin(const MT& min)
+ MT max() const
{
- _min = min;
+ return _max;
}
MT min() const
return _min;
}
- void setMax(const MT& max)
+ Vector3<MT> origin() const
{
- _max = max;
+ return _origin;
}
- MT max() const
+ void setDepth(const size_t& depth)
{
- return _max;
+ _depth = depth;
}
- void setDepth(const size_t& depth)
+ void setDirection(const Vector3<MT>& dir)
{
- _depth = depth;
+ _direction = dir.normalized();
}
- size_t depth() const
+ void setMax(const MT& max)
{
- return _depth;
+ _max = max;
}
- void setValid(const bool valid)
+ void setMin(const MT& min)
{
- _valid = valid;
+ _min = min;
}
- bool valid() const
+ void setOrigin(const Vector3<MT>& org)
{
- return _valid;
+ _origin = org;
}
std::string string() const
{
std::stringstream result;
- result << "(" << _origin.string() << "), (" << _direction.string() << ")";
+ result << "org(" << _origin.string()
+ << "), dir(" << _direction.string()
+ << "), min(" << _min
+ << "), max(" << _max
+ << "), dep(" << _depth
+ << ")";
return result.str();
}
Vector3<MT> _origin;
Vector3<MT> _direction;
- Vector4<uint8_t> _rgb; // color ARGB (0, 255 for now)
MT _min; // near plane value
MT _max; // far plane value
size_t _depth; // recursion depth
- bool _valid;
};