Friday, December 2, 2016

Realistic 2D Planetary Physics Engine?


I'm doing a spaceflight simulator in C++ (using Allegro 5), and I realised that I could just use a physics engine instead of writing my own physics.


So that's what I'm doing.


Since this is going to be a 2D only (for simplicity's sake) simulation, I've looked at 2D physics engines only. And since this will be running on low-end hardware, just not using the z-axis of a 3D engine won't work.


I've narrowed it down to the two big physics engines: Box2D and chipmunk. I'm trying out Box2D now, but the manual says that:




Box2D works with floating point numbers and tolerances have to be used to make Box2D perform well. These tolerances have been tuned to work well with meters-kilogram-second (MKS) units. In particular, Box2D has been tuned to work well with moving objects between 0.1 and 10 meters. So this means objects between soup cans and buses in size should work well. Static objects may be up to 50 meters big without too much trouble.



Obviously I'm going to be using Box2D for objects ranging from 100 m to 1.4e9 m (from a ship to the Sun). However, most of the time I'm going to be flying around in a ship (no collisions), or parked on the surface of a planet. Of course, there will also be accelerations of up to 275 m/s/s (at the surface of the Sun).


Is this order of magnitude going to work with Box2D? Has anyone worked with this kind of stuff in Box2D before? Should I just try another physics engine (suggestions welcome)?



Answer



Well, if you look at it, 1.4e9 is much greater than 50, so obviously it isn't going to work that well. As to whether you should use another physics engine, I'm apprehensive - I can't think of a physics engine that would work well with objects that large. The computations would lose all accuracy - floating point arithmetic only works with numbers that are relatively similar in magnitude - and you may have the issue of overflow.


My personal opinion is that there won't be a (publicly available) physics engine to handle planetary physics, and that it would be best to either make the ship much bigger (and then scale down), or to never come that close to planetary objects - in which case you could use abstract calculations for the planetary physics, and background geometry for the planets, until you come to park - in which case you could then play a cut-scene, or use a different level/world for the landing sequence; this would culminate in a final world for the actual planet. Of course, that many worlds get confusing - it's up to you to decide which way you should go, but I hope I've helped answer your question.


EDIT:


From what you've said, my advised next course of action would be to salvage what you can from your previous physics engine and start again - I still don't think that there's a physics engine out there which can handle planetary physics (but correct me if I'm wrong). In this case, you'd almost certainly benefit from rewriting it from scratch anyways - you'll end up learning a lot more about physics, and it'll likely perform better.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...