1 #ifndef MSP_GEOMETRY_HALFSPACE_H_
2 #define MSP_GEOMETRY_HALFSPACE_H_
10 An infinite shape consisting of the space on one side of a plane. Mostly
11 useful when composited with other shapes.
13 template<typename T, unsigned D>
14 class HalfSpace: public Shape<T, D>
17 LinAl::Vector<T, D> normal;
21 HalfSpace(const LinAl::Vector<T, D> &);
23 virtual HalfSpace *clone() const;
25 const LinAl::Vector<T, D> &get_normal() const { return normal; }
27 virtual BoundingBox<T, D> get_axis_aligned_bounding_box() const;
28 virtual bool contains(const LinAl::Vector<T, D> &) const;
29 virtual unsigned get_max_ray_intersections() const { return 1; }
30 virtual unsigned get_intersections(const Ray<T, D> &, SurfacePoint<T, D> *, unsigned) const;
33 template<typename T, unsigned D>
34 inline HalfSpace<T, D>::HalfSpace()
39 template<typename T, unsigned D>
40 inline HalfSpace<T, D>::HalfSpace(const LinAl::Vector<T, D> &n):
44 template<typename T, unsigned D>
45 inline HalfSpace<T, D> *HalfSpace<T, D>::clone() const
47 return new HalfSpace<T, D>(normal);
50 template<typename T, unsigned D>
51 inline BoundingBox<T, D> HalfSpace<T, D>::get_axis_aligned_bounding_box() const
53 // XXX If the normal is aligned to an axis, should the bounding box reflect that?
54 return ~BoundingBox<T, D>();
57 template<typename T, unsigned D>
58 inline bool HalfSpace<T, D>::contains(const LinAl::Vector<T, D> &point) const
60 return inner_product(point, normal)<=T(0);
63 template<typename T, unsigned D>
64 inline unsigned HalfSpace<T, D>::get_intersections(const Ray<T, D> &ray, SurfacePoint<T, D> *points, unsigned size) const
66 T x = -inner_product(ray.get_start(), normal)/inner_product(ray.get_direction(), normal);
67 if(ray.check_limits(x))
71 points[0].position = ray.get_start()+ray.get_direction()*x;
72 points[0].normal = normal;
73 points[0].distance = x;
82 } // namespace Geometry