Friday, January 13, 2012

[C/C++] Solar System Model

This was a CG project I did for my finals. The result was quite successful although there wasn't much fancy commends or tricks. It primly consists of the glutSolidSphere commend from OpenGL, which is relatively easy to control. To see the program in action, feel free to download it here. The main difference of my model to the ones usually seen is that I have included the asteroid belt and the moons of both Jupiter and Saturn. To make the result even more dramatic (and this is an idea I was so proud of) is that the Sun changes colors! This is to simulate the burning fire ball that it should have been. It successfully caught the attentions of my teacher and peers, which is the goal of our projects. Another notable thing about my model is the scale. The speed of the planets are in scale with the real system. The actual size and distance of the planets, on the other hand, differs greatly from one another. To fit all planets into the frame without shrinking the Earth-like planets and moons into dots is impossible. This is the reason why few models have the right scale for these data. Therefore, to get the model as accurate as possible, I grouped the Earth-like planets and Jupiter-like planets, and scale the two groups differently.  This is the only inaccuracy of my model, I even had the planets rotating in the correct orbital plane angle (see figure below).

The only pity is that I failed notice the massiveness of my rendering method. First of all, all of my spheres were set with the same number of slices and stacks. In my negativeness, I have also chosen to use the LIFO* data construction type instead of vertex array or the VBO*. This slows down my program tremendously and limited the amount of objects I can put into it. The tragedy only presented itself when I attempted to construct the background and fill them with distant suns:

Snapshot of the output
Output with distant suns in the background

It made the overall scene much interesting, but sadly I was out of time and so I did not change any of the original codes regarding the rendering of the planets. It also prevented me from putting any other object into my model. I had plans about putting in a couple of comets to add up complexity. The calculations had even been finished:

From the above figure, we can see that, the tail length and direction differs with the position of the comet with respect to the sun. I thought the idea was pretty neat, and it was depressing that it never got a chance to be put into practice.

I would like to remind all who happens to see this post of mine that, if, by any chance, you happened to need to right a graphic program with dynamic outputs, please learn from my faults. No matter how the simple and friendly pushing-and-popping seems, never consider your program simple enough that acceleration can be neglected. It can't. Life wouldn't ever be easier that way.

------------------------------

*LIFO - Last In First Out, here it refers to the method of data construction. The transformation matrices needed for the rendering of the planets are "stacked" one on top of another. Like stacking books in the corners of our bedrooms, we would have to retrieve the top most book first if we don't want to end up with a pile of paper chaos!

*VBO - Vertex Buffer Object. It is an OpenGL feature that provides methods for uploading data to the video device for non-immediate-mode rendering. (courtesy to Wikipedia)