Ring.cc

Go to the documentation of this file.
00001 
00005 #include "Ring.h"
00006 #include "BoundingBox.h"
00007 #include "HitRecord.h"
00008 #include "Math.h"
00009 #include "Ray.h"
00010 #include <iostream>
00011 #include <stdlib.h>
00012 using namespace std;
00013 
00014 Ring::Ring(Material* material, const Point &c, const Vector& n, const double r1, const double r2)
00015     : Primitive(material), center(c), norm(n), radius1(r1), radius2(r2)
00016 {
00017     r1Sq = r1 * r1;
00018     r2Sq = r2 * r2;
00019 
00020     norm.normalize();
00021     d = Dot(norm, c);
00022 }
00023 
00024 Ring::~Ring()
00025 {
00026 }
00027 
00028 void Ring::intersect(HitRecord& hit, const RenderContext& context, const Ray& ray) const
00029 {
00030     double denom = Dot(norm, ray.direction());
00031     if(Abs(denom) > 1.e-6){
00032         double t = (d-Dot(norm, ray.origin()))/denom;
00033 
00034         Point pt = ray.origin() + ray.direction() * t;
00035 
00036         Vector v = pt - center;
00037     
00038         double l = v.length2();
00039         if (l < r2Sq && l > r1Sq) {
00040             hit.hit(t, this, matl);
00041         }
00042     }
00043 
00044 }
00045 
00046 
00047 void Ring::normal(Vector& normal, const RenderContext&,
00048                    const Point&, const Ray&, const HitRecord&) const
00049 {
00050     normal = norm;
00051 }
00052 
00053 void Ring::getBounds(BoundingBox& bbox) const
00054 {
00055   Vector diag(radius1, radius1, radius1);
00056   bbox.extend(center+diag);
00057   bbox.extend(center-diag);
00058 }
00059 

Generated on Tue Jan 29 21:34:54 2008 for specter by  doxygen 1.4.6