aboutsummaryrefslogtreecommitdiffstats
path: root/src/sphere.cpp
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2021-01-09 20:42:24 +0100
committerladevieq <ladevie.quentin@gmail.com>2021-01-09 20:43:09 +0100
commit2db0d27e7f1744443958717c19b732eed57455f2 (patch)
tree839b8ea513c8c239f015071ab083bd50f03854a5 /src/sphere.cpp
parent4379b46b46563c5a709df8d567ef75affc3fd31c (diff)
Replace old classes with compute shader structs
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;
-}