Homework 5
For this assignment, we implemented a heirarchical modeling system in two
dimensions.
Tasks
We began by developing the Module structure. A Module contians a linked list
of drawing instructions for calls to primitives with their arguments. The user
begins by openning a Module and calling graphics primitives. The primitive
functions called aren't drawn immediately, however. They are added to the
draw record for the Module and are only drawn when the DrawModule() function
is called outside of any open Modules. This allows for proper matrix
manipulation of the points and heirarchical Modules (Modules containing
other Modules which contain other Modules, etc.). Once our primitives and
matrix manipulations were rewritten to follow this scheme, drawing and
manipulating complex (comparatively) scenes became easy. We also created a
View Transformation Matrix and manipulators to allow for the conversion of
real-world coordinates to screen (ppm) cooridinates.
The first required
image is the starship enterprise rendered with the Module system:

Each element is a Module, and there is an over-arching enterprise Module
containing all the elements. Above that is a scene Module which sets the
VTM.
The second required image is a formation of three enterprises rendered several
times:

This image only has one enterprise Module, but the module is used three times
to create a formation Module, which is in turn used three times to create
the fleet.
Extensions
For extensions, I made some pretty pictures:
Fun with the VTM.

Captain! I can't hold her steady!

More fun with the VTM.

A crowd scene.
Questions
- Describe your model structure data type.
Our "Modules" contain a linked list of "Graphic Elements". The GraphicElement
structure contains an opcode (unique int for each drawing function), the number
of arguments, and an array of the arguments. The array is a union of a few
different possible arguments.
- Describe the operation of your DrawStructure routine.
The DrawModule routine starts by checking to see if there is a module open.
If there is, it merely adds itself to the current draw record. If not, it
starts the drawing process. After setting the local transformation matrix to
the identity matrix, it starts executing the operations stored in the
GraphicElement linked list. Using a switch statement, it chooses its actions
based on the opcode. Most operations are straightforward, but drawing another
module within the record is a little bit subtle. The gtm and pen color and
fill color must be saved before recursively calling the DrawModule function on
the Module listed in the linked list. Then, the gtm and colors are restored.
All other cases merely extract the arguments and call the appropriate function.
- What extensions did you do for this assignment, how did you do them,
and how well did they work?
I made some animated gif scenes for my extensions. They worked pretty well, as
you can see above. For the first one, I expanded the view window at an
increasing rate, moving slightly backwards all the while to make it look a
little bit like the ships are moving. For the second, I just made the ship
rotate around a planet and rotate around its own axis at four times that rate.
For the final one, I made the view window follow the spinning ship.
I also made a "crowd" scene of stick figures. The person is a Module, and the
height and location are varied so that the further down on the image the
person is, the larger it will appear, with a bit of randomness thrown in.