CS 351 Assignment 7: 3D Viewing & Modeling
Justin Russell, Nicki Ciociolo-Hinkell, & Adam Lowenstein
In this assignment, we created a three-dimensional modeling system and used it to create basic 3D shapes. We added a z-coordinate to our 2D matrix transformations (translate, shear, rotate, etc.) and also created a new structure, PerspectiveView, that defines the view window and perspective vectors. Then, in order to convert 3D matrices to actual images, we created a function for generating a three-dimensional perspective viewing pipeline. This function, Matrix_set3dView(), takes a Matrix object and a PerspectiveView object as parameters.
In implementing our code, we tested two different versions of code provided by Professor Maxwell. Both codes drew a simple cube, and in each code, the rotation of the cube around the y-axis was controlled by a command line argument in degrees. The following two images show the non-modular code at 0 degrees (no command line arguments)...
...and at 234 degrees of rotation:
The final aspect of the project involved generating our own shapes. Each member of the group created their own three-dimensional object and turned it into an animation. These images are shown below.
As described earlier, the only new structure that we defined was PerspectiveView. PerspectiveView has a field for a Point (for the view reference point), two Vectors (the view plane normal and the view up vector), five doubles (d, the distance in the z-direction of the center of projection; du and dv, the width and height of the view window, respectively; and f and b, the front and back clip planes), and two integers (screenx and screeny, the screen coordinate size).
Most of the coding time in this project was spent creating the Matrix_set3dView() function, which took a PerspectiveView object as one of its parameters (the other parameter being a view transformation matrix, or VTM). Once we had defined the PerspectiveView structure and implemented our three-dimensional module and matrix transformations, we tested our implementations using Professor Maxwell's test code. The non-modular test code is shown above (in white), while the modular version is shown below (in yellow). The first image is a cube rotated at 0 degrees:
...and the second is rotated at 75 degrees:
After successfully generating these images, we then altered Professor Maxwell's test code to create our own shapes and animations. These pictures are show below.
Algorithms & Pictures
The following image was created by Nicki: This shape started as the default cube and I simply modified side lengths to get a nifty prism-type object. When rotating, there are points at which it looks entirely different from itself. It is a simple but nifty graphic to toy with.
The following image was created by Justin: Here we see an animated gif which showcases the process of 3D hierarchical modeling. The ninja depicted performing his hurricane kick (SHORYUKEN!!!) is a composition of lines created in a three dimensional space rendered in two dimensions using a one point projection. I defined his motion through a series of rotations and transformations - to create each frame the ninja's center is translated back to the origin, rotated some amount and finally translated to its new location. For this particular scene the center of projection is fairly close to view reference point, and both are close to the ninja in relation to his size, which highlights the effects of the projection process as the ninja flies toward the view window.
The following image was created by Adam: This image shows an idyllic country cottage illuminated by the moon (not pictured) at night. The most striking feature of this rustic cottage is its chimney, which appears to be sitting on the roof but is actually hovering exactly where the roof would be. This image was created by modifying the test code provided by Professor Maxwell and placing the code within a "for" loop to create a series of pictures that, when put together in sequence, form an animation. In the animation, the cottage rotates around the y-axis, requiring a translation back to the origin, a rotation, and a retranslation back to the center of the image for every sequence of rotation.
Though this project did not require as much altering of our libraries as certain previous projects have, the material that we learned in this project will prove invaluable. We used everything that we'd learned over the course of the year (lines, points, matrices, and modules, to name a few) and combined it with the newly-learned 3D transformations and perspectives to create a complex and powerful new set of tools.