-
Notifications
You must be signed in to change notification settings - Fork 0
/
hit_record.h
29 lines (24 loc) · 1.25 KB
/
hit_record.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 RAYTRACER_HIT_RECORD_H
#define RAYTRACER_HIT_RECORD_H
#include "material.h"
#include "ray.h"
#include <memory>
#include <optional>
struct HitRecord {
Point3 p;
Vec3 normal;
double t;
bool isFrontFace;
std::shared_ptr<Material> material;
static HitRecord build(const Ray &r, const Point3 &p, const Vec3 &outwardNormal, double t, const std::shared_ptr<Material> &m) {
bool isFrontFace = dot(r.direction(), outwardNormal) < 0;
Vec3 normal = isFrontFace ? outwardNormal : -outwardNormal;
return {p, normal, t, isFrontFace, m};
}
HitRecord(const Point3 &p, const Vec3 &normal, double t, bool isFrontFace, const std::shared_ptr<Material> &m) : p(p),
normal(normal),
t(t),
isFrontFace(isFrontFace),
material(m) {}
};
#endif//RAYTRACER_HIT_RECORD_H