]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Plane.hh
stream-based logging classes
[chaz/yoink] / src / Moof / Plane.hh
index 11cd63ec23f2bf7f6517a8b2d5e937eb6f3832f3..b39891790f16a6afc682c9e753642cf8015ebd5e 100644 (file)
@@ -66,39 +66,34 @@ struct Plane : public Shape<3>
                d(scalar) {}
 
 
-       Scalar intersectRay(const Ray<3>& ray, Ray<3>::Intersection& intersection)
+       bool intersectRay(const Ray<3>& ray, Ray<3>::Intersection& hit)
        {
                // solve: [(ray.point + t*ray.direction) dot normal] + d = 0
 
-               Scalar denominator = cml::dot(ray.direction, normal);
+               Scalar denom = cml::dot(ray.direction, normal);
 
                // check for parallel condition
-               if (denominator == SCALAR(0.0))
+               if (denom == SCALAR(0.0))
                {
                        if (isEqual(cml::dot(ray.point, normal), -d))
                        {
                                // the ray lies on the plane
-                               intersection.point = ray.point;
-                               intersection.normal.set(0.0, 0.0, 0.0);
-                               //intersection.normal = normal;
-                               return SCALAR(0.0);
+                               hit.distance = SCALAR(0.0);
+                               hit.normal.set(0.0, 0.0, 0.0);
+                               return true;
                        }
 
                        // no solution
-                       return SCALAR(-1.0);
+                       return false;
                }
 
-               Scalar distance = cml::dot(ray.point, normal) + d;
-               Scalar t = -distance / denominator;
-               if (t > SCALAR(0.0))
-               {
-                       ray.solve(intersection.point, t);
-
-                       if (distance >= 0.0) intersection.normal = normal;
-                       else                 intersection.normal = -normal;
-               }
+               Scalar numer = cml::dot(ray.point, normal) + d;
+               hit.distance = -numer / denom;
+               if (hit.distance < SCALAR(0.0)) return false;
 
-               return t;
+               if (numer >= 0.0) hit.normal = normal;
+               else              hit.normal = -normal;
+               return true;
        }
 
 
This page took 0.022169 seconds and 4 git commands to generate.