Changeset 288 for trunk/src/gfx/keyframed_mesh.cc
- Timestamp:
- 07/23/14 17:37:44 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gfx/keyframed_mesh.cc
r287 r288 19 19 , m_mesh_data( a_data ) 20 20 , m_tag_map( a_tag_map ) 21 , m_start_frame( false )22 , m_stop_frame( false )23 21 , m_last_frame( 0 ) 24 22 , m_next_frame( 0 ) 25 , m_fps( 0 )26 23 , m_interpolation( 0.0f ) 27 , m_looping( false )28 24 , m_active( false ) 29 25 { … … 56 52 } 57 53 58 void keyframed_mesh::setup_animation( uint32 start, uint32 count, uint32 fps, bool loop )59 {60 m_start_frame = start;61 m_stop_frame = start+count-1;62 m_looping = loop;63 m_fps = fps;64 m_active = count > 1;65 m_last_frame = start;66 m_next_frame = (count > 1 ? start + 1 : start );67 m_interpolation = 0.0f;68 }69 70 54 void nv::keyframed_mesh::set_frame( uint32 frame ) 71 55 { … … 76 60 } 77 61 78 void nv::keyframed_mesh::update_animation( animation_entry* , uint32 a_anim_time )62 void nv::keyframed_mesh::update_animation( animation_entry* anim, uint32 a_anim_time ) 79 63 { 80 64 if ( m_active ) 81 65 { 82 uint32 f_diff = (m_stop_frame - m_start_frame); 83 float f_time = 1000 / (float)m_fps; 84 float f_max = ( m_looping ? ( f_diff + 1 ) : f_diff ) * f_time; 85 uint32 time = a_anim_time; 86 if ( time >= f_max ) 66 float tick_time = ( (float)a_anim_time * 0.001f ) * anim->get_frame_rate(); 67 float duration = anim->is_looping() ? anim->get_duration() + 1.0f : anim->get_duration(); 68 if ( tick_time >= duration ) 87 69 { 88 if ( m_looping)70 if ( anim->is_looping() ) 89 71 { 90 ti me = time % static_cast< uint32 >( f_max);72 tick_time = fmodf( tick_time, duration ); 91 73 } 92 74 else 93 75 { 94 76 m_active = false; 95 m_last_frame = m_stop_frame; 96 m_next_frame = m_stop_frame; 77 m_last_frame = (uint32)anim->get_end(); 78 m_next_frame = m_last_frame; 79 m_interpolation = 0.0f; 80 return; 97 81 } 98 82 } 99 float f_pos = time / f_time; 100 101 m_last_frame = (uint32)glm::floor( f_pos ) + m_start_frame; 83 m_last_frame = (uint32)( glm::floor( tick_time ) + anim->get_start() ); 102 84 m_next_frame = m_last_frame + 1; 103 if ( m_next_frame > m_stop_frame ) m_next_frame = m_start_frame;104 m_interpolation = f_pos - glm::floor( f_pos);85 if ( m_next_frame > (uint32)anim->get_end() ) m_next_frame = (uint32)anim->get_start(); 86 m_interpolation = tick_time - glm::floor( tick_time ); 105 87 } 106 88 } … … 121 103 if ( a_anim ) 122 104 { 123 keyframed_animation_entry * anim = down_cast<keyframed_animation_entry>(a_anim); 124 m_active = true; 125 setup_animation( anim->m_start, anim->m_frames, anim->m_fps, anim->m_looping ); 105 m_active = true; 106 m_last_frame = 0; 107 m_next_frame = 0; 108 m_interpolation = 0.0f; 126 109 } 127 110 else
Note: See TracChangeset
for help on using the changeset viewer.