still broken reflective eyelight shader, solution for assignment 2.2b
[MicroTrace.git] / Scene.cxx
1 #include "Scene.hxx"
2 #include "PerspectiveCamera.hxx"
3 #include <limits>
4
5 Scene::Scene()
6 : m_camera(new PerspectiveCamera(Vec3f(0,0,8),
7 Vec3f(0,0,-1),
8 Vec3f(0,1,0),
9 50,
10 640,
11 480)
12 ),
13 m_bgColor(Vec3f(0,0,0))
14 {
15 }
16
17 Scene::~Scene()
18 {
19 delete m_camera;
20 }
21
22 Scene::Scene(const Scene& s)
23 {
24 operator=(s);
25 }
26
27 Scene&
28 Scene::operator=(const Scene& s)
29 {
30 return *this;
31 }
32
33 void
34 Scene::Add(Primitive* p)
35 {
36 m_primitives.push_back(p);
37 }
38
39
40 bool
41 Scene::Intersect(Ray& ray)
42 {
43 bool hit = false;
44 float t = std::numeric_limits<float>::max();
45 for (std::vector<Primitive*>::iterator i = m_primitives.begin();
46 i != m_primitives.end(); i++) {
47 // store closest object hit
48 if (hit |= (*i)->Intersect(ray)) {
49 if (ray.t() < t) {
50 ray.setHit(*i);
51 t = ray.t();
52 }
53 }
54 }
55 return hit;
56 }
57
58 bool
59 Scene::Occluded(Ray& ray)
60 {
61 return false;
62 }
63
64 Vec3f
65 Scene::RayTrace(Ray& ray)
66 {
67 if (Intersect(ray)) {
68 return ray.hit()->shader()->Shade(ray);
69 } else {
70 return Vec3f(0,0,0);
71 }
72 }
73
74 const Camera*
75 Scene::camera() const
76 {
77 return m_camera;
78 }
This page took 0.055845 seconds and 5 git commands to generate.