Changeset 288 for trunk/src/gfx


Ignore:
Timestamp:
07/23/14 17:37:44 (11 years ago)
Author:
epyon
Message:
  • unified animation_entry class
  • virtuals removed from animation_entry
  • lua_table - added missing get_float
  • lua_table - fixed has_field
Location:
trunk/src/gfx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gfx/keyframed_mesh.cc

    r287 r288  
    1919        , m_mesh_data( a_data )
    2020        , m_tag_map( a_tag_map )
    21         , m_start_frame( false )
    22         , m_stop_frame( false )
    2321        , m_last_frame( 0 )
    2422        , m_next_frame( 0 )
    25         , m_fps( 0 )
    2623        , m_interpolation( 0.0f )
    27         , m_looping( false )
    2824        , m_active( false )
    2925{
     
    5652}
    5753
    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 
    7054void nv::keyframed_mesh::set_frame( uint32 frame )
    7155{
     
    7660}
    7761
    78 void nv::keyframed_mesh::update_animation( animation_entry*, uint32 a_anim_time )
     62void nv::keyframed_mesh::update_animation( animation_entry* anim, uint32 a_anim_time )
    7963{
    8064        if ( m_active )
    8165        {
    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 )
    8769                {
    88                         if ( m_looping )
     70                        if ( anim->is_looping() )
    8971                        {
    90                                 time = time % static_cast< uint32 >( f_max );
     72                                tick_time = fmodf( tick_time, duration );
    9173                        }
    9274                        else
    9375                        {
    9476                                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;
    9781                        }
    9882                }
    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() );
    10284                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 );
    10587        }
    10688}
     
    121103        if ( a_anim )
    122104        {
    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;
    126109        }
    127110        else
  • trunk/src/gfx/skeletal_mesh.cc

    r287 r288  
    3333                skeletal_animation_entry * anim = (skeletal_animation_entry*)a_anim;
    3434                float frame_duration = 1000.f / (float)anim->get_frame_rate();
    35                 uint32 anim_duration = uint32( frame_duration * (float)anim->get_frame_count() );
    36                 uint32 new_time = a_anim_time % anim_duration;
    37                 anim->update_skeleton( m_transform.data(), (float)new_time * 0.001f );
     35                float anim_duration = frame_duration * anim->get_duration();
     36                float new_time = fmodf( (float)a_anim_time, anim_duration );
     37                anim->update_skeleton( m_transform.data(), new_time * 0.001f );
    3838
    3939                //m_mesh_data->apply( m_transform.data() );
     
    8787}
    8888
    89 
    90 nv::skeletal_animation_entry_gpu::skeletal_animation_entry_gpu( const std::string& name, const mesh_nodes_data* anim, bool a_looping )
    91         : animation_entry( name )
    92         , m_node_data( anim )
    93 {
    94         uint32 node_count = m_node_data->get_count();
    95 
     89void nv::skeletal_animation_entry_gpu::initialize()
     90{
    9691        m_prepared  = false;
    97         m_looping   = a_looping;
    9892        m_children  = nullptr;
    9993        m_offsets   = nullptr;
     94        uint32 node_count = m_node_data->get_count();
    10095        m_bone_ids  = new sint16[ node_count ];
    10196
Note: See TracChangeset for help on using the changeset viewer.