X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FSphere.hh;h=f1847091c6d0afcc9bad1cbbabcddfdb7cb78dfe;hp=f7b6a95fe7a6d89a450291491ad8c1db012fada2;hb=7f3984f3f9524f5b6813e01ceb2fe576dadff94e;hpb=99ac607f489023a7aa17bfb046113b0e4a65dab6 diff --git a/src/Moof/Sphere.hh b/src/Moof/Sphere.hh index f7b6a95..f184709 100644 --- a/src/Moof/Sphere.hh +++ b/src/Moof/Sphere.hh @@ -77,26 +77,27 @@ struct Sphere : public Cullable, public Drawable, public Shape // a ray inside the sphere will not intersect on its way out - Scalar intersectRay(const Ray& ray, - typename Ray::Intersection& intersection) + bool intersectRay(const Ray& ray, typename Ray::Intersection& hit) { Vector b = point - ray.point; Scalar z = cml::dot(b, ray.direction); // check if the ball is behind the ray - if (z < SCALAR(0.0)) return SCALAR(-1.0); + if (z < SCALAR(0.0)) return false; Scalar d2 = cml::dot(b, b) - z*z; Scalar r2 = radius * radius; // check for an intersection - if (d2 > r2) return SCALAR(-1.0); + if (d2 > r2) return false; - Scalar t = z - std::sqrt(r2 - d2); - ray.solve(intersection.point, t); - intersection.normal = intersection.point - point; + hit.distance = z - std::sqrt(r2 - d2); + if (hit.distance < SCALAR(0.0)) return false; - return t; + Vector surfacePoint; + ray.solve(surfacePoint, hit.distance); + hit.normal = surfacePoint - point; + return true; }