Using interpolated states with external timesteps

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
User avatar
arparso
Posts: 4
Joined: Mon Jan 09, 2012 10:14 am
Location: Germany
Contact:

Using interpolated states with external timesteps

Post by arparso »

I know I can use Space.Update(float dt) to let BEPU handle proper timesteps internally and can afterwards access interpolated state with the BufferedStates.InterpolatedStates properties. However, I'd like to handle timesteps myself outside BEPU (e.g. to collect input for each physics timestep) and will use Space.Update() to calculate each physics step individually.

Can I still use the interpolated states then? I've already seen the Space.BufferedStates.InterpolatedStates.BlendAmount property and guess I'll just need to set that manually (and enable BufferedStates and InterpolatedStates). E.g. if I simulate a new physics step for every 16ms (60fps) and I've got 8ms remaining in my frametime accumulator, I'll simply set BlendAmount to 0.5 and can safely use the interpolated states for rendering!?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Using interpolated states with external timesteps

Post by Norbo »

E.g. if I simulate a new physics step for every 16ms (60fps) and I've got 8ms remaining in my frametime accumulator, I'll simply set BlendAmount to 0.5 and can safely use the interpolated states for rendering!?
That should work. The space's interpolated states manager will need to be enabled, and its Update method has to be called in order for the states to actually change. That's basically all the Space.Update(dt) method does.

Another option would be to hook an event on one of the per timestep events (any of the space update stages Finished events would work) or make a custom Updateable so that your code runs on timesteps called by the built in accumulator. This isn't a strictly better way really, just another option.
User avatar
arparso
Posts: 4
Joined: Mon Jan 09, 2012 10:14 am
Location: Germany
Contact:

Re: Using interpolated states with external timesteps

Post by arparso »

Thanks, I probably would have missed the InterpolatedStates.Update() method. Seems to work great now :)
Post Reply