From c86fa430c135f65274f2d9a5a5964dff037e8ec7 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Mon, 12 Dec 2011 01:18:01 +0900 Subject: [PATCH] =?UTF-8?q?darkroom/objects/aa=5Fplane.hpp=20=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=20darkroom/tracers/raytracer.hpp=20=E3=81=A7=E3=80=81?= =?UTF-8?q?uv=E5=BA=A7=E6=A8=99=E3=81=B8=E3=81=AE=E5=A4=89=E6=8F=9B?= =?UTF-8?q?=E3=81=A7=E4=B8=8A=E4=B8=8B=E3=81=8C=E5=8F=8D=E8=BB=A2=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=81=84=E3=81=9F=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sprout/darkroom/objects.hpp | 1 + sprout/darkroom/objects/aa_plane.hpp | 211 ++++++++++++++++++++++++++ sprout/darkroom/rays/ray.hpp | 2 +- sprout/darkroom/tracers/raytracer.hpp | 2 +- 4 files changed, 214 insertions(+), 2 deletions(-) create mode 100644 sprout/darkroom/objects/aa_plane.hpp diff --git a/sprout/darkroom/objects.hpp b/sprout/darkroom/objects.hpp index 343a2198..0b68c325 100644 --- a/sprout/darkroom/objects.hpp +++ b/sprout/darkroom/objects.hpp @@ -4,5 +4,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_DARKROOM_OBJECTS_HPP diff --git a/sprout/darkroom/objects/aa_plane.hpp b/sprout/darkroom/objects/aa_plane.hpp new file mode 100644 index 00000000..acabcf48 --- /dev/null +++ b/sprout/darkroom/objects/aa_plane.hpp @@ -0,0 +1,211 @@ +#ifndef SPROUT_DARKROOM_OBJECTS_AA_PLANE_HPP +#define SPROUT_DARKROOM_OBJECTS_AA_PLANE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace darkroom { + namespace objects { + // + // aa_plane_direction + // + struct aa_plane_direction { + public: + enum values { + x, + y, + z + }; + }; + // + // basic_aa_plane + // + template + class basic_aa_plane { + public: + typedef Material material_type; + typedef Position position_type; + typedef typename sprout::darkroom::access::unit::type unit_type; + typedef sprout::darkroom::objects::aa_plane_direction aa_plane_direction; + public: + template + struct intersection { + typedef sprout::tuples::tuple< + bool, + unit_type, + position_type, + position_type, + decltype(sprout::darkroom::materials::calc_material( + std::declval(), + std::declval(), + std::declval() + )) + > type; + }; + private: + aa_plane_direction::values direction_value_; + unit_type val_; + material_type mat_; + private: + SPROUT_CONSTEXPR bool is_x() const { + return direction_value_ == aa_plane_direction::x; + } + SPROUT_CONSTEXPR bool is_y() const { + return direction_value_ == aa_plane_direction::y; + } + SPROUT_CONSTEXPR bool is_z() const { + return direction_value_ == aa_plane_direction::z; + } + template + SPROUT_CONSTEXPR typename intersection::type intersect_6( + bool does_intersect, + unit_type distance, + position_type const& point_of_intersection, + position_type const& normal + ) const + { + return typename intersection::type( + does_intersect, + distance, + point_of_intersection, + normal, + sprout::darkroom::materials::calc_material( + mat_, + point_of_intersection, + normal + ) + ); + } + template + SPROUT_CONSTEXPR typename intersection::type intersect_5( + int hit_side, + bool does_intersect, + unit_type distance, + position_type const& point_of_intersection + ) const + { + return intersect_6( + does_intersect, + distance, + point_of_intersection, + (is_x() ? position_type(hit_side > 0 ? 1 : -1, 0, 0) + : is_y() ? position_type(0, hit_side > 0 ? 1 : -1, 0) + : position_type(0, 0, hit_side > 0 ? 1 : -1) + ) + ); + } + template + SPROUT_CONSTEXPR typename intersection::type intersect_4( + Ray const& ray, + int hit_side, + bool does_intersect, + unit_type distance + ) const + { + return intersect_5( + hit_side, + does_intersect, + distance, + does_intersect + ? sprout::darkroom::rays::point_of_intersection(ray, distance) + : position_type(0, 0, 0) + ); + } + template + SPROUT_CONSTEXPR typename intersection::type intersect_3( + Ray const& ray, + unit_type pos_v, + unit_type dir_v, + int hit_side, + bool does_intersect + ) const + { + return intersect_4( + ray, + hit_side, + does_intersect, + does_intersect + ? (pos_v - val_) / -dir_v + : unit_type(-1) + ); + } + template + SPROUT_CONSTEXPR typename intersection::type intersect_2( + Ray const& ray, + unit_type pos_v, + unit_type dir_v, + int hit_side + ) const + { + return intersect_3( + ray, + pos_v, + dir_v, + hit_side, + (hit_side > 0 && dir_v < 0) || (hit_side < 0 && dir_v > 0) + ); + } + template + SPROUT_CONSTEXPR typename intersection::type intersect_1( + Ray const& ray, + unit_type pos_v, + unit_type dir_v + ) const + { + return intersect_2( + ray, + pos_v, + dir_v, + pos_v > val_ ? 1 : -1 + ); + } + public: + SPROUT_CONSTEXPR basic_aa_plane( + aa_plane_direction::values direction_value, + unit_type val, + material_type const& mat + ) + : direction_value_(direction_value) + , val_(val) + , mat_(mat) + {}; + template + SPROUT_CONSTEXPR typename intersection::type intersect(Ray const& ray) const { + return intersect_1( + ray, + (is_x() ? sprout::darkroom::coords::x(sprout::darkroom::rays::position(ray)) + : is_y() ? sprout::darkroom::coords::y(sprout::darkroom::rays::position(ray)) + : sprout::darkroom::coords::z(sprout::darkroom::rays::position(ray)) + ), + (is_x() ? sprout::darkroom::coords::x(sprout::darkroom::rays::direction(ray)) + : is_y() ? sprout::darkroom::coords::y(sprout::darkroom::rays::direction(ray)) + : sprout::darkroom::coords::z(sprout::darkroom::rays::direction(ray)) + ) + ); + } + }; + // + // make_aa_plane + // + template + SPROUT_CONSTEXPR inline sprout::darkroom::objects::basic_aa_plane + make_aa_plane( + sprout::darkroom::objects::aa_plane_direction::values dir_val, + Unit const& val, + Material const& mat + ) + { + return sprout::darkroom::objects::basic_aa_plane(dir_val, val, mat); + } + } // namespace objects + } // namespace darkroom +} // namespace sprout + +#endif // #ifndef SPROUT_DARKROOM_OBJECTS_AA_PLANE_HPP diff --git a/sprout/darkroom/rays/ray.hpp b/sprout/darkroom/rays/ray.hpp index 968ce4c7..32ae94bb 100644 --- a/sprout/darkroom/rays/ray.hpp +++ b/sprout/darkroom/rays/ray.hpp @@ -56,7 +56,7 @@ namespace sprout { sprout::darkroom::coords::scale(sprout::darkroom::rays::direction(ray), dist) ); } - } // namespace ray + } // namespace rays } // namespace darkroom } // namespace sprout diff --git a/sprout/darkroom/tracers/raytracer.hpp b/sprout/darkroom/tracers/raytracer.hpp index a351a80c..1d2bd21d 100644 --- a/sprout/darkroom/tracers/raytracer.hpp +++ b/sprout/darkroom/tracers/raytracer.hpp @@ -41,7 +41,7 @@ namespace sprout { lights, camera.template operator()( static_cast(x) / width - 0.5, - static_cast(y) / height - 0.5 + -(static_cast(y) / height - 0.5) ), depth_max );