CS-460, Assignment 8
Due Date: 5-10-02

In this assignment you are to design and implement Visual C++ 3-D modeling/rendering
program for Windows that enables the user to display and manipulate a perspective view 
of a polygon mesh model of a uniform cubic Bezier surface patch.

When the program first starts, a default view of the projected image of a polygon mesh 
model of the Bezier patch (using the 4-parameter viewing setup discussed in class) should 
appear in the client area of the program's window. The 16 control points for the patch 
and the world coordinate system axes should also appear. The initial view should look 
something like the following:

The program should have a menu bar with the following menu items: "Viewing Parameters", 
"Display", and "Clear". All but the last of these should be popup menus. A set of default 
viewing parameter values should be used for the initial patch image; they should be chosen 
so that the image appears more or less centered in the client area. The initial image 
should be a polygon mesh rendition of the patch. In other words, instead of approximating 
the patch with line segments (as in the notes) you should subdivide the patch into 
polygons. You will need to come up with an array of world coordinate points for the 
vertices of the polygons and the array of polygons, using a systematic numbering
system. In the figure above there are 100 (10 X 10) polygons. Although what the polygons
shown in the figure are quadralaterals, you may want to use triangles instead -- since
triangles are guaranteed to be planar.

The user should be able to adjust the shape of the Bezier patch by selecting control points
and moving them along an axis. One way of doing this is to permit the user to enter the name 
of an axis ("x", "y", or "z") from the keyboard and then click on one of the control points. 
Subsequent presses of the up (down) arrow keyboard key will then cause the control point to 
move by a fixed amount in the + (-) direction along that axis, with the patch redrawing 
itself each time the control point moves. The following figure shows the patch after one of 
the control point has been moved up the z-axis and another out the x axis.

Selecting the "Viewing Parameters" menu item should bring up a popup menu with the 
selections: "Zoom Out" (increase rho), "Zoom In" (decrease rho), "Azimuth +" (increase 
theta), "Azimuth -" (decrease theta), "Polar +" (increase phi), "Polar -" (decrease phi), 
"Screen Dist +" (increase d), "Screen Dist -" (decrease d). In each case, each subsequent 
left click of the mouse should cause an increment or decrement in the chosen viewing 
parameter to occur by some fixed amount. The patch and coordinate axes should then be 
redrawn using the new value of the changed viewing parameter.

The "Display" Popup menu should contain the items "Polygon Mesh" and "Flat Shaded". If the 
user selects "Polygon Mesh", each time the image is displayed it should show all the 
polygons in the patch. They should not be filled (i.e., the background color should show
through each polygon). If the user selects "Flat Shaded", you are to use the Phong 
illumination/reflection model (discussed in class) to display a flat shaded image of the 
Bezier patch. The program should mathematically position a light source with some 
intrinsic intensity somewhere in the 3-D scene. Then using the Phong model with diffuse 
reflection only and a single color for the patch,(e.g., green, so that kg=1, kr=kb=0), 
it should calculate the intensity of light reflected from each polygon in the patch. 
Each result should be scaled to one of the 256 possible green values (0-255) and each 
polygon filled with the resulting color. (We're assuming here that a Windows system with 
24-bit "True Color" is being used. If that is not the case, Windows will dither the colors 
and the image will not be as nice as it should.)

The light source should appear as a point in the image which the user should be able
to select by clicking on it and then, as in the case of the control points, move the 
light source. The following figure shows the kind of image you should get. (Unfortunately, 
in capturing the image from the program, some of the color information was lost -- it 
really lookd much nicer in the program.)

(It should be pointed out that since you are not doing hidden surface removal, for some 
configurations of the patch you may see strange effects like nonexistent holes -- see the 
Extra Credit below.)

Some additional hints:

In order to facilitate the flat shading option, you will eventually want to store other 
information with each polygon in the polygons array. This information might consist of 
data such as the polygon's outward-pointing normal vector and the polygon's diffuse 
reflection coefficients or perhaps its computed color.

After the program computes the 3-D points and polygons arrays, it should perform the 
viewing/projection/window-to-viewport transformations (discussed in class) on each point, 
giving a 2-D array of screen coordinates that is parallel to the 3-D points array. Use 
values for the spherical coordinates (rho, theta, phi) of the viewer's initial position
and for the distance between the viewer and the screen that make the object fit nicely in 
the middle of the window's client area. (These values, of course, are used in the 
transformations.) Once the 2-D screen coordinates of all of the points are calculated, 
the polygons should be drawn in the display area of the screen. How the polygons are 
displayed will depend on what the last choice of "Render Mode" was. The program should 
also display the x, y, and z axes of the world coordinate system in a different color. 
(i.e., apply the chain of viewing/projection transformations to the 3-D coordinates of 
each endpoint of each axis and draw the resulting 2-D lines.)

The next stage consists in adding the interactive "Viewing Parameters" feature to the 
program. Here, once the new value of rho, theta, phi, or d is obtained, each 3-D point 
in the model will have to go through the viewing/projection/window-to-viewport pipeline 
to compute the new 2-D screen coordinates. Then the polygons will be redrawn. Notice 
that the viewing transformation matrix elements will have to be recomputed any time rho, 
theta, or phi is changed.

EXTRA CREDIT: You may choose to do as many of the following as you like:

For up to 15 points extra credit, include specular reflection in your flat-shaded rendition. 
In the most simple implementation, there could be a menu item which gives several possible 
values for for the specular reflection coefficient and specular exponent. The values chosen 
should then be used in the Phong model.

For up to 20 points extra credit, implement Gouraud interpolated shading as a rendering 
option (in addition to the flat shading option).

For up to 20 points extra credit, implement Z-buffer hidden surface removal.