INFO804 Introduction à l'informatique graphique
Loading...
Searching...
No Matches
Scene.h
Go to the documentation of this file.
1/**
2@file Scene.h
3@author JOL
4*/
5#pragma once
6#ifndef _SCENE_H_
7#define _SCENE_H_
8
9#include <cassert>
10#include <vector>
11#include "GraphicalObject.h"
12#include "Light.h"
13
14/// Namespace RayTracer
15namespace rt {
16
17 /**
18 Models a scene, i.e. a collection of lights and graphical objects
19 (could be a tree, but we keep a list for now for the sake of
20 simplicity).
21
22 @note Once the scene receives a new object, it owns the object and
23 is thus responsible for its deallocation.
24 */
25
26 struct Scene {
27 /// The list of lights modelled as a vector.
28 std::vector< Light* > myLights;
29 /// The list of objects modelled as a vector.
30 std::vector< GraphicalObject* > myObjects;
31
32 /// Default constructor. Nothing to do.
33 Scene() {}
34
35 /// Destructor. Frees objects.
37 {
38 for ( Light* light : myLights )
39 delete light;
40 for ( GraphicalObject* obj : myObjects )
41 delete obj;
42 // The vector is automatically deleted.
43 }
44
45 /// This function calls the init method of each of its objects.
46 void init( Viewer& viewer )
47 {
48 for ( GraphicalObject* obj : myObjects )
49 obj->init( viewer );
50 for ( Light* light : myLights )
51 light->init( viewer );
52 }
53 /// This function calls the draw method of each of its objects.
54 void draw( Viewer& viewer )
55 {
56 for ( GraphicalObject* obj : myObjects )
57 obj->draw( viewer );
58 for ( Light* light : myLights )
59 light->draw( viewer );
60 }
61 /// This function calls the light method of each of its lights
62 void light(Viewer& viewer )
63 {
64 for ( Light* light : myLights )
65 light->light( viewer );
66 }
67
68 /// Adds a new object to the scene.
69 void addObject( GraphicalObject* anObject )
70 {
71 myObjects.push_back( anObject );
72 }
73
74 /// Adds a new light to the scene.
75 void addLight( Light* aLight )
76 {
77 myLights.push_back( aLight );
78 }
79
80 /// @param[in] ray the ray that is traveling in the scene
81 ///
82 /// @param[out] object either a null pointer (0) if no object is
83 /// intersected by the ray or a pointer to the closest object
84 /// intersected by the given ray.
85 ///
86 /// @param[out] p if \a object is not null, then it is the point
87 /// of intersection between the ray and this object.
88 ///
89 /// @return a non-positive value if there was an intersection,
90 /// positive otherwise (e.g. could be like the distance to the closest
91 /// object to the ray).
92 Real
93 rayIntersection( const Ray& ray,
94 GraphicalObject*& object,
95 Point3& p )
96 {
97 object = 0;
98 return 1.0f;
99 }
100
101 private:
102 /// Copy constructor is forbidden.
103 Scene( const Scene& ) = delete;
104 /// Assigment is forbidden.
105 Scene& operator=( const Scene& ) = delete;
106 };
107
108} // namespace rt
109
110#endif // #define _SCENE_H_
Namespace RayTracer.
Definition Color.h:11
float Real
the type for representing a real number.
Lights are used to give lights in a scene.
Definition Light.h:17
Definition Ray.h:18
void init(Viewer &viewer)
This function calls the init method of each of its objects.
Definition Scene.h:46
std::vector< GraphicalObject * > myObjects
The list of objects modelled as a vector.
Definition Scene.h:30
Real rayIntersection(const Ray &ray, GraphicalObject *&object, Point3 &p)
Definition Scene.h:93
std::vector< Light * > myLights
The list of lights modelled as a vector.
Definition Scene.h:28
Scene()
Default constructor. Nothing to do.
Definition Scene.h:33
void light(Viewer &viewer)
This function calls the light method of each of its lights.
Definition Scene.h:62
void addObject(GraphicalObject *anObject)
Adds a new object to the scene.
Definition Scene.h:69
void addLight(Light *aLight)
Adds a new light to the scene.
Definition Scene.h:75
~Scene()
Destructor. Frees objects.
Definition Scene.h:36
void draw(Viewer &viewer)
This function calls the draw method of each of its objects.
Definition Scene.h:54