00001 #ifndef AABB_H_
00002 #define AABB_H_
00003
00004 #include "Primitive.h"
00005 #include "../Intersection.h"
00006 #include "../Ray.h"
00007 #include "../math/rcrtmath.h"
00008 #include "Axis.hpp"
00009
00010 namespace rcrt
00011 {
00012
00016 class AABB : public Primitive
00017 {
00018 private:
00019 Point3D minP, maxP, center;
00020
00021 public:
00025 AABB(SolidObject* parent=0);
00026
00032 AABB(const Point3D& min, const Point3D& max, SolidObject* parent=0);
00033 virtual ~AABB();
00034
00035 virtual Intersection intersect(Ray& r) const;
00036 virtual const AABB& getBoundingBox() const;
00037 virtual const Point3D& getCentroid() const;
00038
00042 void extend(const AABB& box);
00043
00047 void extend(const Point3D& p);
00048
00053 float getLength(Axis a) const;
00054
00058 Axis getMainAxis() const;
00059
00064 float getMin(Axis a) const;
00065
00070 float getMax(Axis a) const;
00071
00072 const Point3D& getMinP() const;
00073 const Point3D& getMaxP() const;
00074
00079 bool equals(const AABB& box) const;
00080
00085 AABB transformed(const Matrix4D& mat) const;
00086
00087 virtual Vec3D getSNormal(float a, float b) const;
00088 virtual Vec3D getGNormal(float a, float b) const;
00089 virtual Point2D getUV(float a, float b) const;
00090
00094 float getVolume() const;
00095
00099 float getSurfaceArea() const;
00100
00104 bool isEmpty() const;
00105
00109 void contract(const AABB& box);
00110
00111 virtual void clipPlane(Axis axis, float plane, AABB& lBox, AABB& rBox) const;
00112 };
00113
00114 inline std::ostream& operator<<(std::ostream& o, const AABB& box)
00115 {
00116 o << "AABB(" << box.getMinP() << ", " << box.getMaxP() << ")";
00117 return o;
00118 }
00119
00120 }
00121
00122 #endif