Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Sphere3f.h

Go to the documentation of this file.
00001 // Copyright NVIDIA Corporation 2002-2004
00002 // TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
00003 // *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
00004 // OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
00005 // AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS
00006 // BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
00007 // WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
00008 // BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS)
00009 // ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS
00010 // BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES 
00011 
00012 #pragma once
00013 
00015 #include "nvsgcommon.h"
00016 
00017 #include "nvmath/Vec3f.h"
00018 
00019 namespace nvmath
00020 {
00022   class Sphere3f
00023   {
00024     public:
00026 
00027       NVSG_API Sphere3f( void );
00028 
00030       NVSG_API Sphere3f( const Vec3f &center  
00031                        , float radius         
00032                        );
00033 
00035 
00036       NVSG_API Sphere3f & operator=( const Sphere3f &sphere 
00037                                    );
00038 
00040 
00041       NVSG_API bool operator==( const Sphere3f& sphere      
00042                               ) const;
00043 
00045 
00046       NVSG_API bool operator!=( const Sphere3f& sphere      
00047                               ) const;
00048 
00050 
00053       NVSG_API float operator()( const Vec3f &p             
00054                                ) const;
00055 
00057 
00058       NVSG_API const Vec3f & getCenter( void ) const;
00059 
00061       NVSG_API void setCenter( const Vec3f &center    
00062                              );
00063 
00065 
00066       NVSG_API float getRadius( void ) const;
00067 
00069       NVSG_API void setRadius( float radius           
00070                              );
00071 
00072     private:
00073       Vec3f m_center;
00074       float m_radius;
00075   };
00076 
00077   // - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
00078   // non-member functions
00079   // - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
00084   Sphere3f boundingSphere( const Vec3f *points      
00085                          , size_t numberOfPoints    
00086                          );
00087 
00091   Sphere3f boundingSphere( const Sphere3f &s        
00092                          , const Vec3f &p           
00093                          );
00094 
00098   Sphere3f boundingSphere( const Sphere3f &s0    
00099                          , const Sphere3f &s1    
00100                          );
00101 
00102   // - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
00103   // inlines
00104   // - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
00105   inline Sphere3f::Sphere3f( void )
00106   {
00107   }
00108 
00109   inline Sphere3f::Sphere3f( const Vec3f &center, float radius )
00110     : m_center(center)
00111     , m_radius(radius)
00112   {
00113   }
00114 
00115   inline Sphere3f & Sphere3f::operator=( const Sphere3f &sphere )
00116   {
00117     m_center = sphere.m_center;
00118     m_radius = sphere.m_radius;
00119     return( *this );
00120   }
00121 
00122   inline bool Sphere3f::operator==( const Sphere3f &sphere ) const
00123   {
00124     return( ( m_center == sphere.m_center ) && ( fabsf( m_radius - sphere.m_radius ) < FLT_EPSILON ) );
00125   }
00126 
00127   inline bool Sphere3f::operator!=( const Sphere3f &sphere ) const
00128   {
00129     return( ! (this->operator==( sphere )) );
00130   }
00131 
00132   inline float Sphere3f::operator()( const Vec3f &p ) const
00133   {
00134     return( distance( m_center, p ) - m_radius );
00135   }
00136 
00137   inline const Vec3f & Sphere3f::getCenter( void ) const
00138   {
00139     return( m_center );
00140   }
00141 
00142   inline void Sphere3f::setCenter( const Vec3f &center )
00143   {
00144     m_center = center;
00145   }
00146 
00147   inline float Sphere3f::getRadius( void ) const
00148   {
00149     return( m_radius );
00150   }
00151 
00152   inline void Sphere3f::setRadius( float radius )
00153   {
00154     m_radius = radius;
00155   }
00156 
00158   extern NVSG_API const Sphere3f cUnitSphere;
00159 
00160 } // end namspace nvmath

Generated on Tue Mar 1 13:19:19 2005 for NVSGSDK by NVIDIA