![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * S i n g l e - P r e c i s i o n R a n g e C l a s s * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2004,2009 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU Lesser General Public License as published by * 00010 * the Free Software Foundation; either version 3 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public License * 00019 * along with this program. If not, see <http://www.gnu.org/licenses/> * 00020 ********************************************************************************* 00021 * $Id: FXRangef.h,v 1.24 2009/01/26 09:40:23 fox Exp $ * 00022 ********************************************************************************/ 00023 #ifndef FXRANGEF_H 00024 #define FXRANGEF_H 00025 00026 00027 namespace FX { 00028 00029 00030 class FXSpheref; 00031 class FXMat4f; 00032 00033 00034 /// Bounds 00035 class FXAPI FXRangef { 00036 public: 00037 FXVec3f lower; 00038 FXVec3f upper; 00039 public: 00040 00041 /// Default constructor; value is not initialized 00042 FXRangef(){} 00043 00044 /// Initialize with another range 00045 FXRangef(const FXRangef& bounds):lower(bounds.lower),upper(bounds.upper){} 00046 00047 /// Initialize with a single point 00048 FXRangef(const FXVec3f& p):lower(p),upper(p){} 00049 00050 /// Initialize with corner points 00051 FXRangef(const FXVec3f& l,const FXVec3f& h):lower(l),upper(h){} 00052 00053 /// Initialize with a single point 00054 FXRangef(FXfloat x,FXfloat y,FXfloat z):lower(x,y,z),upper(x,y,z){} 00055 00056 /// Initialize with explicit values 00057 FXRangef(FXfloat xl,FXfloat xh,FXfloat yl,FXfloat yh,FXfloat zl,FXfloat zh):lower(xl,yl,zl),upper(xh,yh,zh){} 00058 00059 /// Initialize box to fully contain the given bounding sphere 00060 FXRangef(const FXSpheref& sphere); 00061 00062 /// Assignment 00063 FXRangef& operator=(const FXRangef& bounds){ lower=bounds.lower; upper=bounds.upper; return *this; } 00064 00065 /// Set value from another range 00066 FXRangef& set(const FXRangef& bounds){ lower=bounds.lower; upper=bounds.upper; return *this; } 00067 00068 /// Set value from single point 00069 FXRangef& set(const FXVec3f& p){ lower=upper=p; return *this; } 00070 00071 /// Set value from corner points 00072 FXRangef& set(const FXVec3f& l,const FXVec3f& h){ lower=l; upper=h; return *this; } 00073 00074 /// Set value from single point 00075 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; } 00076 00077 /// Set value from explicit values 00078 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; } 00079 00080 /// Indexing with 0..1 00081 FXVec3f& operator[](FXint i){ return (&lower)[i]; } 00082 00083 /// Indexing with 0..1 00084 const FXVec3f& operator[](FXint i) const { return (&lower)[i]; } 00085 00086 /// Comparison 00087 FXbool operator==(const FXRangef& r) const { return lower==r.lower && upper==r.upper; } 00088 FXbool operator!=(const FXRangef& r) const { return lower!=r.lower || upper!=r.upper; } 00089 00090 /// Width of box 00091 FXfloat width() const { return upper.x-lower.x; } 00092 00093 /// Height of box 00094 FXfloat height() const { return upper.y-lower.y; } 00095 00096 /// Depth of box 00097 FXfloat depth() const { return upper.z-lower.z; } 00098 00099 /// Longest side 00100 FXfloat longest() const; 00101 00102 /// shortest side 00103 FXfloat shortest() const; 00104 00105 /// Length of diagonal 00106 FXfloat diameter() const; 00107 00108 /// Get radius of box 00109 FXfloat radius() const; 00110 00111 /// Compute diagonal 00112 FXVec3f diagonal() const; 00113 00114 /// Get center of box 00115 FXVec3f center() const; 00116 00117 /// Test if empty 00118 FXbool empty() const; 00119 00120 /// Test if box contains point x,y,z 00121 FXbool contains(FXfloat x,FXfloat y,FXfloat z) const; 00122 00123 /// Test if box contains point p 00124 FXbool contains(const FXVec3f& p) const; 00125 00126 /// Test if box properly contains another box 00127 FXbool contains(const FXRangef& bounds) const; 00128 00129 /// Test if box properly contains sphere 00130 FXbool contains(const FXSpheref& sphere) const; 00131 00132 /// Include point 00133 FXRangef& include(FXfloat x,FXfloat y,FXfloat z); 00134 00135 /// Include point 00136 FXRangef& include(const FXVec3f& v); 00137 00138 /// Include given range into box 00139 FXRangef& include(const FXRangef& box); 00140 00141 /// Include given sphere into this box 00142 FXRangef& include(const FXSpheref& sphere); 00143 00144 /// Intersect box with normalized plane ax+by+cz+w; returns -1,0,+1 00145 FXint intersect(const FXVec4f& plane) const; 00146 00147 /// Intersect box with ray u-v 00148 FXbool intersect(const FXVec3f& u,const FXVec3f& v); 00149 00150 /// Test if boxes a and b overlap 00151 friend FXAPI FXbool overlap(const FXRangef& a,const FXRangef& b); 00152 00153 /// Get corner number 0..7 00154 FXVec3f corner(FXint c) const { return FXVec3f((&lower)[c&1].x,(&lower)[(c>>1)&1].y,(&lower)[c>>2].z); } 00155 00156 /// Transform range by 4x4 matrix 00157 FXRangef transform(const FXMat4f& mat) const; 00158 00159 /// Union of two boxes 00160 friend FXAPI FXRangef unite(const FXRangef& a,const FXRangef& b); 00161 00162 /// Intersection of two boxes 00163 friend FXAPI FXRangef intersect(const FXRangef& a,const FXRangef& b); 00164 00165 /// Save object to a stream 00166 friend FXAPI FXStream& operator<<(FXStream& store,const FXRangef& bounds); 00167 00168 /// Load object from a stream 00169 friend FXAPI FXStream& operator>>(FXStream& store,FXRangef& bounds); 00170 }; 00171 00172 00173 extern FXAPI FXbool overlap(const FXRangef& a,const FXRangef& b); 00174 00175 extern FXAPI FXRangef unite(const FXRangef& a,const FXRangef& b); 00176 extern FXAPI FXRangef intersect(const FXRangef& a,const FXRangef& b); 00177 00178 extern FXAPI FXStream& operator<<(FXStream& store,const FXRangef& bounds); 00179 extern FXAPI FXStream& operator>>(FXStream& store,FXRangef& bounds); 00180 00181 } 00182 00183 #endif 00184
![]() |