]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Sphere.hh
stream-based logging classes
[chaz/yoink] / src / Moof / Sphere.hh
index f7b6a95fe7a6d89a450291491ad8c1db012fada2..f1847091c6d0afcc9bad1cbbabcddfdb7cb78dfe 100644 (file)
@@ -77,26 +77,27 @@ struct Sphere : public Cullable, public Drawable, public Shape<D>
 
 
        // a ray inside the sphere will not intersect on its way out
-       Scalar intersectRay(const Ray<D>& ray,
-                       typename Ray<D>::Intersection& intersection)
+       bool intersectRay(const Ray<D>& ray, typename Ray<D>::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;
        }
 
 
This page took 0.019792 seconds and 4 git commands to generate.