[FIX] Fix an issue on cylinder

This commit is contained in:
NADAL Jean-Baptiste
2024-03-20 18:23:38 +01:00
parent fd5753efeb
commit 9a8e764b56

View File

@@ -95,14 +95,15 @@ Intersections Cylinder::local_intersect(const Ray &a_ray)
Tuple Cylinder::local_normal_at(const Tuple &a_local_point) const Tuple Cylinder::local_normal_at(const Tuple &a_local_point) const
{ {
double the_distance; double the_distance;
// Compute the sqare of the distance from the y axis // Compute the square of the distance from the y axis
the_distance = std::pow(a_local_point.x(), 2) + std::pow(a_local_point.z(), 2); the_distance = std::pow(a_local_point.x(), 2) + std::pow(a_local_point.z(), 2);
if ((the_distance < 1) && (a_local_point.y() >= m_maximum - kEpsilon)) if ((the_distance < 1) && (a_local_point.y() >= m_maximum - kEpsilon))
{ {
return Tuple::Vector(0, 1, 0); return Tuple::Vector(0, 1, 0);
} }
else if ((the_distance < 1) && (a_local_point.y() <= m_maximum + kEpsilon)) else if ((the_distance < 1) && (a_local_point.y() <= m_minimum + kEpsilon))
{ {
return Tuple::Vector(0, -1, 0); return Tuple::Vector(0, -1, 0);
} }
@@ -172,6 +173,7 @@ bool Cylinder::check_cap(const Ray &a_ray, double a_distance_t)
void Cylinder::intersect_caps(const Ray &a_ray, Intersections &an_xs) void Cylinder::intersect_caps(const Ray &a_ray, Intersections &an_xs)
{ {
double the_distance_t; double the_distance_t;
// Caps only matter if the cylinder is closed. and might possibility be intersected the ray. // Caps only matter if the cylinder is closed. and might possibility be intersected the ray.
if ((m_closed == false) or (double_equal(a_ray.direction().y(), 0))) if ((m_closed == false) or (double_equal(a_ray.direction().y(), 0)))
{ {