-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhittable.hpp
49 lines (41 loc) · 1.55 KB
/
hittable.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
#ifndef HITTABLE_HPP
#define HITTABLE_HPP
#include "main.hpp"
#include "ray.hpp"
class material;
struct hit_record { // A Mini ds for containing info about the hit of a surface
point3 p; // The point of contact
vec3 normal; // Don't know
double t; // The "t" that satisfies this equation: P(t) = A + tb
bool front_face;
shared_ptr<material> mat_ptr;
inline void set_face_normal(const ray& r, const vec3& outward_normal) {
// If the ray directions are the same "dot(r.direction(), outward_normal)" will be positive
// If the ray directions are not the same "dot(r.direction(), outward_normal)" will be negative
// If they are different (negative) it is outside otherwise it is inside the surface
front_face = dot(r.direction(), outward_normal) < 0;
if (front_face)
{
// ray is outside the sphere
normal = outward_normal; // keep it the same
}
else
{
//ray inside the sphere
normal = -outward_normal; // flip the normal
}
//normal = front_face ? outward_normal :-outward_normal; BS
}
};
class hittable {
public:
virtual bool hit // It is "virtual" because the hit function will be defined in children of this class
(
const ray& r, // reference to the ray
double t_min, // minimum value of t
double t_max, // maximum value of t
hit_record& rec // a reference to hit record
)
const = 0;
};
#endif