Neat little Euler gravity simulation coded by me
Posted: 04.05.2004, 05:46
Hey guys,
I like this little physics offshoot forum. It's interesting.
A few days ago I decided to learn how to program with OpenGL just for fun, instead of studying for AP tests (i know, bad choice, but whatever).
So I decided to make a simple simulation that approximates more than 2 orbiting bodies by calculating the force of gravity between each body and summing them together at each timestep, to be applied as accelerations, which in turn change the velocities, and then the positions, blah blah blah.
After a few iterations, I got it working in 3d. Use the arrows to rotate the view, the central "star" has 3 lines representing each axis. Enter resets the simulation with a semi-random initial setup. I say semi, because I've programmed it to attempt to make each nth planet orbit around the (n-1)th planet. Oh, and one more thing. The central star IS influenced by the planets that orbit it, but each frame i center the camera on the central star, so it appears not to move. If it wasn't centered on the star, the entire system would eventually move out of the view and it would be no fun to watch.
Looking now, I see that this board doesn't have upload capability, so i'll post a link shortly on some webspace i have for something else. Its at geocities, so if it doesn't work, yell at me and i can put it somewhere else.
http://www.geocities.com/jamesbonduhs/g ... avity.html
I like this little physics offshoot forum. It's interesting.
A few days ago I decided to learn how to program with OpenGL just for fun, instead of studying for AP tests (i know, bad choice, but whatever).
So I decided to make a simple simulation that approximates more than 2 orbiting bodies by calculating the force of gravity between each body and summing them together at each timestep, to be applied as accelerations, which in turn change the velocities, and then the positions, blah blah blah.
After a few iterations, I got it working in 3d. Use the arrows to rotate the view, the central "star" has 3 lines representing each axis. Enter resets the simulation with a semi-random initial setup. I say semi, because I've programmed it to attempt to make each nth planet orbit around the (n-1)th planet. Oh, and one more thing. The central star IS influenced by the planets that orbit it, but each frame i center the camera on the central star, so it appears not to move. If it wasn't centered on the star, the entire system would eventually move out of the view and it would be no fun to watch.
Looking now, I see that this board doesn't have upload capability, so i'll post a link shortly on some webspace i have for something else. Its at geocities, so if it doesn't work, yell at me and i can put it somewhere else.
http://www.geocities.com/jamesbonduhs/g ... avity.html