src/rcrt/Scene.cpp

Go to the documentation of this file.
00001 #include "Scene.h"
00002 #include "materials/Material.h"
00003 
00004 using namespace std;
00005 
00006 namespace rcrt
00007 {
00008 
00009 Scene::Scene(vector<Traceable*>* trList, vector<Light*>* ls, bool s)
00010 :sceneTree(trList),lights(ls),shadows(s),ownLights(ls == 0)
00011 {
00012         if(ls == 0){
00013                 lights = new std::vector<Light*>();
00014         }
00015 }
00016 
00017 Scene::Scene(bool s):sceneTree(),lights(0),shadows(s),ownLights(true)
00018 {
00019         lights = new std::vector<Light*>();
00020 }
00021 
00022 Scene::~Scene()
00023 {
00024         if(ownLights)
00025                 delete lights;
00026 }
00027 
00028 Intersection Scene::intersect(Ray& r) const
00029 {
00030         return sceneTree.intersect(r);
00031 }
00032 
00033 bool Scene::isOccluded(const Point3D& point, const Vec3D& dir, const float& maxDir) const
00034 {
00035         static const float epsi = 0.0001;
00036         Ray r(point+epsi*dir, dir.normalized());
00037         r.setMinDist(epsi);
00038         r.setMaxDist(maxDir);
00039         Intersection ins = intersect(r);
00040         float dist = ins.getDistance();
00041         
00042         if(ins.isValid() && dist+epsi+0.001 < maxDir && !ins.getPrimitive()->getMaterial()->refracts()){/*
00043                 cout << "[Scene]: isOccluded: maxDist=" << maxDir << " actual dist="
00044                         << ins.getDistance() << " point=" << ins.getPosition() << endl;
00045                 cout << "[Scene]:             occluding object:" <<
00046                         ins.getPrimitive()->getParent()->getName() << " Prim=" << ins.getPrimitive() << endl;
00047                 cout << "[Scene]:             direction=" << dir << " from=" << point << endl;*/
00048                 return true;
00049         }
00050         return false;
00051 }
00052 
00053 void Scene::addLight(Light* light)
00054 {
00055         lights->push_back(light);
00056 }
00057 
00058 vector<Light*>* const Scene::getLights() const
00059 {
00060         return lights;
00061 }
00062 
00063 const AABB& Scene::getBoundingBox() const
00064 {
00065         return sceneTree.getBoundingBox();
00066 }
00067 
00068 const Point3D& Scene::getCentroid() const
00069 {
00070         return sceneTree.getBoundingBox().getCentroid();
00071 }
00072 
00073 void Scene::setShadows(bool s)
00074 {
00075         shadows = s;
00076 }
00077 
00078 bool Scene::castShadows() const
00079 {
00080         return shadows;
00081 }
00082 
00083 void Scene::setTraceables(std::vector<Traceable*>* trList)
00084 {
00085         sceneTree.setTraceables(trList);
00086 }
00087 
00088 void Scene::setLights(std::vector<Light*>* ls)
00089 {
00090         if(ls == 0){
00091                 lights = new std::vector<Light*>();
00092         } else {
00093                 lights = ls;
00094         }
00095 }
00096 
00097 void Scene::setName(string na)
00098 {
00099         name = na;
00100 }
00101 
00102 const string& Scene::getName() const
00103 {
00104         return name;
00105 }
00106 
00107 AABB Scene::clipBox(AABB& cbox) const {
00108         return getBoundingBox();
00109 }
00110 
00111 }

Generated on Thu Jan 31 19:26:19 2008 for RenderingCompetitionRayTracer by  doxygen 1.5.3