CS-321 Lab 7: 3-D Transformations and Perspective

[Sample 3-D GUI]

Overview

In this lab you will build upon an existing matrix class to create a transform class. This transform class will be used to render polyhedra from a user-specified viewpoint using a perspective projection. This is a 3-week lab with two phases. A report is due for each phase as outlined below.

These examples show how the application will allow viewing of a model much as a camera allows viewing of the world.

Demonstration (during Friday lecture of week 10)

You will need to demonstrate your final project to the instructor during the week 10 Friday lecture. The demonstration will count for 25% of your Phase II project grade.

Activities


  1. Develop a transform class built around a matrix class. Use this matrix class class, which is free for educational use. Provide functions (perhaps including operator overloading) so that a convenient coding style for applying transforms is supported. The following is an example of one such style. "QPoint3" represents a 3-D point (not actually a Qt class).
        Transform T;
        T.applyTranslate(deltax, deltay, deltaz);
        math::matrix<double> u(3,1), v(3,1), V(3,1), n(3,1), N(3,1);
        // calculate V and N
        u = cross(V,N);
        u /= u.norm(); // normalize u
        // more calculations
        T.applyBasisChange(u, v, n); // objects aligned with u are now aligned with x, etc.
        // apply a perspective transformation
        // ultimately polyhedron::Draw will need access to this transformation
        // ...
        QPoint3 p; // and initialize somewhere
        QPoint pprime = T * p; // transform a single point, accounts for non-unity h, discards z
        QPointArray psPrime = T * myContainerOf3DPoints; // transform a bunch of points (perhaps in a matrix)
  2. Develop a polyhedron class. Objects of this class could just contain a container of line endpoint pairs (but not line objects – that would be inefficient – a polyhedron has 1 color, is read as a single object, etc.). A better implementation would only maintain one copy of each vertex, but this is not required.
  3. Allow the specification of polyhedra using files. The files lab7a.dat (cube), lab7b.dat (tetrahedron), and box.drg ("building" used in figure above) contain examples that specify a polyhedra as a set of edges. (i.e., There are two 3-D points per line. This is not the best long term specification, but it is sufficient for the requirements of this assignment.) You may find it necessary to edit these files to conform to your polyhedron::Read.
  4. When it is time to Draw each polyhedron, you should perform the device transformation (invert the y direction and move the origin to the center of the drawArea).
  5. Allow the user to specify the observer position, the point the user is looking at (which will be rendered in the center of the window), and the look-up direction. The user must also specify the distance to the projection plane from the observer (which is also used as the projection reference point).
  6. An interface that allows the user to easily change a single parameter while being aware of the overall set of viewing parameters is required. See the figure for one example of such an interface.
  7. Augment your derived shell class so that the Zoom, UnZoom, Erase, and Reset buttons work as follows:
    • Zoom—perform a zoom by a factor of 2 by doubling the distance from the observer to the projection plane. (By definition, zoom means moving the projection plane, not the observer.)
    • UnZoom—perform an unzoom by a factor of 2 by halving the distance from the observer to the projection plane.
    • Erase—erase your image and update() the drawing area.
    • Reset—reset the user inputs to some reasonable default values (what is reasonable, exactly, depends on the image, but you can used fixed defaults – up should be specified as preferring the positive y direction, the projection plane should be between the observer and the look at point, etc.) and draw the image.
  8. When it is time to update the view (e.g., the user pressed a particular button), you should calculate a composite transform that moves the drawing into the correct position (viewing transformation) and performs the perspective transformation.

Hints

There are plenty of areas for extra credit with this assignment (e.g., surface modeling and animations [pans, zooms, etc.]), however you must complete the basic requirements in order to receive the extra credit. Consult with your professor in advance before adding extra-credit elements to your program.

Phase 1 Lab Report (due by 11 P.M., the day of the week 9 lab): Transformation Class

Your lab report need not be self-contained. This means that it is not necessary to restate the entire specification in your report.

Phase 2 Lab Report (due by 11 P.M., Friday of week 10): Working 3-D System

Your lab report need not be self-contained. This means that it is not necessary to restate the entire specification in your report.

Course Objectives Addressed