Changeset 471
- Timestamp:
- 09/21/15 19:13:26 (10 years ago)
- Location:
- trunk
- Files:
-
- 8 added
- 28 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv.lua
r466 r471 106 106 -- injection! 107 107 solution( solution().name ) 108 configuration "*"109 includedirs { os.getenv("GLM_PATH") }110 108 configuration "gmake" 111 109 if _ACTION == "gmake-clang" then -
trunk/nv/base/capi.hh
r442 r471 102 102 inline void* nvmemcpy( void *dest, const void *src, size_t count ) 103 103 { 104 if ( dest == src || count == 0 ) return dest; 104 105 NV_ASSERT( dest && src, "Bad parameter to nvmemcpy!" ); 105 if ( dest == src ) return dest;106 106 return NV_CAPI_CALL( memcpy )( dest, src, count ); 107 107 } … … 109 109 inline void* nvmemmove( void *dest, const void *src, size_t count ) 110 110 { 111 if ( dest == src || count == 0 ) return dest; 111 112 NV_ASSERT( dest && src, "Bad parameter to nvmemmove!" ); 112 if ( dest == src ) return dest;113 113 return NV_CAPI_CALL( memmove )( dest, src, count ); 114 114 } -
trunk/nv/base/cmath.hh
r451 r471 19 19 20 20 #include <nv/base/common.hh> 21 22 21 #include <math.h> 23 22 23 namespace nv 24 { 25 26 namespace detail 27 { 28 template< typename T > 29 inline T pow_int( T x, int y ) 30 { 31 unsigned int n = static_cast<unsigned>( y >= 0 ? y : -y ); 32 for ( T z = static_cast<T>( 1 ); ; x *= x ) 33 { 34 if ( ( n & 1 ) != 0 ) 35 z *= x; 36 if ( ( n >>= 1 ) == 0 ) 37 return ( y < 0 ? static_cast<T>( 1 ) / z : z ); 38 } 39 } 40 41 } 42 43 inline double abs( double x ) 44 { 45 return ( ::fabs( x ) ); 46 } 47 48 inline double pow( double x, int y ) 49 { 50 return ( detail::pow_int( x, y ) ); 51 } 52 53 inline float abs( float x ) 54 { 55 return ( ::fabsf( x ) ); 56 } 57 58 inline float acos( float x ) 59 { 60 return ( ::acosf( x ) ); 61 } 62 63 inline float cosh( float x ) 64 { 65 return ( ::coshf( x ) ); 66 } 67 68 inline float acosh( float x ) 69 { 70 return ( ::acoshf( x ) ); 71 } 72 73 inline float asin( float x ) 74 { 75 return ( ::asinf( x ) ); 76 } 77 78 inline float asinh( float x ) 79 { 80 return ( ::asinhf( x ) ); 81 } 82 83 inline float atan( float x ) 84 { 85 return ( ::atanf( x ) ); 86 } 87 88 inline float atanh( float x ) 89 { 90 return ( ::atanhf( x ) ); 91 } 92 93 inline float atan2( float y, float x ) 94 { 95 return ( ::atan2f( y, x ) ); 96 } 97 98 inline float cbrt( float x ) 99 { 100 return ( ::cbrtf( x ) ); 101 } 102 103 inline float ceil( float x ) 104 { 105 return ( ::ceilf( x ) ); 106 } 107 108 inline float cos( float x ) 109 { 110 return ( ::cosf( x ) ); 111 } 112 113 inline float erf( float x ) 114 { 115 return ( ::erff( x ) ); 116 } 117 118 inline float erfc( float x ) 119 { 120 return ( ::erfcf( x ) ); 121 } 122 123 inline float exp( float x ) 124 { 125 return ( ::expf( x ) ); 126 } 127 128 inline float exp2( float x ) 129 { 130 return ( ::exp2f( x ) ); 131 } 132 133 inline float expm1( float x ) 134 { 135 return ( ::expm1f( x ) ); 136 } 137 138 inline float fabs( float x ) 139 { 140 return ( ::fabsf( x ) ); 141 } 142 143 inline float fdim( float x, float y ) 144 { 145 return ( ::fdimf( x, y ) ); 146 } 147 148 inline float floor( float x ) 149 { 150 return ( ::floorf( x ) ); 151 } 152 153 inline float fma( float x, float y, float z ) 154 { 155 return ( ::fmaf( x, y, z ) ); 156 } 157 158 inline float fmax( float x, float y ) 159 { 160 return ( ::fmaxf( x, y ) ); 161 } 162 163 inline float fmin( float x, float y ) 164 { 165 return ( ::fminf( x, y ) ); 166 } 167 168 inline float fmodf( float x, float y ) 169 { 170 return ( ::fmodf( x, y ) ); 171 } 172 173 inline float frexp( float x, int* y ) 174 { 175 return ( ::frexpf( x, y ) ); 176 } 177 178 inline float hypot( float x, float y ) 179 { 180 return ( ::hypotf( x, y ) ); 181 } 182 183 inline int ilogb( float x ) 184 { 185 return ( ::ilogbf( x ) ); 186 } 187 188 inline float ldexp( float x, int y ) 189 { 190 return ( ::ldexpf( x, y ) ); 191 } 192 193 inline float lgamma( float x ) 194 { 195 return ( ::lgammaf( x ) ); 196 } 197 198 inline long long llrint( float x ) 199 { 200 return ( ::llrintf( x ) ); 201 } 202 203 inline long long llround( float x ) 204 { 205 return ( ::llroundf( x ) ); 206 } 207 208 inline float log( float x ) 209 { 210 return ( ::logf( x ) ); 211 } 212 213 inline float log10( float x ) 214 { 215 return ( ::log10f( x ) ); 216 } 217 218 inline float log1p( float x ) 219 { 220 return ( ::log1pf( x ) ); 221 } 222 223 inline float log2( float x ) 224 { 225 return ( ::log2f( x ) ); 226 } 227 228 inline float logb( float x ) 229 { 230 return ( ::logbf( x ) ); 231 } 232 233 inline long lrint( float x ) 234 { 235 return ( ::lrintf( x ) ); 236 } 237 238 inline long lround( float x ) 239 { 240 return ( ::lroundf( x ) ); 241 } 242 243 inline float modf( float x, float* y ) 244 { 245 return ( ::modff( x, y ) ); 246 } 247 248 inline float pow( float x, float y ) 249 { 250 return ( ::powf( x, y ) ); 251 } 252 253 inline float pow( float x, int y ) 254 { 255 return ( detail::pow_int( x, y ) ); 256 } 257 258 inline float remainder( float x, float y ) 259 { 260 return ( ::remainderf( x, y ) ); 261 } 262 263 inline float rint( float x ) 264 { 265 return ( ::rintf( x ) ); 266 } 267 268 inline float round( float x ) 269 { 270 return ( ::roundf( x ) ); 271 } 272 273 inline float sin( float x ) 274 { 275 return ( ::sinf( x ) ); 276 } 277 278 inline float sinh( float x ) 279 { 280 return ( ::sinhf( x ) ); 281 } 282 283 inline float sqrt( float x ) 284 { 285 return ( ::sqrtf( x ) ); 286 } 287 288 inline float tan( float x ) 289 { 290 return ( ::tanf( x ) ); 291 } 292 293 inline float tanh( float x ) 294 { 295 return ( ::tanhf( x ) ); 296 } 297 298 inline float tgamma( float x ) 299 { 300 return ( ::tgammaf( x ) ); 301 } 302 303 inline float trunc( float x ) 304 { 305 return ( ::truncf( x ) ); 306 } 307 308 } 24 309 25 310 #endif // NV_BASE_CMATH_HH -
trunk/nv/base/common.hh
r450 r471 207 207 #endif 208 208 209 enum no_init_t 210 { 211 no_init 212 }; 213 209 214 // Typedefs for fixed size types. 210 215 typedef signed char sint8; … … 288 293 void set_log_handler( log_handler_t ); 289 294 295 template < typename T > 296 constexpr size_t size( const T& t ) 297 { 298 return t.size(); 299 } 300 301 template < typename T, size_t N > 302 constexpr size_t size( const T (&)[N] ) 303 { 304 return N; 305 } 306 307 template < typename T > 308 constexpr bool empty( const T& t ) 309 { 310 return t.empty(); 311 } 312 313 template < typename T, size_t N > 314 constexpr bool empty( const T(&)[N] ) 315 { 316 return N > 0; 317 } 318 319 template < typename T > 320 constexpr auto data( T& t ) -> decltype( t.data() ) 321 { 322 return t.data(); 323 } 324 325 template < typename T > 326 constexpr auto data( const T& t ) -> decltype( t.data() ) 327 { 328 return t.data(); 329 } 330 331 template < typename T, size_t N > 332 constexpr T* data( T(&array)[N] ) 333 { 334 return array; 335 } 336 337 290 338 } // namespace nv 291 339 -
trunk/nv/interface/animated_mesh.hh
r470 r471 30 30 uint32 get_fps() const { return m_fps; } 31 31 // TODO : if loop +1? 32 uint32 get_frame_count() const { int todo;return m_fend - m_fstart; }32 uint32 get_frame_count() const { return m_fend - m_fstart; } 33 33 uint32 get_start_frame() const { return m_fstart; } 34 34 uint32 get_end_frame() const { return m_fend; } -
trunk/nv/interface/interpolation_raw.hh
r459 r471 53 53 { 54 54 quat result; 55 memcpy(reinterpret_cast<float*>(&result), data, sizeof(quat));55 nvmemcpy(reinterpret_cast<float*>(&result), data, sizeof(quat)); 56 56 return result; 57 57 } -
trunk/nv/stl/math.hh
r454 r471 4 4 // This file is part of Nova libraries. 5 5 // For conditions of distribution and use, see copying.txt file in root folder. 6 //7 // TODO: https://github.com/cinder/Cinder/commit/56fd3996be207ccca8063bc81648e199930c909d8 6 9 7 #ifndef NV_STL_MATH_HH … … 11 9 12 10 #include <nv/stl/math/common.hh> 11 #include <nv/stl/math/vec2.hh> 12 #include <nv/stl/math/vec3.hh> 13 #include <nv/stl/math/vec4.hh> 14 #include <nv/stl/math/mat3.hh> 15 #include <nv/stl/math/mat4.hh> 16 #include <nv/stl/math/mat2.hh> 17 #include <nv/stl/math/mat3.hh> 18 #include <nv/stl/math/mat4.hh> 13 19 #include <nv/stl/math/constants.hh> 14 20 #include <nv/stl/math/relational.hh> … … 16 22 #include <nv/stl/math/geometric.hh> 17 23 #include <nv/stl/math/exponential.hh> 24 #include <nv/stl/math/trigonometric.hh> 18 25 #include <nv/stl/math/matrix_transform.hh> 19 26 #include <nv/stl/math/angle.hh> 20 27 #include <nv/stl/math/quaternion.hh> 21 28 #include <nv/stl/math/matrix.hh> 22 29 #include <nv/stl/math/cast.hh> 23 30 -
trunk/nv/stl/math/angle.hh
r454 r471 167 167 static_assert( is_floating_point<T>::value, "Type expected to be floating point!" ); 168 168 169 const T result( acos( clamp( dot( a, b ), T( -1 ), T( 1 ) ) ) );169 const T result( nv::acos( clamp( dot( a, b ), T( -1 ), T( 1 ) ) ) ); 170 170 return mix( result, -result, dot( ref, cross( a, b ) ) < T( 0 ) ); 171 171 } -
trunk/nv/stl/math/basic.hh
r454 r471 77 77 inline static T call( const T& a, const T& b, const U& m ) 78 78 { 79 T result( ctor::uninitialize);80 for ( component_count_t i = 0; i < component_count( a ); ++i )79 T result( no_init ); 80 for ( size_t i = 0; i < nv::size( a ); ++i ) 81 81 result[i] = m[i] ? b[i] : a[i]; 82 82 return result; … … 102 102 }; 103 103 104 template < typename T, typename U>105 struct sign_helper< T, U, false, true >104 template < typename T, bool IsFloating > 105 struct sign_helper< T, T, IsFloating, true > 106 106 { 107 107 inline static T call( const T& a ) 108 108 { 109 typedef typename make_unsigned<T>::type UT; 110 typedef typename make_unsigned<U>::type UU; 111 const U shift( static_cast<U>( sizeof( U ) * 8 - 1 ) ); 112 const T y( UT( -a ) >> UU( shift ) ); 113 return ( a >> shift ) | y; 109 return ( a > T(0) ? T(1) : ( a < T(0) ? T(-1) : T(0) ) ); 114 110 } 115 111 }; … … 278 274 } 279 275 276 template < typename T, typename enable_if< !is_vec<T>::value >::type* = nullptr > 277 constexpr T step( T edge, T x ) 278 { 279 return mix( static_cast<T>( 1 ), static_cast<T>( 0 ), less_than( x, edge ) ); 280 } 281 282 template < typename T, typename enable_if< is_vec<T>::value >::type* = nullptr > 283 constexpr T step( const T& edge, const T& x ) 284 { 285 return mix( static_cast<T>( 1 ), static_cast<T>( 0 ), less_than( x, edge ) ); 286 } 287 288 template < typename T, typename enable_if< is_vec<T>::value >::type* = nullptr > 289 constexpr T step( value_type_t<T> edge, const T& x ) 290 { 291 return mix( static_cast<T>( 1 ), static_cast<T>( 0 ), less_than( x, edge ) ); 292 } 293 294 template < typename T, typename enable_if< is_floating_point<T>::value >::type* = nullptr > 295 constexpr T smoothstep( T edge0, T edge1, T x ) 296 { 297 T y( clamp( ( x - edge0 ) / ( edge1 - edge0 ), static_cast<T>( 0 ), static_cast<T>( 1 ) ) ); 298 return y * y * ( static_cast<T>( 3 ) - static_cast<T>( 2 ) * y ); 299 } 300 301 template < typename T, typename enable_if< is_fp_vec<T>::value >::type* = nullptr > 302 constexpr T smoothstep( const T& edge0, const T& edge1, const T& x ) 303 { 304 T y( clamp( ( x - edge0 ) / ( edge1 - edge0 ), static_cast<T>( 0 ), static_cast<T>( 1 ) ) ); 305 return y * y * ( static_cast<T>( 3 ) - static_cast<T>( 2 ) * y ); 306 } 307 308 template < typename T, typename enable_if< is_fp_vec<T>::value >::type* = nullptr > 309 constexpr T smoothstep( value_type_t<T> edge0, value_type_t<T> edge1, const T& x ) 310 { 311 T y( clamp( ( x - edge0 ) / ( edge1 - edge0 ), static_cast<T>( 0 ), static_cast<T>( 1 ) ) ); 312 return y * y * ( static_cast<T>( 3 ) - static_cast<T>( 2 ) * y ); 313 } 314 280 315 } 281 316 } -
trunk/nv/stl/math/cast.hh
r451 r471 107 107 inline math::tvec2<T> make_vec2( const T * const ptr ) 108 108 { 109 math::tvec2<T> result( math::ctor::uninitialize);109 math::tvec2<T> result( no_init ); 110 110 nvmemcpy( data_cast( result ), ptr, sizeof( math::tvec2<T> ) ); 111 111 return result; … … 115 115 inline math::tvec3<T> make_vec3( const T * const ptr ) 116 116 { 117 math::tvec3<T> result( math::ctor::uninitialize);117 math::tvec3<T> result( no_init ); 118 118 nvmemcpy( data_cast( result ), ptr, sizeof( math::tvec3<T> ) ); 119 119 return result; … … 123 123 inline math::tvec4<T> make_vec4( const T * const ptr ) 124 124 { 125 math::tvec4<T> result( math::ctor::uninitialize);125 math::tvec4<T> result( no_init ); 126 126 nvmemcpy( data_cast( result ), ptr, sizeof( math::tvec4<T> ) ); 127 127 return result; … … 131 131 inline math::tmat2<T> make_mat2( const T * const ptr ) 132 132 { 133 math::tmat2<T> result( math::ctor::uninitialize);133 math::tmat2<T> result( no_init ); 134 134 nvmemcpy( data_cast( result ), ptr, sizeof( math::tmat2<T> ) ); 135 135 return result; … … 139 139 inline math::tmat3<T> make_mat3( const T * const ptr ) 140 140 { 141 math::tmat3<T> result( math::ctor::uninitialize);141 math::tmat3<T> result( no_init ); 142 142 nvmemcpy( data_cast( result ), ptr, sizeof( math::tmat3<T> ) ); 143 143 return result; … … 147 147 inline math::tmat4<T> make_mat4( const T * const ptr ) 148 148 { 149 math::tmat4<T> result( math::ctor::uninitialize);149 math::tmat4<T> result( no_init ); 150 150 nvmemcpy( data_cast( result ), ptr, sizeof( math::tmat4<T> ) ); 151 151 return result; … … 155 155 inline math::tquat<T> make_quat( const T * const ptr ) 156 156 { 157 math::tquat<T> result( math::ctor::uninitialize);157 math::tquat<T> result( no_init ); 158 158 nvmemcpy( data_cast( result ), ptr, sizeof( math::tquat<T> ) ); 159 159 return result; -
trunk/nv/stl/math/common.hh
r459 r471 24 24 25 25 #include <nv/base/cmath.hh> 26 #include <glm/glm.hpp>27 26 28 27 namespace nv … … 31 30 namespace math 32 31 { 33 34 // TODO: Remove 35 using glm::inverse; 36 using glm::transpose; 37 38 using glm::detail::component_count_t; 39 using glm::detail::component_count; 40 41 using glm::ctor; 32 template < typename T > struct tvec2; 33 template < typename T > struct tvec3; 34 template < typename T > struct tvec4; 35 36 template < typename T > struct tmat2; 37 template < typename T > struct tmat3; 38 template < typename T > struct tmat4; 39 40 template < typename T > struct tquat; 41 42 namespace detail 43 { 44 template < typename T > 45 inline tmat2<T> compute_inverse( const tmat2<T> & ); 46 template < typename T > 47 inline tmat3<T> compute_inverse( const tmat3<T> & ); 48 template < typename T > 49 inline tmat4<T> compute_inverse( const tmat4<T> & ); 50 } 51 42 52 43 53 using ::cos; … … 58 68 using ::round; 59 69 60 #if 0 61 template < typename T > using tvec2 = ::glm::detail::tvec2<T, glm::precision::highp>; 62 template < typename T > using tvec3 = ::glm::detail::tvec3<T, glm::precision::highp>; 63 template < typename T > using tvec4 = ::glm::detail::tvec4<T, glm::precision::highp>; 64 template < typename T > using tmat2 = ::glm::detail::tmat2x2<T, glm::precision::highp>; 65 template < typename T > using tmat3 = ::glm::detail::tmat3x3<T, glm::precision::highp>; 66 template < typename T > using tmat4 = ::glm::detail::tmat4x4<T, glm::precision::highp>; 67 #else 68 template < typename T > using tvec2 = ::glm::tvec2<T>; 69 template < typename T > using tvec3 = ::glm::tvec3<T>; 70 template < typename T > using tvec4 = ::glm::tvec4<T>; 71 template < typename T > using tmat2 = ::glm::tmat2x2<T>; 72 template < typename T > using tmat3 = ::glm::tmat3x3<T>; 73 template < typename T > using tmat4 = ::glm::tmat4x4<T>; 74 #endif 75 76 template < typename T > struct is_vec : false_type {}; 77 template < typename T > struct is_mat : false_type {}; 70 template < typename T > struct is_vec : false_type {}; 71 template < typename T > struct is_mat : false_type {}; 72 template < typename T > struct is_quat : false_type {}; 78 73 79 74 template < typename T > struct is_fp : is_floating_point< T > {}; 80 75 template < typename T > struct is_fp_vec : false_type {}; 81 76 template < typename T > struct is_fp_mat : false_type {}; 82 77 template < typename T > struct is_fp_quat : false_type {}; 83 78 template < typename T > struct is_bool_vec : false_type {}; 84 79 … … 86 81 template < typename T > struct is_vec < tvec3< T > > : true_type {}; 87 82 template < typename T > struct is_vec < tvec4< T > > : true_type {}; 83 88 84 template < typename T > struct is_mat < tmat2< T > > : true_type {}; 89 85 template < typename T > struct is_mat < tmat3< T > > : true_type {}; 90 86 template < typename T > struct is_mat < tmat4< T > > : true_type {}; 91 87 88 template < typename T > struct is_quat < tquat< T > > : true_type {}; 89 92 90 template < typename T > struct is_fp < tvec2< T > > : is_floating_point< T > {}; 93 91 template < typename T > struct is_fp < tvec3< T > > : is_floating_point< T > {}; 94 92 template < typename T > struct is_fp < tvec4< T > > : is_floating_point< T > {}; 93 95 94 template < typename T > struct is_fp_vec < tvec2< T > > : is_floating_point< T > {}; 96 95 template < typename T > struct is_fp_vec < tvec3< T > > : is_floating_point< T > {}; 97 96 template < typename T > struct is_fp_vec < tvec4< T > > : is_floating_point< T > {}; 97 98 98 template < typename T > struct is_fp_mat < tmat2< T > > : is_floating_point< T > {}; 99 99 template < typename T > struct is_fp_mat < tmat3< T > > : is_floating_point< T > {}; 100 100 template < typename T > struct is_fp_mat < tmat4< T > > : is_floating_point< T > {}; 101 102 template < typename T > struct is_fp_quat< tquat< T > > : is_floating_point< T > {}; 103 104 template < typename T > struct is_vec_or_quat : is_vec< T > {}; 105 template < typename T > struct is_vec_or_quat< tquat< T > > : true_type {}; 101 106 102 107 template <> struct is_bool_vec < tvec2< bool > > : true_type {}; -
trunk/nv/stl/math/exponential.hh
r454 r471 68 68 inline T inversesqrt( const T& x ) 69 69 { 70 return static_cast<T>( 1 ) / sqrt( x );70 return static_cast<T>( 1 ) / nv::sqrt( x ); 71 71 } 72 72 -
trunk/nv/stl/math/geometric.hh
r469 r471 34 34 inline static T get( const tvec2<T>& a, const tvec2<T>& b ) 35 35 { 36 tvec2<T , P> tmp( a * b );36 tvec2<T> tmp( a * b ); 37 37 return tmp.x + tmp.y; 38 38 } … … 69 69 inline value_type_t<T> length( const T& v ) 70 70 { 71 return sqrt( dot( v, v ) );71 return nv::sqrt( dot( v, v ) ); 72 72 } 73 73 -
trunk/nv/stl/math/matrix_transform.hh
r454 r471 34 34 { 35 35 T const a = angle; 36 T const c = math::cos( a );37 T const s = math::sin( a );36 T const c = nv::cos( a ); 37 T const s = nv::sin( a ); 38 38 39 39 tvec3<T> axis( normalize( v ) ); 40 40 tvec3<T> temp( ( T( 1 ) - c ) * axis ); 41 41 42 tmat4<T> Rotate( ctor::uninitialize);42 tmat4<T> Rotate( no_init ); 43 43 Rotate[0][0] = c + temp[0] * axis[0]; 44 44 Rotate[0][1] = 0 + temp[0] * axis[1] + s * axis[2]; … … 53 53 Rotate[2][2] = c + temp[2] * axis[2]; 54 54 55 tmat4<T> result( ctor::uninitialize);55 tmat4<T> result( no_init ); 56 56 result[0] = m[0] * Rotate[0][0] + m[1] * Rotate[0][1] + m[2] * Rotate[0][2]; 57 57 result[1] = m[0] * Rotate[1][0] + m[1] * Rotate[1][1] + m[2] * Rotate[1][2]; … … 64 64 inline tmat4<T> scale( const tmat4<T>& m, const tvec3<T>& v ) 65 65 { 66 tmat4<T> result( ctor::uninitialize);66 tmat4<T> result( no_init ); 67 67 result[0] = m[0] * v[0]; 68 68 result[1] = m[1] * v[1]; … … 134 134 NV_ASSERT( abs( aspect - epsilon<T>() ) > static_cast<T>( 0 ), "bad parameters to math::perspective!" ); 135 135 136 const T tan_half_fovy = math::tan( fovy / static_cast<T>( 2 ) );136 const T tan_half_fovy = nv::tan( fovy / static_cast<T>( 2 ) ); 137 137 138 138 tmat4<T> result( static_cast<T>( 0 ) ); … … 153 153 154 154 const T rad = fov; 155 const T h = math::cos( static_cast<T>( 0.5 ) * rad ) / math::sin( static_cast<T>( 0.5 ) * rad );155 const T h = nv::cos( static_cast<T>( 0.5 ) * rad ) / math::sin( static_cast<T>( 0.5 ) * rad ); 156 156 const T w = h * height / width; 157 157 -
trunk/nv/stl/math/quaternion.hh
r462 r471 18 18 #include <nv/stl/math/geometric.hh> 19 19 #include <nv/stl/math/angle.hh> 20 #include <nv/base/cmath.hh> 20 21 21 22 namespace nv … … 52 53 : x( q.x ), y( q.y ), z( q.z ), w( q.w ) {} 53 54 54 inline explicit tquat( ctor) {}55 inline explicit tquat( no_init_t ) {} 55 56 constexpr explicit tquat( const T& s, const tvec3<T>& v ) 56 57 : x( v.x ), y( v.y ), z( v.z ), w( s ) {} … … 113 114 typedef tquat< f32 > quat; 114 115 115 template < typename T > struct is_fp_quat : false_type {};116 template < typename T > struct is_quat : false_type {};117 118 template < typename T > struct is_quat< tquat< T > > : true_type {};119 template < typename T > struct is_fp_quat< tquat< T > > : is_floating_point< T > {};120 121 116 namespace detail 122 117 { … … 192 187 else 193 188 { 194 T angle = acos( cos_theta );189 T angle = nv::acos( cos_theta ); 195 190 return ( sin( ( T( 1 ) - m ) * angle ) * a + sin( m * angle ) * b ) / sin( angle ); 196 191 } … … 226 221 else 227 222 { 228 T angle = acos( cos_theta );229 return ( sin( ( T( 1 ) - m ) * angle ) * x + sin( m * angle ) * z ) /sin( angle );223 T angle = nv::acos( cos_theta ); 224 return ( nv::sin( ( T( 1 ) - m ) * angle ) * x + nv::sin( m * angle ) * z ) / nv::sin( angle ); 230 225 } 231 226 } … … 332 327 } 333 328 334 T vmax = sqrt( fmax + T( 1 ) ) * T( 0.5 );329 T vmax = nv::sqrt( fmax + T( 1 ) ) * T( 0.5 ); 335 330 T mult = static_cast<T>( 0.25 ) / vmax; 336 331 337 tquat<T> result( ctor::uninitialize);332 tquat<T> result( no_init ); 338 333 switch ( imax ) 339 334 { … … 392 387 inline tquat<T> angle_axis( T angle, const tvec3<T>& v ) 393 388 { 394 tquat<T> result( ctor::uninitialize);395 T sina = sin( angle * static_cast<T>( 0.5 ) );396 result.w = cos( angle * static_cast<T>( 0.5 ) );389 tquat<T> result( no_init ); 390 T sina = nv::sin( angle * static_cast<T>( 0.5 ) ); 391 result.w = nv::cos( angle * static_cast<T>( 0.5 ) ); 397 392 result.x = v.x * sina; 398 393 result.y = v.y * sina; … … 402 397 403 398 template < typename T > 404 inline tvec4<bool> less_than( const tquat<T>& lhs, const tquat<T>& rhs )405 {406 tvec4<bool> result( ctor::uninitialize );407 for ( component_count_t i = 0; i < component_count( x ); ++i )408 result[i] = rhs[i] < lhs[i];409 return result;410 }411 412 template < typename T >413 inline tvec4<bool> less_than_equal( const tquat<T>& lhs, const tquat<T>& rhs )414 {415 tvec4<bool> result( ctor::uninitialize );416 for ( component_count_t i = 0; i < component_count( x ); ++i )417 result[i] = rhs[i] <= lhs[i];418 return result;419 }420 421 template < typename T >422 inline tvec4<bool> greater_than( const tquat<T>& lhs, const tquat<T>& rhs )423 {424 tvec4<bool> result( ctor::uninitialize );425 for ( component_count_t i = 0; i < component_count( x ); ++i )426 result[i] = rhs[i] > lhs[i];427 return result;428 }429 430 template < typename T >431 inline tvec4<bool> greater_than_equal( const tquat<T>& lhs, const tquat<T>& rhs )432 {433 tvec4<bool, P> result( ctor::uninitialize );434 for ( component_count_t i = 0; i < component_count( x ); ++i )435 result[i] = rhs[i] >= lhs[i];436 return result;437 }438 439 template < typename T >440 inline tvec4<bool> equal( const tquat<T>& lhs, const tquat<T>& rhs )441 {442 tvec4<bool, P> result( ctor::uninitialize );443 for ( component_count_t i = 0; i < component_count( x ); ++i )444 result[i] = rhs[i] == lhs[i];445 return result;446 }447 448 template < typename T >449 inline tvec4<bool> not_equal( const tquat<T>& lhs, const tquat<T>& rhs )450 {451 tvec4<bool> result( ctor::uninitialize );452 for ( component_count_t i = 0; i < component_count( x ); ++i )453 result[i] = rhs[i] != lhs[i];454 return result;455 }456 457 template < typename T >458 399 inline tquat<T>::operator tmat3<T>() 459 400 { -
trunk/nv/stl/math/relational.hh
r454 r471 45 45 }; 46 46 47 template < typename T > 48 struct make_bool_vec< tquat< T > > 49 { 50 typedef tvec4< bool > type; 51 }; 47 52 } 48 53 … … 50 55 using bool_vec_t = typename detail::make_bool_vec<T>::type; 51 56 52 template < typename T, typename enable_if< is_vec <T>::value >::type* = nullptr >57 template < typename T, typename enable_if< is_vec_or_quat<T>::value >::type* = nullptr > 53 58 inline bool_vec_t<T> less_than( const T& lhs, const T& rhs ) 54 59 { 55 bool_vec_t<T> result( ctor::uninitialize);56 for ( component_count_t i = 0; i < component_count( lhs ); ++i )60 bool_vec_t<T> result( no_init ); 61 for ( size_t i = 0; i < nv::size( lhs ); ++i ) 57 62 result[i] = lhs[i] < rhs[i]; 58 63 … … 60 65 } 61 66 62 template < typename T, typename enable_if< is_vec <T>::value >::type* = nullptr >67 template < typename T, typename enable_if< is_vec_or_quat<T>::value >::type* = nullptr > 63 68 inline bool_vec_t<T> less_than_equal( const T& lhs, const T& rhs ) 64 69 { 65 bool_vec_t<T> result( ctor::uninitialize);66 for ( component_count_t i = 0; i < component_count( lhs ); ++i )70 bool_vec_t<T> result( no_init ); 71 for ( size_t i = 0; i < nv::size( lhs ); ++i ) 67 72 result[i] = lhs[i] <= rhs[i]; 68 73 return result; 69 74 } 70 75 71 template < typename T, typename enable_if< is_vec <T>::value >::type* = nullptr >76 template < typename T, typename enable_if< is_vec_or_quat<T>::value >::type* = nullptr > 72 77 inline bool_vec_t<T> greater_than( const T& lhs, const T& rhs ) 73 78 { 74 bool_vec_t<T> result( ctor::uninitialize);75 for ( component_count_t i = 0; i < component_count( lhs ); ++i )79 bool_vec_t<T> result( no_init ); 80 for ( size_t i = 0; i < nv::size( lhs ); ++i ) 76 81 result[i] = lhs[i] > rhs[i]; 77 82 return result; 78 83 } 79 84 80 template < typename T, typename enable_if< is_vec <T>::value >::type* = nullptr >85 template < typename T, typename enable_if< is_vec_or_quat<T>::value >::type* = nullptr > 81 86 inline bool_vec_t<T> greater_than_equal( const T& lhs, const T& rhs ) 82 87 { 83 bool_vec_t<T> result( ctor::uninitialize);84 for ( component_count_t i = 0; i < component_count( lhs ); ++i )88 bool_vec_t<T> result( no_init ); 89 for ( size_t i = 0; i < nv::size( lhs ); ++i ) 85 90 result[i] = lhs[i] >= rhs[i]; 86 91 return result; 87 92 } 88 93 89 template < typename T, typename enable_if< is_vec <T>::value >::type* = nullptr >94 template < typename T, typename enable_if< is_vec_or_quat<T>::value >::type* = nullptr > 90 95 inline bool_vec_t<T> equal( const T& lhs, const T& rhs ) 91 96 { 92 bool_vec_t<T> result( ctor::uninitialize);93 for ( component_count_t i = 0; i < component_count( lhs ); ++i )97 bool_vec_t<T> result( no_init ); 98 for ( size_t i = 0; i < nv::size( lhs ); ++i ) 94 99 result[i] = lhs[i] == rhs[i]; 95 100 return result; 96 101 } 97 102 98 template < typename T, typename enable_if< is_vec <T>::value >::type* = nullptr >103 template < typename T, typename enable_if< is_vec_or_quat<T>::value >::type* = nullptr > 99 104 inline bool_vec_t<T> not_equal( const T& lhs, const T& rhs ) 100 105 { 101 bool_vec_t<T> result( ctor::uninitialize);102 for ( component_count_t i = 0; i < component_count( lhs ); ++i )106 bool_vec_t<T> result( no_init ); 107 for ( size_t i = 0; i < nv::size( lhs ); ++i ) 103 108 result[i] = lhs[i] != rhs[i]; 104 109 return result; … … 109 114 { 110 115 bool result = false; 111 for ( component_count_t i = 0; i < component_count( v ); ++i )116 for ( size_t i = 0; i < nv::size( v ); ++i ) 112 117 result = result || v[i]; 113 118 return result; … … 118 123 { 119 124 bool result = true; 120 for ( component_count_t i = 0; i < component_count( v ); ++i )125 for ( size_t i = 0; i < nv::size( v ); ++i ) 121 126 result = result && v[i]; 122 127 return result; … … 126 131 inline T not_( const T& v ) 127 132 { 128 T result( ctor::uninitialize);129 for ( component_count_t i = 0; i < component_count( v ); ++i )133 T result( no_init ); 134 for ( size_t i = 0; i < nv::size( v ); ++i ) 130 135 result[i] = !v[i]; 131 136 return result; -
trunk/nv/stl/type_erasure.hh
r460 r471 83 83 constexpr pointer operator->() const { return reinterpret_cast<pointer>( m_current ); } 84 84 85 constexprconst_raw_data_iterator& operator++() { m_current += stride; return *this; }86 constexprconst_raw_data_iterator operator++( int ) { const_raw_data_iterator ri( *this ); m_current += stride; return ri; }87 constexprconst_raw_data_iterator& operator--() { m_current -= stride; return *this; }88 constexprconst_raw_data_iterator operator--( int ) { const_raw_data_iterator ri( *this ); m_current -= stride; return ri; }85 inline const_raw_data_iterator& operator++() { m_current += stride; return *this; } 86 inline const_raw_data_iterator operator++( int ) { const_raw_data_iterator ri( *this ); m_current += stride; return ri; } 87 inline const_raw_data_iterator& operator--() { m_current -= stride; return *this; } 88 inline const_raw_data_iterator operator--( int ) { const_raw_data_iterator ri( *this ); m_current -= stride; return ri; } 89 89 90 90 constexpr const_raw_data_iterator operator+( difference_type n ) const { return const_raw_data_iterator( m_current + n * m_stride, m_stride ); } 91 constexprconst_raw_data_iterator& operator+=( difference_type n ) { m_current += n * m_stride; return *this; }91 inline const_raw_data_iterator& operator+=( difference_type n ) { m_current += n * m_stride; return *this; } 92 92 constexpr const_raw_data_iterator operator-( difference_type n ) const { return const_raw_data_iterator( m_current - n * m_stride, m_stride ); } 93 constexprconst_raw_data_iterator& operator-=( difference_type n ) { m_current -= n * m_stride; return *this; }93 inline const_raw_data_iterator& operator-=( difference_type n ) { m_current -= n * m_stride; return *this; } 94 94 constexpr reference operator[]( difference_type n ) const { return *reinterpret_cast<pointer>( m_current + n * m_stride ); } 95 95 -
trunk/src/core/random.cc
r454 r471 21 21 void random::mt_init( uint32 seed ) 22 22 { 23 m_state[0] = static_cast<uint32 _t>( seed & mt_full_mask );23 m_state[0] = static_cast<uint32>( seed & mt_full_mask ); 24 24 for ( int i = 1; i < mersenne_n; i++ ) 25 25 { … … 111 111 { 112 112 f32 angle = frand( math::pi<f32>() * 2.f ); 113 return vec2( math::cos( angle ), math::sin( angle ) );113 return vec2( cos( angle ), sin( angle ) ); 114 114 } 115 115 … … 117 117 { 118 118 f32 cos_theta = frange( -1.0f, 1.0f ); 119 f32 sin_theta = math::sqrt( 1.0f - cos_theta * cos_theta );119 f32 sin_theta = sqrt( 1.0f - cos_theta * cos_theta ); 120 120 f32 phi = frand( 2 * math::pi<f32>() ); 121 121 return vec3( 122 sin_theta * math::sin(phi),123 sin_theta * math::cos(phi),122 sin_theta * sin(phi), 123 sin_theta * cos(phi), 124 124 cos_theta 125 125 ); … … 132 132 if ( r1 > r2 ) swap( r1, r2 ); 133 133 f32 rf = 2* math::pi<f32>()*(r1/r2); 134 return vec2( r2* math::cos( rf ), r2*math::sin( rf ) );134 return vec2( r2*cos( rf ), r2*sin( rf ) ); 135 135 } 136 136 137 137 nv::vec2 nv::random::precise_disk_point() 138 138 { 139 f32 r = math::sqrt( frand() );139 f32 r = sqrt( frand() ); 140 140 f32 rangle = frand( math::pi<f32>() ); 141 return vec2( r* math::cos( rangle ), r*math::sin( rangle ) );141 return vec2( r*cos( rangle ), r*sin( rangle ) ); 142 142 } 143 143 … … 146 146 f32 rad = frand(); 147 147 f32 pi = math::pi<f32>(); 148 f32 phi = math::asin( frange( -1.0f, 1.0f ) ) + pi*.5f;148 f32 phi = asin( frange( -1.0f, 1.0f ) ) + pi*.5f; 149 149 f32 theta = frange( 0.0f, 2 * math::pi<f32>() ); 150 f32 sin_phi = math::sin( phi );150 f32 sin_phi = sin( phi ); 151 151 return vec3( 152 rad * math::cos(theta) * sin_phi,153 rad * math::sin(theta) * sin_phi,154 rad * math::cos(phi)152 rad * cos(theta) * sin_phi, 153 rad * sin(theta) * sin_phi, 154 rad * cos(phi) 155 155 ); 156 156 } … … 158 158 nv::vec3 nv::random::precise_sphere_point() 159 159 { 160 f32 radius = math::pow( frand(), 1.f/3.f );160 f32 radius = pow( frand(), 1.f/3.f ); 161 161 f32 cos_theta = frange( -1.0f, 1.0f ); 162 f32 sin_theta = math::sqrt( 1.0f - cos_theta * cos_theta );162 f32 sin_theta = sqrt( 1.0f - cos_theta * cos_theta ); 163 163 f32 phi = frange( 0.0f, 2 * math::pi<f32>() ); 164 164 return vec3( 165 radius * sin_theta * math::sin(phi),166 radius * sin_theta * math::cos(phi),165 radius * sin_theta * sin(phi), 166 radius * sin_theta * cos(phi), 167 167 radius * cos_theta 168 168 ); … … 203 203 f32 idist2 = iradius * iradius; 204 204 f32 odist2 = oradius * oradius; 205 f32 rdist = math::sqrt( frange( idist2, odist2 ) );205 f32 rdist = sqrt( frange( idist2, odist2 ) ); 206 206 return rdist * precise_unit_vec2(); 207 207 } … … 216 216 f32 idist3 = iradius * iradius * iradius; 217 217 f32 odist3 = oradius * oradius * oradius; 218 f32 rdist = math::pow( frange( idist3, odist3 ), 1.f/3.f );218 f32 rdist = pow( frange( idist3, odist3 ), 1.f/3.f ); 219 219 return rdist * precise_unit_vec3(); 220 220 } … … 237 237 f32 idist2 = ((iradii2.x * iradii2.y) / low ) * odist2; 238 238 239 f32 rdist = math::sqrt( frange( idist2, odist2 ) );239 f32 rdist = sqrt( frange( idist2, odist2 ) ); 240 240 return odir * rdist; 241 241 } … … 260 260 f32 idist2 = ((iradii2.x * iradii2.y * iradii2.z) / low ) * odist2; 261 261 262 f32 odist3 = odist2 * math::sqrt( odist2 );263 f32 idist3 = idist2 * math::sqrt( idist2 );264 265 f32 rdist = math::pow( frange( idist3, odist3 ), 1.f/3.f );262 f32 odist3 = odist2 * sqrt( odist2 ); 263 f32 idist3 = idist2 * sqrt( idist2 ); 264 265 f32 rdist = pow( frange( idist3, odist3 ), 1.f/3.f ); 266 266 return odir * rdist; 267 267 } -
trunk/src/engine/particle_engine.cc
r454 r471 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 = -math::dot( datap->plane_normal, datap->plane_point ) / math::sqrt( math::dot( datap->plane_normal, datap->plane_normal ) );233 datap->distance = -math::dot( datap->plane_normal, datap->plane_point ) / sqrt( math::dot( datap->plane_normal, datap->plane_normal ) ); 234 234 return true; 235 235 } … … 751 751 { 752 752 float emission_angle = math::radians( edata.angle ); 753 float cos_theta = r.frange( math::cos( emission_angle ), 1.0f );754 float sin_theta = math::sqrt(1.0f - cos_theta * cos_theta );753 float cos_theta = r.frange( cos( emission_angle ), 1.0f ); 754 float sin_theta = sqrt(1.0f - cos_theta * cos_theta ); 755 755 float phi = r.frange( 0.0f, 2* math::pi<float>() ); 756 756 pinfo.velocity = orient * 757 ( edata.odir * ( math::cos(phi) * sin_theta ) +758 edata.cdir * ( math::sin(phi)*sin_theta ) +757 ( edata.odir * ( cos(phi) * sin_theta ) + 758 edata.cdir * ( sin(phi)*sin_theta ) + 759 759 edata.dir * cos_theta ); 760 760 } -
trunk/src/formats/assimp_loader.cc
r470 r471 350 350 351 351 uint16 frame_rate = static_cast<uint16>( anim->mTicksPerSecond ); 352 int check_this;353 352 uint16 duration = static_cast<uint16>( anim->mDuration ); 354 353 bool flat = false; -
trunk/src/formats/md3_loader.cc
r451 r471 246 246 { 247 247 float flat = lat * convert; 248 float sin_lat = math::sin( flat );249 float cos_lat = math::cos( flat );248 float sin_lat = nv::sin( flat ); 249 float cos_lat = nv::cos( flat ); 250 250 for ( int lng = 0; lng < 256; ++lng, ++n ) 251 251 { 252 252 float flng = lng * convert; 253 float sin_lng = math::sin( flng );254 float cos_lng = math::cos( flng );253 float sin_lng = nv::sin( flng ); 254 float cos_lng = nv::cos( flng ); 255 255 s_normal_cache[n].x = cos_lat * sin_lng; 256 256 // s_normal_cache[n].y = sin_lat * sin_lng; -
trunk/src/gfx/mesh_creator.cc
r470 r471 17 17 if ( m_data->m_flat ) return; 18 18 merge_keys(); 19 uint 32max_frames = 0;19 uint16 max_frames = 0; 20 20 21 21 nv::vector< sint16 > ids; … … 65 65 size_t count = ( keys ? keys->get_channel_size(0) : 0 ); 66 66 size_t pcount = ( pkeys ? pkeys->get_channel_size(0) : 0 ); 67 max_frames = nv::max<uint 32>( count, max_frames );67 max_frames = nv::max<uint16>( uint16( count ), max_frames ); 68 68 if ( pkeys && pkeys->size() > 0 && keys && keys->size() > 0 ) 69 69 { -
trunk/src/gfx/skeletal_mesh.cc
r470 r471 48 48 { 49 49 float fframe = ( a_ms_time * 0.001f ) * m_fps; 50 uint32 frame = math::floor( fframe);50 uint32 frame = uint32( math::floor( fframe ) ); 51 51 float reminder = fframe - static_cast<float>( frame ); 52 52 uint32 duration = get_frame_count(); -
trunk/src/gfx/texture_atlas.cc
r398 r471 22 22 region r ( ivec2(0,0), size ); 23 23 24 int best_height = INT_MAX;24 int best_height = nv::limits::si_max; 25 25 int best_index = -1; 26 int best_width = INT_MAX;26 int best_width = nv::limits::si_max; 27 27 28 28 for( size_t i=0; i < m_nodes.size(); ++i ) -
trunk/src/gfx/texture_font.cc
r438 r471 172 172 FT_Load_Glyph( face, glyph_index, FT_LOAD_RENDER | FT_LOAD_NO_HINTING); 173 173 slot = face->glyph; 174 g->advance = ivec2( slot->advance.x/64.0f, slot->advance.y/64.0f );174 g->advance = vec2( slot->advance.x/64.0f, slot->advance.y/64.0f ); 175 175 } 176 176 generate_kerning(); -
trunk/src/gl/gl_device.cc
r466 r471 76 76 } 77 77 // TODO: BGR vs RGB, single channel 78 assert( image->format->BytesPerPixel > 2);78 NV_ASSERT( image->format->BytesPerPixel > 2, "bytes per pixel > 2!" ); 79 79 image_format format( image->format->BytesPerPixel == 3 ? RGB : RGBA, UBYTE ); 80 80 image_data* idata = new image_data( format, ivec2( image->w, image->h ), static_cast<nv::uint8*>( image->pixels ) ); -
trunk/src/gui/gui_gfx_renderer.cc
r469 r471 215 215 image_data* data = m_window->get_device()->create_image_data( filename ); 216 216 // TODO: Repitching 217 assert( data->get_depth() == 4);217 NV_ASSERT( data->get_depth() == 4, "depth != 4" ); 218 218 region r = m_atlas.get_region( data->get_size() ); 219 219 m_atlas.set_region( r, data->get_data() ); … … 327 327 position p2 = p + g->size + gp; 328 328 qvec.emplace_back( p + gp, p2, color, g->tl, g->br ); 329 p += g->advance;329 p += ivec2( g->advance ); 330 330 } 331 331 } -
trunk/src/lua/lua_math.cc
r452 r471 214 214 { 215 215 T v = to_vec<T>( L, 1 ); 216 for ( int i = 0; i < v.length(); ++i )216 for ( size_t i = 0; i < v.size(); ++i ) 217 217 { 218 218 lua_pushnumber( L, v[i] ); 219 219 } 220 return v. length();220 return v.size(); 221 221 } 222 222 … … 226 226 T* v = to_pvec<T>( L, 1 ); 227 227 size_t len = 0; 228 int vlen = v->length();228 size_t vlen = v->size(); 229 229 const unsigned char * key = reinterpret_cast<const unsigned char *>( lua_tolstring( L, 2, &len ) ); 230 int idx = 255;230 size_t idx = 255; 231 231 232 232 if ( len == 1 ) … … 264 264 T* v = to_pvec<T>( L, 1 ); 265 265 size_t len = 0; 266 int vlen = v->length();266 size_t vlen = v->size(); 267 267 const unsigned char * key = reinterpret_cast<const unsigned char *>( lua_tolstring( L, 2, &len ) ); 268 int idx = 255;268 size_t idx = 255; 269 269 if( len == 1 ) 270 270 { … … 293 293 T v = to_vec<T>( L, 1 ); 294 294 bool fl = nv::is_floating_point<typename T::value_type>::value; 295 switch ( v. length() )295 switch ( v.size() ) 296 296 { 297 297 case 1: lua_pushfstring( L, ( fl ? "(%f)" : "(%d)" ), v[0] ); break;
Note: See TracChangeset
for help on using the changeset viewer.