EXERCISES FOR WEEK 9
week9-1

For this paper/pencil/calculator exercise, assume the following:

  • There is one positional light, with these properties:
    • Diffuse Intensity (RGB) = (1.0, 0.8, 0.6) ; Specular Intensity (RGB) = (0.9, 0.85, 0.2); Ambient Intensity (RGB) = (0.6, 0.4, 0.4)
    • light position (x,y,z) = (4, 12, 2)
    • eye position (x,y,z) = (-3, 2, 5)
  • There is a global ambient light (RGB) = (0.2, 0.2, 0.2)
  • There is a facet whose color (RGB) will be caculated using the Phong Lighting Model and these facts:
    • a vertex on the facet has coordinates = (0,0,0)
    • the normal vector to the facet at this vertex = <-1, 1, 1>
    • the material of the facet has these properties:
      • material diffuse coefficient (RGB) = (0.8, 0.5, 0.3)
      • material specular coefficient (RGB) = (0.8, 0.5, 0.3)
      • material ambient coefficient (RGB) = (0.8, 0.5, 0.3)
      • material Phong exponent = 57.0
  1. What is the vector s from the vertex to the light source?
  2. What is the length of vector s ?
  3. What is the normalized vector Us ?
  4. What is the vector  v from the vertex to the eye?
  5. What is the vector h (the vector halfway between vector s and vector v?
  6. What is the length of vector h ?
  7. What is the normalized vector Uh?
  8. What is the vector  m (the vector normal to the face at the vertex)?
  9. What is the length of vector m ?
  10. What is the normalized vector Um ?
  11. What is the value of Lambert?
  12. What is the value of Idiffuse (RGB) ?
  13. What is the value of Phong?
  14. What is the value of Phong f
  15. What is the value of Ispecular (RGB) ?
  16. What is the value of Iambient (RGB) ?
  17. Finally, what is the value of I (RGB) at this vertex?

 

week9-2

Compile and run the program 2spheres_b.cpp.

  • Change the materials properties
  • Change the light properties (from the default, which is used)
  • Change the position of the light

Make sure you understand how the changes affect the spheres.

 

week9-3

The program movelight.cpp rotates a light source around an object. When the left mouse button is pressed, the light position rotates an additional 30 degrees. A small, unlit, wireframe cube is drawn to represent tthe position of the light in the scene.

Make the light translate past the object (move left - right or up - down) instead of rotating around it. Hint: Use glTranslated() rather than the first glRotated() in display(), and choose an appropriate value to use instead of spin.

 

week9-4 Continuing with the program movelight.cpp, try to create a light that moves along with the viewpoint. You need to set the light position before the viewing transformation. Then the viewing transformation affects both the light and the viewpoint in the same way. In the following code, the light position is defined in init(), which stores the light position at (0,0,0) in eye coordinates. In other words, the light is shining from the lens of the camera.

GLfloat light_position() = {0.0, 0.0, 0.0, 1.0};
glViewport(0, 0, (GLint) w, (GLint) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0, (GLfloat) w/(GLfloat) h, 1.0, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLightfv(GL_LIGHT0, GL_POSITION, light_position);


If the viewpoint is now moved, the light will move along with it, maintaining (0,0,0) distance, relative to the eye. Next, the global variables (ex,ey,ez) and (upx,upy,upz) control the position of the viewpoint and up vector. The display() routine that's called from the event loop to redraw the scene might be this:

static GLdouble ex,ey,ez,upx,upy,upz;
void display(void)
{
    glClear(GL_COLOR|GL_DEPTH);     
    glPushMatrix();
      gluLookAt (ex,ey,ez,0.0, 0.0, 0.0, upx, upy, upz);
      glutSolidTorus (0.275, 0.85, 8, 15);
    glPopMatrix();
    glFlush();
}

when the lit torus is redrawn, both the light position and the viewpoint are moved to the same location. As the values passed to gluLookAt() change and the eye moves, the object will never appear dark, because it is always being illuminated from the eye position. This method of moving the light can be very useful for simulating carrying a candle or lantern. The light position specified by the call to        glLightfv(GL_LIGHTi, GL_POSITION, position)
would be the x,y, and z distance from the eye position to the illumination source.
week9-5 Go through the recursive subdivide algorithm (by hand) and determine the vertices generated if the original vertices are: v1 = (0,0); v2 = (4,4); v3 = (8,0) and the depth is 2. Sketch the resulting figure.

week9-6 Write a function subdivide( ) that takes four input parameters: 3 vertices (double) and a depth (int) and draws the resulting subdivided triangle. Test it out with various levels.

week9-7

Copy the spotlight demo program in

/classes/cs3014/files/Lighting/spotdemowall.cpp


to your directory. Compile and execute it to make sure you understand what it is doing. Be sure to try all the options.