00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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 ¢er
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 ¢er
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
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
00104
00105 inline Sphere3f::Sphere3f( void )
00106 {
00107 }
00108
00109 inline Sphere3f::Sphere3f( const Vec3f ¢er, 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 ¢er )
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 }