
Binary without source: Click
Source files: Click
I ever wanted to control a swarm of flies in a game. :p
and from my readme:The math needed to calculate accurately the motion of objects within a gravity field (in one, two or even three dimensions) is actually quite simple. We'll be using an iterative method to solve what's called the "two body" problem. We simplify the problem even further to assume the smaller particle has no effect on the black hole.
For each moment in time, we update each particle's position based on its current velocity vector. Next, we calculate the square of the distance between our particle and the black hole. We use this as the (possibly scaled) denominator of a gravity constant to find the force of gravity being felt by the particle, thus implementing the inverse-square-law of gravity (and most other forces). The particle's current velocity vector is then updated to include the force of gravity (the vectors are added together). Lastly, we trim a small amount of velocity away from each particle, in order to simulate a slow decay of the orbits.
This simple algorithm produces true orbital dynamics which subscribe to Kepler and Newton's laws, providing the particles don't approach the singularity too closely. As seen in the image above, the orbits are ellipses, as first realized by Johannes Kepler in the early 1600s after studying the orbits of the planets. Newton later came up with his law of universal gravitation, and showed that orbits can also be parabolic or hyperbolic. Both of the latter orbit forms are "open" (the particle escapes), and can appear in our simulation.
EDIT3:Our Solarsystem is a vast place.
This model has proportional planets and orbits, but their distance to the sun is scaled by 1/100000. In reality those planets would be 100000x farther away...from here you wouldn't be able to see them, not even a pixel. Also the sun's radius is divided by 50. The planets masses, thus gravitational attractions are altered. Except for that, it's as real as it gets. The planets position is calculated by painfully hard maths (I really dont get it), and supposedly accurate for many centuries ahead, The gravitation simulation is somewhat simplified. The maths is painfully easy, even for me, but it obeys newtons laws.The distance you can read down-right is real, so is the speed.
W-A-S-D controls your craft...
W moves your ship straight up, S moves down,
A moves your ship left, D moves right,
think of them as thrusters in 2 axis, up-down, left-right.
It is important to understand that we're moving in zero G. That is nearly zero gravity, because right now...we are chaotically orbiting earth. The blue circle you can sometimes see is your flightmarker, if you look at it and press the left mouse button you will see we're accelerating !!! If you press the right-button your reverse thruster ignites, so it's a truely 3-dimensional movement, still unlike any aircraft you might have ever flown. It can get a little confusing, but you'll get used to it. Search for your flightmarker to understand your movement.
The easiest way to get into an orbit with a planet or the sun is keep looking at it and adjusting your ellipse and distance. Or just sit back and watch Keplerian dynamics unfold...
enjoy...
Code: Select all
scene::IBillboardSceneNode* earthBill = smgr->addBillboardSceneNode(0,core::dimension2df(80,80));
// earthBill->setMaterialFlag(video::E_MATERIAL_FLAG::EMF_LIGHTING, false);
// earthBill->setMaterialType(video::E_MATERIAL_TYPE::EMT_TRANSPARENT_ADD_COLOR);