00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef FXRANGEF_H
00022 #define FXRANGEF_H
00023
00024
00025 namespace FX {
00026
00027
00028 class FXSpheref;
00029 class FXMat4f;
00030
00031
00033 class FXAPI FXRangef {
00034 public:
00035 FXVec3f lower;
00036 FXVec3f upper;
00037 public:
00038
00040 FXRangef(){}
00041
00043 FXRangef(const FXRangef& bounds):lower(bounds.lower),upper(bounds.upper){}
00044
00046 FXRangef(const FXVec3f& p):lower(p),upper(p){}
00047
00049 FXRangef(const FXVec3f& l,const FXVec3f& h):lower(l),upper(h){}
00050
00052 FXRangef(FXfloat x,FXfloat y,FXfloat z):lower(x,y,z),upper(x,y,z){}
00053
00055 FXRangef(FXfloat xl,FXfloat xh,FXfloat yl,FXfloat yh,FXfloat zl,FXfloat zh):lower(xl,yl,zl),upper(xh,yh,zh){}
00056
00058 FXRangef(const FXSpheref& sphere);
00059
00061 FXRangef& operator=(const FXRangef& bounds){ lower=bounds.lower; upper=bounds.upper; return *this; }
00062
00064 FXRangef& set(const FXRangef& bounds){ lower=bounds.lower; upper=bounds.upper; return *this; }
00065
00067 FXRangef& set(const FXVec3f& p){ lower=upper=p; return *this; }
00068
00070 FXRangef& set(const FXVec3f& l,const FXVec3f& h){ lower=l; upper=h; return *this; }
00071
00073 FXRangef& set(FXfloat x,FXfloat y,FXfloat z){ lower.x=upper.x=x; lower.y=upper.y=y; lower.z=upper.z=z; return *this; }
00074
00076 FXRangef& set(FXfloat xl,FXfloat xh,FXfloat yl,FXfloat yh,FXfloat zl,FXfloat zh){ lower.set(xl,yl,zl); upper.set(xh,yh,zh); return *this; }
00077
00079 FXVec3f& operator[](FXint i){ return (&lower)[i]; }
00080
00082 const FXVec3f& operator[](FXint i) const { return (&lower)[i]; }
00083
00085 FXbool operator==(const FXRangef& r) const { return lower==r.lower && upper==r.upper; }
00086 FXbool operator!=(const FXRangef& r) const { return lower!=r.lower || upper!=r.upper; }
00087
00089 FXfloat width() const { return upper.x-lower.x; }
00090
00092 FXfloat height() const { return upper.y-lower.y; }
00093
00095 FXfloat depth() const { return upper.z-lower.z; }
00096
00098 FXfloat longest() const;
00099
00101 FXfloat shortest() const;
00102
00104 FXfloat diameter() const;
00105
00107 FXfloat radius() const;
00108
00110 FXVec3f diagonal() const;
00111
00113 FXVec3f center() const;
00114
00116 FXbool empty() const;
00117
00119 FXbool contains(FXfloat x,FXfloat y,FXfloat z) const;
00120
00122 FXbool contains(const FXVec3f& p) const;
00123
00125 FXbool contains(const FXRangef& bounds) const;
00126
00128 FXbool contains(const FXSpheref& sphere) const;
00129
00131 FXRangef& include(FXfloat x,FXfloat y,FXfloat z);
00132
00134 FXRangef& include(const FXVec3f& v);
00135
00137 FXRangef& include(const FXRangef& box);
00138
00140 FXRangef& include(const FXSpheref& sphere);
00141
00143 FXint intersect(const FXVec4f& plane) const;
00144
00146 FXbool intersect(const FXVec3f& u,const FXVec3f& v) const;
00147
00149 FXVec3f corner(FXint c) const { return FXVec3f((&lower)[c&1].x,(&lower)[(c>>1)&1].y,(&lower)[c>>2].z); }
00150
00152 FXRangef transform(const FXMat4f& mat) const;
00153
00155 ~FXRangef(){}
00156 };
00157
00158
00160 extern FXAPI FXbool overlap(const FXRangef& a,const FXRangef& b);
00161
00163 extern FXAPI FXRangef unite(const FXRangef& a,const FXRangef& b);
00164
00166 extern FXAPI FXRangef intersect(const FXRangef& a,const FXRangef& b);
00167
00169 extern FXAPI FXStream& operator<<(FXStream& store,const FXRangef& bounds);
00170
00172 extern FXAPI FXStream& operator>>(FXStream& store,FXRangef& bounds);
00173
00174 }
00175
00176 #endif
00177