Scene.cpp
Go to the documentation of this file.00001 /**<!--------------------------------------------------------------------> 00002 @file Scene.cpp 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @author Matthew Jacobs (jacobs.mh@gmail.com) 00005 @date Fall 2008 00006 00007 @brief 00008 Contains all primitive and material data representing a given 3D scene 00009 <!-------------------------------------------------------------------->**/ 00010 00011 #include <Scene.h> 00012 #include <shapes.h> 00013 00014 #include <Material.h> 00015 #include <Ray.h> 00016 00017 #include <GL/gl.h> 00018 00019 Scene::~Scene() { 00020 FOREACH(MaterialListIter, m_materials, iter) { 00021 Material *material = *iter; 00022 00023 safeDelete(material); 00024 } 00025 00026 safeDelete(m_shapes); 00027 safeDelete(m_lights); 00028 } 00029 00030 void Scene::init() { 00031 ASSERT(m_shapes); 00032 00033 if (m_initted) 00034 return; 00035 00036 m_initted = true; 00037 if (m_materials.size() == 0) { 00038 Material *m = new Material(); 00039 00040 m->init(); 00041 m_materials.push_back(m); 00042 } 00043 00044 if (m_background == NULL) 00045 m_background = Material::s_nullEmitter; 00046 00047 if (m_shapes->getMaterial() == NULL) 00048 m_shapes->setMaterial(m_materials[0]); 00049 00050 // initialize spatial acceleration and materials for shapes 00051 m_shapes->init(); 00052 00053 m_lights = new ShapeSet(false); 00054 m_lights->setMaterial(m_materials[0]); 00055 SurfacePoint pt; 00056 00057 // record lights separately in addition to normal geometry 00058 FOREACH(PrimitiveListIter, m_shapes->getPrimitives(), iter) { 00059 Shape *shape = *iter; 00060 Material *material = shape->getMaterial(); 00061 00062 if (material && material->isEmitter()) 00063 m_lights->push_back(shape); 00064 } 00065 00066 // initialize spatial acceleration for lights 00067 m_lights->init(false); 00068 00069 m_emitterSampler.init(m_lights); 00070 } 00071 00072 void Scene::preview() { 00073 ASSERT(m_shapes); 00074 00075 // Draw unit coordinate system 00076 glPushAttrib(GL_LIGHTING_BIT); 00077 glDisable(GL_LIGHTING); 00078 00079 glBegin(GL_LINES); 00080 00081 glColor3f(1, 0, 0); 00082 glVertex3f(0, 0, 0); 00083 glVertex3f(1, 0, 0); 00084 00085 glColor3f(0, 1, 0); 00086 glVertex3f(0, 0, 0); 00087 glVertex3f(0, 1, 0); 00088 00089 glColor3f(0, 0, 1); 00090 glVertex3f(0, 0, 0); 00091 glVertex3f(0, 0, 1); 00092 00093 glEnd(); 00094 00095 glPopAttrib(); // GL_LIGHTING_BIT 00096 glColor3f(1, 1, 1); 00097 00098 glPushMatrix(); 00099 m_shapes->preview(); 00100 glPopMatrix(); 00101 } 00102 00103 real_t Scene::getIntersection(const Ray &ray, SurfacePoint &pt) { 00104 ASSERT(m_shapes); 00105 00106 return m_shapes->getIntersection(ray, pt); 00107 } 00108 00109 bool Scene::intersects(const Ray &ray, real_t tMax) { 00110 ASSERT(m_shapes); 00111 00112 return m_shapes->intersects(ray, tMax - EPSILON); 00113 } 00114 00115 SpectralSampleSet Scene::getBackgroundRadiance(const Vector3 &w) { 00116 return m_background->getLe(-w); 00117 } 00118
Generated on 28 Feb 2009 for Milton by
1.5.6