added shapes/Cyl, needs finishing

git-svn-id: svn://anubis/fart/trunk@130 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-02-18 23:06:45 +00:00
parent 395161eb66
commit 561098001a
2 changed files with 80 additions and 0 deletions

57
shapes/Cyl.cc Normal file
View File

@ -0,0 +1,57 @@
#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);
}

23
shapes/Cyl.h Normal file
View File

@ -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