Quote:Original post by h4tt3n
Oh, and by the way... how did you do this? I never got it working properly.
It might be a side effect of how I update my universe, but when I run through the list of all bodies to calculate the gravitational pull of one on another, I keep track of the body that has applied the greatest gravitational forces to each body in that body's "myParent" member variable. From my very basic understanding of the sphere of influence, the body that applies the largest gravitational forces at any time on a body will also be the one that that body orbits around. Then I just grab the orbital elements between each body and its now-predetermined parent each frame and draw an ellipse. Of course you gotta remember to clear each body's parent info at the end of each draw, so that you can recalculate any new parent it might have at the next timestep.
I don't know if this will work in every SINGLE case ever, but I myself can't find a hole in the logic, and in practice it appears to work just fine. Stars can and do swap orbital parents all the time depending on how complex the solar system is, and the ellipses automatically switch with them. It's a great way to see how larger stars can potentially "steal" the moon of a planet and make it just another orbiting body of the star itself!
I had some similar thoughts to you about the whole center-of-mass thing for calculating orbits, I'm stuck trying to work out the quickest method to calculate the center of mass for each "system" in the universe. Probably some sort of tree-structure that relates parents to their satellites each frame so that I can only calculate specific centers of mass based on the leaves of each branch, or something along those lines...