Changeset 454
- Timestamp:
- 07/31/15 20:25:22 (10 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/core/arcball.hh
r453 r454 50 50 vec3 vb = get_arcball_vector( nposition ); 51 51 52 m_angle = math::acos( glm::min( 1.0f, math::dot( va, vb ) ) );53 m_axis = glm::cross( va, vb );52 m_angle = math::acos( math::min( 1.0f, math::dot( va, vb ) ) ); 53 m_axis = math::cross( va, vb ); 54 54 m_last = nposition; 55 55 } … … 65 65 p.z = sqrt( 1.0f - sq ); 66 66 else 67 p = glm::normalize( p );67 p = math::normalize( p ); 68 68 return p; 69 69 } -
trunk/nv/core/position.hh
r395 r454 279 279 { 280 280 if (r.contains(*this)) return false; 281 ul = glm::max( ul, r.ul );282 lr = glm::min( lr, r.lr );283 ul = glm::min( ul, lr );281 ul = math::max( ul, r.ul ); 282 lr = math::min( lr, r.lr ); 283 ul = math::min( ul, lr ); 284 284 return true; 285 285 } … … 294 294 { 295 295 if ( r.get_width() < get_width() || r.get_height() < get_height() ) return false; 296 ( *this ) += glm::min( r.ul - ul, position() );297 ( *this ) -= glm::min( lr - r.lr, position() );296 ( *this ) += math::min( r.ul - ul, position() ); 297 ( *this ) -= math::min( lr - r.lr, position() ); 298 298 return true; 299 299 } … … 315 315 void include_point( position p ) 316 316 { 317 lr = glm::max( lr, p );318 ul = glm::min( ul, p );317 lr = math::max( lr, p ); 318 ul = math::min( ul, p ); 319 319 } 320 320 -
trunk/nv/core/transform.hh
r398 r454 26 26 void set_orientation( const quat& a_orientation ) { m_orientation = a_orientation; } 27 27 void set_orientation( float radians, const vec3& axis ) 28 { // use math::radians if degrees!29 m_orientation = glm::angleAxis( radians, axis );28 { 29 m_orientation = math::angle_axis( radians, axis ); 30 30 } 31 31 … … 36 36 void move( const vec3& heading, float distance ) 37 37 { 38 m_position += glm::normalize( heading ) * distance;38 m_position += math::normalize( heading ) * distance; 39 39 } 40 40 void translate( const vec3& absolute ) … … 42 42 m_position += absolute; 43 43 } 44 //void rotate( const vec3& axis, f32 angle )45 // { // use math::radians if degrees! 46 //quat temp( angle, axis );47 //m_orientation = temp * m_orientation;48 //}44 void rotate( const vec3& axis, f32 angle ) 45 { 46 quat temp( angle, axis ); 47 m_orientation = temp * m_orientation; 48 } 49 49 void set( const mat4& from ) 50 50 { … … 54 54 mat4 extract() const 55 55 { 56 mat4 result = mat 4_cast( m_orientation );56 mat4 result = math::mat4_cast( m_orientation ); 57 57 result[3] = vec4( m_position, 1.0f ); 58 58 return result; … … 60 60 transform inverse() const 61 61 { 62 quat new_orient( glm::inverse( m_orientation ) );62 quat new_orient( math::inverse( m_orientation ) ); 63 63 // TODO: simplify 64 return transform( -mat 3_cast(new_orient) * m_position, new_orient );64 return transform( -math::mat3_cast(new_orient) * m_position, new_orient ); 65 65 } 66 66 … … 99 99 { 100 100 return transform( 101 glm::mix ( a.get_position(), b.get_position(), value ),102 glm::slerp( a.get_orientation(), b.get_orientation(), value )101 math::mix ( a.get_position(), b.get_position(), value ), 102 math::slerp( a.get_orientation(), b.get_orientation(), value ) 103 103 ); 104 104 } -
trunk/nv/gfx/animation.hh
r423 r454 108 108 float time1 = fdata[index1 * static_cast<int>( keyfsize )]; 109 109 float delta = time1 - time0; 110 factor = glm::clamp( ( time - time0 ) / delta, 0.0f, 1.0f );110 factor = math::clamp( ( time - time0 ) / delta, 0.0f, 1.0f ); 111 111 } 112 112 else … … 117 117 return keyfresult; 118 118 } 119 index0 = glm::clamp<int>( int( time ), 0, int( channel.size() ) - 2 );119 index0 = math::clamp( int( time ), 0, int( channel.size() ) - 2 ); 120 120 index1 = index0 + 1; 121 factor = glm::clamp<float>( time - index0, 0.0f, 1.0f );121 factor = math::clamp( time - index0, 0.0f, 1.0f ); 122 122 } 123 123 uint32 ret = 0; … … 167 167 // return; 168 168 // } 169 // size_t index = glm::clamp<size_t>( size_t( frame ), 0, count - 2 );170 // float factor = glm::clamp<float>( frame - index, 0.0f, 1.0f );169 // size_t index = math::clamp( size_t( frame ), 0, count - 2 ); 170 // float factor = math::clamp( frame - index, 0.0f, 1.0f ); 171 171 // interpolate_key( result, keys[index], keys[index+1], factor ); 172 172 // } … … 208 208 // NV_ASSERT( index >= 0, "animation time fail!"); 209 209 // float delta = keys[index + 1].time - keys[index].time; 210 // float factor = glm::clamp( (time - keys[index].time) / delta, 0.0f, 1.0f );210 // float factor = math::clamp( (time - keys[index].time) / delta, 0.0f, 1.0f ); 211 211 // interpolate_key( result, keys[index], keys[index+1], factor ); 212 212 // } -
trunk/nv/interface/camera.hh
r453 r454 28 28 m_view = math::look_at( eye, focus, up ); 29 29 m_position = eye; 30 m_direction = glm::normalize( focus - eye );30 m_direction = math::normalize( focus - eye ); 31 31 } 32 32 … … 79 79 mat4 get_mvp() const { return m_camera.get_projection() * get_modelview(); } 80 80 81 mat4 get_view_inv() const { return glm::inverse( get_view() ); }82 mat4 get_model_inv() const { return glm::inverse( get_model() ); }83 mat3 get_normal() const { return glm::transpose(glm::inverse( mat3( get_modelview() ) ) ); }81 mat4 get_view_inv() const { return math::inverse( get_view() ); } 82 mat4 get_model_inv() const { return math::inverse( get_model() ); } 83 mat3 get_normal() const { return math::transpose( math::inverse( mat3( get_modelview() ) ) ); } 84 84 protected: 85 85 mat4 m_model; -
trunk/nv/interface/interpolation_template.hh
r410 r454 87 87 88 88 template < typename KEY > 89 mat4 extract_matrix_p_impl( const KEY& k ) { return glm::translate(mat4(),k.translation); }90 template < typename KEY > 91 mat4 extract_matrix_r_impl( const KEY& k ) { return glm::mat4_cast( k.rotation ); }92 template < typename KEY > 93 mat4 extract_matrix_s_impl( const KEY& k ) { return glm::scale(mat4(),k.scale); }89 mat4 extract_matrix_p_impl( const KEY& k ) { return math::translate(mat4(),k.translation); } 90 template < typename KEY > 91 mat4 extract_matrix_r_impl( const KEY& k ) { return math::mat4_cast( k.rotation ); } 92 template < typename KEY > 93 mat4 extract_matrix_s_impl( const KEY& k ) { return math::scale(mat4(),k.scale); } 94 94 template < typename KEY > 95 95 mat4 extract_matrix_pr_impl( const KEY& k ) 96 96 { 97 97 // TODO: this is obviously unoptimized 98 mat4 result = glm::mat4_cast( k.rotation );98 mat4 result = math::mat4_cast( k.rotation ); 99 99 result[3] = vec4( k.translation, 1.0f ); 100 100 return result; … … 104 104 { 105 105 // TODO: this is obviously unoptimized 106 mat4 result = glm::mat4_cast( k.rotation );107 return glm::scale(result,k.scale);106 mat4 result = math::mat4_cast( k.rotation ); 107 return math::scale(result,k.scale); 108 108 } 109 109 template < typename KEY > … … 111 111 { 112 112 // TODO: this is obviously unoptimized 113 return glm::scale(glm::translate(mat4(),k.translation),k.scale);113 return math::scale( math::translate(mat4(),k.translation),k.scale); 114 114 } 115 115 template < typename KEY > … … 117 117 { 118 118 // TODO: this is obviously unoptimized 119 return glm::translate(mat4(),k.translation) * glm::mat4_cast( k.rotation ) * glm::scale(mat4(),k.scale);119 return math::translate(mat4(),k.translation) * math::mat4_cast( k.rotation ) * math::scale(mat4(),k.scale); 120 120 } 121 121 -
trunk/nv/lib/assimp.hh
r406 r454 68 68 { 69 69 const float* p = reinterpret_cast<const float*>( &m ); 70 return glm::transpose( make_mat4( p ) );70 return math::transpose( make_mat4( p ) ); 71 71 } 72 72 73 73 inline quat assimp_quat_cast( const aiQuaternion& q ) 74 74 { 75 return nv::quat( q.w, q.x, q.y, q.z );75 return quat( q.w, q.x, q.y, q.z ); 76 76 } 77 77 -
trunk/nv/stl/math.hh
r453 r454 10 10 #define NV_STL_MATH_HH 11 11 12 #include <nv/common.hh>13 12 #include <nv/stl/math/common.hh> 14 13 #include <nv/stl/math/constants.hh> 14 #include <nv/stl/math/relational.hh> 15 #include <nv/stl/math/epsilon.hh> 15 16 #include <nv/stl/math/geometric.hh> 17 #include <nv/stl/math/exponential.hh> 16 18 #include <nv/stl/math/matrix_transform.hh> 19 #include <nv/stl/math/angle.hh> 20 #include <nv/stl/math/quaternion.hh> 21 17 22 #include <nv/stl/math/cast.hh> 18 23 … … 211 216 T interpolate( const T& lhs, const T& rhs, float f ) 212 217 { 213 return glm::mix( lhs, rhs, f );218 return math::mix( lhs, rhs, f ); 214 219 } 215 220 … … 217 222 inline quat interpolate( const quat& lhs, const quat& rhs, float f ) 218 223 { 219 return glm::slerp( lhs, rhs, f );224 return math::slerp( lhs, rhs, f ); 220 225 } 221 226 … … 227 232 { 228 233 typename math::tvec3<T>::value_type sqr = x.x * x.x + x.y * x.y + x.z * x.z; 229 return ( sqr > 0 ? x * glm::inversesqrt(sqr) : def );234 return ( sqr > 0 ? x * math::inversesqrt(sqr) : def ); 230 235 } 231 236 -
trunk/nv/stl/math/common.hh
r453 r454 15 15 16 16 #include <nv/common.hh> 17 #include <nv/stl/ type_traits/common.hh>18 17 #include <nv/stl/utility/common.hh> 18 #include <nv/stl/type_traits.hh> 19 19 #if NV_COMPILER == NV_GNUC 20 20 #pragma GCC system_header … … 33 33 namespace math 34 34 { 35 36 // TODO: Remove 37 using glm::inverse; 38 using glm::transpose; 39 40 using glm::detail::component_count_t; 41 using glm::detail::component_count; 42 43 using glm::ctor; 44 35 45 using ::cos; 36 46 using ::sin; … … 39 49 using ::cosh; 40 50 using ::sinh; 41 using ::abs;42 51 using ::tan; 52 43 53 using ::sqrt; 44 54 using ::pow; 55 using ::log2; 56 using ::log; 57 using ::exp; 58 45 59 using ::floor; 46 using ::ceil;47 60 using ::round; 61 48 62 #if 0 49 63 template < typename T > using tvec2 = ::glm::detail::tvec2<T, glm::precision::highp>; … … 61 75 template < typename T > using tmat3 = ::glm::tmat3x3<T>; 62 76 template < typename T > using tmat4 = ::glm::tmat4x4<T>; 63 template < typename T > using tquat = ::glm::tquat<T, glm::highp>;77 template < typename T > using tquat = ::glm::tquat<T, glm::highp>; 64 78 #endif 65 79 66 80 typedef glm::quat quat; 67 using glm::ctor; 81 82 template < typename T > struct is_vec : false_type {}; 83 template < typename T > struct is_mat : false_type {}; 84 template < typename T > struct is_quat : false_type {}; 85 86 template < typename T > struct is_fp : is_floating_point< T > {}; 87 template < typename T > struct is_fp_vec : false_type {}; 88 template < typename T > struct is_fp_mat : false_type {}; 89 template < typename T > struct is_fp_quat : false_type {}; 90 91 template < typename T > struct is_bool_vec : false_type {}; 92 93 template < typename T > struct is_vec < tvec2< T > > : true_type {}; 94 template < typename T > struct is_vec < tvec3< T > > : true_type {}; 95 template < typename T > struct is_vec < tvec4< T > > : true_type {}; 96 template < typename T > struct is_mat < tmat2< T > > : true_type {}; 97 template < typename T > struct is_mat < tmat3< T > > : true_type {}; 98 template < typename T > struct is_mat < tmat4< T > > : true_type {}; 99 template < typename T > struct is_quat< tquat< T > > : true_type {}; 100 101 template < typename T > struct is_fp < tvec2< T > > : is_floating_point< T > {}; 102 template < typename T > struct is_fp < tvec3< T > > : is_floating_point< T > {}; 103 template < typename T > struct is_fp < tvec4< T > > : is_floating_point< T > {}; 104 template < typename T > struct is_fp_vec < tvec2< T > > : is_floating_point< T > {}; 105 template < typename T > struct is_fp_vec < tvec3< T > > : is_floating_point< T > {}; 106 template < typename T > struct is_fp_vec < tvec4< T > > : is_floating_point< T > {}; 107 template < typename T > struct is_fp_mat < tmat2< T > > : is_floating_point< T > {}; 108 template < typename T > struct is_fp_mat < tmat3< T > > : is_floating_point< T > {}; 109 template < typename T > struct is_fp_mat < tmat4< T > > : is_floating_point< T > {}; 110 template < typename T > struct is_fp_quat< tquat< T > > : is_floating_point< T > {}; 111 112 template <> struct is_bool_vec < tvec2< bool > > : true_type {}; 113 template <> struct is_bool_vec < tvec3< bool > > : true_type {}; 114 template <> struct is_bool_vec < tvec4< bool > > : true_type {}; 115 116 namespace detail 117 { 118 template < typename Vec, typename R = value_type_t<Vec>, typename T = value_type_t<Vec> > 119 struct unary_functor {}; 120 121 template < typename R, typename T > 122 struct unary_functor< tvec2< T >, R, T > 123 { 124 inline static tvec2<R> call( R( *func )( T ), const tvec2<T>& v ) 125 { 126 return tvec2<R>( func( v.x ), func( v.y ) ); 127 } 128 }; 129 130 template < typename R, typename T > 131 struct unary_functor< tvec3< T >, R, T > 132 { 133 inline static tvec3<R> call( R( *func )( T ), const tvec3<T>& v ) 134 { 135 return tvec3<R>( func( v.x ), func( v.y ), func( v.z ) ); 136 } 137 }; 138 139 template < typename R, typename T > 140 struct unary_functor< tvec4< T >, R, T > 141 { 142 inline static tvec4<R> call( R( *Func ) ( T x ), const tvec4<T>& v ) 143 { 144 return tvec4<R>( func( v.x ), func( v.y ), func( v.z ), func( v.w ) ); 145 } 146 }; 147 148 template < typename Vec, typename T = value_type_t<Vec> > 149 struct binary_functor {}; 150 151 template < typename T > 152 struct binary_functor< tvec2< T >, T > 153 { 154 inline static tvec2<T> call( T( *func ) ( T, T ), const tvec2<T>& a, const tvec2<T>& b ) 155 { 156 return tvec2<T>( func( a.x, b.x ), func( a.y, b.y ) ); 157 } 158 }; 159 160 template < typename T > 161 struct binary_functor< tvec3< T >, T > 162 { 163 inline static tvec3<T> call( T( *func ) ( T, T ), const tvec3<T>& a, const tvec3<T>& b ) 164 { 165 return tvec3<T>( func( a.x, b.x ), func( a.y, b.y ), func( a.z, b.z ) ); 166 } 167 }; 168 169 template < typename T > 170 struct binary_functor< tvec4< T >, T > 171 { 172 inline static tvec4<T> call( T( *func ) ( T, T ), const tvec4<T>& a, const tvec4<T>& b ) 173 { 174 return tvec4<T>( func( a.x, b.x ), func( a.y, b.y ), func( a.z, b.z ), func( a.w, b.w ) ); 175 } 176 }; 177 178 template < typename Vec, typename T = value_type_t<Vec> > 179 struct binary_scalar_functor {}; 180 181 template < typename T > 182 struct binary_scalar_functor< tvec2< T >, T > 183 { 184 inline static tvec2<T> call( T( *func ) ( T, T ), const tvec2<T>& a, T b ) 185 { 186 return tvec2<T>( func( a.x, b ), func( a.y, b ) ); 187 } 188 }; 189 190 template < typename T > 191 struct binary_scalar_functor< tvec3< T >, T > 192 { 193 inline static tvec3<T> call( T( *func ) ( T, T ), const tvec3<T>& a, T b ) 194 { 195 return tvec3<T>( func( a.x, b ), func( a.y, b ), func( a.z, b ) ); 196 } 197 }; 198 199 template < typename T > 200 struct binary_scalar_functor< tvec4< T >, T > 201 { 202 inline static tvec4<T> call( T( *func ) ( T, T ), const tvec4<T>& a, T b ) 203 { 204 return tvec4<T>( func( a.x, b ), func( a.y, b ), func( a.z, b ), func( a.w, b ) ); 205 } 206 }; 207 } 68 208 } 69 70 template < typename T >71 struct is_math_vector : false_type {};72 73 template < typename T >74 struct is_math_matrix : false_type {};75 76 template < typename T >77 struct is_math_quat : false_type {};78 79 template < typename T >80 struct is_math_class : bool_constant<81 is_math_vector< T >::value ||82 is_math_matrix< T >::value ||83 is_math_quat< T >::value84 > {};85 86 template < typename T > struct is_math_vector< math::tvec2< T > > : true_type {};87 template < typename T > struct is_math_vector< math::tvec3< T > > : true_type {};88 template < typename T > struct is_math_vector< math::tvec4< T > > : true_type {};89 template < typename T > struct is_math_matrix< math::tmat2< T > > : true_type {};90 template < typename T > struct is_math_matrix< math::tmat3< T > > : true_type {};91 template < typename T > struct is_math_matrix< math::tmat4< T > > : true_type {};92 template < typename T > struct is_math_quat < math::tquat< T > > : true_type {};93 209 94 210 typedef math::tvec2<sint8> i8vec2; … … 118 234 typedef math::quat quat; 119 235 236 237 238 template < typename T > 239 struct make_unsigned< math::tvec2< T > > 240 { 241 typedef math::tvec2< make_unsigned_t< T > > type; 242 }; 243 244 template < typename T > 245 struct make_unsigned< math::tvec3< T > > 246 { 247 typedef math::tvec3< make_unsigned_t< T > > type; 248 }; 249 250 template < typename T > 251 struct make_unsigned< math::tvec4< T > > 252 { 253 typedef math::tvec4< make_unsigned_t< T > > type; 254 }; 255 256 template < typename T > 257 struct make_signed< math::tvec2< T > > 258 { 259 typedef math::tvec2< make_signed_t< T > > type; 260 }; 261 262 template < typename T > 263 struct make_signed< math::tvec3< T > > 264 { 265 typedef math::tvec3< make_signed_t< T > > type; 266 }; 267 268 template < typename T > 269 struct make_signed< math::tvec4< T > > 270 { 271 typedef math::tvec4< make_signed_t< T > > type; 272 }; 273 120 274 } 121 275 -
trunk/nv/stl/math/geometric.hh
r453 r454 15 15 16 16 #include <nv/stl/math/common.hh> 17 #include <nv/stl/math/basic.hh> 18 #include <nv/stl/math/exponential.hh> 17 19 18 20 namespace nv … … 58 60 } 59 61 60 template < typename T >62 template < typename T, typename enable_if< is_floating_point<T>::value >::type* = nullptr > 61 63 inline T length( T x ) 62 64 { 63 static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );64 65 return abs( x ); 65 66 } 66 67 67 template < typename T, t emplate <typename> class Vec>68 inline T length( const Vec<T>& v )68 template < typename T, typename enable_if< is_fp_vec<T>::value >::type* = nullptr > 69 inline value_type_t<T> length( const T& v ) 69 70 { 70 static_assert( is_math_vector< Vec<T> >::value, "math::vecX expected!" );71 static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );72 71 return sqrt( dot( v, v ) ); 73 72 } 74 73 75 template < typename T>76 inline T distance( const T& a, const T&b )74 template < typename T, typename enable_if< is_floating_point<T>::value >::type* = nullptr > 75 inline T distance( T a, T b ) 77 76 { 78 static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );79 77 return length( b - a ); 80 78 } 81 79 82 template < typename T, t emplate <typename> class Vec>83 inline T distance( const Vec<T>& a, const Vec<T>& b )80 template < typename T, typename enable_if< is_fp_vec<T>::value >::type* = nullptr > 81 inline value_type_t<T> distance( const T& a, const T& b ) 84 82 { 85 static_assert( is_math_vector< Vec<T> >::value, "math::vecX expected!" );86 static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );87 83 return length( b - a ); 88 84 } 89 85 90 template < typename T >86 template < typename T, typename enable_if< is_floating_point<T>::value >::type* = nullptr > 91 87 inline T dot( T a, T b ) 92 88 { … … 95 91 } 96 92 97 template < typename T, t emplate <typename> class Vec>98 inline T dot( const Vec<T>& a, const Vec<T>& b )93 template < typename T, typename enable_if< is_fp_vec<T>::value >::type* = nullptr > 94 inline value_type_t<T> dot( const T& a, const T& b ) 99 95 { 100 static_assert( is_math_vector< Vec<T> >::value, "math::vecX expected!" ); 101 static_assert( is_floating_point<T>::value, "Type expected to be floating point!" ); 102 return detail::dot_impl< Vec, T >::get( a, b ); 96 return detail::dot_impl< T >::get( a, b ); 103 97 } 104 98 105 template < typename T >99 template < typename T, typename enable_if< is_floating_point<T>::value >::type* = nullptr > 106 100 inline tvec3<T> cross( const tvec3<T>& a, const tvec3<T>& b ) 107 101 { 108 static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );109 102 return tvec3<T>( 110 a.y * b.z - y.y * b.z,111 a.z * b.x - y.z * b.x,112 a.x * b.y - y.x * b.y103 a.y * b.z - b.y * a.z, 104 a.z * b.x - b.z * a.x, 105 a.x * b.y - b.x * a.y 113 106 ); 114 107 } 115 108 116 template < typename T >117 inline T normalize( const T&x )109 template < typename T, typename enable_if< is_floating_point<T>::value >::type* = nullptr > 110 inline T normalize( T x ) 118 111 { 119 static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );120 112 return x < T( 0 ) ? T( -1 ) : T( 1 ); 121 113 } 122 114 123 template < typename T, t emplate <typename> class Vec>124 inline Vec<T> normalize( const Vec<T>& x )115 template < typename T, typename enable_if< is_fp_vec<T>::value >::type* = nullptr > 116 inline T normalize( const T& x ) 125 117 { 126 static_assert( is_math_vector< Vec<T> >::value, "math::vecX expected!" );127 static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );128 118 return x * inversesqrt( dot( x, x ) ); 129 119 } 130 120 131 template < typename T >132 inline T faceforward( const T& n, const T& i, const T&nref )121 template < typename T, typename enable_if< is_floating_point<T>::value >::type* = nullptr > 122 inline T faceforward( T n, T i, T nref ) 133 123 { 134 124 return dot( nref, i ) < static_cast<T>( 0 ) ? n : -n; 135 125 } 136 126 137 template < typename T, t emplate <typename> class Vec>138 inline Vec<T> faceforward( const Vec<T>& n, const Vec<T>& i, const Vec<T>& nref )127 template < typename T, typename enable_if< is_fp_vec<T>::value >::type* = nullptr > 128 inline T faceforward( const T& n, const T& i, const T& nref ) 139 129 { 140 static_assert( is_math_vector< Vec<T> >::value, "math::vecX expected!" ); 141 return dot( nref, i ) < static_cast<T>( 0 ) ? n : -n; 130 return dot( nref, i ) < static_cast<value_type_t<T>>( 0 ) ? n : -n; 142 131 } 143 132 144 template < typename T >133 template < typename T, typename enable_if< is_fp<T>::value >::type* = nullptr > 145 134 inline T reflect( const T& i, const T& n ) 146 135 { … … 148 137 } 149 138 150 template < typename T >139 template < typename T, typename enable_if< is_floating_point<T>::value >::type* = nullptr > 151 140 inline T refract( const T& i, const T& n, const T& eta ) 152 141 { 153 static_assert( is_floating_point<T>::value, "Type expected to be floating point!" );154 155 142 const T dotv( dot( n, i ) ); 156 143 const T k( static_cast<T>( 1 ) - eta * eta * ( static_cast<T>( 1 ) - dotv * dotv ) ); … … 158 145 } 159 146 160 template < typename T, t emplate <typename> class Vec>161 inline Vec<T> refract( const Vec<T>& i, const Vec<T>& n, Teta )147 template < typename T, typename enable_if< is_fp_vec<T>::value >::type* = nullptr > 148 inline T refract( const T& i, const T& n, value_type_t<T> eta ) 162 149 { 163 static_assert( is_math_vector< Vec<T> >::value, "math::vecX expected!" ); 164 static_assert( is_floating_point<T>::value, "Type expected to be floating point!" ); 150 typedef value_type_t<T> value_type; 165 151 166 Tconst dotv( dot( n, i ) );167 T const k( static_cast<T>( 1 ) - eta * eta * ( static_cast<T>( 1 ) - dotv * dotv ) );168 return ( eta * i - ( eta * dotv + sqrt( k ) ) * n ) * static_cast< T>( k >= static_cast<T>( 0 ) );152 value_type const dotv( dot( n, i ) ); 153 value_type const k( static_cast<T>( 1 ) - eta * eta * ( static_cast<value_type>( 1 ) - dotv * dotv ) ); 154 return ( eta * i - ( eta * dotv + sqrt( k ) ) * n ) * static_cast<value_type>( k >= static_cast<value_type>( 0 ) ); 169 155 } 170 156 -
trunk/nv/stl/math/matrix_transform.hh
r451 r454 37 37 T const s = math::sin( a ); 38 38 39 tvec3<T> axis( glm::normalize( v ) );39 tvec3<T> axis( normalize( v ) ); 40 40 tvec3<T> temp( ( T( 1 ) - c ) * axis ); 41 41 … … 70 70 result[3] = m[3]; 71 71 return result; 72 } 73 74 template < typename T > 75 inline tmat4<T> translate( const tvec3<T>& v ) 76 { 77 return translate( tmat4<T>( 1.0f ), v ); 78 } 79 80 template < typename T > 81 inline tmat4<T> rotate( T angle, const tvec3<T>& v ) 82 { 83 return rotate( tmat4<T>( 1.0f ), angle, v ); 84 } 85 86 template < typename T > 87 inline tmat4<T> scale( const tvec3<T>& v ) 88 { 89 return scale( tmat4<T>( 1.0f ), v ); 72 90 } 73 91 … … 183 201 inline tvec3<T> unproject( const tvec3<T>& win, const tmat4<T>& model, const tmat4<T>& proj, const tvec4<U>& viewport ) 184 202 { 185 tmat4<T> invp = glm::inverse( proj * model );203 tmat4<T> invp = inverse( proj * model ); 186 204 187 205 tvec4<T> temp = tvec4<T>( win, T( 1 ) ); … … 215 233 inline tmat4<T> look_at( const tvec3<T>& eye, const tvec3<T>& center, const tvec3<T>& up ) 216 234 { 217 const tvec3<T> f( glm::normalize( center - eye ) );218 const tvec3<T> s( glm::normalize( glm::cross( f, up ) ) );219 const tvec3<T> u( glm::cross( s, f ) );235 const tvec3<T> f( normalize( center - eye ) ); 236 const tvec3<T> s( normalize( cross( f, up ) ) ); 237 const tvec3<T> u( cross( s, f ) ); 220 238 221 239 tmat4<T> result( 1 ); … … 229 247 result[1][2] = -f.y; 230 248 result[2][2] = -f.z; 231 result[3][0] = - glm::dot( s, eye );232 result[3][1] = - glm::dot( u, eye );233 result[3][2] = glm::dot( f, eye );249 result[3][0] = -dot( s, eye ); 250 result[3][1] = -dot( u, eye ); 251 result[3][2] = dot( f, eye ); 234 252 return result; 235 253 } -
trunk/nv/stl/type_traits/common.hh
r402 r454 227 227 return detail::addressof_impl<T>::f( detail::addressof_helper<T>( v ), 0 ); 228 228 } 229 230 231 template < typename T > 232 struct extract_value_type 233 { 234 typedef typename T::value_type type; 235 }; 236 237 template < typename T > 238 struct extract_size_type 239 { 240 typedef typename T::size_type type; 241 }; 242 243 template < typename T > 244 using value_type_t = typename extract_value_type<T>::type; 245 template < typename T > 246 using size_type_t = typename extract_size_type<T>::type; 229 247 230 248 namespace detail -
trunk/nv/stl/type_traits/transforms.hh
r410 r454 82 82 typedef signed_type< remove_cv_t<T> > signed_type_result; 83 83 public: 84 typedef match_cv< T, typename signed_type_result::type >type;84 typedef typename match_cv< T, typename signed_type_result::type >::type type; 85 85 }; 86 86 … … 107 107 typedef unsigned_type<remove_cv_t<T>> unsigned_type_result; 108 108 public: 109 typedef match_cv< T, typename unsigned_type_result::type >type;109 typedef typename match_cv< T, typename unsigned_type_result::type >::type type; 110 110 }; 111 111 -
trunk/src/core/random.cc
r451 r454 231 231 vec2 opoint = ellipse_edge( oradii ); 232 232 vec2 opoint2 = opoint * opoint; 233 vec2 odir = glm::normalize( opoint );233 vec2 odir = math::normalize( opoint ); 234 234 f32 odist2 = opoint2.x + opoint2.y; 235 235 … … 251 251 vec3 opoint = ellipsoid_edge( oradii ); 252 252 vec3 opoint2 = opoint * opoint; 253 vec3 odir = glm::normalize( opoint );253 vec3 odir = math::normalize( opoint ); 254 254 f32 odist2 = opoint2.x + opoint2.y + opoint2.z; 255 255 -
trunk/src/engine/particle_engine.cc
r453 r454 231 231 datap->plane_normal = normalize_safe( datap->plane_normal, vec3(0.0f,1.0f,0.0f) ); 232 232 datap->bounce = table->get<float>("bounce", 0.0f ); 233 datap->distance = - glm::dot( datap->plane_normal, datap->plane_point ) / math::sqrt(glm::dot( datap->plane_normal, datap->plane_normal ) );233 datap->distance = -math::dot( datap->plane_normal, datap->plane_point ) / math::sqrt( math::dot( datap->plane_normal, datap->plane_normal ) ); 234 234 return true; 235 235 } … … 242 242 particle& pt = p[i]; 243 243 vec3 direction = pt.velocity * factor; 244 if ( glm::dot( datap->plane_normal, pt.position + direction ) + datap->distance <= 0.0f )244 if ( math::dot( datap->plane_normal, pt.position + direction ) + datap->distance <= 0.0f ) 245 245 { 246 float val = glm::dot( datap->plane_normal, pt.position ) + datap->distance;246 float val = math::dot( datap->plane_normal, pt.position ) + datap->distance; 247 247 if ( val > 0.0f ) 248 248 { 249 vec3 part_dir = direction * ( -val / glm::dot( datap->plane_normal, direction ) );249 vec3 part_dir = direction * ( -val / math::dot( datap->plane_normal, direction ) ); 250 250 pt.position = pt.position + part_dir + ( part_dir - direction ) * datap->bounce; 251 pt.velocity = glm::reflect( pt.velocity, datap->plane_normal ) * datap->bounce;251 pt.velocity = math::reflect( pt.velocity, datap->plane_normal ) * datap->bounce; 252 252 } 253 253 } … … 273 273 for ( uint32 i = 0; i < count; ++i ) 274 274 { 275 p[i].color = glm::clamp( p[i].color + adjustment, 0.0f, 1.0f );275 p[i].color = math::clamp( p[i].color + adjustment, 0.0f, 1.0f ); 276 276 } 277 277 } … … 296 296 for ( uint32 i = 0; i < count; ++i ) 297 297 { 298 p[i].size = glm::max( p[i].size + adjustment, vec2() );298 p[i].size = math::max( p[i].size + adjustment, vec2() ); 299 299 } 300 300 } … … 347 347 } 348 348 349 data.common_up = glm::normalize( table.get<vec3>("common_up", vec3(1,0,0) ) );350 data.common_dir = glm::normalize( table.get<vec3>("common_dir", vec3(0,1,0) ) );349 data.common_up = math::normalize( table.get<vec3>("common_up", vec3(1,0,0) ) ); 350 data.common_dir = math::normalize( table.get<vec3>("common_dir", vec3(0,1,0) ) ); 351 351 352 352 vec2 def_size = table.get<vec2>("size", vec2(0.1,0.1) ); … … 409 409 410 410 edata.rate = element.get<float>("rate", 1.0f ); 411 edata.dir = glm::normalize( element.get<vec3>("direction", vec3(0,1,0) ) );411 edata.dir = math::normalize( element.get<vec3>("direction", vec3(0,1,0) ) ); 412 412 413 413 edata.odir = vec3( 0, 0, 1 ); 414 414 if ( edata.dir != vec3( 0, 1, 0 ) && edata.dir != vec3( 0, -1, 0 ) ) 415 edata.odir = glm::normalize( glm::cross( edata.dir, vec3( 0, 1, 0 ) ) ); edata.cdir = glm::cross( edata.dir, edata.odir ); 415 edata.odir = math::normalize( math::cross( edata.dir, vec3( 0, 1, 0 ) ) ); 416 edata.cdir = math::cross( edata.dir, edata.odir ); 416 417 417 418 data.emmiter_count++; … … 563 564 m_model_matrix = s.get_model(); 564 565 m_camera_pos = s.get_camera().get_position(); 565 m_inv_view_dir = glm::normalize(-s.get_camera().get_direction());566 m_inv_view_dir = math::normalize(-s.get_camera().get_direction()); 566 567 567 568 update_emmiters( info, m_last_update ); … … 636 637 637 638 vec3 view_dir( m_inv_view_dir ); 638 if ( accurate_facing ) view_dir = glm::normalize( m_camera_pos - pdata.position );639 if ( accurate_facing ) view_dir = math::normalize( m_camera_pos - pdata.position ); 639 640 640 641 switch ( orientation ) 641 642 { 642 643 case particle_orientation::POINT : 643 right = glm::normalize( glm::cross( view_dir, vec3( 0, 1, 0 ) ) );644 rot_mat = mat3( right, glm::cross( right, -view_dir ), -view_dir );644 right = math::normalize( math::cross( view_dir, vec3( 0, 1, 0 ) ) ); 645 rot_mat = mat3( right, math::cross( right, -view_dir ), -view_dir ); 645 646 break; 646 647 case particle_orientation::ORIENTED : 647 648 pdir = normalize_safe( pdata.velocity, pdir ); 648 right = glm::normalize( glm::cross( pdir, view_dir ) );649 rot_mat = mat3( right, pdir, glm::cross( pdir, right ) );649 right = math::normalize( math::cross( pdir, view_dir ) ); 650 rot_mat = mat3( right, pdir, math::cross( pdir, right ) ); 650 651 break; 651 652 case particle_orientation::ORIENTED_COMMON : 652 right = glm::normalize( glm::cross( common_dir, view_dir ) );653 rot_mat = mat3( right, common_dir, glm::cross( common_dir, right ) );653 right = math::normalize( math::cross( common_dir, view_dir ) ); 654 rot_mat = mat3( right, common_dir, math::cross( common_dir, right ) ); 654 655 break; 655 656 case particle_orientation::PERPENDICULAR : 656 657 pdir = normalize_safe( pdata.velocity, pdir ); 657 right = glm::normalize( glm::cross( common_up, pdir ) );658 rot_mat = mat3( right, common_up, glm::cross( common_up, right ) );658 right = math::normalize( math::cross( common_up, pdir ) ); 659 rot_mat = mat3( right, common_up, math::cross( common_up, right ) ); 659 660 break; 660 661 case particle_orientation::PERPENDICULAR_COMMON : 661 right = glm::normalize( glm::cross( common_up, common_dir ) );662 rot_mat = mat3( right, common_up, glm::cross( common_up, right ) );662 right = math::normalize( math::cross( common_up, common_dir ) ); 663 rot_mat = mat3( right, common_up, math::cross( common_up, right ) ); 663 664 break; 664 665 } -
trunk/src/formats/assimp_loader.cc
r451 r454 134 134 { 135 135 vec3 v = assimp_vec3_cast( mesh->mVertices[i] ); 136 vec3 n = glm::normalize( assimp_vec3_cast( mesh->mNormals[i] ) );137 vec3 t = glm::normalize( assimp_vec3_cast( mesh->mTangents[i] ) );138 vec3 b = glm::normalize( assimp_vec3_cast( mesh->mBitangents[i] ) );136 vec3 n = math::normalize( assimp_vec3_cast( mesh->mNormals[i] ) ); 137 vec3 t = math::normalize( assimp_vec3_cast( mesh->mTangents[i] ) ); 138 vec3 b = math::normalize( assimp_vec3_cast( mesh->mBitangents[i] ) ); 139 139 vec2 s = assimp_st_cast( mesh->mTextureCoords[0][i] ); 140 140 141 vec3 t_i = glm::normalize( t - n * glm::dot( n, t ) );142 float det = ( glm::dot( glm::cross( n, t ), b ) );141 vec3 t_i = math::normalize( t - n * math::dot( n, t ) ); 142 float det = ( math::dot( math::cross( n, t ), b ) ); 143 143 det = ( det < 0.0f ? -1.0f : 1.0f ); 144 144 nv::vec4 vt( t_i[0], t_i[1], t_i[2], det ); … … 441 441 // { 442 442 // vec3 scale_vec0 = assimp_vec3_cast( node->mScalingKeys[0].mValue ); 443 // float scale_value = glm::length( math::abs( scale_vec0 - vec3(1,1,1) ) );443 // float scale_value = math::length( math::abs( scale_vec0 - vec3(1,1,1) ) ); 444 444 // if ( node->mNumScalingKeys > 1 || scale_value > 0.001 ) 445 445 // { -
trunk/src/formats/obj_loader.cc
r442 r454 283 283 if ( ! (tv.x == 0.0f && tv.y == 0.0f && tv.z == 0.0f) ) 284 284 { 285 m_data[a].tangent = vec4( glm::normalize(tv - nv * glm::dot( nv, tv )), 0.0f );286 m_data[a].tangent[3] = ( glm::dot(glm::cross(nv, tv), tan2[a]) < 0.0f) ? -1.0f : 1.0f;285 m_data[a].tangent = vec4( math::normalize(tv - nv * math::dot( nv, tv )), 0.0f ); 286 m_data[a].tangent[3] = ( math::dot( math::cross(nv, tv), tan2[a]) < 0.0f) ? -1.0f : 1.0f; 287 287 } 288 288 } -
trunk/src/gfx/keyframed_mesh.cc
r451 r454 217 217 for ( size_t i = 0; i < m_vertex_count; ++i ) 218 218 { 219 vtx[i].position = glm::mix( prev[i].position, next[i].position, m_interpolation );220 vtx[i].normal = glm::mix( prev[i].normal, next[i].normal, m_interpolation );221 vtx[i].tangent = glm::mix( prev[i].tangent, next[i].tangent, m_interpolation );219 vtx[i].position = math::mix( prev[i].position, next[i].position, m_interpolation ); 220 vtx[i].normal = math::mix( prev[i].normal, next[i].normal, m_interpolation ); 221 vtx[i].tangent = math::mix( prev[i].tangent, next[i].tangent, m_interpolation ); 222 222 } 223 223 } … … 231 231 for ( size_t i = 0; i < m_vertex_count; ++i ) 232 232 { 233 vtx[i].position = glm::mix( prev[i].position, next[i].position, m_interpolation );234 vtx[i].normal = glm::mix( prev[i].normal, next[i].normal, m_interpolation );233 vtx[i].position = math::mix( prev[i].position, next[i].position, m_interpolation ); 234 vtx[i].normal = math::mix( prev[i].normal, next[i].normal, m_interpolation ); 235 235 } 236 236 } -
trunk/src/gfx/mesh_creator.cc
r430 r454 95 95 void nv::mesh_nodes_creator::transform( float scale, const mat3& r33 ) 96 96 { 97 mat3 ri33 = glm::inverse( r33 );97 mat3 ri33 = math::inverse( r33 ); 98 98 mat4 pre_transform ( scale * r33 ); 99 99 mat4 post_transform( 1.f/scale * ri33 ); … … 150 150 { 151 151 vec3& n = *reinterpret_cast<vec3*>( raw_data + vtx_size*i + n_offset ); 152 n = glm::normalize( normal_transform * n );152 n = math::normalize( normal_transform * n ); 153 153 } 154 154 if ( t_offset != -1 ) … … 156 156 { 157 157 vec4& t = *reinterpret_cast<vec4*>(raw_data + vtx_size*i + t_offset ); 158 t = vec4( glm::normalize( normal_transform * vec3(t) ), t[3] );158 t = vec4( math::normalize( normal_transform * vec3(t) ), t[3] ); 159 159 } 160 160 } … … 299 299 vec3 xyz2 = v2 - v1; 300 300 301 //vec3 normal = glm::cross( xyz1, xyz2 );301 //vec3 normal = math::cross( xyz1, xyz2 ); 302 302 // 303 303 //vtcs[ ti0 ].normal += normal; … … 323 323 if ( ! ( t.x == 0.0f && t.y == 0.0f && t.z == 0.0f ) ) 324 324 { 325 tangents[i] = vec4( glm::normalize(t - n * glm::dot( n, t )), 0.0f );326 tangents[i][3] = ( glm::dot(glm::cross(n, t), tangents2[i]) < 0.0f) ? -1.0f : 1.0f;325 tangents[i] = vec4( math::normalize(t - n * math::dot( n, t )), 0.0f ); 326 tangents[i][3] = ( math::dot( math::cross(n, t), tangents2[i]) < 0.0f) ? -1.0f : 1.0f; 327 327 } 328 328 } -
trunk/src/lua/lua_area.cc
r449 r454 255 255 nv::rectangle* a = to_parea( L, 1 ); 256 256 nv::ivec2* c = to_pcoord( L, 2 ); 257 *c = glm::clamp( *c, a->ul, a->lr );257 *c = nv::math::clamp( *c, a->ul, a->lr ); 258 258 return 0; 259 259 } … … 263 263 nv::rectangle* a = to_parea( L, 1 ); 264 264 nv::ivec2* c = to_pcoord( L, 2 ); 265 push_coord( L, glm::clamp( *c, a->ul, a->lr ) );265 push_coord( L, nv::math::clamp( *c, a->ul, a->lr ) ); 266 266 return 0; 267 267 } -
trunk/src/lua/lua_values.cc
r449 r454 25 25 void* nv::lua::detail::raw_check_userdata( lua_State *L, int index, const char* metatable ) 26 26 { 27 return luaL_ checkudata( L, index, metatable );27 return luaL_testudata( L, index, metatable ); 28 28 } 29 29 -
trunk/src/rogue/fov_recursive_shadowcasting.cc
r406 r454 24 24 { 25 25 position max_radius = m_size-m_position; 26 max_radius = glm::max(max_radius,m_position);27 m_radius = static_cast<int>( glm::length( vec2( max_radius ) ) )+1;26 max_radius = math::max(max_radius,m_position); 27 m_radius = static_cast<int>( math::length( vec2( max_radius ) ) )+1; 28 28 } 29 29 m_radius2 = m_radius * m_radius; -
trunk/src/sdl/sdl_audio.cc
r453 r454 75 75 if ( relative != vec3() ) 76 76 { 77 angle = math::degrees( - glm::orientedAngle( m_forward, glm::normalize( relative ), m_up ) );78 distance = glm::clamp( 20.0f * glm::length( relative ), 0.0f, 255.0f );77 angle = math::degrees( -math::oriented_angle( m_forward, math::normalize( relative ), m_up ) ); 78 distance = math::clamp( 20.0f * math::length( relative ), 0.0f, 255.0f ); 79 79 } 80 80 if ( angle < 0.0f ) angle += 360.0f;
Note: See TracChangeset
for help on using the changeset viewer.