mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
add is_from_inside property
This commit is contained in:
parent
014d339803
commit
8e3c426684
4 changed files with 64 additions and 22 deletions
|
@ -114,7 +114,7 @@ namespace sprout {
|
||||||
//
|
//
|
||||||
template<typename... Elements>
|
template<typename... Elements>
|
||||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Elements...>
|
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Elements...>
|
||||||
make_material_image(Elements const&... elems) {
|
make_intersection(Elements const&... elems) {
|
||||||
return sprout::tuples::make_tuple(elems...);
|
return sprout::tuples::make_tuple(elems...);
|
||||||
}
|
}
|
||||||
} // namespace intersects
|
} // namespace intersects
|
||||||
|
|
|
@ -32,6 +32,18 @@ namespace sprout {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
//
|
//
|
||||||
|
// aa_plane_face
|
||||||
|
//
|
||||||
|
struct aa_plane_face {
|
||||||
|
public:
|
||||||
|
enum values {
|
||||||
|
both,
|
||||||
|
negative,
|
||||||
|
positive,
|
||||||
|
same_as_direction
|
||||||
|
};
|
||||||
|
};
|
||||||
|
//
|
||||||
// basic_aa_plane
|
// basic_aa_plane
|
||||||
//
|
//
|
||||||
template<typename Material, typename Position = sprout::darkroom::coords::vector3d_t>
|
template<typename Material, typename Position = sprout::darkroom::coords::vector3d_t>
|
||||||
|
@ -41,6 +53,7 @@ namespace sprout {
|
||||||
typedef Position position_type;
|
typedef Position position_type;
|
||||||
typedef typename sprout::darkroom::access::unit<position_type>::type unit_type;
|
typedef typename sprout::darkroom::access::unit<position_type>::type unit_type;
|
||||||
typedef sprout::darkroom::objects::aa_plane_direction aa_plane_direction;
|
typedef sprout::darkroom::objects::aa_plane_direction aa_plane_direction;
|
||||||
|
typedef sprout::darkroom::objects::aa_plane_face aa_plane_face;
|
||||||
public:
|
public:
|
||||||
template<typename Ray>
|
template<typename Ray>
|
||||||
struct intersection {
|
struct intersection {
|
||||||
|
@ -53,13 +66,15 @@ namespace sprout {
|
||||||
std::declval<material_type const&>(),
|
std::declval<material_type const&>(),
|
||||||
std::declval<unit_type const&>(),
|
std::declval<unit_type const&>(),
|
||||||
std::declval<unit_type const&>()
|
std::declval<unit_type const&>()
|
||||||
))
|
)),
|
||||||
|
bool
|
||||||
> type;
|
> type;
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
aa_plane_direction::values direction_value_;
|
aa_plane_direction::values direction_value_;
|
||||||
unit_type val_;
|
unit_type val_;
|
||||||
material_type mat_;
|
material_type mat_;
|
||||||
|
aa_plane_face::values face_;
|
||||||
private:
|
private:
|
||||||
SPROUT_CONSTEXPR bool
|
SPROUT_CONSTEXPR bool
|
||||||
is_x() const {
|
is_x() const {
|
||||||
|
@ -75,7 +90,7 @@ namespace sprout {
|
||||||
}
|
}
|
||||||
template<typename Ray>
|
template<typename Ray>
|
||||||
SPROUT_CONSTEXPR typename intersection<Ray>::type
|
SPROUT_CONSTEXPR typename intersection<Ray>::type
|
||||||
intersect_5(int hit_side, bool does_intersect, unit_type distance, position_type const& point_of_intersection) const {
|
intersect_5(int hit_side, bool is_from_inside, bool does_intersect, unit_type distance, position_type const& point_of_intersection) const {
|
||||||
return typename intersection<Ray>::type(
|
return typename intersection<Ray>::type(
|
||||||
does_intersect,
|
does_intersect,
|
||||||
distance,
|
distance,
|
||||||
|
@ -99,13 +114,16 @@ namespace sprout {
|
||||||
sprout::darkroom::coords::x(point_of_intersection),
|
sprout::darkroom::coords::x(point_of_intersection),
|
||||||
sprout::darkroom::coords::y(point_of_intersection)
|
sprout::darkroom::coords::y(point_of_intersection)
|
||||||
)
|
)
|
||||||
|
,
|
||||||
|
is_from_inside
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
template<typename Ray>
|
template<typename Ray>
|
||||||
SPROUT_CONSTEXPR typename intersection<Ray>::type
|
SPROUT_CONSTEXPR typename intersection<Ray>::type
|
||||||
intersect_4(Ray const& ray, int hit_side, bool does_intersect, unit_type distance) const {
|
intersect_4(Ray const& ray, int hit_side, bool is_from_inside, bool does_intersect, unit_type distance) const {
|
||||||
return intersect_5<Ray>(
|
return intersect_5<Ray>(
|
||||||
hit_side,
|
hit_side,
|
||||||
|
is_from_inside,
|
||||||
does_intersect,
|
does_intersect,
|
||||||
distance,
|
distance,
|
||||||
does_intersect
|
does_intersect
|
||||||
|
@ -115,10 +133,11 @@ namespace sprout {
|
||||||
}
|
}
|
||||||
template<typename Ray>
|
template<typename Ray>
|
||||||
SPROUT_CONSTEXPR typename intersection<Ray>::type
|
SPROUT_CONSTEXPR typename intersection<Ray>::type
|
||||||
intersect_3(Ray const& ray, unit_type pos_v, unit_type dir_v, int hit_side, bool does_intersect) const {
|
intersect_3(Ray const& ray, unit_type pos_v, unit_type dir_v, int hit_side, bool is_from_inside, bool does_intersect) const {
|
||||||
return intersect_4(
|
return intersect_4(
|
||||||
ray,
|
ray,
|
||||||
hit_side,
|
hit_side,
|
||||||
|
is_from_inside,
|
||||||
does_intersect,
|
does_intersect,
|
||||||
does_intersect
|
does_intersect
|
||||||
? (pos_v - val_) / -dir_v
|
? (pos_v - val_) / -dir_v
|
||||||
|
@ -127,12 +146,13 @@ namespace sprout {
|
||||||
}
|
}
|
||||||
template<typename Ray>
|
template<typename Ray>
|
||||||
SPROUT_CONSTEXPR typename intersection<Ray>::type
|
SPROUT_CONSTEXPR typename intersection<Ray>::type
|
||||||
intersect_2(Ray const& ray, unit_type pos_v, unit_type dir_v, int hit_side) const {
|
intersect_2(Ray const& ray, unit_type pos_v, unit_type dir_v, int hit_side, bool is_from_inside) const {
|
||||||
return intersect_3(
|
return intersect_3(
|
||||||
ray,
|
ray,
|
||||||
pos_v,
|
pos_v,
|
||||||
dir_v,
|
dir_v,
|
||||||
hit_side,
|
hit_side,
|
||||||
|
is_from_inside,
|
||||||
(hit_side > 0 && dir_v < 0) || (hit_side < 0 && dir_v > 0)
|
(hit_side > 0 && dir_v < 0) || (hit_side < 0 && dir_v > 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -143,14 +163,19 @@ namespace sprout {
|
||||||
ray,
|
ray,
|
||||||
pos_v,
|
pos_v,
|
||||||
dir_v,
|
dir_v,
|
||||||
pos_v > val_ ? 1 : -1
|
pos_v > val_ ? 1 : -1,
|
||||||
|
face_ == aa_plane_face::both ? false
|
||||||
|
: face_ == aa_plane_face::negative ? dir_v > 0
|
||||||
|
: face_ == aa_plane_face::positive ? dir_v < 0
|
||||||
|
: (val_ > 0 && dir_v < 0) || (val_ < 0 && dir_v > 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
SPROUT_CONSTEXPR basic_aa_plane(aa_plane_direction::values direction_value, unit_type val, material_type const& mat)
|
SPROUT_CONSTEXPR basic_aa_plane(aa_plane_direction::values direction_value, unit_type val, material_type const& mat, aa_plane_face::values face = aa_plane_face::both)
|
||||||
: direction_value_(direction_value)
|
: direction_value_(direction_value)
|
||||||
, val_(val)
|
, val_(val)
|
||||||
, mat_(mat)
|
, mat_(mat)
|
||||||
|
, face_(face)
|
||||||
{}
|
{}
|
||||||
template<typename Ray>
|
template<typename Ray>
|
||||||
SPROUT_CONSTEXPR typename intersection<Ray>::type
|
SPROUT_CONSTEXPR typename intersection<Ray>::type
|
||||||
|
@ -173,8 +198,14 @@ namespace sprout {
|
||||||
//
|
//
|
||||||
template<typename Material, typename Unit>
|
template<typename Material, typename Unit>
|
||||||
inline SPROUT_CONSTEXPR sprout::darkroom::objects::basic_aa_plane<Material>
|
inline SPROUT_CONSTEXPR sprout::darkroom::objects::basic_aa_plane<Material>
|
||||||
make_aa_plane(sprout::darkroom::objects::aa_plane_direction::values dir_val, Unit const& val, Material const& mat) {
|
make_aa_plane(
|
||||||
return sprout::darkroom::objects::basic_aa_plane<Material>(dir_val, val, mat);
|
sprout::darkroom::objects::aa_plane_direction::values dir_val,
|
||||||
|
Unit const& val,
|
||||||
|
Material const& mat,
|
||||||
|
sprout::darkroom::objects::aa_plane_face::values face_val = sprout::darkroom::objects::aa_plane_face::both
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return sprout::darkroom::objects::basic_aa_plane<Material>(dir_val, val, mat, face_val);
|
||||||
}
|
}
|
||||||
} // namespace objects
|
} // namespace objects
|
||||||
} // namespace darkroom
|
} // namespace darkroom
|
||||||
|
|
|
@ -43,7 +43,8 @@ namespace sprout {
|
||||||
std::declval<material_type const&>(),
|
std::declval<material_type const&>(),
|
||||||
std::declval<unit_type const&>(),
|
std::declval<unit_type const&>(),
|
||||||
std::declval<unit_type const&>()
|
std::declval<unit_type const&>()
|
||||||
))
|
)),
|
||||||
|
bool
|
||||||
> type;
|
> type;
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
|
@ -72,7 +73,8 @@ namespace sprout {
|
||||||
: position_type(0, 0, 0)
|
: position_type(0, 0, 0)
|
||||||
,
|
,
|
||||||
normal_,//hit_side > 0 ? normal_ : sprout::darkroom::coords::negate(normal_),
|
normal_,//hit_side > 0 ? normal_ : sprout::darkroom::coords::negate(normal_),
|
||||||
sprout::darkroom::materials::calculate_material(mat_, unit_type(0), unit_type(0)) // ???
|
sprout::darkroom::materials::calculate_material(mat_, unit_type(0), unit_type(0)), // ???
|
||||||
|
false // !!! is_from_inside
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
template<typename Ray>
|
template<typename Ray>
|
||||||
|
|
|
@ -46,15 +46,17 @@ namespace sprout {
|
||||||
std::declval<material_type const&>(),
|
std::declval<material_type const&>(),
|
||||||
std::declval<unit_type const&>(),
|
std::declval<unit_type const&>(),
|
||||||
std::declval<unit_type const&>()
|
std::declval<unit_type const&>()
|
||||||
))
|
)),
|
||||||
|
bool
|
||||||
> type;
|
> type;
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
typedef sprout::tuples::tuple<bool, unit_type> zwo_type;
|
typedef sprout::tuples::tuple<int, bool, unit_type> zwo_type;
|
||||||
typedef sprout::tuples::tuple<position_type, position_type> drei_type;
|
typedef sprout::tuples::tuple<position_type, position_type> drei_type;
|
||||||
struct zw {
|
struct zw {
|
||||||
SPROUT_STATIC_CONSTEXPR std::size_t does_intersect = 0;
|
SPROUT_STATIC_CONSTEXPR std::size_t hit_side = 0;
|
||||||
SPROUT_STATIC_CONSTEXPR std::size_t distance = 1;
|
SPROUT_STATIC_CONSTEXPR std::size_t does_intersect = 1;
|
||||||
|
SPROUT_STATIC_CONSTEXPR std::size_t distance = 2;
|
||||||
};
|
};
|
||||||
struct dr {
|
struct dr {
|
||||||
SPROUT_STATIC_CONSTEXPR std::size_t point_of_intersection = 0;
|
SPROUT_STATIC_CONSTEXPR std::size_t point_of_intersection = 0;
|
||||||
|
@ -68,6 +70,10 @@ namespace sprout {
|
||||||
SPROUT_STATIC_CONSTEXPR zwo_type
|
SPROUT_STATIC_CONSTEXPR zwo_type
|
||||||
zweitens_1(unit_type const& i1, unit_type const& i2) {
|
zweitens_1(unit_type const& i1, unit_type const& i2) {
|
||||||
return zwo_type(
|
return zwo_type(
|
||||||
|
i2 > 0
|
||||||
|
? i1 < 0 ? -1 : 1
|
||||||
|
: 0
|
||||||
|
,
|
||||||
i2 > 0,
|
i2 > 0,
|
||||||
i2 > 0
|
i2 > 0
|
||||||
? i1 < 0 ? i2 : i1
|
? i1 < 0 ? i2 : i1
|
||||||
|
@ -78,7 +84,7 @@ namespace sprout {
|
||||||
zweitens(bool neg, unit_type const& b, unit_type const& det) {
|
zweitens(bool neg, unit_type const& b, unit_type const& det) {
|
||||||
return neg
|
return neg
|
||||||
? zweitens_1(b - det, b + det)
|
? zweitens_1(b - det, b + det)
|
||||||
: zwo_type(false, -1)
|
: zwo_type(0, false, -1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
template<typename Ray>
|
template<typename Ray>
|
||||||
|
@ -104,7 +110,7 @@ namespace sprout {
|
||||||
}
|
}
|
||||||
template<typename Ray, typename Vec>
|
template<typename Ray, typename Vec>
|
||||||
SPROUT_CONSTEXPR typename intersection<Ray>::type
|
SPROUT_CONSTEXPR typename intersection<Ray>::type
|
||||||
intersect_6(zwo_type const& zwo, drei_type const& drei, Vec const& normal) const {
|
intersect_6(Ray const& ray, zwo_type const& zwo, drei_type const& drei, Vec const& normal) const {
|
||||||
return typename intersection<Ray>::type(
|
return typename intersection<Ray>::type(
|
||||||
sprout::tuples::get<zw::does_intersect>(zwo),
|
sprout::tuples::get<zw::does_intersect>(zwo),
|
||||||
sprout::tuples::get<zw::distance>(zwo),
|
sprout::tuples::get<zw::distance>(zwo),
|
||||||
|
@ -126,13 +132,15 @@ namespace sprout {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
/ sprout::math::half_pi<unit_type>()
|
/ sprout::math::half_pi<unit_type>()
|
||||||
)
|
),
|
||||||
|
sprout::darkroom::coords::dot(normal, sprout::darkroom::rays::direction(ray)) > 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
template<typename Ray>
|
template<typename Ray>
|
||||||
SPROUT_CONSTEXPR typename intersection<Ray>::type
|
SPROUT_CONSTEXPR typename intersection<Ray>::type
|
||||||
intersect_5(zwo_type const& zwo, drei_type const& drei) const {
|
intersect_5(Ray const& ray, zwo_type const& zwo, drei_type const& drei) const {
|
||||||
return intersect_6<Ray>(
|
return intersect_6(
|
||||||
|
ray,
|
||||||
zwo,
|
zwo,
|
||||||
drei,
|
drei,
|
||||||
sprout::tuples::get<dr::normal>(drei)
|
sprout::tuples::get<dr::normal>(drei)
|
||||||
|
@ -141,7 +149,8 @@ namespace sprout {
|
||||||
template<typename Ray>
|
template<typename Ray>
|
||||||
SPROUT_CONSTEXPR typename intersection<Ray>::type
|
SPROUT_CONSTEXPR typename intersection<Ray>::type
|
||||||
intersect_4(Ray const& ray, zwo_type const& zwo) const {
|
intersect_4(Ray const& ray, zwo_type const& zwo) const {
|
||||||
return intersect_5<Ray>(
|
return intersect_5(
|
||||||
|
ray,
|
||||||
zwo,
|
zwo,
|
||||||
drittens(
|
drittens(
|
||||||
ray,
|
ray,
|
||||||
|
|
Loading…
Reference in a new issue