1 #ifndef MSP_GEOMETRY_HALFSPACE_H_
2 #define MSP_GEOMETRY_HALFSPACE_H_
4 #include "boundingbox.h"
11 An infinite shape consisting of the space on one side of a plane. Mostly
12 useful when composited with other shapes.
14 template<typename T, unsigned D>
15 class HalfSpace: public Shape<T, D>
18 LinAl::Vector<T, D> normal;
22 HalfSpace(const LinAl::Vector<T, D> &);
24 virtual HalfSpace *clone() const;
26 const LinAl::Vector<T, D> &get_normal() const { return normal; }
28 virtual BoundingBox<T, D> get_axis_aligned_bounding_box() const;
29 virtual bool contains(const LinAl::Vector<T, D> &) const;
30 virtual unsigned get_max_ray_intersections() const { return 1; }
31 virtual unsigned get_intersections(const Ray<T, D> &, SurfacePoint<T, D> *, unsigned) const;
34 template<typename T, unsigned D>
35 inline HalfSpace<T, D>::HalfSpace()
40 template<typename T, unsigned D>
41 inline HalfSpace<T, D>::HalfSpace(const LinAl::Vector<T, D> &n):
45 template<typename T, unsigned D>
46 inline HalfSpace<T, D> *HalfSpace<T, D>::clone() const
48 return new HalfSpace<T, D>(normal);
51 template<typename T, unsigned D>
52 inline BoundingBox<T, D> HalfSpace<T, D>::get_axis_aligned_bounding_box() const
54 // XXX If the normal is aligned to an axis, should the bounding box reflect that?
55 return ~BoundingBox<T, D>();
58 template<typename T, unsigned D>
59 inline bool HalfSpace<T, D>::contains(const LinAl::Vector<T, D> &point) const
61 return inner_product(point, normal)<=0;
64 template<typename T, unsigned D>
65 inline unsigned HalfSpace<T, D>::get_intersections(const Ray<T, D> &ray, SurfacePoint<T, D> *points, unsigned size) const
67 T x = -inner_product(ray.get_start(), normal)/inner_product(ray.get_direction(), normal);
68 if(ray.check_limits(x))
72 points[0].position = ray.get_start()+ray.get_direction()*x;
73 points[0].normal = normal;
74 points[0].distance = x;
83 } // namespace Geometry