]> git.tdb.fi Git - libs/math.git/blob - source/geometry/shape.h
Add more collision check functions for shapes
[libs/math.git] / source / geometry / shape.h
1 #ifndef MSP_GEOMETRY_SHAPE_H_
2 #define MSP_GEOMETRY_SHAPE_H_
3
4 #include <vector>
5 #include <msp/linal/vector.h>
6
7 namespace Msp {
8 namespace Geometry {
9
10 template<typename T, unsigned D>
11 class HyperBox;
12
13 template<typename T, unsigned D>
14 class Ray;
15
16 template<typename T, unsigned D>
17 class SurfacePoint;
18
19 template<typename T, unsigned D>
20 class Shape
21 {
22 protected:
23         Shape() { }
24 public:
25         virtual ~Shape() { }
26
27         virtual Shape *clone() const = 0;
28
29         virtual HyperBox<T, D> get_axis_aligned_bounding_box() const = 0;
30         virtual bool contains(const LinAl::Vector<T, D> &) const = 0;
31         virtual bool check_intersection(const Ray<T, D> &) const = 0;
32         virtual unsigned get_max_ray_intersections() const = 0;
33         virtual unsigned get_intersections(const Ray<T, D> &, SurfacePoint<T, D> *, unsigned) const = 0;
34         std::vector<SurfacePoint<T, D> > get_intersections(const Ray<T, D> &) const;
35 };
36
37 template<typename T, unsigned D>
38 std::vector<SurfacePoint<T, D> > Shape<T, D>::get_intersections(const Ray<T, D> &ray) const
39 {
40         unsigned max_isect = get_max_ray_intersections();
41         std::vector<SurfacePoint<T, D> > points(max_isect);
42         unsigned count = get_intersections(ray, &points[0], max_isect);
43         points.resize(count);
44         return points;
45 }
46
47 } // namespace Geometry
48 } // namespace Msp
49
50 #endif