-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhittable.h
60 lines (47 loc) · 1.28 KB
/
hittable.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
#pragma once
#include "rt.h"
#include <memory>
enum material_type
{
LAMBERTIAN,
METAL,
DIELETRIC
};
class material;
// a hit point relative infomations
struct hit_record
{
// Hit point coord
point3 p;
// Hit point normal
vec3 normal;
// Hit point t : p = origin + t * direction
double t;
// Whether the hit is object's front_face(outside)
bool front_face;
// Hit point's material
std::shared_ptr<material> mat;
material_type mat_type;
// Hit point's u,v coord
double u, v;
// Assume that the normal (point against) the ray
void set_face_normal(const ray& r, const vec3& outward_normal)
{
// Sets the hit record normal vector
// The outward_normal is Assumed to a unit vector
front_face = dot(normalize(r.direction()), outward_normal) < 0;
normal = front_face ? outward_normal : - outward_normal;
}
void set_normal_y_axis_back()
{
normal.y() = - normal.y();
}
};
class hittable
{
public:
virtual ~hittable() = default;
virtual bool hit(const ray& r, double ray_tmin, double ray_tmax, hit_record& record) const = 0;
virtual bool hit(const ray& r, interval inter, hit_record& record) const = 0;
virtual AABB bounding_box() const = 0;
};