X-Git-Url: http://git.tdb.fi/?p=libs%2Fmath.git;a=blobdiff_plain;f=source%2Fgeometry%2Fhyperbox.h;h=6248d6b0920e906f5bad1ee1ce1b9ba6fbb97fc4;hp=2ade28acddd42ba9da6eefcb8cbefe14040ee535;hb=9260eee3126731c1e6b54ce3407be757d0d71716;hpb=6843cbaeaca73ecdbebe852b7e7899ce48f8a83c diff --git a/source/geometry/hyperbox.h b/source/geometry/hyperbox.h index 2ade28a..6248d6b 100644 --- a/source/geometry/hyperbox.h +++ b/source/geometry/hyperbox.h @@ -1,9 +1,12 @@ #ifndef MSP_GEOMETRY_HYPERBOX_H_ #define MSP_GEOMETRY_HYPERBOX_H_ +#include +#include #include #include "ray.h" #include "shape.h" +#include "surfacepoint.h" namespace Msp { namespace Geometry { @@ -24,7 +27,10 @@ public: T get_dimension(unsigned) const; virtual HyperBox get_axis_aligned_bounding_box() const { return *this; } + virtual bool contains(const LinAl::Vector &) const; virtual bool check_intersection(const Ray &) const; + virtual unsigned get_max_ray_intersections() const { return 2; } + virtual unsigned get_intersections(const Ray &, SurfacePoint *, unsigned) const; }; template @@ -51,26 +57,67 @@ inline T HyperBox::get_dimension(unsigned i) const return dimensions[i]; } +template +inline bool HyperBox::contains(const LinAl::Vector &point) const +{ + for(unsigned i=0; idimensions[i]/2) + return false; + return true; +} + template inline bool HyperBox::check_intersection(const Ray &ray) const { + return get_intersections(ray, 0, 1); +} + +template +inline unsigned HyperBox::get_intersections(const Ray &ray, SurfacePoint *points, unsigned size) const +{ + using std::abs; + LinAl::Vector half_dim = dimensions/T(2); + unsigned n = 0; + T first_depth = T(); for(unsigned i=0; i0) + if(x<0) + continue; + + LinAl::Vector p = ray.get_start()+ray.get_direction()*x; + + bool inside = true; + for(unsigned k=0; (inside && k p = ray.get_start()+ray.get_direction()*x; - bool inside = true; - for(unsigned k=0; (inside && k=-half_dim[k] && p[k](); + points[n].normal[i] = j; + if(n==0) + first_depth = x; + else if(n==1 && x