Hierarchical Modeling System - Writeup
Phil Katz and Stephen St.Vincent
home   |   images
Lab description


Lab summary:

For this lab we implemented a module structure. The purpose of this structure is to allow our system to draw multiple instances of a given object (with different scale, rotation, and locations) with ease.

The module was implemented as a list of "elements", that could be either an object to be drawn or a matrix transformation to be applied to the next drawn element.


Questions:
  1. Describe the operation of your DrawStructure routine.
    Our structure drawing routine recursed through the module structure, which was implemented as a linked list. Each item in this list was an Element structure, which has a "type" field and a void pointer to an object. If the type field specified a point, line, polygon, or polyline, then we drew that object to the image after multiplying it by the LTM, GTM, then VTM. If the type was a matrix, we multiplied the current LTM by that matrix. Similarly, if the type was "identity" then we set the LTM to the identity matrix. If the object was a color, we changed the current drawing color. Finally, if the type was a module, we called our structure drawing function recursively, passing the object field of the element as the module and the product of the current GTM and LTM as the new GTM. The function ended whenever the head pointer to the module was null.

  2. Describe how you made use of hierarchical modeling when you made one or more of your images. Show the code for your main program where you create the module, and then somehow show a representation of the module as a graph.
    We created a Cake module that was just the cake (see image 3). For each image in the animated gif, we create a Scene module. For each individual Cake in the Scene, we add the necessary matrix operations, then add the Cake module. While the Cake was reusable, the Scene unfortunately was not.

    Below is the code for creating the Cake module, assuming that there is already a Polygon p and a Line line:

    Cake = Module_create();
    Module_addPolygon(Cake, p);
    Module_addColor(Cake, Yellow);
    Module_scale2D(Cake, 0.75, 0.75);
    Module_translate2D(Cake, 10, -29);
    Module_addPolygon(Cake, p);
    Module_addColor(Cake, Pink);
    Module_scale2D(Cake, 0.75, 0.75);
    Module_translate2D(Cake, 10, -29);
    Module_addPolygon(Cake, p);
    Module_addColor(Cake, Green);
    Module_translate2D(Cake, 10, -12);
    Module_addLine(Cake, &line);
    Module_translate2D(Cake, 10, 0);
    Module_addLine(Cake, &line);
    Module_translate2D(Cake, 10, 0);
    Module_addLine(Cake, &line);


    Next is the code for creating one Scene:

    Scene = Module_create();
    Matrix_identity(>M);
    Matrix_identity(&VTM);
    Module_translate2D(Scene, 100+i, 100+i);
    Module_addModule(Scene, Cake);
    Module_identity(Scene);
    Module_translate2D(Scene, 100+2*i, 100+2*i);
    Module_addModule(Scene, Cake);
    Module_identity(Scene);
    Module_scale2D(Scene, (float)i/(float)n, (float)i/(float)n);
    Module_translate2D(Scene, 400, 100);
    Module_addModule(Scene, Cake);
    Module_identity(Scene);
    Module_translate2D(Scene, 50, 50);
    Module_rotateZ(Scene, cos((float)i/(float)n*2.0*3.1415926),                                 -sin((float)i/(float)n*2.0*3.1415926));
    Module_translate2D(Scene, 400, 400);
    Module_addModule(Scene, Cake);
    Module_draw(Scene, &VTM, >M, LtGrey, src);


    Next are the "graphs" for our Scene and Cake modules:

    Scene
    |
    |-Translate2D(100+i, 100+i);
    |
    |-Cake
    |
    |-Identity
    |
    |-Translate2D(100+2*i, 100+2*i);
    |
    |-Cake
    |
    |-Identity
    |
    |-Scale2D(i/n, i/n);
    |
    |-Translate2D(400, 100);
    |
    |-Cake
    |
    |-Identity
    |
    |-Translate2D(50, 50);
    |
    |-RotateZ(cos(i/n*2*pi), sin(i/n*2*pi));
    |
    |-Cake
    |
    |-Draw


    Cake
    |
    |-addColor(grey)
    |
    |-addPolygon(p)
    |
    |-addColor(yellow)
    |
    |-Scale2D(0.75, 0.75)
    |
    |-Translate2D(10, -29)
    |
    |-addColor(grey)
    |
    |-addPolygon(p)
    |
    |-addColor(pink)
    |
    |-Scale2D(0.75, 0.75)
    |
    |-Translate2D(10, -29)
    |
    |-addColor(green)
    |
    |-addLine(line)
    |
    |-Translate2D(10, -12)
    |
    |-addLine(line)
    |
    |-Translate2D(10, 0)
    |
    |-addLine(line)


  3. What extensions did you do for this assignment, how did you do them, and how well did they work?
    We did not do any extensions for this assignment.