1: Polygon Clipping (75 points)
Show the steps in applying the SutherlandHodgman polygon clipping algorithm to the polygon described below where an edge connects each vertex to the next and the final vertex back to the first. The clip rectangle stretches from x=10 to x=70, and y=40 to y=110. The clipping edges should be checked in the order: Ymax, Xmax, Ymin, Xmin. List each of the points (including coordinates) and draw a diagram showing the state of the clipping after each pass labeling all the points.
Initially:
A (0, 125) B (75, 125) C (75, 100) 
D (25, 100) E (25, 75) F (50, 75) 
G (50, 50) H (25, 50) I (25, 25) 
J (75, 25) K (75, 0) L (0, 0) 
2: 3D Graphics (75 points)
Assume you are creating a perspective view of the following two polygons defined by the following coordinates in X, Y, Z assuming a righthanded coordinate system:
Polygon 1: (10,10,0), (20,10,0), (20,20,0), (10,20,0)
Polygon 2: (10,10,0), (10,10,10), (10,20,0)
For each of the following conditions draw and label a diagram showing the X, Y and Z axis, the U, V, and N axis, the two polygons, the PRP, and the window. In a second drawing, show what will appear inside the window. Note that the position of the objects within the window is critical.
VRP 10,10,0 VPN 0,0,1 VUP 0,1,0 PRP 0,0,20 U 11 to 11 V –11 to 11 
VRP 10,10,0 VPN 1,0,0 VUP 0,1,0 PRP 0,0,20 U 11 to 11 V –11 to 11 
VRP 10,10,0 VPN 0,1,0 VUP 1,0,0 PRP 0,0,20 U 11 to 11 V –11 to 11 
3: 2D OpenGL (150 points)
Given the standard shell we have been using for the
homework assignments (given on the next page), and the three
polygonal drawing functions given here:
void DrawSquare(void) /* Draw a square centered at the origin with
sides of length 1 */
void DrawCircle(void) /* Draw a circle centered at the origin with
diameter of length 1 */
void DrawTriangle(void) /* Draw a triangle with the three corners
(1,0), (1,0), (0,1) */
and the typical OpenGL translation, rotation and scaling
functions, and the ever popular LoadIdentity(), PushMatrix(), and
PopMatrix(), write the code to draw the following scene on the
screen. Please comment your code thoroughly so I know what you are
trying to draw with each block of code. The scene shows a
minimalistic house, tree, and car which should be drawn as shown
below – you should use the grid system as a guide to positioning
and sizing the objects correctly. The house and tree remain
stationary each frame, but the car should move left and right
under user control using the ‘j’ and ‘l’ keys respectively. The
entire car should always remain on the screen so you should not
allow it to move past the edge of the screen.
/* EECS 488 Fall 2000 Midterm shell */
#include <stdlib.h>
#include <stdio.h>
#include <GL/glut.h>
/**********
keyboard **********/
void keyboard(unsigned char c, int x, int y)
{
/* update stuff goes here */
}
/**********
update **********/
void update(int value)
{
/* update stuff goes here */
glutTimerFunc(5,
update,
1); /* at the end of this function reinstate the timer callback */
}
/**********
display **********/
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT); /* clear the screen to the clear
colour */
/* display
stuff goes here */
glutSwapBuffers();
/*
swap buffers */
}
/**********
main **********/
int main(int argc, char **argv)
{
glutInit(&argc, argv); /* deal with any GLUT command Line
options */
glutInitDisplayMode(GLUT_DOUBLE

GLUT_RGB); /* create an output window */
glutInitWindowSize(500, 500);
glutCreateWindow("EECS 488  Midterm");
glutKeyboardFunc(keyboard); /* set up for accepting keyboard commands */
glMatrixMode(GL_PROJECTION);
/*
set up the logical graphics space */
glLoadIdentity();
gluOrtho2D(200, 200, 200, 200);
glClearColor(0.0, 0.0, 0.0, 1.0);
glutDisplayFunc(display);
/*
assign the display function */
glutIdleFunc(display); /* assign the idle function */
glutTimerFunc(5, update, 1); /* set up a timer to regularly update
the scene */
glutMainLoop(); /* set everything going */
return 0;
}
1. BSP Trees
Given the following set of 6 polygons with frontfacing normals shown, generate the BSP tree starting with A and adding polygons in alphabetical order. Once that is done generate the far to near sequence of polygons for each of the eye positions (1 and 2).
2. Shading Methods
For each of the following shading models, show how the colour is calculated at the grey point near the center of the triangular polygon.
You can define the normal for the polygon as Np, and the normals at each of the vertices as N1, N2, and N3 respectively.
If any interpolation is used, show which values are used in the computation and how the values for interpolation are defined on the diagram (ie you will need to define some new points on the diagram and draw a line or two).
Flat Shaded
Goraud Shaded
Phong Shaded
3. OpenGL
One of the types of games that we did not code in the course is the ‘fixed gun emplacement’ game, where the player has a cannon at a fixed location, and things are moving towards the player and the player must blow them up by getting the angle right on the projectiles. You can decide what these things are (rocks, aliens, tomatoes) depending on your personal preferences. In this question you are to write the complete code for such a game given the following constraints.
 the cannon should look like a simple cannon – you can assume you have a drawCube() function that draws a cube centered at 0,0,0 with a side of length 2 to help create it.
 the cannon sits in the center on top of a large square green plane
 you can elevate or lower the barrel to change its angle using the I (elevate) and K (lower) keys
 you can rotate the gun to change the direction of the shot using the J (counterclockwise) and L (clockwise) keys
 the canon should show the change in elevation or direction by tilting or moving
 you can change your viewpoint on the scene using the A key to rotate the plane (and everything on it) counterclockwise and D key to rotate the plane (and everything on it) clockwise. Your viewpoint will always be slightly above the height of the plane. (It would be better for you to be able to look over the plane from above and then tilt the plane but we’ll skip that to make the problem easier)
 the F key fires a shot. There can be a maximum of 10 shots on the screen at once
 the shots should follow parabolic paths (like in the real world) so your cannon imparts an initial horizontal and vertical velocity and then gravity pulls the shell back down to the plane
 the ‘bad guys’ come in from the edges of the plane at a random place on the edge
 only one bad guy can be on the screen at any given time (out of a total of 20 bad guys in the game)
 if the bad guy gets hit by a shot the bad guy is destroyed
 if the shot hits the ground then the shot is destroyed
 if any of the bad guys get to the center (where the canon is) then the player loses
 if the player destroys all 20 bad guys then the player wins
 simple sound effects would be nice
 the program should use diffuse lighting, back face culling, zbuffering and perspective viewing
 literate programming is really valuable here so I get a good idea what you are doing
