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

FXSphered.h

00001 /******************************************************************************** 00002 * * 00003 * D o u b 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 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: FXSphered.h,v 1.5 2004/03/21 19:07:57 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXSPHERED_H 00025 #define FXSPHERED_H 00026 00027 00028 namespace FX { 00029 00030 00031 class FXRanged; 00032 00033 00034 // Spherical bounds 00035 class FXAPI FXSphered { 00036 public: 00037 FXVec3d center; 00038 FXdouble radius; 00039 public: 00040 00041 /// Default constructor 00042 FXSphered(){} 00043 00044 /// Copy constructor 00045 FXSphered(const FXSphered& sphere):center(sphere.center),radius(sphere.radius){} 00046 00047 /// Initialize from center and radius 00048 FXSphered(const FXVec3d& cen,FXdouble rad):center(cen),radius(rad){} 00049 00050 /// Initialize from center and radius 00051 FXSphered(FXdouble x,FXdouble y,FXdouble z,FXdouble rad):center(x,y,z),radius(rad){} 00052 00053 /// Initialize sphere to fully contain the given bounding box 00054 FXSphered(const FXRanged& bounds); 00055 00056 /// Assignment 00057 FXSphered& operator=(const FXSphered& sphere){ center=sphere.center; radius=sphere.radius; return *this; } 00058 00059 // Diameter of sphere 00060 FXdouble diameter() const { return radius*2.0; } 00061 00062 /// Test if empty 00063 FXbool empty() const { return radius<0.0; } 00064 00065 /// Test if sphere contains point x,y,z 00066 FXbool contains(FXdouble x,FXdouble y,FXdouble z) const; 00067 00068 /// Test if sphere contains point p 00069 FXbool contains(const FXVec3d& p) const; 00070 00071 /// Test if sphere contains another box 00072 FXbool contains(const FXRanged& box) const; 00073 00074 /// Test if sphere contains another sphere 00075 FXbool contains(const FXSphered& sphere) const; 00076 00077 /// Include point 00078 FXSphered& include(FXdouble x,FXdouble y,FXdouble z); 00079 00080 /// Include point 00081 FXSphered& include(const FXVec3d& p); 00082 00083 /// Include given range into this one 00084 FXSphered& include(const FXRanged& box); 00085 00086 /// Include given sphere into this one 00087 FXSphered& include(const FXSphered& sphere); 00088 00089 // Intersect sphere with plane ax+by+cz+w; returns -1,0,+1 00090 FXint intersect(const FXVec4d& plane) const; 00091 00092 /// Intersect sphere with ray u-v 00093 FXbool intersect(const FXVec3d& u,const FXVec3d& v) const; 00094 00095 /// Test if box overlaps with sphere 00096 friend FXAPI FXbool overlap(const FXRanged& a,const FXSphered& b); 00097 00098 /// Test if sphere overlaps with box 00099 friend FXAPI FXbool overlap(const FXSphered& a,const FXRanged& b); 00100 00101 /// Test if spheres overlap 00102 friend FXAPI FXbool overlap(const FXSphered& a,const FXSphered& b); 00103 00104 /// Save object to a stream 00105 friend FXAPI FXStream& operator<<(FXStream& store,const FXSphered& sphere); 00106 00107 /// Load object from a stream 00108 friend FXAPI FXStream& operator>>(FXStream& store,FXSphered& sphere); 00109 }; 00110 00111 } 00112 00113 #endif

Copyright © 1997-2004 Jeroen van der Zijp