6 #include "PerspectiveCamera.hxx"
7 #include "EyeLightShader.hxx"
8 #include "Triangle.hxx"
11 : m_camera(new PerspectiveCamera(Vec3f(0,0,8),
18 m_bgColor(Vec3f(0,0,0)),
30 for(unsigned int i
= 0; i
< m_primitives
.size(); ++i
)
32 delete m_primitives
[i
];
37 Scene::Scene(const Scene
& s
)
43 Scene::operator=(const Scene
& s
)
49 Scene::Add(Primitive
* p
)
51 m_primitives
.push_back(p
);
57 m_lights
.push_back(l
);
61 Scene::Intersect(Ray
& ray
)
63 bool intersect
= false;
65 for(unsigned int i
= 0; i
< m_primitives
.size(); ++i
)
67 intersect
|= m_primitives
[i
]->Intersect(ray
);
74 Scene::Occluded(Ray
& ray
)
76 return this->Intersect(ray
);
80 Scene::RayTrace(Ray
& ray
)
82 bool intersect
= this->Intersect(ray
);
83 return (intersect
) ? ray
.hit()->shader()->Shade(ray
) : m_bgColor
;
99 Scene::setCamera(const Camera
* camera
)
103 m_camera
= const_cast<Camera
*>(camera
);
107 Scene::ParseOBJ(const std::string
& file
, float scale
)
109 std::cerr
<< "(Scene): Parsing OBJ file : " << file
<< std::endl
;
115 // for the moment, we will attach a white eyelight shader to each object
116 // in the future, you will extend your parser to also read in material definitiions
117 if(m_shader
== 0) // not yet defined
118 m_shader
= new EyeLightShader(this, Vec3f(1.0,1.0,1.0));
123 in
.open(file
.c_str(), std::ios::in
);
124 if(in
.bad() || in
.fail())
126 std::cerr
<< "(Scene): Could not open file " << file
<< std::endl
;
134 std::getline(in
, line
);
135 this->parseOBJLine(line
);
138 // finished parsing file -> close fileStream
141 // build triangle list from parsed vertices
142 this->buildTriangleList(scale
);
144 std::cerr
<< "(Scene): Finished parsing." << std::endl
;
149 Scene::parseOBJLine(const std::string
& line
)
151 std::istringstream
iss(line
);
157 this->parseVertex(iss
);
162 this->parseFace(iss
);
167 Scene::parseVertex(std::istringstream
& iss
)
170 iss
>> v
[0] >> v
[1] >> v
[2];
172 m_vertices
.push_back(v
);
177 Scene::parseFace(std::istringstream
& iss
)
180 iss
>> f
[0] >> f
[1] >> f
[2];
181 m_faces
.push_back(f
);
185 Scene::buildTriangleList(float fac
)
187 for(unsigned int f
= 0; f
< m_faces
.size(); ++f
)
189 // stores indices of triangle into vertex list
190 // remember: indices start at 1!!
191 Vec3f face_idx
= m_faces
[f
];
192 this->Add(new Triangle(m_vertices
[ face_idx
[0]-1 ] * fac
,
193 m_vertices
[ face_idx
[1]-1 ] * fac
,
194 m_vertices
[ face_idx
[2]-1 ] * fac
,
198 m_centroid
/= static_cast<float>(m_vertices
.size());
199 std::cerr
<< "(Scene): Model centroid = " << m_centroid
* fac
<< std::endl
;
208 Scene::GetSceneBox() const
This page took 0.047731 seconds and 5 git commands to generate.