Changeset 509
- Timestamp:
- 07/26/16 20:24:02 (9 years ago)
- Location:
- trunk
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/core/random.hh
r503 r509 10 10 #include <nv/common.hh> 11 11 #include <nv/stl/math.hh> 12 #include <nv/stl/limits.hh> 12 13 #include <nv/stl/type_traits/primary.hh> 13 14 14 15 namespace nv 15 16 { 17 enum class random_dist 18 { 19 LINEAR, 20 GAUSSIAN, 21 RGAUSSIAN, 22 STEP_1, 23 STEP_2, 24 STEP_3, 25 STEP_4, 26 MLINEAR, 27 MGAUSSIAN, 28 MRGAUSSIAN, 29 MSTEP_1, 30 MSTEP_2, 31 MSTEP_3, 32 MSTEP_4, 33 }; 34 35 36 template< typename T > 37 struct random_range 38 { 39 T min; 40 T max; 41 random_dist dist = random_dist::LINEAR; 42 }; 43 16 44 17 45 class random_base … … 42 70 } 43 71 72 bool coin_flip() 73 { 74 return rand() % 2 == 0; 75 } 76 44 77 f32 frand() 45 78 { … … 54 87 inline sint32 srange( sint32 min, sint32 max ) 55 88 { 56 NV_ASSERT( max >= min, "Bad srange argument!");89 if ( max < min ) ::nv::swap( max, min ); 57 90 // this method probably reduces range // 58 91 uint32 roll = urand( static_cast<uint32>( max - min ) + 1 ); … … 62 95 inline uint32 urange( uint32 min, uint32 max ) 63 96 { 64 NV_ASSERT( max >= min, "Bad srange argument!");97 if ( max < min ) ::nv::swap( max, min ); 65 98 return urand( max - min + 1 ) + min; 66 99 } … … 68 101 inline f32 frange( f32 min, f32 max ) 69 102 { 70 NV_ASSERT( max >= min, "Bad srange argument!");103 if ( max < min ) ::nv::swap( max, min ); 71 104 return frand( max - min ) + min; 72 105 } … … 84 117 85 118 template < typename T > 86 math::tvec2<T> range( math::tvec2<T> min, math::tvec2<T> max ) 87 { 88 return math::tvec2<T>( 89 range_impl( min.x, max.x, is_floating_point<T>() ), 90 range_impl( min.y, max.y, is_floating_point<T>() ) 91 ); 92 } 93 94 template < typename T > 95 math::tvec3<T> range( math::tvec3<T> min, math::tvec3<T> max ) 96 { 97 return math::tvec3<T>( 98 range_impl( min.x, max.x, is_floating_point<T>() ), 99 range_impl( min.y, max.y, is_floating_point<T>() ), 100 range_impl( min.z, max.z, is_floating_point<T>() ) 101 ); 102 } 103 104 template < typename T > 105 math::tvec4<T> range( math::tvec4<T> min, math::tvec4<T> max ) 106 { 107 return math::tvec4<T>( 108 range_impl( min.x, max.x, is_floating_point<T>() ), 109 range_impl( min.y, max.y, is_floating_point<T>() ), 110 range_impl( min.z, max.z, is_floating_point<T>() ), 111 range_impl( min.w, max.w, is_floating_point<T>() ) 112 ); 113 } 119 T range( T min, T max ) 120 { 121 return component_wise<T>::apply( min, max, range_op( this ) ); 122 123 // return component_wise<T>::apply( min, max, [&]( auto a, auto b ) 124 // { 125 // return range_impl( a, b ); 126 // } ); 127 } 128 129 130 // template < typename T > 131 // math::tvec2<T> range( math::tvec2<T> min, math::tvec2<T> max ) 132 // { 133 // return math::tvec2<T>( 134 // range_impl( min.x, max.x, is_floating_point<T>() ), 135 // range_impl( min.y, max.y, is_floating_point<T>() ) 136 // ); 137 // } 138 // 139 // template < typename T > 140 // math::tvec3<T> range( math::tvec3<T> min, math::tvec3<T> max ) 141 // { 142 // return math::tvec3<T>( 143 // range_impl( min.x, max.x, is_floating_point<T>() ), 144 // range_impl( min.y, max.y, is_floating_point<T>() ), 145 // range_impl( min.z, max.z, is_floating_point<T>() ) 146 // ); 147 // } 148 // 149 // template < typename T > 150 // math::tvec4<T> range( math::tvec4<T> min, math::tvec4<T> max ) 151 // { 152 // return math::tvec4<T>( 153 // range_impl( min.x, max.x, is_floating_point<T>() ), 154 // range_impl( min.y, max.y, is_floating_point<T>() ), 155 // range_impl( min.z, max.z, is_floating_point<T>() ), 156 // range_impl( min.w, max.w, is_floating_point<T>() ) 157 // ); 158 // } 114 159 115 160 … … 209 254 vec3 precise_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii ); 210 255 256 // Box Muller 257 template < typename T = f32 > 258 T gaussian_bm() 259 { 260 T u1; 261 T u2; 262 do { u1 = frand(); u2 = frand(); } while ( u1 <= numeric_limits<T>::min() ); 263 T z0 = sqrt( T(-2) * log( u1 ) ) * cos( math::two_pi<T>() * u2 ); 264 return z0; 265 } 266 267 // Marsaglia 268 template < typename T = f32 > 269 T gaussian_m() 270 { 271 T x1, x2, w, y1; 272 do 273 { 274 x1 = T( 2 ) * frand() - T( 1 ); 275 x2 = T( 2 ) * frand() - T( 1 ); 276 w = x1 * x1 + x2 * x2; 277 } while ( w >= T( 1 ) ); 278 w = sqrt( ( T(-2) * log( w ) ) / w ); 279 y1 = x1 * w; 280 return y1; 281 } 282 283 template < typename T = f32 > 284 T gaussian_01( T sigma = T( 0.1 ) ) 285 { 286 T g = T( 0.5 ) + gaussian_m<T>() * sigma * T(0.5); 287 return math::clamp( g, T( 0 ), T( 1 ) ); 288 } 289 290 template < typename T = f32 > 291 T rgaussian_01( T sigma = T( 0.1 ) ) 292 { 293 T g = gaussian_01<T>( sigma ) - T(0.5); 294 if ( g < T(0) ) g += T(1); 295 return math::clamp( g, T( 0 ), T( 1 ) ); 296 } 297 298 template < typename T > 299 T eval( const random_range<T>& r ) 300 { 301 switch ( r.dist ) 302 { 303 case random_dist::LINEAR : return component_wise<T>::apply( r.min, r.max, range_op( this ) ); 304 case random_dist::GAUSSIAN : return component_wise<T>::apply( r.min, r.max, gaussian_op( this ) ); 305 case random_dist::RGAUSSIAN : return component_wise<T>::apply( r.min, r.max, rgaussian_op( this ) ); 306 case random_dist::STEP_1 : return component_wise<T>::apply( r.min, r.max, coin_flip_op( this ) ); 307 case random_dist::STEP_2 : return component_wise<T>::apply( r.min, r.max, step_op( this, 2 ) ); 308 case random_dist::STEP_3 : return component_wise<T>::apply( r.min, r.max, step_op( this, 3 ) ); 309 case random_dist::STEP_4 : return component_wise<T>::apply( r.min, r.max, step_op( this, 4 ) ); 310 case random_dist::MLINEAR : return frand() * ( r.max - r.min ) + r.min; 311 case random_dist::MGAUSSIAN : return gaussian_01<float>() * ( r.max - r.min ) + r.min; 312 case random_dist::MRGAUSSIAN : return rgaussian_01<float>() * ( r.max - r.min ) + r.min; 313 case random_dist::MSTEP_1 : return coin_flip() ? r.min : r.max; 314 case random_dist::MSTEP_2 : return fstep( r.min, r.max, 2 ); 315 case random_dist::MSTEP_3 : return fstep( r.min, r.max, 3 ); 316 case random_dist::MSTEP_4 : return fstep( r.min, r.max, 4 ); 317 default: return T(); 318 } 319 } 320 211 321 protected: 212 322 static seed_type randomized_seed(); 213 323 214 template <typename T> 215 T range_impl( T min, T max, const true_type& ) 216 { 217 return frange( min, max ); 218 } 219 220 template <typename T> 221 T range_impl( T min, T max, const false_type& ) 222 { 223 return srange( min, max ); 224 } 324 struct range_op 325 { 326 range_op( random_base* base ) : self( base ) {} 327 random_base* self; 328 template <typename T, typename enable_if< is_floating_point<T>::value >::type* = nullptr> 329 T operator()( T a, T b ) { return self->frange( a, b ); } 330 template <typename T, typename enable_if< !is_floating_point<T>::value >::type* = nullptr> 331 T operator()( T a, T b ) { return self->srange( a, b ); } 332 }; 333 334 struct coin_flip_op 335 { 336 coin_flip_op( random_base* base ) : self( base ) {} 337 random_base* self; 338 template <typename T> 339 T operator()( T a, T b ) { return self->coin_flip() ? a : b; } 340 }; 341 342 struct step_op 343 { 344 step_op( random_base* base, uint32 s ) : self( base ), steps(s) {} 345 uint32 steps; 346 random_base* self; 347 template <typename T> 348 T operator()( T a, T b ) { return self->fstep( a, b, steps ); } 349 }; 350 351 struct gaussian_op 352 { 353 gaussian_op( random_base* base ) : self( base ) {} 354 random_base* self; 355 template <typename T> 356 T operator()( T a, T b ) { return self->gaussian_01<T>() * ( b - a ) + a; } 357 }; 358 359 struct rgaussian_op 360 { 361 rgaussian_op( random_base* base ) : self( base ) {} 362 random_base* self; 363 template <typename T> 364 T operator()( T a, T b ) { return ( self->rgaussian_01<T>() ) * ( b - a ) + a; } 365 }; 366 367 template <typename T, typename enable_if< !math::is_vec<T>::value >::type* = nullptr > 368 T fstep( T min, T max, uint32 steps ) 369 { 370 return T( srand( steps + 1 ) ) * ( max - min ) / T( steps ) + min; 371 } 372 373 template <typename T, typename enable_if< math::is_vec<T>::value >::type* = nullptr > 374 T fstep( T min, T max, uint32 steps ) 375 { 376 return value_type_t<T>( srand( steps + 1 ) ) * ( max - min ) / value_type_t<T>( steps ) + min; 377 } 378 379 template < typename T > 380 struct component_wise 381 { 382 template < typename Functor > 383 static T apply( T min, T max, typename enable_if< is_arithmetic<T>::value, Functor >::type f ) 384 { 385 return f( min, max ); 386 } 387 }; 388 389 template < typename T > 390 struct component_wise< math::tvec2< T > > 391 { 392 template < typename Functor > 393 static math::tvec2<T> apply( math::tvec2<T> min, math::tvec2<T> max, Functor f ) 394 { 395 return math::tvec2<T>( 396 f( min.x, max.x ), 397 f( min.y, max.y ) 398 ); 399 } 400 }; 401 402 template < typename T > 403 struct component_wise< math::tvec3< T > > 404 { 405 template < typename Functor > 406 static math::tvec3<T> apply( math::tvec3<T> min, math::tvec3<T> max, Functor f ) 407 { 408 return math::tvec3<T>( 409 f( min.x, max.x ), 410 f( min.y, max.y ), 411 f( min.z, max.z ) 412 ); 413 } 414 }; 415 416 template < typename T > 417 struct component_wise< math::tvec4< T > > 418 { 419 template < typename Functor > 420 static math::tvec4<T> apply( math::tvec4<T> min, math::tvec4<T> max, Functor f ) 421 { 422 return math::tvec4<T>( 423 f( min.x, max.x ), 424 f( min.y, max.y ), 425 f( min.z, max.z ), 426 f( min.w, max.w ) 427 ); 428 } 429 }; 430 225 431 }; 226 432 … … 251 457 public: 252 458 explicit random_xor128( seed_type seed = randomized_seed() ); 253 virtual seed_type set_seed( seed_type seed = 0 ); 459 random_xor128( const random_xor128& other ) 460 { 461 m_state[0] = other.m_state[0]; 462 m_state[1] = other.m_state[1]; 463 m_state[2] = other.m_state[2]; 464 m_state[3] = other.m_state[3]; 465 } 466 virtual seed_type set_seed( seed_type seed = randomized_seed() ); 254 467 virtual result_type rand(); 255 468 private: -
trunk/nv/core/resource.hh
r505 r509 45 45 virtual bool exists( resource_id id ) = 0; 46 46 virtual bool load_resource( const string_view& ) { return false; }; 47 virtual void remove( resource_id id ) = 0; 48 virtual void rename( resource_id id, resource_id new_id ) = 0; 47 49 48 50 template< typename T > … … 247 249 } 248 250 251 template < typename T > 252 void remove( shash64 id ) 253 { 254 auto m = m_handlers.find( resource_type_id( rtti_type_hash<T>::value ) ); 255 NV_ASSERT( m != m_handlers.end(), "Resource type unrecognized!" ); 256 m->second->remove( id ); 257 } 258 259 template < typename T > 260 void rename( shash64 id, shash64 new_id ) 261 { 262 auto m = m_handlers.find( resource_type_id( rtti_type_hash<T>::value ) ); 263 NV_ASSERT( m != m_handlers.end(), "Resource type unrecognized!" ); 264 m->second->rename( id, new_id ); 265 } 266 267 template < typename T > 268 bool exists( shash64 id ) 269 { 270 auto m = m_handlers.find( resource_type_id( rtti_type_hash<T>::value ) ); 271 NV_ASSERT( m != m_handlers.end(), "Resource type unrecognized!" ); 272 return m->second->exists( id ); 273 } 274 249 275 virtual ~resource_manager() 250 276 { -
trunk/nv/engine/animation.hh
r508 r509 76 76 vector< animator_layer_data > layers; 77 77 pose_data_set* poses; 78 string64 id; 78 79 }; 79 80 -
trunk/nv/engine/default_resource_manager.hh
r508 r509 32 32 { 33 33 public: 34 explicit default_resource_manager( context* context );34 explicit default_resource_manager( context* context, bool clear_material_paths = true ); 35 35 36 36 void initialize( lua::state* lua ); … … 46 46 } 47 47 48 mesh_source get_source( resource< data_channel_set > mesh ) 49 { 50 return m_mesh_datas->get_source( mesh ); 51 } 52 48 53 nv::string_view resolve( nv::shash64 h ) 49 54 { … … 52 57 53 58 void reload_data(); 54 pr ivate:59 protected: 55 60 lua::state* m_lua; 56 61 image_manager* m_images; -
trunk/nv/engine/material_manager.hh
r505 r509 27 27 struct material 28 28 { 29 string128 id; 29 30 string128 paths[ 8 ]; 30 31 }; … … 43 44 virtual string_view get_storage_name() const { return "materials"; } 44 45 virtual string_view get_resource_name() const { return "material"; } 46 explicit material_manager( bool clear_paths ) : m_clear_paths( clear_paths ) {} 45 47 protected: 46 48 virtual bool load_resource( lua::table_guard& table, shash64 id ); 47 49 private: 50 bool m_clear_paths; 48 51 }; 49 52 -
trunk/nv/engine/mesh_manager.hh
r508 r509 39 39 struct mesh_data 40 40 { 41 string128 path; 41 42 vector< data_node_info > infos; 42 43 vector< resource< data_channel_set > > meshes; … … 65 66 }; 66 67 68 struct mesh_source 69 { 70 resource< mesh_data > mesh; 71 uint32 index; 72 }; 73 67 74 class mesh_data_manager : public file_resource_manager< mesh_data > 68 75 { … … 74 81 resource< mesh_data > default = resource< mesh_data >(), 75 82 data_node_info* info = nullptr ); 83 84 mesh_source get_source( resource< data_channel_set > mesh ) 85 { 86 auto it = m_source_map.find( mesh.id() ); 87 if ( it != m_source_map.end() ) return it->second; 88 return mesh_source{}; 89 } 90 76 91 ~mesh_data_manager() { delete m_strings; } 77 92 protected: 78 93 virtual bool load_resource( const string_view& id ); 79 80 mesh_manager* m_mesh_manager;81 string_table* m_strings;94 nv::hash_store< resource_id, mesh_source > m_source_map; 95 mesh_manager* m_mesh_manager; 96 string_table* m_strings; 82 97 }; 83 98 -
trunk/nv/engine/model_manager.hh
r508 r509 33 33 resource< material > material; 34 34 transform local; 35 sint16 attach_id; 36 float chance; 37 bool random_rotate_y; 38 bool force; 35 random_range< vec3 > position; 36 random_range< vec3 > rotation; 39 37 vector< model_node* > children; 40 41 model_node() : attach_id( 0 ), chance( 1.0f ), random_rotate_y( false ), force( false ) {} 38 sint16 attach_id = -1; 39 uint16 weight = 0; 40 float chance = 1.0f; 41 bool force = false; 42 bool choice = false; 43 44 void clone_values_to( model_node* target ) const 45 { 46 target->mesh = mesh; 47 target->material = material; 48 target->local = local; 49 target->rotation = rotation; 50 target->position = position; 51 52 target->attach_id = attach_id; 53 target->weight = weight; 54 target->chance = chance; 55 target->force = force; 56 target->choice = choice; 57 } 42 58 43 59 ~model_node() … … 62 78 sint16 parent_id; 63 79 transform local; 80 uint32 flags; 64 81 }; 65 82 66 83 struct flat_model 67 84 { 68 flat_model_element elements[ 8];85 flat_model_element elements[16]; 69 86 uint32 count; 70 87 shash64 attach; … … 73 90 74 91 NV_RTTI_DECLARE_NAME( model, "model" ) 92 93 enum flat_model_flags 94 { 95 FMF_SELECTED = 0x01, 96 FMF_FOCUS = 0x02, 97 FMF_FAIL_CHANCE = 0x04, 98 FMF_FAIL_CHOICE = 0x08, 99 FMF_RANGE_GHOST = 0x10, 100 }; 101 102 enum flatten_flags 103 { 104 FF_GENERATE_CHANCE = 0x02, 105 FF_GENERATE_CHOICE = 0x04, 106 FF_GENERATE_GHOST = 0x08, 107 }; 75 108 76 109 class model_manager : public lua_resource_manager< model > … … 85 118 virtual string_view get_storage_name() const { return "models"; } 86 119 virtual string_view get_resource_name() const { return "model"; } 87 static flat_model flatten( const model* m, random_base& rng )120 static flat_model flatten( const model* m, random_base& rng, vector< const model_node* >* map = nullptr, uint32 gen_flags = 0, const model_node* select = nullptr ) 88 121 { 89 122 flat_model result; … … 92 125 result.local = m->root; 93 126 result.count = 0; 94 flatten( result, m, rng, transform(), -1 );127 flatten( result, m, rng, transform(), -1, map, gen_flags, 0, select ); 95 128 return result; 96 129 } 97 130 protected: 98 static void flatten( flat_model& result, const model_node* m, random_base& rng, const transform& ptr, sint16 parent_id ) 131 static void flatten( 132 flat_model& result, 133 const model_node* m, 134 random_base& rng, 135 const transform& ptr, 136 sint16 parent_id, 137 vector< const model_node* >* map, 138 uint32 gen_flags, 139 uint32 parent_flags, 140 const model_node* selected 141 ) 99 142 { 100 143 if ( m->chance < 1.0f ) 101 144 if ( rng.frand() > m->chance ) 102 return; 145 { 146 if ( gen_flags & FF_GENERATE_CHANCE ) 147 parent_flags |= FMF_FAIL_CHANCE; 148 else 149 return; 150 } 103 151 transform tr = ptr * m->local; 104 if ( m->random_rotate_y ) 105 tr = tr * transform( math::angle_axis( nv::math::pi<float>() * 2.0f * rng.frand(), vec3( 0.0f, 1.0f, 0.0f ) ) ); 152 vec3 position = rng.eval( m->position ); 153 vec3 rotation = rng.eval( m->rotation ); 154 transform rtr = transform( position, nv::quat( rotation ) ); 155 tr = tr * rtr; 156 157 if ( m == selected ) parent_flags |= FMF_FOCUS; 106 158 107 159 if ( m->mesh || m->force ) … … 114 166 re.parent_id = parent_id; 115 167 re.attach_id = m->attach_id; 168 re.flags = parent_flags; 169 if ( map ) map->push_back( m ); 116 170 parent_id = sint16(id); 171 172 if ( m == selected ) 173 { 174 re.flags |= FMF_SELECTED; 175 if ( gen_flags & FF_GENERATE_GHOST && 176 ( m->position.max != m->position.min || 177 m->rotation.max != m->rotation.min ) ) 178 { 179 uint32 min_id = result.count++; 180 flat_model_element& min_re = result.elements[min_id]; 181 min_re.mesh = m->mesh; 182 min_re.material = m->material; 183 min_re.local = ( ptr * m->local ) * transform( m->position.min, nv::quat( m->rotation.min ) ); 184 min_re.parent_id = parent_id; 185 min_re.attach_id = m->attach_id; 186 min_re.flags = parent_flags | FMF_RANGE_GHOST; 187 188 uint32 max_id = result.count++; 189 flat_model_element& max_re = result.elements[max_id]; 190 max_re.mesh = m->mesh; 191 max_re.material = m->material; 192 max_re.local = ( ptr * m->local ) * transform( m->position.max, nv::quat( m->rotation.max ) ); 193 max_re.parent_id = parent_id; 194 max_re.attach_id = m->attach_id; 195 max_re.flags = parent_flags | FMF_RANGE_GHOST; 196 } 197 } 117 198 } 118 for ( auto c : m->children ) 199 200 if ( m->choice ) 119 201 { 120 flatten( result, c, rng, tr, parent_id ); 202 uint16 total_weight = 0; 203 for ( auto c : m->children ) 204 total_weight += c->weight; 205 if ( total_weight > 0 ) 206 { 207 sint32 roll = rng.srand( total_weight ); 208 model_node* pick = nullptr; 209 for ( auto c : m->children ) 210 { 211 roll -= c->weight; 212 if ( roll < 0 ) 213 { 214 pick = c; 215 break; 216 } 217 } 218 if ( gen_flags & FF_GENERATE_CHOICE ) 219 for ( auto c : m->children ) 220 { 221 uint32 flags = parent_flags; 222 if ( c != pick ) flags |= FMF_FAIL_CHOICE; 223 flatten( result, c, rng, tr, parent_id, map, gen_flags, flags, selected ); 224 } 225 else 226 flatten( result, pick, rng, tr, parent_id, map, gen_flags, parent_flags, selected ); 227 } 121 228 } 229 else 230 for ( auto c : m->children ) 231 { 232 flatten( result, c, rng, tr, parent_id, map, gen_flags, parent_flags, selected ); 233 } 122 234 } 123 235 -
trunk/nv/engine/resource_system.hh
r505 r509 114 114 protected: 115 115 116 virtual void remove( resource_id id ) 117 { 118 auto m = m_store.find( shash64( id ) ); 119 if ( m != m_store.end() ) 120 { 121 release( m->second ); 122 m_store.erase( shash64( id ) ); 123 } 124 } 125 126 virtual void rename( resource_id id, resource_id new_id ) 127 { 128 auto m = m_store.find( shash64( id ) ); 129 if ( m != m_store.end() ) 130 { 131 auto mdata = m->second; 132 m_store.erase( shash64( id ) ); 133 add( new_id, mdata ); 134 } 135 } 136 116 137 resource_type add( shash64 id, stored_type resource ) 117 138 { -
trunk/nv/gfx/debug_draw.hh
r469 r509 36 36 void push_line( const vec3& a, const vec3& b, const vec3& color ); 37 37 void push_aabox( const vec3& a, const vec3& b, const vec3& color ); 38 void push_gizmo( const nv::transform& tr, float length ); 38 39 ~debug_data(); 39 40 private: -
trunk/nv/lua/lua_state.hh
r505 r509 371 371 const_string get_string( string_view element, string_view defval = string_view() ); 372 372 string128 get_string128( string_view element, string_view defval = string_view() ); 373 373 string64 get_string64( string_view element, string_view defval = string_view() ); 374 374 375 char get_char( string_view element, char defval = ' ' ); 375 376 int get_integer( string_view element, int defval = 0 ); -
trunk/nv/stl/math/constants.hh
r453 r509 197 197 } 198 198 199 template < typename T >199 template < typename T, typename enable_if< is_arithmetic<T>::value >::type* = nullptr > 200 200 constexpr T radians( T degrees ) 201 201 { 202 static_assert( is_f loating_point<T>::value, "Type expected to be floating point!" );203 return degrees * static_cast<T>( 0.01745329251994329576923690768489 );204 } 205 206 template < typename T >202 static_assert( is_fp<T>::value, "Type expected to be floating point!" ); 203 return degrees * T( 0.01745329251994329576923690768489 ); 204 } 205 206 template < typename T, typename enable_if< is_arithmetic<T>::value >::type* = nullptr > 207 207 constexpr T degrees( T radians ) 208 208 { 209 static_assert( is_floating_point<T>::value, "Type expected to be floating point!" ); 210 return radians * static_cast<T>( 57.295779513082320876798154814105 ); 209 static_assert( is_fp<T>::value, "Type expected to be floating point!" ); 210 return radians * T( 57.295779513082320876798154814105 ); 211 } 212 213 template < typename T, typename enable_if< is_vec<T>::value >::type* = nullptr > 214 constexpr T radians( T degrees ) 215 { 216 static_assert( is_fp<T>::value, "Type expected to be floating point!" ); 217 return degrees * value_type_t<T>( 0.01745329251994329576923690768489 ); 218 } 219 220 template < typename T, typename enable_if< is_vec<T>::value >::type* = nullptr > 221 constexpr T degrees( T radians ) 222 { 223 static_assert( is_fp<T>::value, "Type expected to be floating point!" ); 224 return radians * value_type_t<T>( 57.295779513082320876798154814105 ); 211 225 } 212 226 -
trunk/nv/stl/math/quaternion.hh
r505 r509 320 320 inline T roll( const tquat<T>& q ) 321 321 { 322 return T( atan( T( 2 ) * ( q.x * q.y + q.w * q.z ), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z ) );322 return T( ::nv::atan2( T( 2 ) * ( q.x * q.y + q.w * q.z ), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z ) ); 323 323 } 324 324 … … 326 326 inline T pitch( const tquat<T>& q ) 327 327 { 328 return T( atan( T( 2 ) * ( q.y * q.z + q.w * q.x ), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z ) );328 return T( ::nv::atan2( T( 2 ) * ( q.y * q.z + q.w * q.x ), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z ) ); 329 329 } 330 330 … … 332 332 inline T yaw( const tquat<T>& q ) 333 333 { 334 return asin( T( -2 ) * ( q.x * q.z - q.w * q.y) );334 return ::nv::asin( T( T( -2 ) * ( q.x * q.z - q.w * q.y ) ) ); 335 335 } 336 336 -
trunk/src/core/random.cc
r504 r509 271 271 nv::random_base::seed_type nv::random_xor128::set_seed( seed_type seed /*= 0 */ ) 272 272 { 273 if ( seed == 0 ) seed = randomized_seed(); 273 274 uint32 s = uint32( 4294967296 - seed ); 274 275 m_state[0] = 123456789 * s; -
trunk/src/engine/animation.cc
r508 r509 34 34 35 35 nv::animator_data* animator = new nv::animator_data; 36 animator->id = table.get_string64( "id" ); 36 37 animator->poses = poses; 37 38 if ( poses == nullptr ) -
trunk/src/engine/default_resource_manager.cc
r508 r509 9 9 using namespace nv; 10 10 11 default_resource_manager::default_resource_manager( context* context )11 default_resource_manager::default_resource_manager( context* context, bool clear_material_paths ) 12 12 { 13 13 m_images = register_resource_handler< image_data >( new image_manager ); … … 15 15 m_binds = register_resource_handler< animator_bind_data >( new animator_bind_manager ); 16 16 m_animators = register_resource_handler< animator_data >( new animator_manager ); 17 m_materials = register_resource_handler< material >( new material_manager );17 m_materials = register_resource_handler< material >( new material_manager( clear_material_paths ) ); 18 18 m_programs = register_resource_handler< program >( new program_manager( context ) ); 19 19 m_gpu_meshes = register_resource_handler< gpu_mesh >( new gpu_mesh_manager( context, m_meshes ) ); … … 27 27 m_lua = lua; 28 28 29 m_lua->register_enum( "RND_LINEAR", static_cast<int>( random_dist::LINEAR ) ); 30 m_lua->register_enum( "RND_GAUSSIAN", static_cast<int>( random_dist::GAUSSIAN ) ); 31 m_lua->register_enum( "RND_RGAUSSIAN", static_cast<int>( random_dist::RGAUSSIAN ) ); 32 m_lua->register_enum( "RND_STEP_1", static_cast<int>( random_dist::STEP_1 ) ); 33 m_lua->register_enum( "RND_STEP_2", static_cast<int>( random_dist::STEP_2 ) ); 34 m_lua->register_enum( "RND_STEP_3", static_cast<int>( random_dist::STEP_3 ) ); 35 m_lua->register_enum( "RND_STEP_4", static_cast<int>( random_dist::STEP_4 ) ); 36 m_lua->register_enum( "RND_LINEAR", static_cast<int>( random_dist::LINEAR ) ); 37 m_lua->register_enum( "RND_MGAUSSIAN", static_cast<int>( random_dist::MGAUSSIAN ) ); 38 m_lua->register_enum( "RND_MRGAUSSIAN", static_cast<int>( random_dist::MRGAUSSIAN ) ); 39 m_lua->register_enum( "RND_MSTEP_1", static_cast<int>( random_dist::MSTEP_1 ) ); 40 m_lua->register_enum( "RND_MSTEP_2", static_cast<int>( random_dist::MSTEP_2 ) ); 41 m_lua->register_enum( "RND_MSTEP_3", static_cast<int>( random_dist::MSTEP_3 ) ); 42 m_lua->register_enum( "RND_MSTEP_4", static_cast<int>( random_dist::MSTEP_4 ) ); 43 29 44 m_lua->register_enum( "INT_NONE", static_cast<int>( interpolation::NONE ) ); 30 45 m_lua->register_enum( "INT_LINEAR", static_cast<int>( interpolation::LINEAR ) ); -
trunk/src/engine/material_manager.cc
r508 r509 63 63 if ( table.is_string( "path" ) ) 64 64 { 65 m->id = table.get_string128( "id" ); 65 66 string128 path = table.get_string128( "path" ); 66 67 for ( uint32 i = 0; i < 5; ++i ) … … 77 78 if ( i != TEX_EMISSIVE ) 78 79 NV_LOG_ERROR( "Texture file not found! : ", m->paths[i] ); 79 //m->paths[i].clear(); 80 if ( m_clear_paths ) 81 m->paths[i].clear(); 80 82 } 81 83 } -
trunk/src/engine/mesh_manager.cc
r508 r509 114 114 result->node_names[(*nd)[i].name] = i; 115 115 } 116 117 resource< mesh_data > rmesh = add( id, result ); 118 116 119 for ( uint32 i = 0; i < loader->get_mesh_count(); ++i ) 117 120 { … … 122 125 auto mesh = m_mesh_manager->add( shash64( id.get_hash() + i ), data ); 123 126 result->meshes.push_back( mesh ); 127 m_source_map[mesh.id()] = mesh_source{ rmesh, i }; 124 128 } 129 result->path.assign( id ); 125 130 delete loader; 126 if ( result )127 add( id, result );128 131 return result != nullptr; 129 132 } -
trunk/src/engine/model_manager.cc
r508 r509 13 13 bool nv::model_manager::load_resource( lua::table_guard& table, shash64 id ) 14 14 { 15 auto vec4_to_quat = [] ( const vec4& v ) { return quat( v.w, v.x, v.y, v.z ); }; 16 15 17 model* gm = new model; 16 18 gm->attach = table.get_string_hash_64( "attach" ); 17 gm->root = transform( table.get<vec3>( "position", vec3() ) ); 18 19 gm->root.set_position( table.get<vec3>( "root_position", vec3() ) ); 20 gm->root.set_orientation( vec4_to_quat( table.get<vec4>( "root_orientation", vec4(0.0f,0.0f,0.0f,1.0f) ) ) ); 21 19 22 resource< mesh_data > def_data; 20 23 if ( table.is_string( "path" ) ) … … 45 48 void nv::model_manager::read_model_node( lua::table_guard& table, model_node* node, resource< mesh_data > def_data ) 46 49 { 50 auto vec4_to_quat = [] ( const vec4& v ) { return quat( v.w, v.x, v.y, v.z ); }; 51 47 52 resource< data_channel_set > cmesh; 48 53 resource< material > cmaterial; … … 59 64 attach_id = info.parent_id; 60 65 } 66 67 if ( table.has_field( "local_position" ) ) 68 node->local.set_position( table.get<vec3>( "local_position", vec3() ) ); 69 if ( table.has_field( "local_orientation" ) ) 70 node->local.set_orientation( vec4_to_quat( table.get<vec4>( "local_orientation", vec4( 0.0f, 0.0f, 0.0f, 1.0f ) ) ) ); 71 72 if ( table.has_field( "position" ) ) 73 { 74 node->position.min = table.get<vec3>( "position", vec3() ); 75 node->position.max = node->position.min; 76 } 77 if ( table.has_field( "rotation" ) ) 78 { 79 node->rotation.min = table.get<vec3>( "rotation", vec3() ); 80 node->rotation.max = node->rotation.min; 81 } 82 if ( table.has_field( "position_min" ) ) node->position.min = table.get<vec3>( "position_min", vec3() ); 83 if ( table.has_field( "position_max" ) ) node->position.max = table.get<vec3>( "position_max", vec3() ); 84 if ( table.has_field( "position_dist" ) ) node->position.dist = random_dist( table.get_unsigned( "position_dist", 0 ) ); 85 if ( table.has_field( "rotation_min" ) ) node->rotation.min = table.get<vec3>( "rotation_min", vec3() ); 86 if ( table.has_field( "rotation_max" ) ) node->rotation.max = table.get<vec3>( "rotation_max", vec3() ); 87 if ( table.has_field( "rotation_dist" ) ) node->rotation.dist = random_dist( table.get_unsigned( "rotation_dist", 0 ) ); 61 88 62 89 if ( table.has_field( "attach" ) ) … … 76 103 } 77 104 78 node->force = table.get_boolean( "force", false );79 node->ch ance = table.get_float( "chance", 1.0f);80 node-> random_rotate_y = table.get_boolean( "random_rotate", false);81 82 node->mesh = cmesh;105 node->force = table.get_boolean( "force", false ); 106 node->choice = table.get_boolean( "choice", false ); 107 node->chance = table.get_float( "chance", 1.0f ); 108 node->weight = table.get_unsigned( "weight", 1 ); 109 node->mesh = cmesh; 83 110 node->attach_id = attach_id; 84 node->material = cmaterial;111 node->material = cmaterial; 85 112 86 113 for ( uint32 i = 1; i <= table.get_size(); ++i ) -
trunk/src/gfx/debug_draw.cc
r504 r509 86 86 } 87 87 88 void nv::debug_data::push_gizmo( const transform& tr, float length ) 89 { 90 vec3 s( 0.0f, 0.0f, 0.0f ); 91 vec3 r( length, 0.0f, 0.0f ); 92 vec3 g( 0.0f, length, 0.0f ); 93 vec3 b( 0.0f, 0.0f, length ); 94 s = s * tr; 95 r = r * tr; 96 g = g * tr; 97 b = b * tr; 98 push_line( s, r, vec3( 1.0f, 0.0f, 0.0f ) ); 99 push_line( s, g, vec3( 0.0f, 1.0f, 0.0f ) ); 100 push_line( s, b, vec3( 0.0f, 0.0f, 1.0f ) ); 101 } 102 88 103 nv::debug_data::~debug_data() 89 104 { -
trunk/src/lua/lua_state.cc
r505 r509 324 324 return result; 325 325 } 326 327 nv::string64 nv::lua::table_guard::get_string64( string_view element, string_view defval /*= string_view() */ ) 328 { 329 lua_getfield( m_state, -1, element.data() ); 330 size_t l = 0; 331 const char* str = nullptr; 332 if ( lua_type( m_state, -1 ) == LUA_TSTRING ) 333 { 334 str = lua_tolstring( m_state, -1, &l ); 335 } 336 else 337 { 338 l = defval.size(); 339 str = defval.data(); 340 } 341 string64 result( str, l ); 342 lua_pop( m_state, 1 ); 343 return result; 344 } 345 326 346 327 347 char lua::table_guard::get_char( string_view element, char defval /*= "" */ )
Note: See TracChangeset
for help on using the changeset viewer.