CS 324: More on Programming Assignment 3 ---------------------------------------- The third programming assignment will be due on Tuesday, April 17. For this assignment, you will add the ability to do lighting and materials to my GObject system. This file contains the full set of requirements for the assignment. You will need to modify the files GObject.h and GObject.cc and write a main program that uses your modifications. Please turn in a printout with your modifications clearly marked. The main program that you write should show some sort of hierarhical, lit scene with at least two light sources. An obvious idea would be to convert your program from Assignment 2 to use lighting and materials. Turn in a printout of your main program, and let me know where I can find the executable. You should make a new class called Material. This can be a fairly simple class that simply contains five public member variables to represent diffuse, specular, ambient, and emissive color and shininess. (If you want, you can drop the ambient color and always use the same color for both the ambient and diffuse components.) It would be useful to have a constructor that assigns default values to these variables and a public member function named apply() that applies all the material properties, by calling glMaterial four or five times. Add a new member variable of type Material or Material* to my basic GObject class, and add some member functions for setting material properties. In GObject.cc, you will have to modify GObject::setRenderContext() so that it saves the current lighting and material properties and applies the object's material (if any). Fortunately, it's easy to save lighting and material settings. You can do with a single call to glPushAttrib(GL_LIGHTING_BIT). The previous settings have to be restored in GObject::restoreRenderContext(). This is done with a matching call to glPopAttrib() (with no parameter). You also have to provide for lighting of the scene. I suggest that you stick to simple lights that have no properties except color and position. You can use the same value for both diffuse and specular color. The question is, where to put the code for implementing the lights? A simple solution, which you can use if you want, is to make a subclass of GModel called GLitModel. A GLitModel object should have a method for adding a light to the model (or, ideally, more than one light). The assumption is that the light will only apply to objects in that model, so the light can be enabled as the first step in drawing the model and disabled as the last step. Presumably, the main model in your program will be a GLitModel which will contain all the lights for your scene. But you have more flexibility if you need it. You are not required to do things this way, but your solution should be object-oriented. The details are up to you. (You might think that it would be better to make lights into another type of GObject and treat them just like other GObjects. The problem is that a light must be enabled before the objects that it lights are drawn. If you add the lights as GObjects, you would still have to deal with them in some special way. For example, you could traverse the scene graph once to turn on all the lights, once to draw the objects, and once to turn off the lights. The big advantage of this is that you could then apply transformations to the lights without applying them to the other objects. With my GLitModel idea, this isn't possible. If you want to animate the lights, you will have to do it some other way.)