Ray Tracer  2020
Scene.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifndef SCENE_H_INCLUDED
4 #define SCENE_H_INCLUDED
5 
6 #include <memory>
7 #include <string>
8 #include <vector>
9 
10 #include "Camera.h"
11 #include "Colour.h"
12 #include "LightSource.h"
13 #include "Material.h"
14 #include "NonCopyable.h"
15 #include "Object.h"
16 #include "Ray.h"
17 #include "RayIntersection.h"
18 
44 class Scene : private NonCopyable {
45 
46 public:
47 
53  Scene();
54 
56  ~Scene();
57 
73  void setCamera(std::shared_ptr<Camera> camera) {
74  camera_ = camera;
75  }
76 
84  void addObject(std::shared_ptr<Object> object) {
85  objects_.push_back(object);
86  }
87 
95  void addLight(std::shared_ptr<LightSource> light) {
96  lights_.push_back(light);
97  }
98 
99 
109  void render() const;
110 
112 
114 
115  unsigned int maxRayDepth;
116 
125  bool hasCamera() const;
126 
127  unsigned int renderWidth;
128  unsigned int renderHeight;
129  std::string filename;
130 
131 private:
132 
133  std::shared_ptr<Camera> camera_;
134  std::vector<std::shared_ptr<Object> > objects_;
135  std::vector<std::shared_ptr<LightSource> > lights_;
136 
146  RayIntersection intersect(const Ray& ray) const;
147 
173  Colour computeColour(const Ray& ray, unsigned int rayDepth = 0) const;
174 
175 };
176 
177 #endif
Camera class header file.
Colour class header file.
LightSource class header file.
Material class header file.
NonCopyable class header file.
Object class header file.
Ray class header file.
RayIntersection class header file.
Class to store colour information.
Definition: Colour.h:25
NonCopyable class.
Definition: NonCopyable.h:27
Rays as a starting Point and Direction.
Definition: Ray.h:20
Class to store the intersection of a Ray and an Object.
Definition: RayIntersection.h:27
A Scene to be ray traced.
Definition: Scene.h:44
unsigned int maxRayDepth
Maximum number of reflected Rays to trace.
Definition: Scene.h:115
std::string filename
File to save the image to.
Definition: Scene.h:129
unsigned int renderWidth
Width in pixels of the image to render.
Definition: Scene.h:127
void setCamera(std::shared_ptr< Camera > camera)
Set the Scene's Camera.
Definition: Scene.h:73
~Scene()
Scene destructor.
Definition: Scene.cpp:13
void addLight(std::shared_ptr< LightSource > light)
Add a new LightSource.
Definition: Scene.h:95
std::vector< std::shared_ptr< LightSource > > lights_
Collection of LightSources in the Scene.
Definition: Scene.h:135
Colour computeColour(const Ray &ray, unsigned int rayDepth=0) const
Compute the Colour seen by a Ray in the Scene.
Definition: Scene.cpp:52
bool hasCamera() const
Check if the Scene has a Camera.
Definition: Scene.cpp:105
void render() const
Render an image of the Scene.
Definition: Scene.cpp:17
Colour backgroundColour
Colour for any Ray that does not hit an Object.
Definition: Scene.h:111
std::shared_ptr< Camera > camera_
Camera to render the image with.
Definition: Scene.h:133
Colour ambientLight
Ambient light level and Colour in the Scene.
Definition: Scene.h:113
RayIntersection intersect(const Ray &ray) const
Intersect a Ray with the Objects in a Scene.
Definition: Scene.cpp:37
void addObject(std::shared_ptr< Object > object)
Add a new Object.
Definition: Scene.h:84
Scene()
Default Scene constructor. This creates an empty Scene, with a black background and no ambient light....
Definition: Scene.cpp:9
std::vector< std::shared_ptr< Object > > objects_
Collection of Objects in the Scene.
Definition: Scene.h:134
unsigned int renderHeight
Height in pixels of the image to render.
Definition: Scene.h:128