plane.cpp

Go to the documentation of this file.
00001 /* file name  : staticinit.cpp
00002  * author     : Michael Brailsford
00003  * created    : Sun Oct 07 01:35:17 -0500 2007
00004  * copyright  : 2007 Michael Brailsford
00005  */
00006 
00007 #include "plane.h"
00008 
00009 // This actually makes the static init work.
00010 Plane::StaticInit Plane::m_init;
00011 
00012 //{{{
00013 Plane::Plane(Point3D p1, Point3D p2, Point3D p3, std::string color, std::string material_name, std::string bumpmap_name) 
00014     : m_point(p1)
00015 {
00016     m_normal = Ray(p1, cross_product((p2 - p1), (p3 - p1)));
00017     m_d = dot_product(m_point, m_normal.direction());
00018 
00019     Scene * scene = Scene::get_instance();
00020     m_material = scene->get_material(material_name);
00021 
00022     m_bumpmap = scene->get_bumpmap(bumpmap_name);
00023 }
00024 //}}}
00025 //{{{
00026 bool Plane::collides_with(const Ray &ray, double &t) const {
00027     Point3D orig = ray.origin();
00028     Vector dir = ray.direction();
00029 
00030     double denominator = dot_product(dir, m_normal.direction());
00031     if(denominator > -0.0001 && denominator < 0.0001) {
00032         return false;
00033     }
00034 
00035     double numerator = m_d - dot_product(orig, m_normal.direction());
00036     if(numerator > -0.0001 && numerator < 0.0001) {
00037         return false;
00038     }
00039 
00040     t = numerator / denominator;
00041 
00042     // The ray collides behind the origin.
00043     if(t <= 0) {
00044         return false;
00045     }
00046     
00047     return true;
00048 }
00049 //}}}
00050 //{{{
00051 Ray Plane::get_normal(const Point3D &p) const {
00052     return Ray(p, m_normal.direction() );
00053 }
00054 //}}}

Generated on Tue Oct 30 22:12:15 2007 for mbrt by  doxygen 1.5.2