Math 155A - Introduction to Computer Graphics – Spring 2022
Instructor: Sam Buss,  UC San Diego

Project #2 – Modify Solar System program by adding a binary sun, a submoon, San Diego, and a tilt.

Due date: Friday, April 15, 2020; 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. 

Grading will be personalized in a one-on-one in-person session with one of the four TAs or with Professor Sam Buss.  You will meet in the APM B349 (or B432) lab, and run your project either on a lab PC, or cloudlabs in a browser or on your personal laptop. You will have to discuss 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 promptly, preferably no later than the due date for the next programming assignment.


1.      As preparatory work, you can look at the SimpleAnimModern and SolarModern programs, available at the textbook’s website and the accompanying webpages explaining how the code works. (Some of this you do not need to know for Project #2, notably the use of the projection matrix for perspective). Project #2 asks you to modify the program SolarModern.

2.      Download the SolarModern project from the textbook’s web page.

a.      There are three core source files: SolarModern.cpp and two source files ShaderMgrSLR.h and ShaderMgrSLR.cpp. The only source file you will change for Project #2 is SolarModern.cpp. Start by renaming it to SolarProj.cpp. (Please use this name exactly, including the same capitalization.)

b.     Download the five files LinearR3.cpp, LinearR3.h, LinearR4.cpp, LinearR4.h, and MathMisc.h.  There is a link on the textbook’s webpage to download these five (5) files, under GlLinearMath. You will NOT need to change these five files.

c.      Download the six files GlGeomSphere.cpp and GlGeomSphere.h and GlGeomBase.cpp and GlGeomBase.h.  There is another link on the textbook’s web page to the GlGeomShapes project to download these files. You also will NOT need to change these four files. You do not need to get the other GlGeom* files in the GlGeomShapes project.

d.     The ZIP file contains an executable file SolarProj_Demp.exe. This shows, approximately, what your solution for Project #2 should look like.

e.      Form a new Visual Studio C++ project called (say) SolarProject.  Put all 12 source files into this new project. Include GLEW and GLFW files if needed on your system.  It should now be able to compile and run.

3.      Understand the code in the SolarModern program. Read the online documentation of the SolarModern program. Compile and run the program. You may find the solar program runs way too fast or too slow on your system, so that the earth and moon zip around their orbits many times per second or move very slowly.  If so, you can press up/down arrow keys to adjust the speed. (Or, set the initial value for the variable AnimateIncrement smaller or larger. Test out the keyboard controls:

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

b.      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.

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

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

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

f.       Examine the code in SolarSModern.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 and updated. Also understand how the spinMode and singleStep variables are used to control the animation.

g.      Compare the starter code in SolarModern.cpp to the reference executable, SolarProj_Demo.exe: SolarProj_Demo2022.exe has

                                                    i.     A binary sun,

                                                  ii.     Earth and moon as before (but with orbits and sizes adjusted).

                                                 iii.     The Earth’s moon has its own orbiting satellite, (this is called a “subsatellite” or “submoon” or “moonmoon”,)

                                                 iv.     A second, bright magenta, planet (Planet X) in a retrograde orbit around the sun,

                                                   v.     The position of San Diego on the Earth is marked with a small yellow sphere.

                                                 vi.     The earth system (earth, moon, submoon and San Diego) is tilted, similar to the tilt of the real Earth that causes the seasons.

h.      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. But you will not change this part of the code.

i.       The GlGeomSphere objects are used to render the spheres. This handles all the work of creating and drawing the VAO and VBO (and EBO), for the spheres.

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 (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 a class meeting; or you may discuss on piazza.) 

4.      The “demo” executable, “SolarProj_Demo.exe, in the zip file shows what your Project #2 should look like (approximately) when you are finished with the steps 4-12 below. It is suggested to add features one-by-one.

5.      Change the sun to be a binary sun.  The two suns revolve around the center of the solar system. You may set their orbital rate to look good, say similar to the orbital rate in the demo code. You should also adjust the distance between the suns and the size of the suns so that they look good.  (Hint: You may wish to add another LinearMapR4 variable or two to your program to control the rotation of the sun.)

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). In the SolarDemo program, Planet X is magenta, but you may use whatever color you like. Planet X does not rotate on its axis.  Hint: Since the PlanetX year is a different length than the earth’s year, Planet X’s “day of year” will be different from the “day of year” of the earth. You will need an extra variable for this; for example, named “DayOfYearX”.

7.      Add a small yellow sphere marking the position of San Diego on the Earth. This sphere should stay at a fixed position on the earth, so it moves with the earth as it rotates. San Diego’s latitude is approximately 33 degrees. (This is properly visible only when you slow down the motion.)  You can reuse the “Earth” or “Moon1” GlGeomSphere object to render the San Diego sphere, or you can create a new GlGeomSphere object for this.

8.      Add a submoon revolving around the Earth’s moon. You can use the same “Moon1” GlGeomSphere to render the submoon as the moon, but of course with a smaller radius and a different color.

9.      Add a tilt to the earth, of about 24 degrees. This tilts the earth and its moon system, but not the orbital path of the earth. It is similar to the tilt that causes the seasons of the real earth. The tilt is always rightward in the scene.  We will discuss in lecture some hints for how to do this; see also item 10 below.
The perspective in the Solar program can make it hard to see the tilt well: The tilt will be easier to see if you change the viewAzimuth variable to equal 0.0 instead of 0.25 radians, so that you are viewing the solar system directly from the side. You can watch the orbital plane of the moon as the earth system goes around the sun: it should tilt with the earth’s tilt.

10.   As part of steps 4-9, adjust the orbital radii, the orbital rates, view distance, colors, etc. Make changes to the sizes and colors 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, and San Diego clearly visible and distinguishable. You do not need to match the supplied demo program.

11.   Hints for the tilt: This probably the hardest part, because the natural way to do this is tilt the earth before revolving it around the sun, but then the revolving around the sun affects the direction of the tilt.  There are several ways to make this work. One way is to make the tilt on the earth’s system be applied along a different axis than the z-axis, chosen to make the final tilt come out right.   A second way, perhaps better, is to instead of using a translation plus a rotation to revolve the earth around the sun, just use a single translation to move the earth to the correct location, as calculated with the aid of sine and cosine functions). (There are other ways to implement the tilt besides these two suggestions.) In any case, implement the tilt so that an inhabitant of the earth still sees 365 days during each earth year. This last part can be a bit tricky! 

12.   Turn in the project by uploading (only) your source file SolarProj.cpp to gradescope.  The gradescope files are primarily to time-stamp your project; uploading to gradescope does not suffice to get graded.

13.   To get graded, see Professor Buss or (after the due date) one of the TA’s. Grading is drop-on/on-demand (no reservations) in the computer lab hours in the APM basement computers. See the preliminary version of the grading rubric.                 

Program grading: Scale of 0 to 20.  Personal zoom 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.