diff --git a/shapes/Cyl.cc b/shapes/Cyl.cc index cca5ca3..a8dc515 100644 --- a/shapes/Cyl.cc +++ b/shapes/Cyl.cc @@ -87,9 +87,7 @@ Shape::IntersectList Cyl::intersect(const Ray & ray) double b = m_bottom_radius; QuadraticSolver solver(Rdx * Rdx + Rdy * Rdy - m2 * Rdz * Rdz, 2.0 * (R0x*Rdx + R0y*Rdy - m2*R0z*Rdz - m*Rdz*b), - R0x*R0x + R0y*R0y - - m2*R0z*R0z - b*b - 2*m*R0z*b - ); + R0x*R0x + R0y*R0y - m2*R0z*R0z - b*b - 2*m*R0z*b); Solver::Result solutions = solver.solve(); for (int i = 0; i < solutions.numResults; i++) @@ -123,6 +121,19 @@ Vector Cyl::getNormalAt(const Vector & pt) } else { + if (m_slope == 0.0) + { + normal = Vector(local_pt[0], local_pt[1], 0.0); + normal.normalize(); + } + else + { + double norm_slope = -1.0 / m_slope; + double z = sqrt(local_pt[0]*local_pt[0] + local_pt[1]*local_pt[1]) + * norm_slope; + normal = Vector(local_pt[0], local_pt[1], z); + normal.normalize(); + } } return m_transform.transform_normal(normal); diff --git a/shapes/Shape.h b/shapes/Shape.h index 19ade8a..ddb17e8 100644 --- a/shapes/Shape.h +++ b/shapes/Shape.h @@ -40,9 +40,10 @@ class Shape refptr m_material; }; -#include "Sphere.h" -#include "Plane.h" #include "Box.h" +#include "Cyl.h" +#include "Plane.h" +#include "Sphere.h" #endif