Math 155  - Winter 2001
The ModelView program

The ModelView program will let you experiment with using 4x4 matrices to perform transformations in 3-space.  The purpose of this program for this class is twofold:

• Gain experience with model view transformations.  This will be helpful in understanding how to compose transformations in your own OpenGL programs.
• Provide an example of how to use MFC widgets (specifically the dialog box).   Learning how to do this is *optional* for this class, since you can use the "glut" routines to control your programs via keyboard input or via popup menus.

Getting started:  Find the ModelView program in the public (P:) Projects folder.  Copy the project to your Projects folder.  Compile and run.  Try the following items:

• Note that you can toggle between displaying a solid letter "F" and a teapot.
• Enter a scaling transformation: for instance make the diagonal entries of the matrix "2", "1" and "0.5" and then press the Apply button.  Observe what happens.  Which axes are the x, y, z axes?  Does this make sense?  Is it a righthanded coordinate system?
• Enter a transformation that rotates around the y-axis:
 ( ) 0 0 -1 0 0 1 0 0 1 0 0 0 0 0 0 1
• Try some translation transformations (by setting the three upper entries in the fourth column).
• For fun: what happens if you use the identity matrix, but change the lower right 1 to 2 (or to 0.5)?  Why does this happen?
• (This is harder than the above.)  Figure out what matrix makes a 45 degree rotation around the z-axis.  Then find the matrix that makes a 45 degree rotation around the x axis.

Composing transformations.  The other buttons can be used to compose transformations, e.g., to see the effect of a translation followed by a rotation (or vice-versa.)
The operation of the program is little difficult to explain, but here goes:  There are 3 matrices that are being maintained, there is a matrix M (main matrix), a matrix C (current matrix) and the displayed matrix D.    The transformation that is applied to the teapot or the letter F is the matrix CM. (the matrix product).

Initially all matrices are the identity.   The D matrix is what you edit on the screen.  The buttons on the dialog have the following functions:

• Apply: sets C := D.  No change to M.
• Reset and Apply: Sets M equal to the identity and C := D.
• Premultiply and Apply: Sets M := CM.  Then sets C := D.
• Identity Matrix.  Sets D equal to the identity.

Important:  The transformations are composed by pre-multiplying.   This is the easy way to intuitively create and visualize the composition of transformations.  However, in OpenGL, transformations are post-multiplied, so your programs have to apply the transformations in the reverse order from how you apply them in this demonstration program.

Try it out: Smooth vs. Flat shading:  Find the place in the code where the teapot is drawn in ModelviewView.cpp.  Change GL_FLAT to GL_SMOOTH to do smooth shading.  (Make sure you change the place where the teapot is drawn, not the "F".  Then recompile and run the program again.  How does this change the appearance of the teapot?    You might want to scale the teapot by a factor of 2 or 3 to see the difference more clearly.  Can you see the individual polygons in the smooth shading mode?
Explanation:  The teapot's surface is being approximated by a slot of small more-or-less rectangular polygons.  In the "smooth" mode,