aboutsummaryrefslogtreecommitdiffstats
path: root/src/sphere.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sphere.cpp')
-rw-r--r--src/sphere.cpp38
1 files changed, 2 insertions, 36 deletions
diff --git a/src/sphere.cpp b/src/sphere.cpp
index e7be715..7ac4185 100644
--- a/src/sphere.cpp
+++ b/src/sphere.cpp
@@ -1,39 +1,5 @@
#include "sphere.hpp"
-sphere::sphere(point3 center, double radius, std::shared_ptr<material> material)
- : center(center), radius(radius), mat_ptr(material)
+sphere::sphere(point3 center, material material, float radius)
+ : center(center), radius(radius), mat(material)
{}
-
-bool sphere::hit(const ray& r, double t_min, double t_max, struct hit_info& info) const {
- // Vector from the ray origin to sphere position
- vec3 origin_center = r.origin - center;
-
- double a = r.direction.dot(r.direction);
- double half_b = r.direction.dot(origin_center);
- double c = origin_center.dot(origin_center) - radius * radius;
- double discriminant = half_b * half_b - a * c;
-
- if (discriminant < 0) {
- return false;
- }
-
- double sq_discriminant = sqrt(discriminant);
- double t = (-half_b - sq_discriminant) / a ;
-
- if (t_min > t || t_max < t) {
- t = (-half_b + sq_discriminant) / a ;
-
- if (t_min > t || t_max < t) {
- return false;
- }
- }
-
- info.t = t;
- info.point = r.at(t);
- info.mat_ptr = mat_ptr;
-
- vec3 out_normal = (info.point - center) / radius;
- info.set_face_normal(r, out_normal);
-
- return true;
-}