Physics Engine Timing Suggestions?
#1 Members - Reputation: 139
Posted 03 October 2012 - 05:39 PM
Related Posts :
http://gafferongames.com/game-physics/fix-your-timestep/
http://blog.allanbishop.com/box-2d-2-1a-tutorial-part-10-fixed-time-step/
Now, my system essentially works this way as of current. This is a pretty simplified explanation, but I have a list of Physical Objects, and a Queue of Pairs(or tuples) that have an objectID and a Vector (The mathematical vector). Each Pair represents a force. Then I have my collision handling code. (As I said, horribly oversimplified)
How have you guys solved this problem? Could you offer any clarification on what is explained in these posts?
#2 Crossbones+ - Reputation: 5185
Posted 03 October 2012 - 06:55 PM
My article on the subject might clarify some things: http://lspiroengine.com/?p=378
You basically have to divide your loop into 2 halves. One does logic and one does rendering. Although they are handled inside the same function, they operate at different intervals. My post explains how it works.
L. Spiro
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
#3 Members - Reputation: 139
Posted 04 October 2012 - 12:38 PM
#4 Members - Reputation: 346
Posted 04 October 2012 - 01:34 PM
28 36 33 34 29 38 ... but average will be = 33.333 ms and usualy there is no need to pass parameter to update function Update( 33333ULL ) if its your own engine;
To render smoothly you need calc interpolation variable alpha=0.0..1.0 to know how far you are to next update.
So engine gives alpha, renderer draws according to this alpha.
Edited by serumas, 04 October 2012 - 01:44 PM.
#7 Crossbones+ - Reputation: 5185
Posted 04 October 2012 - 02:32 PM
It is not possible to fix something to an exact interval.I don't understand how that could work though. I thought the point of this was to make sure that physics ticks at an exact interval.
You are misunderstanding that the updates have to be spaced at every 33.33 actual real-life milliseconds.
In fact, inside the simulation, if you made 2 updates of 33.33 milliseconds each, but in 1 case they are done immediately back-to-back, 0.00001 milliseconds apart, and in another case they are done closer to real-world time at exactly 33.33 milliseconds apart, the simulation result is the same.
In either case, you just told the simulation to update 2 times, at 33.33 milliseconds each. How much actual time was between those updates does not matter to the simulation.
With that understood, that means you now understand that you can update any number of times within a single game loop. Meaning if the simulation falls behind real-world time you can catch it up by updating multiple times instead of just updating once by a longer amount of time.
Likewise, if too little time has passed since the last update (as in, fewer than 33.33 milliseconds) then you can update 0 times. Just move on.
The concept should become simple. Updates are always done at a fixed amount of time, and then in order to keep the simulation as close to real-time as possible, each frame you check to see how many times you should perform an update. If you are running at 60 FPS, the every second frame will update 0 times, and every other frame will update 1 time.
If you suddenly drop to 10 FPS, every frame you will update 3 times. This catches the simulation up to the current real-world time without allowing it to go beyond the current real-world time.
The renderer. Physics won’t updated at an interval fast enough to provide interpolations meant for the renderer. Since they are only meant for the renderer, they should be updated by the renderer.Also, when it comes time to render, who does the interpolation, the renderer, or the physics engine? I ask because my system is multi-threaded.
L. Spiro
Edited by L. Spiro, 04 October 2012 - 02:36 PM.
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
#8 Members - Reputation: 139
Posted 04 October 2012 - 02:54 PM
#9 Crossbones+ - Reputation: 5185
Posted 04 October 2012 - 03:01 PM
Also, if you are running these on different threads just for the sake of keeping them on different threads, you should put them back on the same thread. You will encounter both synchronization issues and performance issues otherwise.
This isn’t how multi-threaded rendering is supposed to work; this is a different type of decoupling.
L. Spiro
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
#10 Members - Reputation: 139
Posted 04 October 2012 - 09:07 PM
#11 Members - Reputation: 139
Posted 06 October 2012 - 02:54 PM
Thanks again for all the effort you guys have put into helping me.
#12 Crossbones+ - Reputation: 5185
Posted 06 October 2012 - 04:31 PM
The physics engine has nothing to do with rendering and should not prepare any information for the renderer. Any information passed between physics and rendering is intermediate. In other words the fact that there is a current and previous transform for interpolation is only because a layer was injected into the system specifically to bind physics and rendering together. Otherwise they would and should be entirely completely unrelated systems.
The physics system prepares only date related to physics, which in this case means the current transform of each object.
An intermediate layer stores the current transform into to the “lastTransform” for an object on each physical update.
And finally the renderer is run each frame using the above transforms with a time value to interpolate between them. The time value and the interpolation process are repeated for each frame. No information from the physics is prepared except for what the physics itself does: The current transform.
L. Spiro
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
#13 GDNet+ - Reputation: 1751
Posted 08 October 2012 - 12:56 AM
I'm afraid not.I have one last simple question, and I believe I know the answer. I assume the safest way to handle passing the data from Physics to Rendering would be all at once in a structure. For example, have a PhysicsFrame class that holds the ObjectID, its transformation, and the Matrix of every changed object in the physics frame. Then pass that to the Renderer, and have it apply the percentage of interpolation between the new matrix and the old matrix per object. Does that make sense?
First, objectID or ids in general are typically unnecessary. We have far better tools which are pointers. Personally, I'm against most uses of IDs.
For Bullet, object transform is just poured out to the external code by using a proper interface. That is, if it's good enough for Bullet, I guess it will be good enough for you as well.
Edited by Krohm, 08 October 2012 - 12:57 AM.






