CS-460/560, Assignment # 6
New Due Date: 4-13-2010

Part A.

In this part of assignment you are to write a Visual C++ MFC program that 
implements the 2-D viewing transformation and the Sutherland-Hodgemen polygon
clipping algorithm discussed in class. The program should perform the 
following tasks:

1. Specify the coordinates of the lower-left-hand corner and upper-right-hand 
corner of a rectangular clipping window in a world coordinate space such that  
-5 <= x <= 5 and  -5 <= y <= 5. An example might be (-0.8,-2.5), (0.7,1.0). This 
can be hard-coded.

2. Specify the world coordinates of the vertices of the polygon to be clipped. 
An example might be the list: (-1.5,0.5), (0.5,1.5), (1.3,0.2), (1.3,-1.0),
(0.6,-1.9), (-0.5,-1.9), (-1.5,-1.0). These can also be hard-coded.

3. Specify the coordinates of the upper-left-hand corner and lower-right-hand 
corner of two non-overlapping, rectangular viewports on the screen. Examples 
might be (40,40), (290,190) and (310,290), (560,440). (Here it is assumed that 
the client area is at least 570 X 460 pixels.) These also are to be hard-coded.

4. Perform a window-to-viewport (viewing) transformation on the polygon to the 
first viewport in # 3 above. The resulting polygon should be displayed in some 
color that is not the same as the color of the first viewport so that the user 
can observe both the polygon and the viewport. (Portions of the polygon should 
lie outside of the viewport.)

5. Clip the original polygon to the world coordinate window specifed in # 1 
above. The Sutherman-Hodgeman polygon clipping algorithm should be used. The 
result should be a new list of polygon vertices.

6. Perform a window-to-viewport (viewing) transformation on the clipped polygon 
to the second viewport specified in # 3. The resulting polygon should be 
displayed in some color that is not the same as the color of the second 
viewport so that the user can observe both the clipped polygon and the viewport.

The final display will show the unclipped polygon in the screen's first 
viewport and the clipped polygon in the screen's second viewport.

The above procedure should be repeated  for at least two other polygons that 
you define, using different windows and viewports.

Hint: To implement the viewing transformations, you can use the result derived
in class for the x-coordinate equation, but you will have to derive the 
correct y-coordinate equation because of the window client area's downward 
pointing y-axis.)

For up to 10 points extra credit implement the clipping using the Weiler-
Atherton polygon clipping algorithm.

Part B.

In this part of the program you are to write a Visual C++ MFC program that 
allows the user to "draw" a uniform cubic Bezier curve in response to choosing 
a "Bezier" menu item. When this item is chosen, the program should permit the 
user to input four control points with the mouse. Each click of the left-hand
mouse button provides a new control point, which should be drawn as a small 
rectangle on the screen. After the fourth control point is entered, 
the program should draw the uniform cubic Bezier curve determined by the 
control points that were entered.

After the Bezier curve is drawn, the program should permit the user to use the 
left-hand mouse button to adjust the curve by moving any of its control points. 
This should be done in response to choosing a "Move Points" menu item. After 
choosing that menu item, pressing the left-hand mouse button over a control 
point selects that point. While the button is down, the user moves the mouse to
position the control point. The control point's rectangle should "follow" the 
motion of the mouse on the screen, and a rubber band Bezier curve that reflects 
each new position as the selected control point moves should be continually 
redrawn. The curve should be made "permanent" when the user releases the left 
mouse button. This adjustment of the curve by moving selected control points 
should continue until the user selects some other menu item.

[Hint on rubberbanding: Think about using the R2_XORPEN or R2_NOTXORPEN rasterop. 
The first time a curve is drawn in this mode it will appear in the current pen 
color; if  the same curve is redrawn a second time in in R2_XORPEN or R2_NOTXORPEN 
mode (depending on the background color of the window's client area), it will
cause  the curve to disappear. The rasterop is an attribute that can be set by
making a call to CDC::SetROP2(). See the on-line help.]

You are required to compute each new Bezier curve by using the Forward
Difference method discussed in class.

For up to 10 points extra credit add a menu item that permits the user to extend
the Bezier curve by adding groups of 3 extra control points. For each new group of
three control points a new curve segment will be added to the right-hand end of
the curve. There should be level-0 and level-1 continuity between the segments, as
discussed in class.