summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--object.h3
-rw-r--r--sphere.h4
2 files changed, 7 insertions, 0 deletions
diff --git a/object.h b/object.h
index 26548c5..c679d83 100644
--- a/object.h
+++ b/object.h
@@ -28,6 +28,9 @@ public:
return hit(r, t, t1, std::numeric_limits<double>::infinity());
}
+ // If given position is on the object's surface.
+ virtual bool is_on(const vec3d &p) const = 0;
+
// Given a point on the surface, returns the normalized outer normal vector on that point.
virtual vec3d normal_vector(const vec3d &where) const = 0;
diff --git a/sphere.h b/sphere.h
index fa181e7..a5a935e 100644
--- a/sphere.h
+++ b/sphere.h
@@ -81,6 +81,10 @@ public:
return hit;
}
+ bool is_on(const vec3d &p) const override {
+ return ((p - center).mod2() - radius * radius) < 1e-10;
+ }
+
pixel8b color() const override {
return pixel8b::from_normalized(1.0, 0.0, 0.0);
}