00001
00002
00003
00004
00005
00006 #ifndef AABOUNDINGBOX_H
00007 #define AABOUNDINGBOX_H
00008
00009 #include<Ray.h>
00010 #include<Vertex3.h>
00011
00012 class ObjectFile;
00013
00016 class AABoundingBox
00017 {
00018 friend ostream &operator<<(ostream &stream, const AABoundingBox &b);
00019 friend ObjectFile &operator>>(ObjectFile &f, AABoundingBox &b);
00020 public:
00021 AABoundingBox();
00022 AABoundingBox(Vertex3 &f, Vertex3 &t);
00023
00024 Vertex3 size() const {
00025 return to - from;
00026 }
00027 Vertex3 center() const {
00028 return (to + from)*0.5;
00029 }
00030 void setRange(const Vertex3 &f, const Vertex3 &t);
00031 void getRange(Vertex3 &f, Vertex3 &t) const;
00032 const Vertex3 &getFrom() const {
00033 return from;
00034 }
00035 const Vertex3 &getTo() const {
00036 return to;
00037 }
00038
00039 void clear();
00040 bool empty() const;
00041 void set(const Vertex3 &v, real r);
00042 void operator =(const Vertex3 &v) {
00043 from = v;
00044 to = v;
00045 }
00046
00047
00048 void sweep(Vertex3 &v);
00049 void operator +=(const Vertex3 &v);
00050
00051 void operator =(const AABoundingBox &box) {
00052 from = box.from;
00053 to = box.to;
00054 }
00055 void operator +=(const AABoundingBox &box);
00056 void operator *=(const AABoundingBox &box);
00057 void sphere(const Vertex3 &v, real r);
00058
00059 real distance(const Vertex3 &v) const;
00060 bool intersect(const AABoundingBox &box) const;
00061 bool intersect(const Ray &ray) const {
00062 real t0;
00063 real t1;
00064 return intersect(ray, t0, t1);
00065 }
00066 bool intersect(const Ray &ray, real &t0, real &t1) const;
00067
00068 protected:
00069 Vertex3 from;
00070 Vertex3 to;
00071 };
00072 #endif