]> git.tdb.fi Git - libs/math.git/commitdiff
Record distance in SurfacePoint
authorMikko Rasa <tdb@tdb.fi>
Mon, 20 May 2013 16:33:20 +0000 (19:33 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 20 May 2013 16:33:20 +0000 (19:33 +0300)
source/geometry/hyperbox.h
source/geometry/hypersphere.h
source/geometry/surfacepoint.h
source/geometry/transformedshape.h

index 7d363f246a8a48e25cbb07762e351f7f4dc58936..10c28d5d1f4c20a15937e7b0aa696f3074151aec 100644 (file)
@@ -83,7 +83,6 @@ inline unsigned HyperBox<T, D>::get_intersections(const Ray<T, D> &ray, SurfaceP
 
        LinAl::Vector<T, D> half_dim = dimensions/T(2);
        unsigned n = 0;
-       T first_depth = T();
        for(unsigned i=0; i<D; ++i)
        {
                if(!ray.get_direction()[i])
@@ -108,9 +107,9 @@ inline unsigned HyperBox<T, D>::get_intersections(const Ray<T, D> &ray, SurfaceP
                                        points[n].position = p;
                                        points[n].normal = LinAl::Vector<T, D>();
                                        points[n].normal[i] = j;
-                                       if(n==0)
-                                               first_depth = x;
-                                       else if(n==1 && x<first_depth)
+                                       points[n].distance = x;
+
+                                       if(n==1 && x<points[0].distance)
                                                std::swap(points[0], points[1]);
                                }
 
index ed2b49ff161141e4364a5bd81773ed0c9cc16632..48fdb8aa2b98bfeb91cee5b62c21d375ff35a247 100644 (file)
@@ -96,6 +96,7 @@ inline unsigned HyperSphere<T, D>::get_intersections(const Ray<T, D> &ray, Surfa
                        {
                                points[n].position = ray.get_start()+ray.get_direction()*x;
                                points[n].normal = normalize(points[n].position);
+                               points[n].distance = x;
                        }
 
                        ++n;
index 251964cef854d91469f6ed9c10280534d3519535..a5bd794f90052bc96fcc307dfdb67b74244707c8 100644 (file)
@@ -14,6 +14,7 @@ struct SurfacePoint
 {
        LinAl::Vector<T, N> position;
        LinAl::Vector<T, N> normal;
+       T distance;
 };
 
 } // namespace Geometry
index 01253680f6340a9ed277f76664b906313f8314e2..34fd2989f2cfeaadddcf40ef6822ae2fb37c62d0 100644 (file)
@@ -107,6 +107,7 @@ inline unsigned TransformedShape<T, D>::get_intersections(const Ray<T, D> &ray,
                        /* XXX This is not correct for nonuniform scaling.  Inverse of the
                        transpose of the upper DxD part of the matrix should be used. */
                        points[i].normal = transformation.transform(points[i].normal);
+                       points[i].distance = inner_product(points[i].position-ray.get_start(), ray.get_direction());
                }
        }
        return count;