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

Plane3f.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/nvmath.h"
00018 #include "nvmath/Vec3f.h"
00019 
00020 namespace nvmath
00021 {
00023   class Plane3f
00024   {
00025     public:
00027 
00028       NVSG_API Plane3f( void );
00029 
00031       NVSG_API Plane3f( const Vec3f &n  
00032                       , float c         
00033                       );
00034 
00036       NVSG_API Plane3f( const Vec3f &n  
00037                       , const Vec3f &p  
00038                       );
00039 
00041       NVSG_API Plane3f( const Vec3f &p0 
00042                       , const Vec3f &p1 
00043                       , const Vec3f &p2 
00044                       );
00045 
00047 
00048       NVSG_API Plane3f operator-( void ) const;
00049 
00051 
00052       NVSG_API Plane3f & operator=( const Plane3f &pl 
00053                                   );
00054 
00056 
00057       NVSG_API bool operator==( const Plane3f& pl     
00058                               ) const;
00059 
00061 
00062       NVSG_API bool operator!=( const Plane3f& pl     
00063                               ) const;
00064 
00066 
00067       NVSG_API float operator()( const Vec3f &p       
00068                                ) const;
00069 
00071 
00072       NVSG_API Vec3f & n( void );
00073 
00075 
00076       NVSG_API const Vec3f & n( void ) const;
00077 
00079 
00080       NVSG_API float & c( void );
00081 
00083 
00084       NVSG_API const float & c( void ) const;
00085 
00086     private:
00087       Vec3f m_normal;
00088       float m_offset;
00089   };
00090 
00091   // - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
00092   // non-member functions
00093   // - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
00097   inline bool areOnOppositeSides( const Plane3f &plane    
00098                                 , const Vec3f &p0         
00099                                 , const Vec3f &p1         
00100                                 )
00101   {
00102     return( plane( p0 ) * plane( p1 ) < 0 );
00103   }
00104 
00108   inline bool areOnSameSide( const Plane3f &plane    
00109                            , const Vec3f &p0         
00110                            , const Vec3f &p1         
00111                            )
00112   {
00113     return( plane( p0 ) * plane( p1 ) > 0 );
00114   }
00115 
00119   inline float signedDistance( const Plane3f &pl   
00120                              , const Vec3f &p      
00121                              )
00122   {
00123     return( pl( p ) );
00124   }
00125 
00129   inline float distance( const Plane3f &pl   
00130                        , const Vec3f &p      
00131                        )
00132   {
00133     return( fabsf( pl( p ) ) );
00134   }
00135 
00139   inline Vec3f nearestPoint( const Plane3f &pl  
00140                            , const Vec3f &p     
00141                            )
00142   {
00143     return( p - pl( p ) * pl.n() );
00144   }
00145 
00146   // - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
00147   // inlines
00148   // - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
00149   inline Plane3f::Plane3f( void )
00150   {
00151   }
00152 
00153   inline Plane3f::Plane3f( const Vec3f &n, float c )
00154     : m_normal(n)
00155     , m_offset(c)
00156   {
00157     __ASSERT( isNormalized( m_normal ) );
00158   }
00159 
00160   inline Plane3f::Plane3f( const Vec3f &n, const Vec3f &p )
00161     : m_normal(n)
00162     , m_offset(-p*n)
00163   {
00164     __ASSERT( isNormalized( m_normal ) );
00165   }
00166 
00167   inline Plane3f::Plane3f( const Vec3f &p0, const Vec3f &p1, const Vec3f &p2 )
00168   {
00169     __ASSERT( ( p0 != p1 ) && ( p0 != p2 ) && ( p1 != p2 ) );
00170     m_normal = normalize( ( p1 - p0 ) ^ ( p2 - p0 ) );
00171     m_offset = - m_normal * p0;
00172   }
00173 
00174   inline Plane3f Plane3f::operator-( void ) const
00175   {
00176     return( Plane3f( -m_normal, -m_offset ) );
00177   }
00178 
00179   inline Plane3f & Plane3f::operator=( const Plane3f &pl )
00180   {
00181     m_normal = pl.n();
00182     m_offset = pl.c();
00183     return( *this );
00184   }
00185 
00186   inline bool Plane3f::operator==( const Plane3f &pl ) const
00187   {
00188     return( m_normal == pl.n() && ( fabsf( m_offset - pl.c() ) < FLT_EPSILON ) );
00189   }
00190 
00191   inline bool Plane3f::operator!=( const Plane3f &pl ) const
00192   {
00193     return( ! (this->operator==( pl )) );
00194   }
00195 
00196   inline Vec3f & Plane3f::n( void )
00197   {
00198     return( m_normal );
00199   }
00200 
00201   inline const Vec3f & Plane3f::n( void ) const
00202   {
00203     return( m_normal );
00204   }
00205 
00206   inline float & Plane3f::c( void )
00207   {
00208     return( m_offset );
00209   }
00210 
00211   inline const float & Plane3f::c( void ) const
00212   {
00213     return( m_offset );
00214   }
00215 
00216 } // end namspace nvmath

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