]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/shape.h
Add more collision check functions for shapes
[libs/math.git] / source / geometry / shape.h
index 528a77ca6d97d42e748bb4a47a17f88508394bfa..1f8176418a4e9a948b460701e6e682d56ae31771 100644 (file)
@@ -1,6 +1,9 @@
 #ifndef MSP_GEOMETRY_SHAPE_H_
 #define MSP_GEOMETRY_SHAPE_H_
 
+#include <vector>
+#include <msp/linal/vector.h>
+
 namespace Msp {
 namespace Geometry {
 
@@ -10,6 +13,9 @@ class HyperBox;
 template<typename T, unsigned D>
 class Ray;
 
+template<typename T, unsigned D>
+class SurfacePoint;
+
 template<typename T, unsigned D>
 class Shape
 {
@@ -21,9 +27,23 @@ public:
        virtual Shape *clone() const = 0;
 
        virtual HyperBox<T, D> get_axis_aligned_bounding_box() const = 0;
+       virtual bool contains(const LinAl::Vector<T, D> &) const = 0;
        virtual bool check_intersection(const Ray<T, D> &) const = 0;
+       virtual unsigned get_max_ray_intersections() const = 0;
+       virtual unsigned get_intersections(const Ray<T, D> &, SurfacePoint<T, D> *, unsigned) const = 0;
+       std::vector<SurfacePoint<T, D> > get_intersections(const Ray<T, D> &) const;
 };
 
+template<typename T, unsigned D>
+std::vector<SurfacePoint<T, D> > Shape<T, D>::get_intersections(const Ray<T, D> &ray) const
+{
+       unsigned max_isect = get_max_ray_intersections();
+       std::vector<SurfacePoint<T, D> > points(max_isect);
+       unsigned count = get_intersections(ray, &points[0], max_isect);
+       points.resize(count);
+       return points;
+}
+
 } // namespace Geometry
 } // namespace Msp