Jump to content

[SOLVED] Animation speed at a specified fps rate?


Roland
 Share

Recommended Posts

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?

Roland Strålberg
Website: https://rstralberg.com

Link to comment
Share on other sites

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;
}

Roland Strålberg
Website: https://rstralberg.com

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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 );

}

Roland Strålberg
Website: https://rstralberg.com

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...