Math 155A - Introduction to Computer Graphics – Winter 2018
Sam Buss,  Univ. of California, San Diego

Project #2 - Modify the Solar System program by adding a Moon, a Moonlet, Planet X and a tilt.

Due date: Friday, January 26, 10:00pm.

Goals:  Learn more about how to use OpenGL, interrupt-driven programming, animation, and transformations. Program some additions to an animated solar system.  Use OpenGL commands to generate transformations that control the animation. 

What to hand in:  When you are done, place your C++ files, executable, and Visual Studio solution together in a separate folder, preferably named “Solar” or “Project2”, in your PC computer account in the APM basement labs.  There should be nothing in this folder except your files for this homework assignment, and the creation/modification dates should be before the turn in deadline.   The program must compile and run on these computers.  As before grading will be personalized and one-on-one with a TA Jonathan Conder and Xiudi Tang,  or with Sam Buss.  Your program must run on the PC lab, you must come into the PC lab and meet one of us.  You will have to show your source code, run the program, make changes on the spot to your program and recompile as requested by the grader, and be able to explain how your program works and why it renders what it does.  The grading should be completed no later than Friday one week after the due date.  


1.      Download the Solar program from the zip file  Extract these into a directory named “Solar” or “Project2” in your home directory (If you have problem with link, the full URL for the zip file is:  In this zip file, you will find an executable SolarDemo.exe and 10 (ten) source files (.cpp and .h) files.  Create a new Visual Studio workspace/project called SolarProj, and include all 10 of these source files into new project.  Your assignment is to add onto SolarProj.cpp so as to approximately match the actions of SolarDemo.

2.      Understand the code in the SolarProj program. Compile and run the program. You may find the solar program runs way too fast, so that the earth and moon zip their orbits many times per second.  The easiest way is to set the initial value for the variable AnimateIncrement smaller, in order to make the program take smaller steps in the animation of the solar system.  Test out the keyboard controls. 

a.      Pressing “r” will start and stop the animation.

b.      Pressing “s” will put the program in “single step” mode so that the animation steps one time frame each time “s” is pressed.

c.      Pressing the up and down arrows will change the animation step size. Pressing the up arrow makes the animation run faster by taking bigger time steps each time the solar system is rendered. Pressing the down arrow makes it run more slowly.

d.      Pressing “c” will toggle the culling of backfaces.

e.      You will a very simple solar system (in SolarProj) with a central yellow sun, a blue planet (Earth) rotating on its axis once every 24 hours and revolving around the sun every 356 days, and a moon revolving around the Earth 12 times per year.

f.       If you compare to SolarDemo.exe, you will see also a second planet (Planet X), and second moon on the Earth with a retrograde motion, and moonlet orbiting the Earth’s moon.

g.      You should understand the callback-driven style of the program, and how the keyboard controls are handled by the program, and when myRenderScene is called.

h.      Examine the code in SolarProj.cpp, to understand how it makes items a.-e. work. There are variables HourOfDay, DayOfYear, and AnimateIncrement. Find all their occurrences in the source code, and understand how they are being used an updated. Also understand how the spinMode and singleStep  variables are used to control the animation.

i.       The GlGeomSphere objects are used to render the spheres. They handle all the work of creating and drawing the VAO and VBO (and EBO), so you do not need to do this in your code for this assignment.

j.       When the program first starts, aliasing causes the planet to appear to not be rotating, but instead always keeping the same face to the sun.   Slow down the animation (up/down arrow keys) to see the "true" motion.  Figure out why the animation code makes this happen.  Understand what was meant by "aliasing" three sentences ago. (We will discuss this in class, too.)  See also the “Troubleshooting” section below.

3.      There is an executable in the zip file called “SolarDemo.exe”. This shows what your Project #2 should look like (approximately) when you are finished with the steps 4-9 below.

4.      Add a second moon to the Earth with a retrograde orbit.  The second moon should orbit the Earth twice times as fast as the first moon (that is, 24 times per year). Its orbit should go in the opposite direction of the first moon, so it is a retrograde orbit.

5.      Add a “moonlet” which orbits the Earth’s first moon. The moonlet should orbit the moon 36 times per Earth year.

6.      Add a “Planet X”, a second planet orbiting the Sun.  Planet X should orbit the Sun once every 500 days (that is, once every 500 Earth days).
(LATE ADDITION).  Make PlanetX rotate on its axis. The Demo program sets the PlanetX day to be 23 hours long (that is, 23 Earth hours).  This will involve adding a new variable HourOfDayX, that is used with PlanetX the same HourOfDay is used with the Earth.

7.      As part of steps 4, 5, and 6, adjust the orbital radii, the orbital rates, view distance, colors, etc. Make changes to the sizes of the suns, planets and moons and to the radii of the orbits, so as to make viewing the solar system convenient.  (You may need to adjust the values of Xmax, Ymax, Znear, Zfar.)  Choose colors that make all planets and moons clearly visible and distinguishable.

8.      Add a 30 degree tilt to the Earth system.   Give the whole Earth system (the Earth and its moons) a 30 degree tilt.  The kind of tilt is similar to the somewhat smaller tilt of our real earth that causes the earth to have seasons. This means that the orbital path of the Earth should not be tilted; instead the tilt just applies to the orientation of the Earth and to the paths followed by the moons.  Thus the tilt should always be in the same direction (in the direction of the positive x axis, for instance): it should not always be tilting at the same angle relative to the sun.  This means it will be “summer” in the northern hemisphere when the Earth is at its leftmost position on the screen, and will be “winter” when the Earth is at the rightmost position on the screen.
     The orbits of the Earth's moon and its satellite should be tilted by the same amount so that they are always above the equator of the planet.  That is to say, the centers of the Earth, the moon and the moonlet are co-planar and rotation axis for the Earth is perpendicular to this plane.
     The visual effect is that the whole Earth system is always leaning rightward 30 degrees. 

9.      Turn in the project as described above.

Program grading: Scale of 0 to 10.  Personal grading session with one of the TAs or Professor Sam Buss. For grading, be ready to discuss any of the above topics, plus be prepared to make small modifications to the source code and recompile.