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

Project #3 – Construct a 3D-Letter (Alphabet Symbol), based on your Initial.
Due date: Friday, January 31, 9:00pm.

Goals: Learn how to model simple scenes with ellipsoids and cylinders; get more practice with matrices and affine transformations in 3-space. Create some custom animation.   Discover that wireframe objects, especially when combined with animation and moving viewpoint can look very three-dimensional.  Discover, however, that flat, solidly colored objects look much too flat and non-three-dimensional.  Grading will be based mostly on technical merit and but also on artistic merit.
    We will use this project as a basis for the next two projects, which will add another shape, and then add materials and lighting.

What to hand in.

·        You do not need to have this assignment graded individually right away. If you prefer, you may wait until you finish Project #4, and then have them graded jointly.  However, it is permitted to have an individual grading; it is especially encouraged if you had difficulties or found parts of it confusing! This is because your code will be used again in Project 4.
If you wish to be graded right away, the procedure is as usual: ask Professor Buss or a TA for grading in APM B325, run Visual Studio, and be ready to demo and discuss your project.

·        You must however, upload two items to gradescope, deadline is as above.  (Late uploads are accepted, but subject to a point deduction).

o   You must upload your main source file, called MyInitial.ccp. 

o   You must upload a PDF document, one or two pages long, showing two (or at most three) images of your scene.  Your scene will be animated, so your two pictures should give a good view of your scene plus show clearly what the animation does.

o   The two files should be put in zip file to be uploaded to gradescope.

·        Also, and this is important: make a copy of all your Project #3 source files, and place them a separate folder for safekeeping. (Perhaps even move them a Google drive folder.)  This will be available for you and us to refer back as needed, either for in-person grading or in case they are needed for Project 4.

INSTRUCTIONS:

1.      Download the file InitialProject.zip from the web.  This zip file contains 7 files:  Four (4) C++ source files, one file of GLSL shader programs and two executables InitialProj.exe and InitialProj2018.exe.  The rest of the C++ files will be obtained as described below. The full URL for the zip file is:
http://www.math.ucsd.edu/~sbuss/CourseWeb/Math155A_2020Winter/Project_3/InitialProject.zip.)

2.      Run the two executables (InitialProj.exe and InitialProj2018.exe) on a PC. (If you are not on a PC, you can build InitialProj.exe with the source code supplied, as described below. However, InitialProj2018.exe is available only for Windows) For InitialProj.exe, the GLSL source file InitialProj.glsl must be available. To do this, extract the executable files and InitialProj.glsl from the zipped compressed folder and place them together in another folder.   In these programs, you will see a scene with

a.      a rectangular floor,

b.      a couple of cylinders,

c.      Either an “X” shape formed from two cylinders, a torus and a revolving ellipse;
or an “S” shape formed with cylinders and ellipsoids with an animation in the middle of “S”, depending on which program you are running.

The following commands act on the scene:

a.      Pressing the arrow keys changes the view position. 

b.      Pressing the “W” or “w” key toggles wire frame mode.  Note how flat and non-three-dimensional the objects look when filled in.  (We will fix this in project 5, by adding material properties and lights to the scene.)

c.      Pressing the “C” or “c” key toggles culling of back faces. 

d.      Pressing the “M” or “m” key increases or decreases the mesh resolution on the spheres (ellipsoids) and cylinders.

e.      The animation can be turned off and on by pressing “R” or “r”. It can be put into single step mode by pressing “S” or “s”.  The animation can be made to run faster or slower by pressing “F” (faster) or “f” (slower).

f.       In InitialProject.exe, you can use the HOME and END keys to move the viewpoint closer to or further away from the scene.

3.      Your job is to re-create these programs -- sort of!!  Specifically, you will do something creative based on your own first initial instead of the "X" or the “S”.   You must also supply some novel animation.

4.      Form a new project and solution.  You must collect the following twenty source files. 

