-
Notifications
You must be signed in to change notification settings - Fork 0
/
hittable.h
29 lines (23 loc) · 874 Bytes
/
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
#ifndef HITTABLE_H
#define HITTABLE_H
#include "ray.h"
class material;
struct hit_record {
point3 p; // hit point
vec3 normal; // normal vector
shared_ptr<material> mat_ptr; // pointer to material class
double t; // t value of the ray
bool front_face; // whether hit in the front face
// set boolean variable front_face, set normal to point outward
inline void set_face_normal(const ray& r, const vec3& outward_normal) {
front_face = dot(r.direction(), outward_normal) < 0;
normal = front_face ? outward_normal : -outward_normal;
}
};
class hittable {
public:
// t_min to t_max gives the range of a hit that 'counts'
virtual bool hit(const ray& r, double t_min, double t_max,
hit_record& rec) const = 0;
};
#endif