cleaning up shapes/Cyl a bit
git-svn-id: svn://anubis/fart/trunk@190 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
feeaa34d62
commit
1ad08d9998
@ -17,6 +17,8 @@ Cyl::Cyl(double bottom_radius, double top_radius, double height)
|
||||
if (m_height == 0.0)
|
||||
m_height = 1.0;
|
||||
m_slope = (m_top_radius - m_bottom_radius) / m_height; /* rise over run */
|
||||
if ( ! FP_EQUAL(m_slope, 0.0) )
|
||||
m_inv_slope = -1.0 / m_slope;
|
||||
}
|
||||
|
||||
Shape::IntersectionList Cyl::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
@ -34,7 +36,7 @@ Shape::IntersectionList Cyl::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
{
|
||||
Vector isect_point = ray_inv[solutions.results[0]];
|
||||
if (isect_point[0]*isect_point[0] + isect_point[1]*isect_point[1]
|
||||
< m_bottom_radius_2)
|
||||
<= m_bottom_radius_2)
|
||||
{
|
||||
res.add(Intersection(_this,
|
||||
m_transform.transform_point(isect_point)));
|
||||
@ -52,7 +54,7 @@ Shape::IntersectionList Cyl::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
{
|
||||
Vector isect_point = ray_inv[solutions.results[0]];
|
||||
if (isect_point[0]*isect_point[0] + isect_point[1]*isect_point[1]
|
||||
< m_top_radius_2)
|
||||
<= m_top_radius_2)
|
||||
{
|
||||
res.add(Intersection(_this,
|
||||
m_transform.transform_point(isect_point)));
|
||||
@ -97,7 +99,7 @@ Shape::IntersectionList Cyl::intersect(refptr<Shape> _this, const Ray & ray)
|
||||
if (solutions.results[i] >= 0.0)
|
||||
{
|
||||
Vector isect_point = ray_inv[solutions.results[i]];
|
||||
if (isect_point[2] >= 0.0 && isect_point[2] <= m_height)
|
||||
if (isect_point[2] > 0.0 && isect_point[2] < m_height)
|
||||
{
|
||||
res.add(Intersection(_this,
|
||||
m_transform.transform_point(isect_point)));
|
||||
@ -124,19 +126,25 @@ Vector Cyl::getNormalAt(const Vector & pt)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_slope == 0.0)
|
||||
if ( FP_EQUAL(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();
|
||||
double x = local_pt[0];
|
||||
double y = local_pt[1];
|
||||
double dist = sqrt( local_pt[0] * local_pt[0]
|
||||
+ local_pt[1] * local_pt[1] );
|
||||
if (dist > 0.0)
|
||||
{
|
||||
double scale = 1.0 / dist;
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
}
|
||||
normal = Vector(x, y, m_inv_slope);
|
||||
}
|
||||
normal.normalize();
|
||||
}
|
||||
|
||||
return m_transform.transform_normal(normal);
|
||||
|
@ -18,6 +18,7 @@ class Cyl : public Shape
|
||||
double m_top_radius_2;
|
||||
double m_height;
|
||||
double m_slope;
|
||||
double m_inv_slope;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user