Game Development Reference
In-Depth Information
How it works...
Due to the extreme difficulty in creating a stable solar system with more than three bodies,
StellarBody controls the need to have a static orbit around the center of the system.
Using 0 as mass ensures that they aren't affected by gravity. The orbit field represents the
orbit's distance from the center of the system, and it will rotate around the center using
speed as a factor. The cycle field stores information on how far along its orbit it has come,
and will reset once it reaches two PI (a full circle).
The getGravity method returns the gravity relative to the position that is supplied,
which in this case is the location of the ship. It first determines the direction and then ap-
plies the gravity based on the distance between the two.
By using the gravitationalBodies list, we have a dynamic way to simply add up all
the gravitational forces in the system to a single Vector3f object, which we then apply to
the spaceship in the update method of the application.
Search WWH ::




Custom Search