58 lines
1.2 KiB
C++
58 lines
1.2 KiB
C++
|
|
#include "Cyl.h"
|
|
#include "util/Solver.h"
|
|
#include <math.h>
|
|
#include <iostream>
|
|
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);
|
|
}
|