diff --git a/shapes/Cyl.cc b/shapes/Cyl.cc new file mode 100644 index 0000000..5e287b6 --- /dev/null +++ b/shapes/Cyl.cc @@ -0,0 +1,57 @@ + +#include "Cyl.h" +#include "util/Solver.h" +#include +#include +using namespace std; + +#define FP_EQUAL(x,y) (fabs((x)-(y)) < 0.000001) + +Cyl::Cyl(double bottom_radius, double top_radius, double height) +{ + m_bottom_radius = fabs(bottom_radius); + m_bottom_radius_2 = bottom_radius * bottom_radius; + m_top_radius = fabs(top_radius); + m_top_radius_2 = top_radius * top_radius; + m_height = fabs(height); + if (m_height == 0.0) + m_height = 1.0; +} + +Shape::IntersectList Cyl::intersect(const Ray & ray) +{ + Ray ray_inv = m_inverse.transform_ray(ray); + + IntersectList res; + /* + * Ray equation: R = R0 + tRd + * x = R0x + tRdx + * y = R0y + tRdy + * z = R0z + tRdz + * Side equation: x^2 + y^2 = + * Combined: + */ + + return res; +} + +Vector Cyl::getNormalAt(const Vector & pt) +{ + Vector local_pt = m_inverse.transform_point(pt); + + Vector normal; + + if ( FP_EQUAL(local_pt[2], 0.0) && m_bottom_radius > 0.0 ) + { + normal = Vector(0, 0, -1); + } + else if ( FP_EQUAL(local_pt[2], m_height) && m_top_radius > 0.0 ) + { + normal = Vector(0, 0, 1); + } + else + { + } + + return m_transform.transform_normal(normal); +} diff --git a/shapes/Cyl.h b/shapes/Cyl.h new file mode 100644 index 0000000..ad1afcf --- /dev/null +++ b/shapes/Cyl.h @@ -0,0 +1,23 @@ + +#ifndef CYL_H +#define CYL_H CYL_H + +#include "Shape.h" + +class Cyl : public Shape +{ + public: + Cyl(double bottom_radius, double top_radius, double height); + IntersectList intersect(const Ray & ray); + Vector getNormalAt(const Vector & pt); + + protected: + double m_bottom_radius; + double m_bottom_radius_2; + double m_top_radius; + double m_top_radius_2; + double m_height; +}; + +#endif +