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

Vec3f.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  <algorithm>
00018 #include  <vector>
00019 #include  "nvmath/Vecnf.h"
00020 
00021 // __WIN64__wa__XXX macros to workaround some win64 issues
00022 #include "__WIN64__workarounds.h"
00023 
00024 namespace nvmath
00025 {
00026   class Sphere3f;
00027   class Vec4f;
00028 
00030   class Vec3f : public Vecnf<3>
00031   {
00032     public:
00034 
00035       NVSG_API Vec3f( void );
00036 
00038 
00039       NVSG_API Vec3f( float x   
00040                     , float y   
00041                     , float z   
00042                     );
00043 
00045       NVSG_API Vec3f( const Vecnf<3> &v 
00046                     );
00047 
00049 
00050       NVSG_API Vec3f( const Vecnf<4> &v 
00051                     );
00052 
00054 
00056       NVSG_API Vec3f& operator=( const Vec4f &v   
00057                                );
00058 
00060 
00061       NVSG_API Vec3f operator-(void) const;
00062       // don't hide base class' operator-
00063       using Vecnf<3>::operator-;
00064 
00066       NVSG_API void set( float x    
00067                        , float y    
00068                        , float z    
00069                        );
00070   };
00071 
00072   // - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
00073   // non-member functions
00074   // - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
00078   inline Vec3f normalize( const Vec3f& v  
00079                         )
00080   {
00081     float norm = __WIN64__wa__std_max( length(v), FLT_EPSILON );
00082     // return value optimization: safe construction/destruction of a temporary object 
00083     return( Vec3f( v[0]/norm, v[1]/norm, v[2]/norm ) );
00084   }
00085 
00088   inline  void  normalizeV( const std::vector<Vec3f> &vecIn, std::vector<Vec3f> &vecOut )
00089   {
00090     // std::transform (the MS implementation) is not intelligent enough. It does not reserve enough memory
00091     // to hold the transformed elements from input, but reallocates memory with every single element copied.
00092     // Reserving memory on our own will spare us the insert iterator here :-)
00093     vecOut.reserve( vecIn.size() );
00094     std::transform( vecIn.begin(), vecIn.end(), vecOut.begin(), &normalize );
00095   }
00096 
00100   inline Vec3f operator*( float f         
00101                         , const Vec3f &v  
00102                         )
00103   {
00104     return( v * f );
00105   }
00106 
00111   inline Vec3f  operator^( const Vecnf<3> &v0, const Vecnf<3> &v1 )
00112   {
00113     return( Vec3f( v0[1] * v1[2] - v0[2] * v1[1],
00114                    v0[2] * v1[0] - v0[0] * v1[2],
00115                    v0[0] * v1[1] - v0[1] * v1[0]
00116                 )
00117           );
00118   }
00119 
00124   inline bool areCollinear( const Vec3f &v0   
00125                           , const Vec3f &v1   
00126                           )
00127   {
00128     return( length( v0 ^ v1 ) <= FLT_EPSILON );
00129   }
00130 
00133   NVSG_API void  smoothNormals( const std::vector<Vec3f> &vertices, const Sphere3f &sphere, float creaseAngle,
00134                                 std::vector<Vec3f> &normals );
00135 
00136   // - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
00137   // inlines
00138   // - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
00139   inline Vec3f::Vec3f( void )
00140   {
00141   }
00142 
00143   inline Vec3f::Vec3f( float x, float y, float z )
00144   {
00145     (*this)[0]=x;
00146     (*this)[1]=y;
00147     (*this)[2]=z;
00148   }
00149 
00150   inline Vec3f::Vec3f( const Vecnf<3> &v )
00151     : Vecnf<3>( v )
00152   {
00153   }
00154 
00155   inline Vec3f::Vec3f( const Vecnf<4> &v )
00156   {
00157     (*this)[0] = v[0];
00158     (*this)[1] = v[1];
00159     (*this)[2] = v[2];
00160   }
00161 
00162   inline void Vec3f::set( float x, float y, float z )
00163   {
00164     (*this)[0]=x;
00165     (*this)[1]=y;
00166     (*this)[2]=z;
00167   }
00168 
00169   inline Vec3f Vec3f::operator-(void) const
00170   {
00171     return (Vec3f(-m_vec[0], -m_vec[1], -m_vec[2]));
00172   }
00173 
00174 } // end namspace nvmath

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