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

Project #2 - Modify the SolarModern program by adding a Double Sun, a Lunar Lander, another Moon, a Planet X and a tilt.

Due date: Friday, January 25, 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 labs.  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, 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 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.

b. Upload your main source file (.cpp file) to gradescope.

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

1.     As preparatory work, you should look at the SimpleAnimModern program, available at http://www.math.ucsd.edu/~sbuss/MathCG2/OpenGLsoft/SimpleAnimModern/index.html along with a webpage explaining how the code works. (Some of this you do not need to know yet, notably the use of the projection matrix for perspective). But Project #2 asks you to modify a different program, SolarModern.

2.     Download the SolarModern program, from the MathCG2 website at http://www.math.ucsd.edu/~sbuss/MathCG2/OpenGLsoft/SolarModern/index.html
You will download a total of eleven (11) files:

a.     In the zip file SolarModern.zip: There are three (3) source files SolarModern.cpp, ShaderSLR[.h, .cpp].  The main source file SolarModern is the only file you will modify for this project.

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

c.      Download the files GlGeomSphere.cpp and GlGeomSphere.h.  There is another link on the same webpage to download these two (2) files. You also will not need to change these two files. (You do not need to get the GlGeomCylinder files.)

d.     Download the executable file SolarDemo2019.exe from SolarDemo2019.zip.  (The full URL is http://www.math.ucsd.edu/~sbuss/CourseWeb/Math155A_2019Winter/Project_2/SolarDemo2019.zip.)

e.      Form a new Visual Studio C++ project called SolarProj. Rename SolarModern.cpp to SolarProj.cpp.  Put all 10 source files (SolarProj.cpp, plus the nine other files) into a new project, say named SolarProj.  It should now be able to compile and run.

3.     Understand the code in the SolarProj (SolarModern) program. Read the online documentation of the code. 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.      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.

b.     You will see 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 365 days, and a moon revolving around the Earth 12 times per year.

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

g.     Compare SolarProj (SolarModern) to the reference code, SolarDemo.exe: SolarDemo.exe has

                                               i.     a binary sun,  

                                             ii.     a second, magenta, planet (Planet X),

                                            iii.     a second, green, moon on the Earth with a retrograde motion, and

                                            iv.     a small red sphere on the back side of the moon at approximately the location of the Change’e 4 lunar lander.

                                              v.     The earth 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.

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 on Wednesday; or go ahead and discuss on piazza before then.) 

4.     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-11 below.

5.     Change the sun to be a binary sun.  The two suns revolve around the center of the solar system.

6.     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. In the SolarDemo program, this second moon is green, but it is OK to use another color.

7.     Add a red sphere marking the approximate location of the Change’e 4 lunar lander.  This is on a fixed location on the moon. It is approximately directly away from the earth, but 45 degrees south (below the equator of the moon).  (Lunar longitude is180 degrees, latitude is 45 degrees, south).

8.     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.  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, the demo source code, it is named “DayOfYearX”.

9.     Add a tilt to the earth, of 24 degrees. This tilts the earth, but not the orbital path of the earth, nor the orbital path of the moon. It is similar to the tilt that causes the seasons of the real earth. The tilt is always rightward in the scene.

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 lander location 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, but the suggested way is as follows: 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). For full credit, implement this so that an inhabitant of the earth still sees 365 days during each earth year. 

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