-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsurface.h
87 lines (67 loc) · 2.52 KB
/
surface.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
#ifndef SURFACE_HEADER
#define SURFACE_HEADER
#include "math.h"
#include "shader.h"
#include "util.h"
#include "hittable.h"
#include <memory>
#include <vector>
class Surface : public Renderable
{
public:
void setMaterial(std::unique_ptr<Shader> shader);
virtual Util::Color computeColor(
const std::vector<std::unique_ptr<LightSource>> & lightSources,
Math::Ray viewRay,
std::shared_ptr<Renderable> surface,
std::shared_ptr<Util::HitRecord> hitRecord
) const;
virtual bool hit(Math::Ray ray, float t0, float t1, std::shared_ptr<Util::HitRecord> & hitRecord) const = 0;
virtual Math::Box boundingBox() const = 0;
std::unique_ptr<Shader> shader = NULL;
};
class Sphere: public Surface
{
public:
Sphere();
Sphere(float radius);
Sphere(float radius, Math::Vector3 center);
float getRadius() const;
Math::Vector3 getCenter() const;
void setRadius(float radius);
void setCenter(Math::Vector3 center);
bool hit(Math::Ray ray, float t0, float t1, std::shared_ptr<Util::HitRecord> & hitRecord) const;
Math::Box boundingBox() const;
private:
float radius;
Math::Vector3 center;
};
class Triangle: public Surface
{
public:
Triangle();
// let vertex1, vertex2, and vertex3 be in counterclockwise order
Triangle(Math::Vector3 vertex1, Math::Vector3 vertex2, Math::Vector3 vertex3);
// let the triangle have these three vertices but make it so that the normal faces toward the facingDirection
Triangle(Math::Vector3 vertex1, Math::Vector3 vertex2, Math::Vector3 vertex3, Math::Vector3 facingDirection);
std::vector<Math::Vector3> getVertices() const;
Math::Vector3 getUnitNormal() const;
void setVertices(Math::Vector3 vertex1, Math::Vector3 vertex2, Math::Vector3 vertex3);
bool hit(Math::Ray ray, float t0, float t1, std::shared_ptr<Util::HitRecord> & hitRecord) const;
Math::Box boundingBox() const;
private:
Math::Vector3 vertex1, vertex2, vertex3;
};
class GroupSurface: public Surface
{
public:
GroupSurface();
void addSurface(std::unique_ptr<Surface> surface);
Util::Color computeColor(const std::vector<std::unique_ptr<LightSource>> &lightSources, Math::Ray viewRay, std::shared_ptr<Renderable> surface, std::shared_ptr<Util::HitRecord> hitRecord) const;
bool hit(Math::Ray ray, float t0, float t1, std::shared_ptr<Util::HitRecord> & hitRecord) const;
Math::Box boundingBox() const;
private:
std::vector<std::unique_ptr<Surface>> surfaces;
Math::Vector3 minBound, maxBound;
};
#endif