aboutsummaryrefslogtreecommitdiffstats
path: root/include/hittable.hpp
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2020-12-20 21:59:33 +0100
committerladevieq <ladevie.quentin@gmail.com>2020-12-20 21:59:33 +0100
commitc7c4f8f82c66cfe89b72d176ee51dab8bd30dc95 (patch)
treed0c2caeccda953d86806cb7c7b27c8941e0ef845 /include/hittable.hpp
parentfc601fd503ec1ebd08e4daffeb9aa0812aff2b71 (diff)
Add hittable interface and hit infos on hit
Diffstat (limited to 'include/hittable.hpp')
-rw-r--r--include/hittable.hpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/include/hittable.hpp b/include/hittable.hpp
new file mode 100644
index 0000000..4978e57
--- /dev/null
+++ b/include/hittable.hpp
@@ -0,0 +1,23 @@
+#ifndef __HITTABLE_HPP_
+#define __HITTABLE_HPP_
+
+#include "ray.hpp"
+
+struct hit_info {
+ double t;
+ point3 point;
+ vec3 normal;
+ bool front_face;
+
+ inline void set_face_normal(const ray& r, const vec3& outward_normal) {
+ front_face = r.direction.dot(outward_normal) < 0.0;
+ normal = front_face ? outward_normal : -outward_normal;
+ }
+};
+
+class hittable {
+ public:
+ virtual bool hit(const ray& r, double t_min, double t_max, struct hit_info& info) const = 0;
+};
+
+#endif // !__HITTABLE_HPP_