Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXSpheref.h

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

Copyright © 1997-2010 Jeroen van der Zijp