Monday, February 16, 2015

Physics Solar System

In our physics Engine class the past couple weeks we had to create a Planetary Simulation. This project also allowed me to get into OpenGL, and is the first time I have used it. In order to create everything I use a Force Generator which which takes scaled numbers to calculate the gravity equation G * (m1* m2) / r^2 r being the distance between them. In order to produce it on a screen 1 distance in openGl is the same as the distance from the Sun to the earth. As for Mass 1 is a solar mass so the mass of the sun. As well all planets are scaled properly except for the earth moon and sun. The Sun would eat Mercury and Venus if proper, as well the Earth is too large and you would be unable to see the moon. The initial distance is also the heliocentric position which is when it is closest to the sun. This location has a given velocity which is a percentage of the earths initial velocity which is given. If you failed to give an initial velocity in the y or z, it would just be all eaten by the sun. The velocities and accelerations on bottom are scaled by 10 ^ 9 so they can be seen on the GLUI. For this project I use GLUI for the UI and I use SOIL in order to load images into a graphics section of the planets and simple skybox.

The video software states that its running at one FPS, but that text is just an error with the video. It would be a lot worse at one FPS, because I have a DPF which is days per second because I have a game timer in my simulation. This way a loss in frame rate doesn't slow the simulation down itself. So when my when an update occurs it runs through the physics system, that many times between 0 and 150 which are the min and max. This way it does the math day by day instead of just doing it one large jump which would cause a lot of errors, both floating points and getting correct velocity and acceleration for each section. Since I am using euler physics there are errors overtime, some calculations were done before putting it into the system so it would round less and I could use doubles for maths, but save as floats. However there is some rounding and just using the general gravity does not produce a perfect simulation. If I was going to take this farther I would use Keplers' laws of planetary motion to create a better simulation, but it would have required a lot more time than I had.