Roland Posted January 3, 2012 Share Posted January 3, 2012 Guys. How do you tackle the 'frame' parameter in void Animate( TEntity entity, flt frame, flt blend=1, int sequence=0, int recursive=1 ) I can get my animation done in what seems to be a correct speed by just setting that one to AppTime()/1000*fps, where fps desired animation speed in frames per second. But, to tell the truth I'm not sure what I'm doing there although it seems to work. fps set to 30 (same as my animation) gives something that looks ok. How do you control that you get the desired animation speed in frames per second? Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
Rick Posted January 3, 2012 Share Posted January 3, 2012 I increase my frames by my own timer logic. off the top of my head something like below if time > last_time + animation_speed then frame++ last_time = time end Quote Link to comment Share on other sites More sharing options...
Roland Posted January 3, 2012 Author Share Posted January 3, 2012 Rick. Thats simple and simple is good. Thanks Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
Clackdor Posted January 4, 2012 Share Posted January 4, 2012 That's very similar to what I do. And, yeah, it was based off of what Rick told me some time ago. Quote Link to comment Share on other sites More sharing options...
Rick Posted January 4, 2012 Share Posted January 4, 2012 And mine was based off of what someone told me some time ago Quote Link to comment Share on other sites More sharing options...
Roland Posted January 4, 2012 Author Share Posted January 4, 2012 Haha... Thats exactly what I'm going to say in a year if someone asks :-) Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
Roland Posted January 4, 2012 Author Share Posted January 4, 2012 By the way I found that you have to take AppSpeed into the calculation to get the same results on different computers. This what I did and it seem to solve that problem quite nicely. At an FPS of 60 AppSpeed will be 1.0, at higher FPS as mine 1.200 FPS its about 0.04. if( appTime > _lastTime ) { _lastTime = appTime; _frame += AppSpeed() ; if( _frame == _frames ) _frame = 0; } Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
Clackdor Posted January 4, 2012 Share Posted January 4, 2012 By the way I found that you have to take AppSpeed into the calculation to get the same results on different computers. This what I did and it seem to solve that problem quite nicely. At an FPS of 60 AppSpeed will be 1.0, at higher FPS as mine 1.200 FPS its about 0.04. if( appTime > _lastTime ) { _lastTime = appTime; _frame += AppSpeed() ; if( _frame == _frames ) _frame = 0; } I have AppSpeed() plus an additional animationspeed variable so I can tweek how the animations look in code, as well. Now, go blend animations. Whenever a new animation starts my code sets blend to 1.0 and counts it down over a period of 0.25 seconds. Looks very nice. if (blend >= 0.0f) { blend = blend - AppSpeed()*0.0667f; } else { blend = 0.0f; } //Perform the animations Animate(mesh,frame2,blend,0,true); Animate(mesh,frame1,1.0f-blend,0,true); Quote Link to comment Share on other sites More sharing options...
Roland Posted January 4, 2012 Author Share Posted January 4, 2012 Now things seems to work. Animation speed taking FPS into account and also can be tweak (as suggested above). Blending in and out works. Great tips guys. Thanks void Animation::Animate( Float appTime, const Animation::Blending& blending) switch( blending ) { // no blending case None: _blend = 1; break; // blend in case In: _blend += _fadeIn*AppSpeed(); _blend = std::min<Float>(_blend,1); break; // blend out case Out: _blend -= _fadeOut*AppSpeed(); _blend = std::max<Float>(_blend,0); break; } Update(appTime); } void Animation::Update( Float appTime ) { // time to update frame counter? if( appTime > _lastTime ) { _lastTime = appTime; // increment taking FPS rate into account _frame += AppSpeed() * _speed ; // correction for under- and overflows _frame = std::max<Float>(0,_frame); _frame = std::min<Float>(_frame,static_cast<Float>(_frames)); // restart? if( _frame == _frames ) _frame = 0; } // don't bother about animations with blend values of 0 if( _blend > 0 ) _model.Animate( _frame, _blend, _seq ); } Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.