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

BoundingSphere.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/Mat44f.h"
00018 #include "nvmath/Sphere3f.h"
00019 
00020 namespace nvmath
00021 {
00023 
00026   class BoundingSphere : public Sphere3f
00027   {
00028     public:
00030       BoundingSphere();
00031 
00032     public:
00034 
00037       NVSG_API bool extend( const Sphere3f &sphere    
00038                           );
00039 
00041 
00043       NVSG_API const Sphere3f & getSphere( void ) const;
00044 
00046 
00047       NVSG_API void setSphere( const Sphere3f &sphere );
00048 
00050 
00052       NVSG_API const Vec3f & getCenter( void ) const;
00053 
00055 
00057       NVSG_API float getRadius( void ) const;
00058 
00060 
00061       NVSG_API void invalidate( void );
00062 
00064 
00066       NVSG_API bool isValid( void ) const;
00067 
00069 
00071       NVSG_API bool set( const Vec3f * vertices       
00072                        , size_t        numVertices    
00073                        );
00074 
00076 
00077       NVSG_API void transform( const Mat44f &m    
00078                              );
00079 
00081       NVSG_API void enlarge( float factor   
00082                            );
00083 
00084     private:
00085       bool    m_valid;
00086   };
00087 
00088   // - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
00089   // inlines
00090   // - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
00091   inline  BoundingSphere::BoundingSphere()
00092   : m_valid(false)
00093   {
00094   }
00095 
00096   inline const Sphere3f & BoundingSphere::getSphere( void ) const
00097   {
00098     __ASSERT( m_valid );
00099     return( *this );
00100   }
00101 
00102   inline void BoundingSphere::setSphere( const Sphere3f &sphere )
00103   {
00104     m_valid = true;
00105     setCenter( sphere.getCenter() );
00106     setRadius( sphere.getRadius() );
00107   }
00108 
00109   inline const Vec3f & BoundingSphere::getCenter( void ) const
00110   {
00111     __ASSERT( m_valid );
00112     return( Sphere3f::getCenter() );
00113   }
00114 
00115   inline float BoundingSphere::getRadius( void ) const
00116   {
00117     __ASSERT( m_valid );
00118     return( Sphere3f::getRadius() );
00119   }
00120 
00121   inline  void  BoundingSphere::invalidate( void )
00122   {
00123     m_valid = false;
00124   }
00125 
00126   inline  bool  BoundingSphere::isValid( void ) const
00127   {
00128     return( m_valid );
00129   }
00130 
00131   inline  void  BoundingSphere::transform( const Mat44f &m )
00132   {
00133     __ASSERT( m_valid );
00134     setCenter( Vec3f( m * Vec4f( Sphere3f::getCenter(), 1.0f ) ) );
00135   }
00136 
00137   inline  void  BoundingSphere::enlarge( float factor )
00138   {
00139     __ASSERT( m_valid );
00140     setRadius( Sphere3f::getRadius() * factor );
00141   }
00142 
00143   inline bool  BoundingSphere::set( const Vec3f * vertices, size_t numVertices )
00144   {
00145     __ASSERT( numVertices > 1 );
00146     bool m_valid = false;
00147     for ( size_t i=1 ; !m_valid && i<numVertices ; i++ )
00148     {
00149       m_valid = ( FLT_EPSILON < distance( vertices[0], vertices[i] ) );
00150     }
00151     if ( m_valid )
00152     {
00153       setSphere( boundingSphere( vertices, numVertices ) );
00154     }
00155     return( m_valid );
00156   }
00157 
00158   inline bool  BoundingSphere::extend( const Sphere3f &sphere )
00159   {
00160     setSphere( m_valid ? boundingSphere( getSphere(), sphere ) : sphere );
00161     return( m_valid );
00162   }
00163 
00164 } // end namspace nvmath

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