a.      The four (4) C++ sources InitialProj.[cpp,.h] and MyInitial.[cpp,h] in the zip file.

b.      The GLSL source file InitialProj.glsl from the zip file. This contains shader programs.

c.      The five (5) GlLinearMath source files (MathMisc.h, and LinearR3.[cpp,h] and LinearR4.[cpp,h]), all available from the GlLinear web page accessible from http://www.math.ucsd.edu/~sbuss/MathCG2/OpenGLsoft/.  These are the same as you used in Project #2.

d.      The two (2) C++ programs GlShaderMgr.[cpp,h] available from the GlShader page at same URL as in item c. These programs handle reading GLSL source files and compiling and linking the shader programs.

e.      The eight (8) C++ files GlGeomSphere.[cpp,h] and GlGeomCylinder.[cpp,h] and GlGeomTorus.[cpp,h] and GlGeomBase.[cpp,h]. The six for GlGeomSphere and GlGeomTorus and GlGeomBase, you used already for the Solar program – it draws unit spheres or torii centered at the origin. The two new ones, for GlGeomCylinder, draw cylinders of height two and radius 1, centered at the origin.  These are available from the GlGeomShapes page, also at the same URL.

f.       Include all nineteen (19) source files into your new C++ project. There are 19 source files (nine .cpp files and ten header files). These files can be added to your project all at once, as Visual Studio lets you select multiple files (use control or shift keys) to be added to the project/solution all at the same tile. When compiled, this code should run identically to the supplied executable InitialProj.exe.  The supplied source code handles all the keystroke commands, draws the flat base plane, draws two placeholder cylinders, and makes an “X” shape from cylinders, a torus and an ellipsoid.  (The ellipsoid is a transformed sphere).  The routines that make the “X” shape are what you need to rewrite to form a geometry based on your initials. The code you will change and write is all in MyInitial.cpp.

g.      IMPORTANT: Place a copy of the GLSL source file InitialProj.glsl in the same directory as your Visual Studio project files. (The folder is probably the same one that contains your “.vcproJ” project file and/or your “.sln” solution file.)

h.      You may add the InitialProj.glsl file to the Visual Studio project if you wish: it doesn’t make much difference, but it does make it convenient to read and edit the code in Visual Studio. (You do not need to edit it!)

5.      Understand the various components of the source code, at least at a high level. 

a.      The main program was getting rather long and complicated, so it is now split into two source files, InitalProj.cpp and MyInitial.cpp, and their associated header (.h) files. MyInitial.cpp holds the code for setting up, and rendering the “X” shape. It also controls the animation.  Most (probably all) of your programming for this project will be to modify MyInitial.cpp.  The other file, InitialProj.cpp, has the part of the code that draws the floor and the two placeholder cylinders. It also handles all the general OpenGL setup, shader compilation, keystrokes, OpenGL error checking, etc.

b.      Variables are shared between different .cpp source files, by using header files, and extern declarations.  This means that one .cpp source file defines the actual variable, but other .cpp source files are able to access it via the header files.
If this is new to you, please google to learn about it, or ask the professor, a TA or someone else about it.

c.      The vertex shader and fragment shader are unchanged from the previous (Solar) project: however, they are now included in the InitialProj.glsl file.

d.      A new GlGeom object, GlGeomCylinder has been added (in new .cpp and .h files).  This works generally similar to GlGeomSphere: It creates a cylinder of radius 1 and height 2, centered at the origin. Of course, the cylinder’s position and shape can be controlled by scaling matrices, translation matrices, rotation matrices, or any other affine transformation.

e.      The GlShaderMgr methods lets your program read GLSL shader source code from a file, and compile and link it. This is done by two lines in the InitialProj.cpp file.  If you look at the code, you will see how easy GlShaderMgr makes it.

f.       (Optional for now). The rectangular floor is rendered by glDrawElements() command instead of a glDrawArrays() command.  This form of drawing allows vertices to be put in an array without duplication, and then rendered based on the indices of the vertices.  We will use this more in the next project, but you do not need to change this for the current project.        

