Planetary Gravity Physics

BlitzMax Forums/BlitzMax Programming/Planetary Gravity Physics

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

A couple of tips:

- I'd certainly make all of the major masses like Stars, Planets and Moons affect each other and everything else. Ships, Bullets and Missiles are negligible in comparison so they need to be affected by the major masses but not each other.

- There is no real performance problem doing n-body calculations in realtime for n up to 20, 30 or maybe 50. By 100 it is definitely bogging down an average PC. Much of the fun comes from the chaotic effects of masses on each other so I'd go with proper calculations rather than pre-determined elipses for orbits.

- You can combine the gravity calculations with collision detection since you need the distance in both cases. You need objects to have an appreciable radius and to do collision detection. Point masses can get too close to each other and exert enormous force. By the next calculation step they have overstepped each other so don't 'feel' a corresponding pull back to slow them down. Objects zoom out of your system from close encounters. This does actually happen in reality as asteroids, comets and even stars can be 'ejected' by close encounters. However if you don't mask the effect with a radius it is unrealistic.

- For n bodies, a simplistic approach is to calculate each body against each other body requiring n * (n-1) calculations. A better approach is to consider them in pairs (A, B). Once you have the distance of A from B, it is the same distance from B to A and there are common terms that can be found in the equations for the force of A on B and the force of B on A. This leads to only n * (n - 1) / 2 calculations which is better. Use somthing like:

For A = 1 to n
For B = A + 1 to n
CalcForce(A, B) ' Accumulate components of force in both A and B
Next B

CalcNetEffect(A) ' All forces applied to A. Can now calculate its acceleration and new position.
Next A

This is just pseudocode. You need to define what is in the objects and how to iterate through them.

For a real challenge:

BlitzMax is quite capable of doing realtime image scaling and rotation so you can get fancy by having spinning worlds and being able to zoom in and out. Use real images. Make the view track an object to see others whizzing past. Leave object trails. Draw vectors on objects showing their velocity and acceleration.

A very rich topic.