-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene.hpp
84 lines (66 loc) · 2.17 KB
/
scene.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef SCENE_H
#define SCENE_H
#include "vec3.hpp"
#include <vector>
#include "sphere.hpp"
#include "camera.hpp"
#include "color.hpp"
#include "hittable_list.hpp"
#include "sampler.hpp"
#include "bvh_tree.hpp"
#include <iostream>
#include <fstream>
#include <string>
#include <limits>
#include <memory>
#include <vector>
using namespace std;
const int SAMPLES = 1;
const int REFL_SAMPLES = 2;
const int REFR_SAMPLES = 4;
class scene
{
public:
//Scene constructor
scene(camera cam, color bgColor, hittable_list surfaces, vector<shared_ptr<light>> lights, int samples, int width, int height)
{
this->cam = cam;
this->bgColor = bgColor;
this->surfaces = surfaces;
this->lights = lights;
this->WIDTH = width;
this->HEIGHT = height;
}
void traceScene(string name)
{
//create BVH tree
bvh_tree bvtree(2, surfaces, 1);
//write out file
ofstream outFile;
outFile.open(name + ".ppm");
outFile << "P3\n" << WIDTH << " " << HEIGHT << "\n255\n";
for (int j = HEIGHT - 1; j >= 0; j--)
{
//cout << "\rSCANLINES REMAINING: " << j << ' ' << flush;
for (int i = 0; i < WIDTH; i++)
{
//sampler: structure for generating samples for a given pixel.
sampler Sampler = sampler(SAMPLES, REFL_SAMPLES, REFR_SAMPLES, i, j, cam, bgColor);
color pixel_color = Sampler.sample_scene(surfaces, lights); //given a list of surfaces, returns a color for the given pixel that the ray intersects
write_color(outFile, pixel_color); //writes the color to the ppm file
}
}
cout << "\nBEEP BOOP BEEP BOOP DONE!" << endl;
outFile.close();
}
private:
int WIDTH;
int HEIGHT;
camera cam;
int samples;
color ambientColor;
color bgColor;
hittable_list surfaces; //all the surfaces in a scene that a ray can hit
vector<shared_ptr<light>> lights;
};
#endif