Forgive me if I am wrong, but shouldn't a true physics engine not behave exactly the same way every time? I refreshed 5 times and every time the word Hey ended up vertical against the word GitHub. I would expect the interactions between colliding objects to vary every reload.
I tried 4 times, but on my machine (Firefox on Linux) I get the exact same result every time, up to the last pixel.
In theory you would expect a physics engine to always behave exactly the same every time (as long as there are no random forces in the simulation, obviously). In practice, I can think of some ways that would influence the result. For example, x86 can use extended (80-bit) precision for intermediate floating point calculations internally, but will always store them as 64 bit in registers or memory. Depending on the timing of thread context switches, you can imagine subtle roundoff errors caused by going from extended precision to double precision. When using SSE math you get similar effects but even more pronounced, because SSE is not always fully IEEE compliant.
Usually the introduced error is infinitely small and most algorithms are robust enough to cancel it out. Stuff like non-linear regression or a physics simulation are notable exceptions, because the calculations they do are iterative and progressive, meaning any introduced error can propagate and get amplified along the way. I've seen deterministic non-linear fit algorithms go in completely different directions for unstable problems on different machines, just because of CPU differences (64-bit vs 32-bit, x86 vs. sparc, etc).
>> Always fun to know about non-determinism at the hardware level.
Strictly speaking, the non-determinism isn't actually in the hardware, because the OS schedules thread context switches ;-)
Assuming the CPU is running a completely single-threaded program or uses a deterministic way to schedule thread context switches, the result should always be perfectly identical.
Why would you have that as a requirement? Output shouldn't vary unless input does. Real world physics only vary because input conditions are never the same.
It's my impression that it's always easier to add randomness to such an engine. So if you have a deterministic engine you can always sprinkle on some randomness afterwards if you want it more interesting.
But I'm not very experienced in physics engines so I might be on thin ground.
>Real world physics only vary because input conditions are never the same.
Not exactly. Classical physics is a deterministic approximation of quantum physics at macro scales. In reality, outcomes vary even if the initial conditions are the same (although you may need special equipment to observe that there is any difference. You can choose to call all of the quantum events "inputs" but that's dodging the point.
That said, most applications would not benefit from simulating at a quantum level, and doing so at large scales is currently intractable. So while real world physics is not deterministic, macro scale physics engines should be.
nope, a true physics engine behaves the same time, always - if there are no outside forces. if you kick stuff around (use your mouse of fingers on touch devices) == outside force -> different outcome
this 2d world has no intrinsic random/chaotic forces (i.e. no wind) so everything behaves the same, always, forever. if you want your world to be more random you could write something like this (during the world initiation phase a.k.a. the first box2d-jquery call)
However, different binaries may generally yield slightly different results due to compilers ordering floating-point operations differently, for example.