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

Project #2 – Modify Solar System program by adding a Double Sun, a Torus encircling the earth, a Moonlet, a tilt and a Planet X.

Due date: Friday, January 24, 8: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:  

a. Place your C++ files, executable, and Visual Studio solution, in your PC computer account in the APM basement lab.  The program must compile and run on these computers.  As before, grading will be personalized and one-on-one with a TA, or with Professor Buss.  Your program must run on the PC lab, you must come into the PC lab after the due date and meet one of usYou 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.

b. Upload your main source file (.cpp file) to gradescope by the due date.

FOR PROJECT #2, PLEASE DO THE FOLLOWING STEPS #1 - #12.

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 a program SolarSystemProject, which is a modified version of SolarModern.

2.     Download the SolarSystemProject starter code.

a.     There are three core source files SolarSystemProject.cpp and two source files SolarMgrSLR.h and SolarMgrSLR.cpp which you obtain from the zip file W2020_Project2File.zip. The only source file you will change for Project #2 is SolarSystemProject.cpp.

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 GlGeomTorus.cpp and GlGeomTorus.h and GlGeomBase.cpp and GlGeomBase.h.  There is another link on the same webpage (GlGeomShapes) to download these files. You also will NOT need to change these six files. (You do not need to get the GlGeomCylinder files.)

d.     The same zip file from item a. (W2020_Project2File.zip) contains an executable file SolarDemo2020.exe. This shows, approximately, what your solution for Project #2 should look like.

e.      Form a new Visual Studio C++ project called (say) SolarSystemProject.  Put all 14 source files into this new project.  It should now be able to compile and run.

3.     Understand the code in the SolarSystemProject.cpp program. Read the online documentation of the SolarModern program. Compile and run the program. You may find the solar program runs way too fast, so that the earth and moon zip around 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.      You will see a very simple solar system (in SolarSystemProject) with a central yellow sun with a red ring (a torus), 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 the shift button and the up or down arrows will adjust the view point up and down.

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

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

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

g.     Examine the code in SolarSystemProject.cpp, to understand how it makes items a.-f. 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.

h.     Compare the starter code in SolarSystemProject.cpp to the reference executable, SolarDemo2020.exe: SolarDemo2020.exe has

                                               i.     a binary sun,  (and no torus with the suns)

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

                                            iii.     A thin red torus marking the orbit of Earth’s moon. The torus does not rotate with the earth or the moon.

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

                                              v.     a small, green “moonlet” rotating around the Earth’s moon, and

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

i.      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. (This was discussed in class this past Tuesday.) But you will not change this part of the code.

j.      The GlGeomSphere objects are used to render the spheres. The GlGeomTorus object is used to render the torus. They handle all the work of creating and drawing the VAO and VBO (and EBO), so you do not need to work with VAO’s and VBO’s in your code for this assignment.

k.     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 by next Tuesday; or you may discuss on piazza before then.) 

4.     The “demo” executable, “SolarDemo2020.exe, in the zip file shows what your Project #2 should look like (approximately) when you are finished with the steps 4-12 below.

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.  Remove the torus from the sun; use it with the earth and moon instead.

6.     Add a red torus showing the orbital path of the Earth’s main moon.  The torus should NOT rotate with either the moon or the earth. Instead, the moon “slides” along the torus.

7.     Add a moonlet that rotates around the Earth’s moon.   The second moon should orbit the Earth twice times as fast as the first moon orbits the Earth’s moon (that is, 24 times per year). In the demo program, this second moon is green, but it is OK to use another color.

8.     Add a “Planet X”, a second planet orbiting the Sun.  Planet X should orbit the Sun once every 600 days (that is, once every 600 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”.

9.     Add a tilt to the earth, of about 18 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 11 below.

10.  As part of steps 4-8, 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 and the torus clearly visible and distinguishable.

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, and 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). In either case, implement the tilt so that an inhabitant of the earth still sees 365 days during each earth year. 

12.  Turn in the main source code to gradescope.

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.