00001
00002 #include "renderable.h"
00003 #include "scene.h"
00004 #include "material.h"
00005 #include "sceneparser.h"
00006
00007 #include <iostream>
00008 #include <cstdlib>
00009 #include <sstream>
00010
00011 using std::string;
00012 using std::vector;
00013 using std::string;
00014 using std::ostringstream;
00015
00016 Scene * Scene::inst = NULL;
00017
00018
00019 Scene * Scene::get_instance(string scene_file_name) {
00020 if ( inst == NULL ) {
00021 log_debug("get_instance()\n");
00022 inst = new Scene();
00023 SceneParser sp(scene_file_name);
00024 }
00025
00026 return inst;
00027 }
00028
00029
00030 Scene::Scene()
00031 : scene(),
00032 camera(),
00033 pixel_width(WIDTH),
00034 pixel_height(HEIGHT),
00035 output_filename("scene.png"),
00036 subpixels(SUBPIXEL_SQRT),
00037 max_depth(MAX_DEPTH)
00038 {
00039 }
00040
00041
00042 Scene::~Scene() {
00043 scene.clear();
00044 }
00045
00046
00047
00048 Renderable * Scene::find_collision(const Ray &ray, double &dist) const {
00049 vector<Renderable *>::const_iterator iter, end;
00050 Renderable * rv = NULL;
00051
00052 for (iter = scene.begin(), end = scene.end(); iter != end; ++iter) {
00053 double d = dist;
00054 if ((*iter)->collides_with(ray, d)) {
00055 if ( d < dist + 0.00001 && d > -0.00001) {
00056 rv = *iter;
00057 dist = d;
00058 }
00059 }
00060 }
00061 return rv;
00062 }
00063
00064
00065 std::string Scene::get_geometry() {
00066 ostringstream str;
00067 str << pixel_width << "x" << pixel_height;
00068 return str.str();
00069 }
00070