Half of your score is based on the implementation and half of the score is based on your design so I would work out the design first and how you are going to break the program into modules before coding.
Q1: Shading Methods
For each of the following shading models, show how the colour is calculated at the grey point near the center of the triangular polygon.
You can define the normal for the polygon as Np, and the normals at each of the vertices as N1, N2, and N3 respectively.
If any interpolation is used, show which values are used in the computation and how the values for interpolation are defined on the diagram (ie you will need to define some new points on the diagram and draw a line or two).
Flat Shaded
Goraud Shaded
Phong Shaded
Depth Sort
2: Depth Sort
Here is the algorithm we discussed in class:
1. Sort all polygons based on their farthest z
coordinate
2. Resolve ambiguities
3. Draw the polygons in order from back to front
Where step 2 deals with any polygons whose z extents overlap. We start with the furthest polygon and call it P. Polygon P must be compared with every polygon Q whose z extent overlaps P's x extent. 5 comparisons are made. If any comparison is true then P can be written before Q. If at least one comparison is true for each of the Qs then P is drawn and the next polygon from the back is chosen as the new P.
1. do P and Q's xextents not overlap.
2. do P and Q's yextents not overlap.
3. is P entirely on the opposite side of Q's plane from the
viewport.
4. is Q entirely on the same side of P's plane as the viewport.
5. do the projections of P and Q onto the (x,y) plane not overlap.
If all 5 tests fail we quickly check to see if switching P and Q will work. Tests 1, 2, and 5 do not differentiate between P and Q but 3 and 4 do. So we rewrite 3 and 4
3’ is Q entirely on the opposite side of P's plane from the viewport.
4’ is P entirely on the same side of Q's plane as the viewport.
If either of these two tests succeed then Q and P are swapped and the new P (formerly Q) is tested against all the polygons whose z extent overlaps it's z extent.
On the next page draw me an example for each of these 6 cases (1, 2, 3, 4, 5, 3’ or 4’) to illustrate the condition where that case is satisfied but the previous conditions were not. For example for #3 you need to draw a scene where condition 1 and 2 are false, but 3 is true.
Make sure the drawings are clear.
3. OpenGL
One of the types of games that we did not code in the course is the ‘lunar lander’ game, where the player has control of, well, a lunar lander. The lander is falling towards the lunar surface and the player must bring it to a gentle landing. In this question you are to write the complete code for such a game given the following constraints.
 the lunar lander can be a pretty simple model – you can assume you have a drawCube() function that draws a cube centered at 0,0,0 with a side of length 2 to help create it.
 the lunar surface is square, but not flat. An ASCII data file defines the elevated plane as a 50 by 50 grid and gives the height of each element – 0 through 9 with 0 being the surface and 9 being a mountain peak
 the lander starts off in the center of the plane N meters above the grayish lunar surface
 gravity is pulling the lander downwards
 you can thrust upwards using the K key
 you can thrust laterally using the J, L, I, and M keys to move west, east, north, south respectively
 you can change your viewpoint on the scene using the A key to rotate the scene counterclockwise and D key to rotate the scene clockwise. Your viewpoint will always be situated 50 meters above the surface. (It would be better if you could tilt the plane but we’ll skip that to make the problem easier)
 if the player lands in the center of an area of the plane that is flat for 9 squares (ie in the center of a 3X3 cluster of squares that all have the same height) and has vertical velocity < A meters per second, and horizontal velocity < B meters per second then the player wins
 the player has limited fuel and each use of a thruster costs fuel
 if the player runs out of fuel then the player can’t use any of the thrusters
 if the player hits the surface in the center of an area that is not flat for 9 squares (3X3) or hits the surface with a vertical velocity is >= A meters per second, or hits the surface with a horizontal velocity >= B meters per second then the player loses
 simple sound effects would be nice
 the program should use diffuse lighting, back face culling, zbuffering and perspective viewing
 literate programming is really valuable here so I get a good idea what you are doing
Half of your score is based on the implementation and half of the score is based on your design so I would work out the design first and how you are going to break the program into modules before coding.