1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-08-03 12:49:50 +00:00

[sprout.darkroom] implemented refraction

This commit is contained in:
bolero-MURAKAMI 2013-12-06 01:57:31 +09:00
parent 8e3c426684
commit 8e306168da
8 changed files with 197 additions and 37 deletions

View file

@ -59,6 +59,17 @@ namespace sprout {
return sprout::darkroom::coords::vector3d_t(x, y, z);
}
//
// is_zero
//
template<typename Vector>
inline SPROUT_CONSTEXPR bool
is_zero(Vector const& vec) {
return sprout::darkroom::coords::x(vec) == 0
&& sprout::darkroom::coords::y(vec) == 0
&& sprout::darkroom::coords::z(vec) == 0
;
}
//
// length_sq
//
@ -204,6 +215,37 @@ namespace sprout {
sprout::darkroom::coords::scale(nor, sprout::darkroom::coords::dot(incid, nor) * 2)
);
}
//
// refract
//
namespace detail {
template<typename Incident, typename Normal, typename Refraction, typename InNor, typename K>
inline SPROUT_CONSTEXPR Incident
refract_impl_1(Incident const& incid, Normal const& nor, Refraction const& eta, InNor const& t, K const& k) {
return k < 0 ? sprout::tuples::remake<Incident>(incid, 0, 0, 0)
: sprout::darkroom::coords::sub(
sprout::darkroom::coords::scale(incid, eta),
sprout::darkroom::coords::scale(nor, eta * t * sprout::sqrt(k))
)
;
}
template<typename Incident, typename Normal, typename Refraction, typename InNor>
inline SPROUT_CONSTEXPR Incident
refract_impl(Incident const& incid, Normal const& nor, Refraction const& eta, InNor const& t) {
return sprout::darkroom::coords::detail::refract_impl_1(
incid, nor, eta,
t, 1 - eta * eta * (1 - t * t)
);
}
} // namespace detail
template<typename Incident, typename Normal, typename Refraction>
inline SPROUT_CONSTEXPR Incident
refract(Incident const& incid, Normal const& nor, Refraction const& eta) {
return sprout::darkroom::coords::detail::refract_impl(
incid, nor, eta,
sprout::darkroom::coords::dot(incid, nor)
);
}
} // namespace coords
} // namespace darkroom
} // namespace sprout