/* bound.h -*-C++-*- * by Will Wagner * last updated 20 Sep 1997, 17:21:29 wwagner * * This file contains the automatic bounding shapes for POVRay. * * Changes * 11 Aug 1997 * - Added this comment block * * 18 Aug 1997 * - Figured out how to do the inheritance for the types of * bounding objects; added the BoundingObject, BoundingSphere, and * BoundingCylinder; cleaned up the BoundingBox interface, to be * reworked later. * * 19 Aug 1997 * - Added by-element constructors. * * 20 Sep 1997 * - Added recompute and intersect methods. * * Things to do * - Deal with transforming the radius member of the * BoundingSphere in the recompute and recomputeInverse methods. * Also figure out how to do intersections with all the shapes. * */ #ifndef __INC_BOUND_H__ #define __INC_BOUND_H__ #include "vector.h" class BoundingObject { protected: pov_vector location; public: BoundingObject(); BoundingObject(const pov_vector& pos) : location(pos) { }; BoundingObject(const BoundingObject& o) : location(o.location) { }; virtual ~BoundingObject() { }; inline virtual void recompute(const Transformation& t) { location = t.TransformPoint(location); }; inline virtual void recomputeInverse(const Transformation& t) { location = t.InverseTransformPoint(location); }; inline virtual int intersect(const Ray& r) { return FALSE; }; }; class BoundingSphere : public BoundingObject { protected: DBL radius; public: BoundingSphere(); BoundingSphere(const pov_vector& pos, T rad) : BoundingObject(pos) { radius = rad; }; BoundingSphere(const BoundingSphere& o) : BoundingObject((const BoundingObject&)o) { radius = o.radius; }; virtual ~BoundingSphere() { }; inline virtual void recompute(const Transformation& t); inline virtual void recomputeInverse(const Transformation& t); inline virtual int intersect(const Ray& r); }; class BoundingCylinder : public BoundingSphere { protected: pov_vector axis; public: BoundingCylinder(); BoundingCylinder(const pov_vector& pos, const pov_vector& ax, DBL rad) : BoundingSphere(pos, rad), axis(ax) { }; BoundingCylinder(const BoundingCylinder& o) : BoundingSphere((const BoundingSphere&)o), axis(o.axis) { }; virtual ~BoundingCylinder() { }; inline virtual void recompute(const Transformation& t) { BoundingSphere::recompute(t); axis = t.TransformPoint(axis); }; inline virtual void recomputeInverse(const Transformation& t) { BoundingSphere::recomputeInverse(t); axis = t.InverseTransformPoint(axis); }; inline virtual int intersect(const Ray& r); }; class BoundingBox : public BoundingObject { protected: pov_vector size; public: BoundingBox(); BoundingBox(const pov_vector& pos, const pov_vector& sz) : BoundingObject(pos), size(sz) { }; BoundingBox(const BoundingBox& o) : BoundingObject((const BoundingObject&)o), size(sz) { }; virtual ~BoundingBox() { }; inline virtual void recompute(const Transformation& t) { BoundingObject::recompute(t); size = t.TransformPoint(size); }; inline virtual void recomputeInverse(const Transformation& t) { BoundingObject::recomputeInverse(t); size = t.InverseTransformPoint(size); }; inline virtual int intersect(const Ray& r); }; #endif /* __INC_BOUND_H__ */