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,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: FXSpheref.h,v 1.10 2005/01/16 16:06:06 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXSPHEREF_H 00025 #define FXSPHEREF_H 00026 00027 00028 namespace FX { 00029 00030 00031 class FXRangef; 00032 00033 00034 /// Spherical bounds 00035 class FXAPI FXSpheref { 00036 public: 00037 FXVec3f center; 00038 FXfloat radius; 00039 public: 00040 00041 /// Default constructor 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 /// Diameter of sphere 00060 FXfloat diameter() const { return radius*2.0f; } 00061 00062 /// Test if empty 00063 FXbool empty() const { return radius<0.0f; } 00064 00065 /// Test if sphere contains point x,y,z 00066 FXbool contains(FXfloat x,FXfloat y,FXfloat z) const; 00067 00068 /// Test if sphere contains point p 00069 FXbool contains(const FXVec3f& p) const; 00070 00071 /// Test if sphere properly contains another box 00072 FXbool contains(const FXRangef& box) const; 00073 00074 /// Test if sphere properly contains another sphere 00075 FXbool contains(const FXSpheref& sphere) const; 00076 00077 /// Include point 00078 FXSpheref& include(FXfloat x,FXfloat y,FXfloat z); 00079 00080 /// Include point 00081 FXSpheref& include(const FXVec3f& p); 00082 00083 /// Include given range into this one 00084 FXSpheref& include(const FXRangef& box); 00085 00086 /// Include given sphere into this one 00087 FXSpheref& include(const FXSpheref& sphere); 00088 00089 /// Intersect sphere with normalized plane ax+by+cz+w; returns -1,0,+1 00090 FXint intersect(const FXVec4f& plane) const; 00091 00092 /// Intersect sphere with ray u-v 00093 FXbool intersect(const FXVec3f& u,const FXVec3f& v) const; 00094 00095 /// Test if box overlaps with sphere 00096 friend FXAPI FXbool overlap(const FXRangef& a,const FXSpheref& b); 00097 00098 /// Test if sphere overlaps with box 00099 friend FXAPI FXbool overlap(const FXSpheref& a,const FXRangef& b); 00100 00101 /// Test if spheres overlap 00102 friend FXAPI FXbool overlap(const FXSpheref& a,const FXSpheref& b); 00103 00104 /// Save object to a stream 00105 friend FXAPI FXStream& operator<<(FXStream& store,const FXSpheref& sphere); 00106 00107 /// Load object from a stream 00108 friend FXAPI FXStream& operator>>(FXStream& store,FXSpheref& sphere); 00109 }; 00110 00111 } 00112 00113 #endif
Copyright © 1997-2005 Jeroen van der Zijp |