[ODE] interpolating between physics frames to get the actual positions in the render time

John DeWeese deweese at ict.usc.edu
Wed Apr 16 21:33:01 2003


Oh, this reminds me... there's an article titled "Scheduling Game 
Events" by Michael Harvey and Carl S. Marshall in Game Programming Gems 
3 that shows how to make a realtime task scheduler, much like in an OS 
kernel. They provide some sample code in the book.

David Whittaker wrote:

>The standard way of solving this problem is to slow your render speed down
>to match up with the physics, something like this:
>
>unsigned long curTime, lastTime = 0;
>
>void mainloop()
>{
>  curTime = time();  //whatever ms resolution timer you have access to
>  if (lastTime + (stepsize*1000) - curTime > 0)
>    sleep(lastTime + stepsize - curTime);
>  lastTime = curTime;
>
>  //draw the world
>
>  //forces, joint motors, collision detection, etc.
>  dWorldStep(...);
>}
>
>Something like that should make your graphics match your physics
>perfectly, unless the physics take longer than the stepsize, then you have
>a whole other problem.  It might be simpler, depending on the architecture
>you are building your program in (i.e. MFC vs. Qt vs. drawstuff...) to use
>an event-based timer to invalidate your window, draw the last frame at the
>top of your draw function, and at the end, run the physics step.  Then
>make your stepsize as small as you can and still have a little bit of
>sleep time on most runs through the loop.  If you really insist on running
>the graphics faster than the the physics, you'll have to do the
>interpolation yourself.
>
>The only time that will come out of sync now is when your system is so
>large or complex that it takes longer than the timestep to run the
>worldStep.  So what can be done about that?  Well, there are a variety of
>speed hacks you can try.  Reducing the complexity of the system, either by
>turning multiple bodies and joints into a single body "fake" (who needs to
>physically simulate toes, for example, when the whole foot as a single
>body is good enough).  Disabling bodies that are at rest.   Trying my soon
>to be added to the CVS stepFast solver.  Using frictionless or infinite
>friction contacts where possible.  There's more in the manual.  And when
>all else fails, increase the stepsize.
>
>David
>
>  
>
>>Using the fixed time step physics results in slight time difference
>>between the actual
>>render time and physic time which can cause choppiness to the movements
>>of objects...the effect would be more noticeable with kind of large
>>timesteps tho.
>>
>>Instead of using just the last physics step position/orientation one
>>could interpolate
>>between the last two physics steps and get the position/orientation
>>exactly at the
>>rendering time..
>>
>>
>>Therefore my question is..
>>
>>Is there any way to do that with ODE?
>>
>>It's certainly possible to do that outside ODE but it's kinda
>>hassle..and what do you think about lerping between the frames in
>>general..
>>
>>
>>
>>cheers,
>>
>>
>>
>>juhnu
>>
>>
>>
>>
>>
>>ps. oh my first posting to this list ever.. have to buy a cake or
>>something
>>
>>
>>
>>
>>    
>>
>
>
>
>_______________________________________________
>ODE mailing list
>ODE@q12.org
>http://q12.org/mailman/listinfo/ode
>  
>