physics & rendering loop

I’ve read through the thread with “the discreet rendering loop” but I still have some questions:

I am programming a physics engine with unlimited forces acting on unlimited numbers of objects in a environment. For each object I am calculating the result of the forces and applying it correctly. This is already working.

But I use for the physics a loop with an interval of 50 ms, which means that it will be calculated 20 times per second. Until now I have a passive rendering mode, which means that I do a repaint() in the physics loop.

What I don’t understand: Even if I would do a rendering loop, the position of the objects won’t change for 50 ms, so what is actually the reason of repainting when there isn’t something new to display ?

When an object reaches a suffisent fast velocity, it changes its position in 50ms for let’s say 20pixels…this means that I will get a sloppy movement animation even if I render at more than 50ms !!!

What am I doing wrong ?

A solution I could imagine would be to move the object in the rendering loop just enough so that it will be a smooth animation…but I don’t know exactly…

The entire code is quite big and I don’t want to annoy you here with bad code.

Hi
You have two options really, increase the speed of your physics loop so that it updates as fast as you are rendering, or, interpolate, interpolation is good over a network as it means reduced coms, but if your not worried about a network layer then just redner as fast as you can and call you update method on your physics loop every frame.
If you arn’t already doing it then you will need to modify your physics loop so that it works of a time since last move, rather than a fixed 50ms update, then it will be nice and smooth :slight_smile:

HTH

Endolf

[quote]Hi
You have two options really, increase the speed of your physics loop so that it updates as fast as you are rendering, or, interpolate,
[/quote]
At 20 fps, how effective are the different ways of interpolating physics?

E.g. You could

[] zero all forces between physics frames, and hold all velocities constant. The lower the acceleration on an object the nearer this would be to perfect, but without having to do anything but linear interpolation
[
] hold all resultant forces constant, and interpolate changes to velocities. This would presumably be less expensive than doing a full calculation?

But how are you managing collisions? Interpolating between physics frames is going to cause “bounces” if you only do the collision checks at physic frames (i.e. interpolates through a wall, then the physics kicks in and bounces it back again. At 20 fps the human eye will consciously see this very obviously. At 75 fps there will be a noticeable flicker, but most humans won’t know why. If you had physics at 100 fps, theoretically no-one would even see the bounces).

Hi
Thats why I didn’t really go into interpolation, it’s bad enough when you are just doing it on movement of objects like ships or people, but this would be even worse, but if there is a network in there then it’s probably the best choice. The best bet with no network is just to run the physics engine as fast as your rendering loop, the extra load from the physics will reduce the frame rate, but will look alot better than if you render faster than you are drawing.

HTH

Endolf

Thats what I currently do. However, if I was to stick a network into the equation I’d still run the physics as fast as the renderer. EDIT: Effectively I suppose its the same thing, its just the way you choose to interpolate.

However, the server would override the positions/velocities of things if they were out of sync. This only works if you use your second option above, storing the resultant forces and continuing calculating what you think the server will calculate between updates. I’ve used this in the past and it gives results you’d expect, if something happens between updates that your client simply couldn’t predict you get a jump.

Kev

I am still using a passive renderer but I now manage to run it at 10 ms interval. I know this may sound stupid but I ain’t that good in english and therefor … what exactly is this interpolating thing ?