CS 351: Assignment #6

### Hierarchical Modeling System

Due midnight 20 October 2008 (Monday night)

In this assignment you'll implement a hierachical modeling system in 2D and learn how to build scene graphs using primitives and matrix transforms.

Read the entire assignment before starting. If you don't, bad things will happen.

The Graphics System Specification outlines the functions required for a 2D hierarchical modeling system that allows you to create modules and draw them. You will create a new set of functions for inserting graphics primitives, transforms, and other attributes into an open module. Each function will do approximately the same thing: put an instance of the object, transform, or attribute on the module's list.

As indicated in the graphics spec, the only required visual objects for the modeling system will be points, lines, polylines, and polygons. All of these primitives are described by one or more Point types. The important thing to remember about the insert function for these items is that graphics primitives need to be copied into the module so that the module has a local copy of the points constituting the object. If you do not copy the data into the module, bad things will happen.

The exception to the copy rule is inserting one module into another. In that case, a pointer to the sub-module needs to be stored in the parent. Modules should not be copied when they are inserted into another module. If you make copies of modules, bad things will happen.

The only tricky function to write is the function that actually traverses a Module's list and draws the scene onto the screen. The lectures notes include an algorithm for proper traversal of the scene graph. The most important aspect of the algorithm is how to organize the matrices.

• Within the context of traversing the elements a single module, use a local transformation matrix, the LTM, to hold all of the matrix operations. Left multiply new matrices onto the LTM. If you right multiply, bad things will happen.
• When the Module_draw() function begins, it will be handed two matrices, the view transformation matrix [VTM] and the Global Transformation Matrix [GTM]. All points should be multiplied by the LTM, then the GTM and then the VTM before they are drawn on the screen. Remember that the original points stored in the module should never be changed. Use temporary points to hold the results of transforming the original points. If you modify the points stored in a module, bad things will happen.

Pscreen = VTM * GTM * LTM * Porg

• When the function Module_draw() gets called recursively, the GTM argument handed to the function should be the product of the GTM and the local LTM.

GTMpass = GTM * LTM

### Viewing Transforms

For this assignment, you will only need to have a 2D viewing transform that is specified by the view window in world coordinates and the screen size in pixels. In the next assignment you will be executing a 3D viewing transformation. The graphics specification for this week includes the function Matrix_2DView(Matrix *m, 2DView *view) that takes in the view information stored in 2DView and returns the matrix that generates the view.

### Required Images

1. Run the C code using your system. The program taks up to 3 arguments on the command line.
2. Create a formation of at least 3 models (starships/planes/trains/cars/whatever) as a hierarchical structure and then create a scene containing at least three formations acting independently.

### Extensions

• Use the modeling commands creatively to develop complex scenes.
• Create animated sequences and build an animated GIF.
• Enable ellipse and circle drawing with general transformations (hint, use polygons).
• Add Module_PopMatrix and Module_PushMatrix commands to store and restore transformation matrices.
• Write routines for reading in lines or polygons from a file so you can create complex polygons using a text editor.
• Write routines that let you read in and write out modules from a human-editable file so you can create stuff off-line.
• Allow the use of run-time parameters in your structures. In other words, you would have to be able to specify when you build a structure that some of the parameters are not fixed, but should be gotten from the user when they execute a Module_draw() command. Then, your Module_draw function would include, not only a pointer to the structure, but also a pointer to the run-time parameter values. If you do something like this, it allows you to execute animations without having to recreate your structures for each frame. (tricky, but doable)

### Writeup

All writeups should suggest the format of a lab report. They do not have to be long, but need to provide enough information that I have some idea you knew what you were doing.

1. Abstract: 200 word description (at most) of what you did and a picture to go along with it.
2. Description of the task, in your own words. Be brief, but write it as though explaining it to a fellow student not in the course.
3. Description of how you solved the task, including any key equations or algorithms. You should also include algorithms or descriptions of what you did for any extensions. Include pictures here.
4. More pictures. Please put a caption on each picture explaining something about it. If you have nothing else, give it a name and indicate whose picture it is.
5. Summary of what you learned.

### Handin

Put your code files in your handin folder. Send the prof an email with the URL for your writeup (wiki or standard web page) when it's done. In either case, please edit the assignment handin page on the wiki so there is a link to your assignment.