Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
|
00001 /******************************************************************************** 00002 * * 00003 * D o u b 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,2005 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (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 GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXRanged.h,v 1.9 2005/01/16 16:06:06 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXRANGED_H 00025 #define FXRANGED_H 00026 00027 00028 namespace FX { 00029 00030 00031 class FXSphered; 00032 00033 00034 /// Bounds 00035 class FXAPI FXRanged { 00036 public: 00037 FXVec3d lower; 00038 FXVec3d upper; 00039 public: 00040 00041 /// Default constructor 00042 FXRanged(){} 00043 00044 /// Copy constructor 00045 FXRanged(const FXRanged& bounds):lower(bounds.lower),upper(bounds.upper){} 00046 00047 /// Initialize from two vectors 00048 FXRanged(const FXVec3d& lo,const FXVec3d& hi):lower(lo),upper(hi){} 00049 00050 /// Initialize from six numbers 00051 FXRanged(FXdouble xlo,FXdouble xhi,FXdouble ylo,FXdouble yhi,FXdouble zlo,FXdouble zhi):lower(xlo,ylo,zlo),upper(xhi,yhi,zhi){} 00052 00053 /// Initialize box to fully contain the given bounding sphere 00054 FXRanged(const FXSphered& sphere); 00055 00056 /// Assignment 00057 FXRanged& operator=(const FXRanged& bounds){ lower=bounds.lower; upper=bounds.upper; return *this; } 00058 00059 /// Indexing with 0..1 00060 FXVec3d& operator[](FXint i){ return (&lower)[i]; } 00061 00062 /// Indexing with 0..1 00063 const FXVec3d& operator[](FXint i) const { return (&lower)[i]; } 00064 00065 /// Width of box 00066 FXdouble width() const { return upper.x-lower.x; } 00067 00068 /// Height of box 00069 FXdouble height() const { return upper.y-lower.y; } 00070 00071 /// Depth of box 00072 FXdouble depth() const { return upper.z-lower.z; } 00073 00074 /// Longest side 00075 FXdouble longest() const; 00076 00077 /// shortest side 00078 FXdouble shortest() const; 00079 00080 /// Length of diagonal 00081 FXdouble diameter() const; 00082 00083 /// Compute diagonal 00084 FXVec3d diagonal() const; 00085 00086 /// Get center of box 00087 FXVec3d center() const; 00088 00089 /// Test if empty 00090 FXbool empty() const; 00091 00092 /// Test if box contains point x,y,z 00093 FXbool contains(FXdouble x,FXdouble y,FXdouble z) const; 00094 00095 /// Test if box contains point p 00096 FXbool contains(const FXVec3d& p) const; 00097 00098 /// Test if box properly contains another box 00099 FXbool contains(const FXRanged& bounds) const; 00100 00101 /// Test if box properly contains sphere 00102 FXbool contains(const FXSphered& sphere) const; 00103 00104 /// Include point 00105 FXRanged& include(FXdouble x,FXdouble y,FXdouble z); 00106 00107 /// Include point 00108 FXRanged& include(const FXVec3d& v); 00109 00110 /// Include given range into box 00111 FXRanged& include(const FXRanged& box); 00112 00113 /// Include given sphere into this box 00114 FXRanged& include(const FXSphered& sphere); 00115 00116 /// Intersect box with normalized plane ax+by+cz+w; returns -1,0,+1 00117 FXint intersect(const FXVec4d &plane) const; 00118 00119 /// Intersect box with ray u-v 00120 FXbool intersect(const FXVec3d& u,const FXVec3d& v); 00121 00122 /// Test if bounds overlap 00123 friend FXAPI FXbool overlap(const FXRanged& a,const FXRanged& b); 00124 00125 /// Get corner number 0..7 00126 FXVec3d corner(FXint c) const { return FXVec3d((&lower)[c&1].x, (&lower)[(c>>1)&1].y, (&lower)[c>>2].z); } 00127 00128 /// Union of two boxes 00129 friend FXAPI FXRanged unite(const FXRanged& a,const FXRanged& b); 00130 00131 /// Intersection of two boxes 00132 friend FXAPI FXRanged intersect(const FXRanged& a,const FXRanged& b); 00133 00134 /// Save object to a stream 00135 friend FXAPI FXStream& operator<<(FXStream& store,const FXRanged& bounds); 00136 00137 /// Load object from a stream 00138 friend FXAPI FXStream& operator>>(FXStream& store,FXRanged& bounds); 00139 }; 00140 00141 } 00142 00143 #endif 00144
Copyright © 1997-2005 Jeroen van der Zijp |