CS 351 Assignment 6: Hierarchical Modeling Systems
Justin Russell, Nicki Ciociolo-Hinkell, & Adam Lowenstein
In this assignment, we created a library of two-dimensional transformations and implemented them using a hierarchical modeling system. Unlike previous projects, the transformations in this assignment were not applied directly to lines, circles, polygons, etc. Instead, we considered points, lines, matrices, and other shapes to be elements. Then, using a linked list, we combined various elements into different figures and created objects that called modules. Each module had its own relative coordinate system and could be translated, scaled, sheared, and rotated without disrupting the rest of the image. Creating duplicates was as easy as making a new instance of the same module,.
To create complex images (like those seen below), we organized modules in a hierarchical structure. The biggest module (generally known as the Scene module) formed the canvas for the image, and "smaller" modules (those lower in the hierarchy) were added to the linked list of a larger module. In turn, when the larger module was altered, the smaller element would be transformed correspondingly. The image below was created using test code provided in the assignment:
We defined three data types for this assignment: objects, elements, and modules. An object could be any of the shapes or primitives that we had generated in earlier assignments, including points, lines, pixels, polygons, and matrices. An element consisted of an object and a pointer to the next object (used in turn to implement the linked list). Finally, a module consisted of two pointer elements: head, which referred to the head of the linked list, and tail, which referred to the last object in the linked list. Every element then pointed to the next element.
After defining these data types, we created basic operations for elements, including functions to initialize and delete different types of elements. These functions were used to create a variety of module operations. We then used the module functions to create and manipulate various images. The first image we generated (after countless hours of debugging) was the result of Professor Maxwell's test code. It is pictured in the Abstract section above. After successfully generating that image, we each created animations involving a variety of different modules and module transformations. These images are show in the Algorithms & Pictures section below.
Algorithms & Pictures
The following image was created by Nicki: My images contain 3 cars crashing. In the first images, they are moving along across the image towards each other. My code is actually set up to set the given arguments as distance between modules (cars) rather than locations of cars. I thus needed to run my code several times before managing to fit all my vehicles in the same window. So. The yellow car is chugging along and the blue car is charging toward it and the red car is tailing the blue car. They get closer and closer. Then the blue car hits the yellow car. I was contemplating jamming the hoods up a little but I didn't have time to work out the details. In the last image, the red car joins the crash.
The following image was created by Justin: The scene depicts three ships following different trajectories. The ship farthest left follows a straight path, the one farthest right is spinning out after being shot down (possibly by CS351 Assignment 6), and the middle ship goes out a ways before turning around to come back after thinking better of its quest (most likely CS351 Assignment 7). Each of the three ships is actually a copy of the same basic ship structure, which is in turn made up of distinct polygons. I preformed a series of transformations and rotations on the individual copies to get the resulting animation that you see. The fire propulsion for the ships was accomplished by creating polygons with variable vertices and variable colors (within a red/orange range) then altering their values for within each frame of the animation.
The following image was created by Adam: This image is of a Brohan doing a front flip on a diving board. I used four modules to create the scene: the Brohan (the smallest element), the Board, the Pool, and the Scene (which forms the overall image). To make the Brohan do a front flip, over the course of the animation I had different variables and parameters change depending on what part of the animation was currently executing. I created the motion of the Brohan's flip by moving the module back to the origin, rotating by a small percentage of pi/2, and then moving the module back to its correct location before translating it by a small amount. I created the bending of the diving board using a vertical shear. Shred on, Brohan!
In this project, we created a substantial library of functions to create, control, and transform modules. The hierarchical modeling system that we now know how to implement is a powerful tool for generating complex images with minimal "busy work," so more time can be spent on creative design. We also learned the importance of creating correct code the first time around... after fixing numerous problems in our code from previous assignments (problems that resulted in hours and hours of painstaking debugging), we now have solid base code from which we will continue to create more complex images.