![]() |
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 S p h e r 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: FXSpheref.h,v 1.26 2009/01/26 09:40:23 fox Exp $ * 00022 ********************************************************************************/ 00023 #ifndef FXSPHEREF_H 00024 #define FXSPHEREF_H 00025 00026 00027 namespace FX { 00028 00029 00030 class FXRangef; 00031 class FXMat4f; 00032 00033 00034 /// Spherical bounds 00035 class FXAPI FXSpheref { 00036 public: 00037 FXVec3f center; 00038 FXfloat radius; 00039 public: 00040 00041 /// Default constructor; value is not initialized 00042 FXSpheref(){} 00043 00044 /// Copy constructor 00045 FXSpheref(const FXSpheref& sphere):center(sphere.center),radius(sphere.radius){} 00046 00047 /// Initialize from center and radius 00048 FXSpheref(const FXVec3f& cen,FXfloat rad=0.0f):center(cen),radius(rad){} 00049 00050 /// Initialize from center and radius 00051 FXSpheref(FXfloat x,FXfloat y,FXfloat z,FXfloat rad=0.0f):center(x,y,z),radius(rad){} 00052 00053 /// Initialize sphere to fully contain the given bounding box 00054 FXSpheref(const FXRangef& bounds); 00055 00056 /// Assignment 00057 FXSpheref& operator=(const FXSpheref& sphere){ center=sphere.center; radius=sphere.radius; return *this; } 00058 00059 /// Set value from another sphere 00060 FXSpheref& set(const FXSpheref& sphere){ center=sphere.center; radius=sphere.radius; return *this; } 00061 00062 /// Set value from center and radius 00063 FXSpheref& set(const FXVec3f& cen,FXfloat rad=0.0f){ center=cen; radius=rad; return *this; } 00064 00065 /// Set value from center and radius 00066 FXSpheref& set(FXfloat x,FXfloat y,FXfloat z,FXfloat rad=0.0f){ center.set(x,y,z); radius=rad; return *this; } 00067 00068 /// Comparison 00069 FXbool operator==(const FXSpheref& s) const { return center==s.center && radius==s.radius;} 00070 FXbool operator!=(const FXSpheref& s) const { return center!=s.center || radius!=s.radius;} 00071 00072 /// Diameter of sphere 00073 FXfloat diameter() const { return radius*2.0f; } 00074 00075 /// Test if empty 00076 FXbool empty() const { return radius<0.0f; } 00077 00078 /// Test if sphere contains point x,y,z 00079 FXbool contains(FXfloat x,FXfloat y,FXfloat z) const; 00080 00081 /// Test if sphere contains point p 00082 FXbool contains(const FXVec3f& p) const; 00083 00084 /// Test if sphere properly contains another box 00085 FXbool contains(const FXRangef& box) const; 00086 00087 /// Test if sphere properly contains another sphere 00088 FXbool contains(const FXSpheref& sphere) const; 00089 00090 /// Include point 00091 FXSpheref& include(FXfloat x,FXfloat y,FXfloat z); 00092 00093 /// Include point 00094 FXSpheref& include(const FXVec3f& p); 00095 00096 /// Expand radius to include point 00097 FXSpheref& includeInRadius(FXfloat x,FXfloat y,FXfloat z); 00098 00099 /// Expand radius to include point 00100 FXSpheref& includeInRadius(const FXVec3f& p); 00101 00102 /// Include given range into this one 00103 FXSpheref& include(const FXRangef& box); 00104 00105 /// Expand radius to include box 00106 FXSpheref& includeInRadius(const FXRangef& box); 00107 00108 /// Include given sphere into this one 00109 FXSpheref& include(const FXSpheref& sphere); 00110 00111 /// Expand radius to include sphere 00112 FXSpheref& includeInRadius(const FXSpheref& sphere); 00113 00114 /// Intersect sphere with normalized plane ax+by+cz+w; returns -1,0,+1 00115 FXint intersect(const FXVec4f& plane) const; 00116 00117 /// Intersect sphere with ray u-v 00118 FXbool intersect(const FXVec3f& u,const FXVec3f& v) const; 00119 00120 /// Transform sphere by 4x4 matrix 00121 FXSpheref transform(const FXMat4f& mat) const; 00122 00123 /// Test if box overlaps with sphere 00124 friend FXAPI FXbool overlap(const FXRangef& a,const FXSpheref& b); 00125 00126 /// Test if sphere overlaps with box 00127 friend FXAPI FXbool overlap(const FXSpheref& a,const FXRangef& b); 00128 00129 /// Test if spheres overlap 00130 friend FXAPI FXbool overlap(const FXSpheref& a,const FXSpheref& b); 00131 00132 /// Save object to a stream 00133 friend FXAPI FXStream& operator<<(FXStream& store,const FXSpheref& sphere); 00134 00135 /// Load object from a stream 00136 friend FXAPI FXStream& operator>>(FXStream& store,FXSpheref& sphere); 00137 }; 00138 00139 00140 extern FXAPI FXbool overlap(const FXRangef& a,const FXSpheref& b); 00141 extern FXAPI FXbool overlap(const FXSpheref& a,const FXRangef& b); 00142 extern FXAPI FXbool overlap(const FXSpheref& a,const FXSpheref& b); 00143 00144 extern FXAPI FXStream& operator<<(FXStream& store,const FXSpheref& sphere); 00145 extern FXAPI FXStream& operator>>(FXStream& store,FXSpheref& sphere); 00146 00147 } 00148 00149 #endif
![]() |