# EECS 488: Assignment 2

## Clipping Polygons & 2D Matrix Transformations

Out: 2/13/96
Due: 3/05/96 at 4:00pm

In this assignment you will implement the Cohen-Sutherland line clipping algotithm, the Sutherland-Hodgman Polygon Clipping algorithm, and perform interactive 2D transformation composition in homogeneous coordinates as discussed in class and in the textbook using C and Mesa. This will show you how the frame buffer works in dynamic situations, and how transformations affect the user's view of the model.

Since you implemented your own line drawing routine in the first assignment you can now use the OpenGL version in this assignment. You may not however use any of the OpenGL matrix commands or viewport commands.

You can find a shell for the program here

Your program should be run as:
assignment2 polygon-file-name

where polygon-file-name is in the same format as in the first assignment. This time, however, the coordinates of the polygon are in world-space. The polygon will be drawn as a connected series of white line segments. As in the first assignment the polygon can be concave with crossing edges.

The space should also contain a green X axis (worldspace Y=0) and Y axis (worldspace X=0.) The axis (which should be at least 1000 units long in workd-space) will allow you to see the relative movement of the polygon when its transformation matrix is altered.

You will need to maintain two transformation matrices, one for the polygon, and one for the viewport. These matrices will be controlled from the keyboard:

`left  arrow: move viewport left 5 units of worldspaceright arrow: move viewport right 5 units of worldspaceup    arrow: move viewport up 5 units of worldspacedown  arrow: move viewport down 5 units of worldspacej key:       move the object left 5 units of worldspacel key:       move the object right 5 units of worldspacei key:       move the object up 5 units of worldspacek key:       move the object down 5 units of worldspacea key:       scale the object by 110%z key:       scale the object by 90%f key:       rotate the object 10 degrees counterclockwiseg key:       rotate the object 10 degrees clockwise`

Once the polygon is read in, its coordinates should not change. It will only be affected through changes made to its transformation matrix. Both the axis and the polyogn will be affected by changes to the viewport transformation matrix. Initially the axis should be centered in the viewport.

To draw the scene you will need to apply the appropriate transformations to the polygon and the axis and then clip them against a viewport that is smaller than the window by 10 pixels on each side. OpenGL will automatically perform clipping at the boundary of the window but you are responsible for clipping to this smaller region (using line clipping for the axis and polygon clipping for the polygon.) As discussed in class, the polygon clipping algorithm may introduce new edges at the borders of the clipping rectangle - this is OK.

As with assignment 1, your program should be well commented and be a good example of literate programming; again it will be submitted electronically; and again be sure it can be compiled and executed with acc and Mesa on the EECS suns.

I would suggest first creating the axis, and the viewing transformation matrix so you can see if you are moving the viewport correctly. Then add in your existing code to read in the polygon and draw it; then add in the code to modify the objects's transformation matrix. Finally integrate the line clipping and polygon clipping routines.