CS-460/560, Assignment 7
Due Date: 4-27-2010

CS-460 Students should do all of the following except the implementation 
of the "Transformations" menu item.

CS-560 students should do all parts of the assignment.

In this assignment you are to write a Windows MFC program that implements 
a polygon mesh model of a 3-D scene and displays a perspective view of it 
in the program's window client area. The scene should contain at least four 
objects: for example, the ground, a house and two trees. The ground could 
be a single big rectangle upon which the other objects are placed. The 
house could be a 10-vertex (or more) polyhedron, one tree a cone on top of 
a cylinder (pine tree) and the other a sphere on top of a cylinder 
(deciduous tree). You may add other objects as desired. (Trying to model a 
car or a human figure would be very interesting and worth up to five points 
extra credit!) The 4-parameter viewing setup discussed in class should be 
implemented. A set of default viewing parameters should be used for the 
initial image so that the objects appear more or less centered in the client 
area. The initial image should be a polygon mesh rendition with no hidden 
faces removed.

In addition to displaying an image of the scene, the program should also
allow the user to interactively change the viewing parameters (rho, theta,
phi, and screen distance). This might be done by having a "Viewing
Parameters" popup menu with the following 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, the increment or decrement in each viewing parameter
should be some fixed amount. Each left click of the mouse in the window 
client area should repeat the effect of the current "Viewing Parameter" 
selection. In other words, if the user last clicked on the "Zoom Out" menu 
item, each subsequent click in the window's client area should increase rho 
by the same amount and redraw the scene.

A "Render" Popup should contain the menu items: "All Faces" and "Remove
Hidden Faces." If the user selects "All Faces", each time the image is
displayed the program should draw ALL the polygons in the scene. They 
should not be filled (i.e., the background color should show through each 
polygon). If the user selects "Remove Hidden Faces", only those polygons
facing toward the viewpoint should be displayed. The back-face culling
technique discussed in class should be used to determine which polygons
are visible. Again the background should show through the polygons.

A "Fly Around" menu item should cause the viewpoint to move about the
scene. For example it might zoom in on the scene, rotate about it in the
azimuthal and polar directions and then zoom out again. After each change
in rho, theta, and phi, the old image should be erased and the image as
seen from the new viewpoint should be redrawn. The effect will be that of
a fly around the scene. You may choreagraph the details of this as you wish.

The following part (in bold letters) is only for CS-560 students:

A "Transformations" popup menu should have the following options:
"Translate x +" (move objects in the + x direction), "Translate x -" (move
objects in the - x direction), "Translate y +" (move objects in + y
direction), "Translate y -" (move object in - y direction), "Translate z
+" (move objects in + z direction), "Translate z -" (move objects in - z
direction), "Rotate x +" (rotate objects in + sense about x axis), "Rotate
x -" (rotate objects in - sense about x axis), "Rotate y +" (rotate objects
in + sense about y axis), "Rotate y -" (rotate objects in - sense about y
axis), "Rotate z +" (rotate object in + sense about z axis), "Rotate z -"
(rotate objects in - sense about z axis), "Scale +" (make objects larger),
Scale -" (make objects smaller). For the translations, a fixed distance
increment or decrement should be used; for the rotations a fixed angle of
rotation should be used. For scaling, the sx, sy, and sz scaling factors
should be the same (uniform scaling). In the case of "Scale +", the
scaling factor should be greater than 1; for "Scale -" it should be less
than 1. For all of these transformations, the objects should be redrawn in
their new positions; As in the case of "Viewing Parameters," each subsequent
left click in the window client area should repeat the effect of the
current "Transformations" selection. The coordinate axes (x, y, z) should 
also be displayed, perhaps in a different color, when the user has selected 
any of these transformation menu actions.

This assignment should be done in stages. First polygon mesh models of
each object you choose to implement should be created. For each, choose a
convenient modeling coordinate system and define an array of 3-D points,
each of which lies on the surface of the object. (How you do this will
depend on the geometry of the object. For a house, for example, simply 
list the x-y-z coordinates of each of the house vertices as in the pyramid
example given in class; for other objects, the points may have to be
generated procedurally as outlined in the cone and sphere examples 
mentioned in class.) After the program computes the 3-D points for each
object, an appropriate modeling transformation (3-D translation, scaling, 
and/or rotation) should be applied to each point to position it in the 
scene. The result will be an array of 3-D world coordinate points.

For each object, you should also define an array of polygons, each of
which represents one face of the object. Each element of this array should
contain the number of vertices of the polygon and a list of indices into
the 3-D points array that specifies which points constitute the vertices
of the polygon in question (as in the pyramid example in class). Both this
array and the points array should be defined in a systematic way for each 

After the program computes the 3-D world coordinate points array and the
array of polygons for each object, 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 d 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

The next stage consists in adding the interactive "Viewing Parameters"
feature to the program. Here, once a 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 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 computed each time rho, theta, or phi is
changed. CS-560 students will also have to implement the "Transformations" 
menu item actions. 

The next (final) assignment will build on this assignment, so it is very
important that you get this assignment done correctly.