00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #pragma once
00013
00015 #include "nvsgcommon.h"
00016
00017 #include <algorithm>
00018 #include <vector>
00019 #include "nvmath/Vecnf.h"
00020
00021
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
00063 using Vecnf<3>::operator-;
00064
00066 NVSG_API void set( float x
00067 , float y
00068 , float z
00069 );
00070 };
00071
00072
00073
00074
00078 inline Vec3f normalize( const Vec3f& v
00079 )
00080 {
00081 float norm = __WIN64__wa__std_max( length(v), FLT_EPSILON );
00082
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
00091
00092
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
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 }