Sign in to follow this  
Redee

Laggy sfml Moving object, how to fix it ?

Recommended Posts

Hi to all !
Month ago I start research smooth fixed constant moving.
I wrote this C++ code with Sfml after read this article >>
http://gafferongames.com/game-physics/fix-your-timestep/

Then was begun some tests.
And problem is !!!

Again I see a little bit laggy if You see some more time on movObject.
What my wrong ?
Maybe some improved interpolation needs ?
Please specify how to fix and achieve smooth moving using constant velocity.

Here sources (MSVS) >> https://www.dropbox.com/s/nkkegjudjtoosly/Moving%20object%20c%2B%2B.zip?dl=1
-
Here main code to easy fast read > http://pastebin.com/he8TMHgi

Thanks in advance!

Share this post


Link to post
Share on other sites

Not an expert on Gaffer's stuff, but the thing that sticks out to me, it looks like your then interpolating prevState and currState, but those will basically be nearly the same because of that assignment.

  accum += elTmeMicros;
  while(accum >= tmeStep)
  {
     prevState = currState;  // <-- What's this?
     currState.x += velX * tmeStep;
     currState.y += velY * tmeStep;
     accum -= tmeStep;
  }
Edited by ferrous

Share this post


Link to post
Share on other sites

Yes people - I fully understand interpolation.

My goal is to achieve smooth moving using constant velocity.

Using for this interpolation, extrapolation or some other simpler methods.

 

What you using for stable motion on different fps ?

Hope you can share your sources for understand.

Thank you !

Share this post


Link to post
Share on other sites
gaffer has this part like this:

const double alpha = accumulator / dt;
State state = currentState * alpha + previousState * ( 1.0 - alpha );

render( state );

it means that when rendering, you interpolate precisely between states on timesteps, not just render data from full timesteps.

Share this post


Link to post
Share on other sites

Nope Gaffer has prevState, currState and State (for interpolation). Here no deal !(

Please download my sources / binaries and look how moves object.

There no mistakes but I want more stable motion.

Share this post


Link to post
Share on other sites
actually i copied that from the article, so that is how he has it. and looking at your code that is how you have it too. it looks ok and it's a proper way of doing it. can you insert some prints in your code to show values of elTmeMicrosec and alpha per frame?

Share this post


Link to post
Share on other sites

Maybe you advice me your own method to moving objects and code also ???

Yo no understand basic things of C++ language ?? (use -- cout << variable << endl;)

For what we now talking then,  hmmmm.. ((

Its very difficult part of game development and no simple talking around this.

Otherwise need complete solution to fix motion.

 

My solution looks like sufficient but want more proper motion.

If you using somewhere Box2D you can see normal motion, but me need simple motion for simple constant velocity ONLY.

 

Thanks for responds!

Edited by Redee

Share this post


Link to post
Share on other sites
i also use the method from the last paragraph of gaffer's article. and i was not asking if you are able to program that, but asking you to actually do it to take a look at the timings. the reason i asked that is because the method should provide you with smooth movement - if it doesn't, there may be something off about the timings. also please don't get insulting, i am not trying to piss you off, i am trying to narrow down the area where the problem may come from. by just looking at a few dozen lines of per-frame-timings we may be able to spot what is causing the jitter you experience. besides the elapsedTime and alpha, also check if and how often the accum loop gets executed per frame.

Share this post


Link to post
Share on other sites

Sfml is famous framework - no wrong with drawing and display !!!

Gaffer method in my implementation also all good.

 

Ok no information for me.

I hoped for some new interpolation or other new method.

 

Thank you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this