- Timestamp:
- 07/07/13 17:34:37 (12 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/formats/md3_loader.hh
r148 r149 38 38 virtual const md3_tag* get_tag( const std::string& name ) const; 39 39 virtual mat4 get_tag( sint32 frame, const std::string& name ) const; 40 sint32 get_max_frames() const; 41 void load_tags( std::vector<mat4>& t, const std::string& tag ); 40 42 void load_positions( std::vector<vec3>& p, sint32 frame =-1 ); 41 43 void load_normals( std::vector<vec3>& n, sint32 frame =-1 ); -
trunk/nv/time.hh
r121 r149 41 41 * Get microsecond count based on std::clock 42 42 */ 43 uint 32get_cpu_us();43 uint64 get_cpu_us(); 44 44 45 45 /** … … 51 51 * Get microsecond count based on system counter 52 52 */ 53 uint 32get_system_us();53 uint64 get_system_us(); 54 54 55 struct cpu_ms_timer { uint32 operator()() { return get_cpu_ms(); } }; 56 struct cpu_us_timer { uint32 operator()() { return get_cpu_us(); } }; 57 struct system_ms_timer { uint32 operator()() { return get_system_ms(); } }; 58 struct system_us_timer { uint32 operator()() { return get_system_us(); } }; 55 struct cpu_ms_timer 56 { 57 typedef uint32 value_type; 58 static const value_type second = 1000; 59 value_type operator()() { return get_cpu_ms(); } 60 }; 61 62 struct cpu_us_timer 63 { 64 typedef uint64 value_type; 65 static const value_type second = 1000000; 66 uint64 operator()() { return get_cpu_us(); } 67 }; 68 69 struct system_ms_timer 70 { 71 typedef uint32 value_type; 72 static const value_type second = 1000; 73 value_type operator()() { return get_system_ms(); } 74 }; 75 76 struct system_us_timer 77 { 78 typedef uint64 value_type; 79 static const value_type second = 1000000; 80 value_type operator()() { return get_system_us(); } 81 }; 59 82 60 83 /** … … 65 88 { 66 89 public: 90 typedef typename Timer::value_type value_type; 91 67 92 timer_class() : last( Timer()() ) {} 68 93 void mark() 69 94 { 70 uint32now = Timer()();95 value_type now = Timer()(); 71 96 stored = now - last; 72 97 last = now; 73 98 } 74 uint32elapsed() const99 value_type elapsed() const 75 100 { 76 101 return stored; 77 102 } 78 103 private: 79 uint32last;80 uint32stored;104 value_type last; 105 value_type stored; 81 106 }; 82 107 … … 88 113 { 89 114 public: 115 typedef typename Timer::value_type value_type; 116 90 117 fps_counter_class() : frames(1), last(0) {} 91 118 bool tick() 92 119 { 93 uint32now = Timer()();94 if ( now - last >= 1000)120 value_type now = Timer()(); 121 if ( now - last >= Timer::second ) 95 122 { 96 123 value = (static_cast<float>(frames) / 97 static_cast<float>(now - last))* 1000;124 static_cast<float>(now - last))*Timer::second; 98 125 frames = 1; 99 126 last = now; … … 108 135 } 109 136 private: 110 uint32last;111 uint32 frames;112 f32 value;137 value_type last; 138 uint32 frames; 139 f32 value; 113 140 }; 114 141 -
trunk/src/formats/md3_loader.cc
r148 r149 100 100 sint16 y; 101 101 sint16 z; 102 sint16 normal;102 uint16 normal; 103 103 }; 104 104 … … 118 118 md3_tag_t* tags; 119 119 md3_surface_t* surfaces; 120 // extra information (not in md3 file) 121 sint32 vertices_per_frame; 120 122 }; 121 123 … … 208 210 209 211 source.seek( md3->header.ofs_surfaces, origin::SET ); 212 md3->vertices_per_frame = 0; 210 213 211 214 for ( sint32 i = 0; i < md3->header.num_surfaces; ++i ) … … 213 216 if ( !read_surface( md3->surfaces + i, source ) ) return false; 214 217 if ( md3->header.num_frames != md3->surfaces[i].header.num_frames ) return false; 218 md3->vertices_per_frame += md3->surfaces[i].header.num_verts; 215 219 } 216 220 return true; … … 228 232 } 229 233 230 static inline vec3 md3_vec3( const md3_vertex_t& v ) 231 { 232 // return vec3( v.x * MD3_XYZ_SCALE, v.y * MD3_XYZ_SCALE, v.z * MD3_XYZ_SCALE ); 233 return vec3( v.x * MD3_XYZ_SCALE, v.z * MD3_XYZ_SCALE, v.y * MD3_XYZ_SCALE ); 234 } 235 236 static inline vec3 md3_normal( const md3_vertex_t& v ) 237 { 238 float pi = glm::pi<float>(); 239 float lat = (((v.normal >> 8) & 255) * (2 * pi)) / 255.0f; 240 float lng = ((v.normal & 255) * (2 * pi)) / 255.0f; 241 return vec3( 242 glm::cos( lat ) * glm::sin( lng ), 243 // glm::sin( lat ) * glm::sin( lng ), 244 // glm::cos( lng ) 245 glm::cos( lng ), 246 glm::sin( lat ) * glm::sin( lng ) 247 ); 248 } 249 234 static vec3 s_normal_cache[256*256]; 235 static bool s_normal_ready = false; 250 236 251 237 md3_loader::md3_loader() 252 238 : m_md3( nullptr ), m_size( 0 ) 253 239 { 254 240 if ( !s_normal_ready ) 241 { 242 float pi = glm::pi<float>(); 243 float convert = (2 * pi) / 255.0f; 244 int n = 0; 245 for ( int lat = 0; lat < 256; ++lat ) 246 { 247 float flat = lat * convert; 248 float sin_lat = glm::sin( flat ); 249 float cos_lat = glm::cos( flat ); 250 for ( int lng = 0; lng < 256; ++lng, ++n ) 251 { 252 float flng = lng * convert; 253 float sin_lng = glm::sin( flng ); 254 float cos_lng = glm::cos( flng ); 255 s_normal_cache[n].x = cos_lat * sin_lng; 256 // s_normal_cache[n].y = sin_lat * sin_lng; 257 // s_normal_cache[n].z = cos_lng; 258 s_normal_cache[n].z = sin_lat * sin_lng; 259 s_normal_cache[n].y = cos_lng; 260 } 261 } 262 263 s_normal_ready = true; 264 } 255 265 } 256 266 … … 318 328 } 319 329 330 void nv::md3_loader::load_tags( std::vector<mat4>& t, const std::string& tag ) 331 { 332 md3_t* md3 = (md3_t*)m_md3; 333 t.clear(); 334 for ( sint32 f = 0; f < md3->header.num_frames; ++f ) 335 { 336 for ( sint32 i = 0; i < md3->header.num_tags; ++i ) 337 { 338 const md3_tag_t& rtag = md3->tags[i + md3->header.num_tags * f]; 339 std::string rname((char*)(rtag.name)); 340 if (rname == tag) 341 { 342 vec4 axisx = vec4( md3_vec3( rtag.axis[0] ), 0.0 ); 343 vec4 axisz = vec4( md3_vec3( rtag.axis[1] ), 0.0 ); 344 vec4 axisy = vec4( md3_vec3( rtag.axis[2] ), 0.0 ); 345 vec4 origin = vec4( md3_vec3( rtag.origin ), 1.0 ); 346 t.emplace_back( axisx, axisy, axisz, origin ); 347 } 348 } 349 350 } 351 } 352 353 sint32 nv::md3_loader::get_max_frames() const 354 { 355 return ((md3_t*)m_md3)->header.num_frames; 356 } 357 320 358 mat4 md3_loader::get_tag( sint32 frame, const std::string& name ) const 321 359 { … … 352 390 sint32 frame_count = ( frame == -1 ? md3->header.num_frames : 1 ); 353 391 392 p.reserve( md3->vertices_per_frame * frame_count ); 393 354 394 while ( frame_count > 0 ) 355 395 { … … 359 399 sint32 vcount = surface.header.num_verts; 360 400 sint32 offset = vcount * current_frame; 361 p.reserve( p.size() + vcount );362 for (sint32 j = 0; j < vcount; ++j )401 sint32 limit = vcount + offset; 402 for (sint32 j = offset; j < limit; ++j ) 363 403 { 364 p.push_back( md3_vec3( surface.vertices[j + offset] ) ); 404 md3_vertex_t& v = surface.vertices[j]; 405 p.push_back( vec3( v.x * MD3_XYZ_SCALE, v.z * MD3_XYZ_SCALE, v.y * MD3_XYZ_SCALE ) ); 365 406 } 366 407 } … … 378 419 sint32 frame_count = ( frame == -1 ? md3->header.num_frames : 1 ); 379 420 421 n.reserve( md3->vertices_per_frame * frame_count ); 422 380 423 while ( frame_count > 0 ) 381 424 { … … 385 428 sint32 vcount = surface.header.num_verts; 386 429 sint32 offset = vcount * current_frame; 387 n.reserve( n.size() + vcount );388 for (sint32 j = 0; j < vcount; ++j )430 sint32 limit = vcount + offset; 431 for (sint32 j = offset; j < limit; ++j ) 389 432 { 390 n.push_back( md3_normal( surface.vertices[j + offset] ));433 n.push_back( s_normal_cache[ surface.vertices[j].normal ] ); 391 434 } 392 435 } -
trunk/src/time.cc
r121 r149 67 67 } 68 68 69 nv::uint 32nv::get_cpu_us()69 nv::uint64 nv::get_cpu_us() 70 70 { 71 return (uint 32)( (f32)( clock() - zero_timer.clock_zero ) / ( (f32)CLOCKS_PER_SEC / 1000000.0 ) ) ;71 return (uint64)( (f32)( clock() - zero_timer.clock_zero ) / ( (f32)CLOCKS_PER_SEC / 1000000.0 ) ) ; 72 72 } 73 73 … … 78 78 QueryPerformanceCounter(&now); 79 79 LONGLONG result = now.QuadPart - zero_timer.query_zero.QuadPart; 80 return (uint32) (1000.0 * result / zero_timer.frequency.QuadPart);80 return (uint32) (1000.0 * result / (double) zero_timer.frequency.QuadPart); 81 81 #else 82 82 struct timeval now; … … 86 86 } 87 87 88 nv::uint 32nv::get_system_us()88 nv::uint64 nv::get_system_us() 89 89 { 90 90 #if NV_COMPILER == NV_MSVC … … 92 92 QueryPerformanceCounter(&now); 93 93 LONGLONG result = now.QuadPart - zero_timer.query_zero.QuadPart; 94 return (uint 32) (1000000.0 * result /zero_timer.frequency.QuadPart);94 return (uint64) (1000000.0 * result / (double) zero_timer.frequency.QuadPart); 95 95 #else 96 96 struct timeval now;
Note: See TracChangeset
for help on using the changeset viewer.