2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2015-01-10 10:13:57 +00:00
|
|
|
Copyright (c) 2011-2015 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_OBJECTS_INTERSECT_HPP
|
|
|
|
#define SPROUT_DARKROOM_OBJECTS_INTERSECT_HPP
|
|
|
|
|
|
|
|
#include <sprout/config.hpp>
|
2014-04-30 07:30:26 +00:00
|
|
|
#include <sprout/workaround/std/cstddef.hpp>
|
2013-12-12 14:29:50 +00:00
|
|
|
#include <sprout/tuple/flex.hpp>
|
2013-09-24 01:05:47 +00:00
|
|
|
#include <sprout/type_traits/enabler_if.hpp>
|
2013-09-24 06:08:36 +00:00
|
|
|
#include <sprout/darkroom/access/traits.hpp>
|
2011-11-26 06:20:35 +00:00
|
|
|
#include <sprout/darkroom/access/access.hpp>
|
|
|
|
#include <sprout/darkroom/intersects/intersection.hpp>
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace darkroom {
|
|
|
|
namespace objects {
|
2013-09-24 06:08:36 +00:00
|
|
|
template<typename Object, typename Ray>
|
|
|
|
struct intersection_result;
|
|
|
|
|
|
|
|
namespace detail {
|
2013-12-12 14:29:50 +00:00
|
|
|
template<typename Object, typename Ray, typename IndexTuple>
|
|
|
|
struct intersection_result_impl;
|
|
|
|
template<typename Object, typename Ray, sprout::index_t... Indexes>
|
|
|
|
struct intersection_result_impl<Object, Ray, sprout::index_tuple<Indexes...> >
|
|
|
|
: public sprout::tuples::common_recursive_flex_type<
|
|
|
|
typename sprout::darkroom::objects::intersection_result<typename sprout::darkroom::access::element<Indexes, Object>::type, Ray>::type...
|
|
|
|
>
|
|
|
|
{};
|
|
|
|
|
2013-09-24 06:08:36 +00:00
|
|
|
template<typename Object, typename Ray, bool IsTuple>
|
|
|
|
struct intersection_result;
|
|
|
|
template<typename Object, typename Ray>
|
|
|
|
struct intersection_result<Object, Ray, false>
|
|
|
|
: public Object::template intersection<Ray>
|
|
|
|
{};
|
|
|
|
template<typename Object, typename Ray>
|
|
|
|
struct intersection_result<Object, Ray, true>
|
2013-12-12 14:29:50 +00:00
|
|
|
: public sprout::darkroom::objects::detail::intersection_result_impl<
|
|
|
|
Object, Ray,
|
|
|
|
typename sprout::make_index_tuple<sprout::darkroom::access::size<Object>::value>::type
|
|
|
|
>
|
2013-09-24 06:08:36 +00:00
|
|
|
{};
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
//
|
|
|
|
// intersection_result
|
|
|
|
//
|
|
|
|
template<typename Object, typename Ray>
|
|
|
|
struct intersection_result
|
|
|
|
: public sprout::darkroom::objects::detail::intersection_result<
|
|
|
|
Object, Ray,
|
|
|
|
sprout::darkroom::access::is_tuple<Object>::value
|
|
|
|
>
|
|
|
|
{};
|
|
|
|
template<typename Object, typename Ray>
|
|
|
|
struct intersection_result<Object const, Ray>
|
|
|
|
: public sprout::darkroom::objects::intersection_result<Object, Ray>
|
|
|
|
{};
|
|
|
|
template<typename Object, typename Ray>
|
|
|
|
struct intersection_result<Object volatile, Ray>
|
|
|
|
: public sprout::darkroom::objects::intersection_result<Object, Ray>
|
|
|
|
{};
|
|
|
|
template<typename Object, typename Ray>
|
|
|
|
struct intersection_result<Object const volatile, Ray>
|
|
|
|
: public sprout::darkroom::objects::intersection_result<Object, Ray>
|
|
|
|
{};
|
|
|
|
|
2011-11-26 06:20:35 +00:00
|
|
|
//
|
|
|
|
// intersect
|
|
|
|
//
|
2013-09-24 01:05:47 +00:00
|
|
|
template<
|
|
|
|
typename Object, typename Ray,
|
|
|
|
typename sprout::enabler_if<!sprout::darkroom::access::is_tuple<Object>::value>::type = sprout::enabler
|
|
|
|
>
|
2013-09-24 06:08:36 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::darkroom::objects::intersection_result<Object, Ray>::type
|
2013-09-24 01:05:47 +00:00
|
|
|
intersect(Object const& obj, Ray const& ray);
|
|
|
|
template<
|
|
|
|
typename Object, typename Ray,
|
|
|
|
typename sprout::enabler_if<sprout::darkroom::access::is_tuple<Object>::value>::type = sprout::enabler
|
|
|
|
>
|
2013-09-24 06:08:36 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::darkroom::objects::intersection_result<Object, Ray>::type
|
2013-09-24 01:05:47 +00:00
|
|
|
intersect(Object const& obj, Ray const& ray);
|
2011-11-26 06:20:35 +00:00
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
template<std::size_t N>
|
|
|
|
struct intersect_list_impl {
|
|
|
|
private:
|
|
|
|
template<typename Objects, typename Ray, typename A, typename B>
|
2013-09-24 06:08:36 +00:00
|
|
|
SPROUT_CONSTEXPR typename sprout::darkroom::objects::intersection_result<Objects, Ray>::type
|
2011-11-26 06:20:35 +00:00
|
|
|
comp(A const& a, B const& b) const {
|
2013-12-12 14:29:50 +00:00
|
|
|
typedef typename sprout::darkroom::objects::intersection_result<Objects, Ray>::type type;
|
2011-11-26 06:20:35 +00:00
|
|
|
return sprout::darkroom::intersects::does_intersect(a)
|
|
|
|
&& sprout::darkroom::intersects::does_intersect(b)
|
|
|
|
? sprout::darkroom::intersects::distance(a) < sprout::darkroom::intersects::distance(b)
|
2013-12-12 14:29:50 +00:00
|
|
|
? sprout::tuples::recursive_flex<type>(a)
|
|
|
|
: sprout::tuples::recursive_flex<type>(b)
|
2011-11-26 06:20:35 +00:00
|
|
|
: sprout::darkroom::intersects::does_intersect(a)
|
2013-12-12 14:29:50 +00:00
|
|
|
? sprout::tuples::recursive_flex<type>(a)
|
|
|
|
: sprout::tuples::recursive_flex<type>(b)
|
2011-11-26 06:20:35 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
template<typename Objects, typename Ray>
|
2013-09-24 06:08:36 +00:00
|
|
|
SPROUT_CONSTEXPR typename sprout::darkroom::objects::intersection_result<Objects, Ray>::type
|
2011-11-26 06:20:35 +00:00
|
|
|
operator()(Objects const& objs, Ray const& ray) const {
|
|
|
|
return comp<Objects, Ray>(
|
|
|
|
sprout::darkroom::objects::intersect(sprout::darkroom::access::get<N>(objs), ray),
|
|
|
|
intersect_list_impl<N - 1>()(objs, ray)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template<>
|
|
|
|
struct intersect_list_impl<0> {
|
|
|
|
public:
|
|
|
|
template<typename Objects, typename Ray>
|
2013-09-24 06:08:36 +00:00
|
|
|
SPROUT_CONSTEXPR typename sprout::darkroom::objects::intersection_result<Objects, Ray>::type
|
2011-11-26 06:20:35 +00:00
|
|
|
operator()(Objects const& objs, Ray const& ray) const {
|
2013-12-12 14:29:50 +00:00
|
|
|
return sprout::tuples::recursive_flex(
|
|
|
|
sprout::darkroom::objects::intersect(sprout::darkroom::access::get<0>(objs), ray)
|
|
|
|
);
|
2011-11-26 06:20:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace detail
|
2013-09-24 01:05:47 +00:00
|
|
|
//
|
|
|
|
// intersect_list
|
|
|
|
//
|
2011-11-26 06:20:35 +00:00
|
|
|
template<typename Objects, typename Ray>
|
2013-09-24 06:08:36 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::darkroom::objects::intersection_result<Objects, Ray>::type
|
2011-11-26 06:20:35 +00:00
|
|
|
intersect_list(Objects const& objs, Ray const& ray) {
|
|
|
|
return sprout::darkroom::objects::detail::intersect_list_impl<
|
|
|
|
sprout::darkroom::access::size<Objects>::value - 1
|
|
|
|
>()(objs, ray);
|
|
|
|
}
|
2013-09-24 01:05:47 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// intersect
|
|
|
|
//
|
|
|
|
template<
|
|
|
|
typename Object, typename Ray,
|
2013-09-24 06:08:36 +00:00
|
|
|
typename sprout::enabler_if<!sprout::darkroom::access::is_tuple<Object>::value>::type
|
2013-09-24 01:05:47 +00:00
|
|
|
>
|
2013-09-24 06:08:36 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::darkroom::objects::intersection_result<Object, Ray>::type
|
2013-09-24 01:05:47 +00:00
|
|
|
intersect(Object const& obj, Ray const& ray) {
|
|
|
|
return obj.intersect(ray);
|
|
|
|
}
|
|
|
|
template<
|
|
|
|
typename Object, typename Ray,
|
2013-09-24 06:08:36 +00:00
|
|
|
typename sprout::enabler_if<sprout::darkroom::access::is_tuple<Object>::value>::type
|
2013-09-24 01:05:47 +00:00
|
|
|
>
|
2013-09-24 06:08:36 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename sprout::darkroom::objects::intersection_result<Object, Ray>::type
|
2013-09-24 01:05:47 +00:00
|
|
|
intersect(Object const& obj, Ray const& ray) {
|
|
|
|
return sprout::darkroom::objects::intersect_list(obj, ray);
|
|
|
|
}
|
2011-11-26 06:20:35 +00:00
|
|
|
} // namespace objects
|
|
|
|
} // namespace darkroom
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_DARKROOM_OBJECTS_INTERSECT_HPP
|