-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scene.h
100 lines (87 loc) · 2.11 KB
/
Scene.h
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef SCENE_H
#define SCENE_H
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <Eigen/Dense>
#include <Eigen/Core>
#include <Eigen/LU>
using namespace std;
struct Color {
double red;
double green;
double blue;
};
struct HitRecord {
float t;
Color c;
};
class Camera {
public:
Camera();
Camera(Eigen::Vector3d fromInput, Eigen::Vector3d atInput, Eigen::Vector3d upInput, double angleInput, double hitherInput, int resxInput, int resyInput);
Eigen::Vector3d from;
Eigen::Vector3d at;
Eigen::Vector3d up;
double angle;
double hither;
int resx;
int resy;
double left;
double right;
double top;
double bottom;
double d;
double aspectRatio;
Eigen::Vector3d u;
Eigen::Vector3d v;
Eigen::Vector3d w;
};
struct Ray {
Ray(double i, double j, Camera camera);
Eigen::Vector3d origin; //eye
Eigen::Vector3d direction; //direction
};
class Shape {
public:
Shape();
virtual bool intersect (const Ray &r, double t0, double t1, HitRecord *hr) = 0;
};
class Triangle {
public:
Triangle(Eigen::Vector3d firstVertex, Eigen::Vector3d secondVertex, Eigen::Vector3d thirdVertex);
bool intersect (const Ray &r, double t0, double t1, HitRecord *hr);
friend ostream& operator<<(ostream& os, const Triangle& triangle);
private:
Eigen::Vector3d vertex1;
Eigen::Vector3d vertex2;
Eigen::Vector3d vertex3;
};
class Polygon: public Shape {
public:
Polygon(std::vector<Eigen::Vector3d> inputVertices);
bool intersect (const Ray &r, double t0, double t1, HitRecord *hr);
//write a destructor
std::vector<Eigen::Vector3d> vertices;
std::vector<Triangle> triangles;
friend ostream& operator<<(ostream& os, const Polygon& polygon);
Color color;
};
class Scene {
public:
Scene(string filename);
void calcIntersections();
void RayTrace();
void WriteToPPM();
friend ostream& operator<<(ostream& os, const Scene& scene);
Camera camera;
std::vector<Polygon> shapes;
Color backgroundColor;
Eigen::Vector3d xDir;
Eigen::Vector3d yDir;
Eigen::Vector3d zDir;
vector<vector<array<double, 3>>> pixels;
//vector<int[3]> pixels;
};
#endif