description.
For this lab, we developed a 2D hierarchical modeling system that allows us to create structures and draw them and integrated it with our graphics environment so that the appropriate graphics variables get passed to the graphics primitive routines.
questions.
1. Describe your model structure data type.
Our model structure is a linked list. At every node of our linked list we have an opcode and an array of variables related to it. If we want to translate a structure for example, the opcode TRANSLATE is added to the list, and the variables are stored. If the want to add a structure to the model structure, it gets added just like any other opcode, but the arguments are stored as another linked list. Later, when we go to the draw mode, this linked list gets called recursively and we get the desired structure drawn.

fig1. diagram showing the model structure.
2. Describe the operation of your DrawStructure routine.
We defined a global variable "mode" and by default the mode is "DRAW". When beginStructure(&structurename) is called, the mode becomes "BUILD" and we add the commands to our model structure. For every command, we add to the linked list a node associated with that command (see fig1). When we're done with adding commands, we call endStructure which makes mode "DRAW" again.
After this, a drawStructure (&structureName) command draws the structure by going throught the linked list. Every opcode needs to be handled differently (although similarly), so for every opcode we have a different case statement that takes care of them. The hard part is to handle a DRAWTRUCTRE opcode, but that is taken care of by recursion.
3. Describe how you made use of hierarchical modeling when you made your starship. Somehow show a representation of the final structure graph.
Let's take a look at CROWN-1 below. We first start with defining the basic structures that'll be used to build sub-structures; wing, gun, main-body. Then we scale, rotate, translate... these basic structures to form a somewhat more complex structure (in this case the DUDE-xyz5 structure). Once we are done with that, we can then use all of our basic structures AND the structures we have developed so far to construct other structures. In fact we can keep doing this and create more complex structures easily.
Here's a sample routine for creating CROWN-1:
--creating basics
beginStructure(wing);
... define points
endStucture();
beginStructure(mainBody);
... define points
endStucture();
beginStructure(gun);
... define points
endStucture();
--creating DUDE-xyz5
beginStructure(DUDE-xyz5);
...rotate, translate, scale...
drawStructure(wing);
...rotate, translate, scale...
drawStructure(wing);
...rotate, translate, scale...
drawStructure(gun);
...rotate, translate, scale...
drawStructure(gun);
...rotate, translate, scale, color...
drawStructure(gun);
...rotate, translate, scale...
drawStructure(gun);
...rotate, translate, scale, color...
drawStructure(mainbody);
...rotate, translate, scale, color...
drawStructure(wing); //orange window
endStructure();
--creating CROWN-xyz5
beginStructure(crown);
...rotate, translate, scale, color...
drawStructure(DUDE-xyz5);
...rotate, translate, scale, color...
drawStructure(DUDE-xyz5);
...rotate, translate, scale, color...
drawStructure(DUDE-xyz5);
endStucture();
once we're done with definitions, then we can do:
translate, rotate...
drawStructure(crown);
and this would put the crown structure into the scene |
 |
| fig2: Pieces of the starship. The engines and the guns are the same structure; the engines are scaled. Wing 2 is wing 1 rotated. |
 |
| fig3: DUDE-xyz5: The starship put assembled with appropriate transformations. The orange window is actually a wing rotated and scaled (don't tell anyone) |
 |
| fig 4: CROWN-1: This structure is three DUDE-xyz5's put together with proper transformations. |
|
4. What extensions did you do for this assignment, how did you do them, and how well did they work?
To extend this lab, we made animated gif sequences that demonstrate different structures acting independently of each other. Doing the animations wasn't hard; once we had the hierarchical modeling system set up, we defined the behavior of each structure in the scene and generated the frames in a for loop and it worked pretty well.
animation 1: four structures acting independently

animation 2: fleets of enterprises flying around
|