2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2014-01-08 07:48:12 +00:00
|
|
|
Copyright (c) 2011-2014 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
=============================================================================*/
|
2011-11-26 06:20:35 +00:00
|
|
|
#ifndef SPROUT_DARKROOM_RAYS_RAY_HPP
|
|
|
|
#define SPROUT_DARKROOM_RAYS_RAY_HPP
|
|
|
|
|
|
|
|
#include <sprout/config.hpp>
|
2013-12-05 16:57:31 +00:00
|
|
|
#include <sprout/limits.hpp>
|
2011-11-26 06:20:35 +00:00
|
|
|
#include <sprout/tuple/tuple.hpp>
|
|
|
|
#include <sprout/utility/forward.hpp>
|
|
|
|
#include <sprout/darkroom/access/access.hpp>
|
|
|
|
#include <sprout/darkroom/coords/vector.hpp>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace darkroom {
|
|
|
|
namespace rays {
|
|
|
|
//
|
|
|
|
// position
|
|
|
|
// direction
|
|
|
|
//
|
|
|
|
template<typename T>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR auto
|
|
|
|
position(T&& t)
|
2014-02-22 07:32:51 +00:00
|
|
|
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<0>(SPROUT_FORWARD(T, t))))
|
|
|
|
-> decltype(sprout::darkroom::access::get<0>(SPROUT_FORWARD(T, t)))
|
2011-11-26 06:20:35 +00:00
|
|
|
{
|
2014-02-22 07:32:51 +00:00
|
|
|
return sprout::darkroom::access::get<0>(SPROUT_FORWARD(T, t));
|
2011-11-26 06:20:35 +00:00
|
|
|
}
|
|
|
|
template<typename T>
|
2012-10-05 15:58:56 +00:00
|
|
|
inline SPROUT_CONSTEXPR auto
|
|
|
|
direction(T&& t)
|
2014-02-22 07:32:51 +00:00
|
|
|
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::darkroom::access::get<1>(SPROUT_FORWARD(T, t))))
|
|
|
|
-> decltype(sprout::darkroom::access::get<1>(SPROUT_FORWARD(T, t)))
|
2011-11-26 06:20:35 +00:00
|
|
|
{
|
2014-02-22 07:32:51 +00:00
|
|
|
return sprout::darkroom::access::get<1>(SPROUT_FORWARD(T, t));
|
2011-11-26 06:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// make_ray
|
|
|
|
//
|
|
|
|
template<typename Position, typename Direction>
|
2012-07-15 07:04:05 +00:00
|
|
|
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Position, Direction>
|
2011-11-26 06:20:35 +00:00
|
|
|
make_ray(Position const& pos, Direction const& dir) {
|
|
|
|
return sprout::tuples::make_tuple(pos, dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// ray
|
|
|
|
//
|
2013-03-26 17:02:16 +00:00
|
|
|
typedef sprout::tuples::tuple<sprout::darkroom::coords::vector3d_t, sprout::darkroom::coords::vector3d_t> ray;
|
2011-11-26 06:20:35 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// point_of_intersection
|
|
|
|
//
|
|
|
|
template<typename Ray, typename Distance>
|
2012-04-04 13:23:41 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::darkroom::access::unit<Ray>::type
|
2011-11-26 06:20:35 +00:00
|
|
|
point_of_intersection(Ray const& ray, Distance const& dist) {
|
|
|
|
return sprout::darkroom::coords::add(
|
|
|
|
sprout::darkroom::rays::position(ray),
|
|
|
|
sprout::darkroom::coords::scale(sprout::darkroom::rays::direction(ray), dist)
|
|
|
|
);
|
|
|
|
}
|
2013-12-05 16:57:31 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// detach_position
|
|
|
|
//
|
|
|
|
template<typename Position, typename Direction>
|
|
|
|
inline SPROUT_CONSTEXPR Position
|
|
|
|
detach_position(Position const& pos, Direction const& dir) {
|
|
|
|
return sprout::darkroom::coords::add(
|
|
|
|
pos,
|
|
|
|
sprout::darkroom::coords::resize(
|
|
|
|
dir,
|
|
|
|
sprout::numeric_limits<typename sprout::darkroom::access::unit<Direction>::type>::epsilon() * 256
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// make_detached_ray
|
|
|
|
//
|
|
|
|
template<typename Position, typename Direction>
|
|
|
|
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Position, Direction>
|
|
|
|
make_detached_ray(Position const& pos, Direction const& dir) {
|
|
|
|
return sprout::darkroom::rays::make_ray(
|
|
|
|
sprout::darkroom::rays::detach_position(pos, dir),
|
|
|
|
dir
|
|
|
|
);
|
|
|
|
}
|
2011-12-11 16:18:01 +00:00
|
|
|
} // namespace rays
|
2011-11-26 06:20:35 +00:00
|
|
|
} // namespace darkroom
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_DARKROOM_RAYS_RAY_HPP
|