- _last_time_sec = sim_time_sec - _duration_sec;
-
- vector<SGPropertyNode_ptr> nodes = props->getChildren( "branch-duration-sec" );
- size_t nb = nodes.size();
- for ( size_t i = 0; i < nb; i++ ) {
- size_t ind = nodes[ i ]->getIndex();
- while ( ind >= _branch_duration_specs.size() ) {
- _branch_duration_specs.push_back( DurationSpec( _duration_sec ) );
- }
- SGPropertyNode_ptr rNode = nodes[ i ]->getChild("random");
- if ( rNode == 0 ) {
- _branch_duration_specs[ ind ] = DurationSpec( nodes[ i ]->getDoubleValue() );
- } else {
- _branch_duration_specs[ ind ] = DurationSpec( rNode->getDoubleValue( "min", 0.0 ),
- rNode->getDoubleValue( "max", 1.0 ) );
- }
- }
- if ( !_use_personality ) {
- for ( size_t i = 0; i < _branch_duration_specs.size(); i++ ) {
- DurationSpec &sp = _branch_duration_specs[ i ];
- double v = sp._min + sg_random() * ( sp._max - sp._min );
- _branch_duration_sec.push_back( v );
- _total_duration_sec += v;
- }
- }
- ((ssgSelector *)getBranch())->selectStep(_step);
-}
-
-SGTimedAnimation::~SGTimedAnimation ()
-{
-}
-
-int
-SGTimedAnimation::update()
-{
- if ( _use_personality ) {
- SGPersonalityBranch *key = current_object;
- if ( !key->getIntValue( this, INIT ) ) {
- double total = 0;
- for ( size_t i = 0; i < _branch_duration_specs.size(); i++ ) {
- DurationSpec &sp = _branch_duration_specs[ i ];
- double v = sp._min + sg_random() * ( sp._max - sp._min );
- key->setDoubleValue( v, this, BRANCH_DURATION_SEC, i );
- total += v;
- }
- key->setDoubleValue( sim_time_sec, this, LAST_TIME_SEC );
- key->setDoubleValue( total, this, TOTAL_DURATION_SEC );
- key->setIntValue( 0, this, STEP );
- key->setIntValue( 1, this, INIT );
- }
-
- _step = key->getIntValue( this, STEP );
- _last_time_sec = key->getDoubleValue( this, LAST_TIME_SEC );
- _total_duration_sec = key->getDoubleValue( this, TOTAL_DURATION_SEC );
- while ( ( sim_time_sec - _last_time_sec ) >= _total_duration_sec ) {
- _last_time_sec += _total_duration_sec;
- }
- double duration = _duration_sec;
- if ( _step < (int)_branch_duration_specs.size() ) {
- duration = key->getDoubleValue( this, BRANCH_DURATION_SEC, _step );
- }
- if ( ( sim_time_sec - _last_time_sec ) >= duration ) {
- _last_time_sec += duration;
- _step += 1;
- if ( _step >= getBranch()->getNumKids() )
- _step = 0;
- }
- ((ssgSelector *)getBranch())->selectStep( _step );
- key->setDoubleValue( _last_time_sec, this, LAST_TIME_SEC );
- key->setIntValue( _step, this, STEP );
- } else {
- while ( ( sim_time_sec - _last_time_sec ) >= _total_duration_sec ) {
- _last_time_sec += _total_duration_sec;
- }
- double duration = _duration_sec;
- if ( _step < (int)_branch_duration_sec.size() ) {
- duration = _branch_duration_sec[ _step ];
- }
- if ( ( sim_time_sec - _last_time_sec ) >= duration ) {
- _last_time_sec += duration;
- _step += 1;
- if ( _step >= getBranch()->getNumKids() )
- _step = 0;
- ((ssgSelector *)getBranch())->selectStep( _step );
- }