6.      Your grade will be partly on technical merit and partly on artistic/creative merit. So please put a little thought into designing an attractive scene with some attractive animation.
The “X” demo is rather simplistic to code, and a bit lower in technical merit than desirable; however, it is attractive and thus fairly good on artistic merit.  The “S” demo is technically more challenging in its animation as it is hard to make the animation work the way it does; but to be honest, it is not very attractive to look at, so it is weak on artistic merit.  For artistic merit, try to do something a little innovative, and different than in the two supplied executables.
Please feel free to talk with a professor or TA (or other students) about creative/artistic aspects for your design.

7.      MAIN PART OF THE PROJECT: Design some geometric shapes that are based (*loosely* based is OK) on the first initial of your first name or last name, --- or even some other letter, if you prefer.  Do something creative so that no two of you have the same geometry.  Your scene should be somewhat more complex than the scene supplied in the sample code rendering an “X”.  Try to be a bit artistic and creative. 
Suggestions: Use primarily the GlGeomSphere. GlGeomTorus, and GlGeomCylinder routines.  These are similar to what you already used for the solar system. Cylinders work similarly to spheres, and there are examples how use them in the code of MyInitial.cpp and IntialProj.cpp
You may optionally use triangles, triangle fans, triangle strips. However, you should NOT make use of points or lines; the objects should have “outside surfaces”.  It is important that all surfaces are outward facing. 

8.      SECOND MAIN PART OF THE ASSIGNMENT: Animate some portion of your geometry.  This should be something comparable to what is done in the supplied code with the “X” or the “S”. But, you do not need use the same kind of animation as in the supplied code. In the “X” example, there is just a pure circular motion. In the “S” example, note that the middle pieces of the "S" is animated part of the time and stationary part the time.  This gives smooth motion based on a Bezier curve.  It is not necessary to have this kind of start-and-stop animation in your program: it is OK if the animation runs all the time.  It is also OK if you want to make the animation happen only when triggered by a keyboard or mouse event.
Your animation should run smoothly, not jerkily.  A viewer watching it run should be able to see what is happening in the animation.

9.      The keyboard controls that toggle back face culling and wireframe mode, and also the mesh resolution controls, should also apply to your new geometries whenever possible. The arrow keys should still work to change the view position.

10.   Leave the rectangular base plane the same as it is in the supplied code. Leave the two cylinders in the right front unchanged. (These will get changed in Project #4 in a couple weeks.)  Your finished program should look the same as the supplied demo executable, except the "X” or “S" is replaced by your own creation and with animation of your own design.

11.   Turn in the project as described above.   There are two things to upload to gradescope (a PDF file and your main source program).  In addition, make copies of all your files and save them somewhere safe.
Uploading to gradescope:

a.      Upload your source file MyInitial.cpp to gradescope. 

b.      Your PDF file should have two images showing your scene at different points in the animation. For these, choose a viewpoint so that it is easy to see what is in the scene. Then choose two points in the animation that do a good job of illustrating the action of your animation.  If really helpful, you may use three pictures instead of two. You may create the PDF file in various ways:  screen shots (CNTL-ALT-PRINTSCREEN or FN-CNTL-ALT-PRINTSCREEN) can be stored to PDF files, and then multiple PDF files can be combined into a single PDF (using an appropriate PDF editor). Another good way, is to form a Word document or google doc, insert your screenshots as images (it is best to use text boxes to hold your images), and then print your document to PDF. Please put your name in the PDF, but NOT YOUR PID (for privacy).

Program grading: Scale of 0 to 10.  You may request a personal grading session with a TA or Professor Sam Buss right away.  OR, wait and have your project #3 graded together with project #4.  It is encouraged to get a personal grading session early in fact, as this may help with your Project #4. This is especially true if you feel like you having difficulties with either Project 3 or 4.