Computer Graphics
Summer 2007

Tuesdays, 6pm - 8:20pm
WWH 101

Assigment 2
DUE: 6/11/06 11:59pm

This assignment is an extension of the first assignment. In this part you will add camera motion to the static scene you created in hw1 with some user interaction. This refers to viewing, projection and viewport transformations.

Your program should have the following modes:

Mode 1: Fly to the center of the table.
Mode 2: Fly away from the center of the table.
Mode 3: Fly around the center of the table, looking at the center.
Mode 4: Camera does not move, one of the chairs move away from the table (perpendicular to the side it is at).
Mode 5: Camera does not move, one of the chairs move towards the table ( again in perpendicular direction ).

Once the mode is chosen, when the left mouse button is clicked, the camera starts moving and the second click stops it (and third starts it again). Modes can be changed at anytime where the last position of the camera before the change should be the first position of the camera after the change.

You can implement the modes as key presses (e.g. pressing key '1' changes mode to 1, key '2' to mode 2, etc). You may choose to implement the modes using a pop-up menu for extra credit.
Make sure to specify HOW you implemented the user controls in your readme file


Do not use the following commands in this assignment:
*any aux or glut commands for drawing objects
*glTranslate, glRotate, glScale - implement their functionality using the formulas we discussed in class.

For matrix operations only use glLoadMatrix, glMultMatrix, glPushMatrix, glPopMatrix.

Note: Feel free to use all these commands for debugging your code. Once you are sure everything else works replace these calls with your versions.

To see the scene, we need a light source. If we do not put a light somewhere, the polygons of the scene are still visible, but they are flat- shaded i.e. all pixels in the image of any polygon have the same color. Pictures
like this do not look very interesting, especially if all polygons have the same color (default is white). To make things more interesting, either make boxes of different colors, using glColor3f() function calls or use a single light.

We will  discuss lighting in greater detail later. For this assignment, add the following  OpenGL calls after you create your GLUT window, but before you call the glutMainLoop function.
This will add two lights, red and blue, to your scene.

GLfloat diffuse[] = {0.8, 0.8, 0.8, 1.0};
GLfloat lgt1_diffuse[] = { 0.05f, 0.05f, 0.6f, 1.0f };
GLfloat lgt2_diffuse[] = { 0.6f, 0.05f, 0.05f, 1.0f };
GLfloat light_pos1[] = { 5.0f, 5.0f, 0.0f, 1.0f };
GLfloat light_pos2[] = { -5.0f, 5.0f, 0.0f, 1.0f };
glMaterialfv( GL_FRONT, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT1, GL_POSITION,light_pos1);
glLightfv(GL_LIGHT1, GL_DIFFUSE, lgt1_diffuse);
glLightfv(GL_LIGHT2, GL_POSITION,light_pos2);
glLightfv(GL_LIGHT2, GL_DIFFUSE, lgt2_diffuse);

To make the lighting work, you also need to specify normals for each polygon.
Here is an example of the code that defines a unit square in the XY plane with
normal pointing along Z:

glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(1.0f, 0.0f, 0.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);

Implementation Suggestions

Use the same implementation suggestions from hw 1.
For extra credit, you can add creative different modes or implement user interaction using glut menus.

Adapted from one of Denis Zorin's assignments.