aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/hittable.hpp23
-rw-r--r--include/hittable_list.hpp21
-rw-r--r--include/ray.hpp2
-rw-r--r--include/rt.hpp18
-rw-r--r--include/sphere.hpp16
-rw-r--r--include/vec3.hpp8
6 files changed, 83 insertions, 5 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_
diff --git a/include/hittable_list.hpp b/include/hittable_list.hpp
new file mode 100644
index 0000000..41d8f4a
--- /dev/null
+++ b/include/hittable_list.hpp
@@ -0,0 +1,21 @@
+#ifndef __HITTABLE_LIST_HPP_
+#define __HITTABLE_LIST_HPP_
+
+#include <vector>
+#include <memory>
+
+#include "hittable.hpp"
+
+class hittable_list : public hittable {
+ public:
+ hittable_list();
+
+ void add(std::shared_ptr<hittable> hittable);
+ void clear();
+
+ virtual bool hit(const ray&r, double t_min, double t_max, struct hit_info& info) const;
+
+ std::vector<std::shared_ptr<hittable>> hittables;
+};
+
+#endif // !__HITTABLE_LIST_HPP_
diff --git a/include/ray.hpp b/include/ray.hpp
index 3f8542b..b3d88ae 100644
--- a/include/ray.hpp
+++ b/include/ray.hpp
@@ -8,7 +8,7 @@ class ray {
ray(const point3& origin, const vec3& direction);
- point3 at(double t);
+ point3 at(double t) const;
point3 origin;
vec3 direction;
diff --git a/include/rt.hpp b/include/rt.hpp
new file mode 100644
index 0000000..60170ac
--- /dev/null
+++ b/include/rt.hpp
@@ -0,0 +1,18 @@
+#ifndef __RT_HPP_
+#define __RT_HPP_
+
+#include <limits>
+
+const double pi = 3.1415926535897932385;
+const double infinity = std::numeric_limits<double>::infinity();
+
+inline double deg_to_rad(double deg) {
+ return deg * pi / 180.0;
+}
+
+#include "vec3.hpp"
+#include "ray.hpp"
+#include "color.hpp"
+#include "sphere.hpp"
+
+#endif // !__RT_HPP_
diff --git a/include/sphere.hpp b/include/sphere.hpp
new file mode 100644
index 0000000..5bf0ab9
--- /dev/null
+++ b/include/sphere.hpp
@@ -0,0 +1,16 @@
+#ifndef __SPHERE_HPP_
+#define __SPHERE_HPP_
+
+#include "hittable.hpp"
+
+class sphere : public hittable {
+ public:
+ sphere(point3 center, double radius = 1.0);
+
+ virtual bool hit(const ray& r, double t_min, double t_max, struct hit_info& info) const;
+
+ point3 center;
+ double radius;
+};
+
+#endif // !__SPHERE_HPP_
diff --git a/include/vec3.hpp b/include/vec3.hpp
index 48f0ae3..e658e71 100644
--- a/include/vec3.hpp
+++ b/include/vec3.hpp
@@ -10,7 +10,7 @@ class vec3 {
vec3(double x, double y, double z);
- void operator-();
+ vec3 operator-() const;
vec3& operator+=(vec3& vec);
@@ -18,15 +18,15 @@ class vec3 {
vec3& operator/=(double numerator);
- double length();
+ double length() const;
- double length_sq();
+ double length_sq() const;
double dot(const vec3& vec) const;
vec3 cross(const vec3& vec) const;
- vec3 unit();
+ vec3 unit() const;
double x, y, z;
};