Add geom::ray primitive
This commit is contained in:
parent
e53d5fba13
commit
4410597e44
1 changed files with 59 additions and 0 deletions
59
libs/geom/include/psemek/geom/ray.hpp
Normal file
59
libs/geom/include/psemek/geom/ray.hpp
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/geom/vector.hpp>
|
||||
#include <psemek/geom/point.hpp>
|
||||
|
||||
namespace psemek::geom
|
||||
{
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
struct ray
|
||||
{
|
||||
point<T, N> origin;
|
||||
vector<T, N> direction;
|
||||
|
||||
auto operator()(T const & t) const
|
||||
{
|
||||
return origin + t * direction;
|
||||
}
|
||||
|
||||
ray & operator += (vector<T, N> const & v)
|
||||
{
|
||||
origin += v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ray & operator -= (vector<T, N> const & v)
|
||||
{
|
||||
origin -= v;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
ray(point<T, N>, vector<T, N>) -> ray<T, N>;
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
ray<T, N> advance(ray<T, N> r, T const & t)
|
||||
{
|
||||
r.origin = r(t);
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
ray<T, N> operator + (ray<T, N> const & r, vector<T, N> const & v)
|
||||
{
|
||||
auto res = r;
|
||||
res += v;
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
ray<T, N> operator - (ray<T, N> const & r, vector<T, N> const & v)
|
||||
{
|
||||
auto res = r;
|
||||
res -= v;
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue