Computer Graphics (CMSC 427) - Spring 2000

                                                Prof. Ben Bederson

                                                Homework Seven: OpenGL and Magician

                                                Due: Tuesday, Mar 30th, 2000

   

The purpose of this homework is to make sure you understand all of the major aspects of the 3D graphics pipeline that we have discussed so far by building a hierarchical object viewer with view control and perspective.

You must read in a data file that specifies a hierarchical 3D model with transformations at certain points.  You must build an internal data structure that represents that model, including interactive scrollbars that the user can use to manipulate the specified transforms.  You must render the model in perspective every time a transform is changed so that the user can dynamically move the model.  Finally, you must give the ability to specify the camera position and viewing direction.  The data file format and a simple sample file is specified below.  You must also submit two other data files that you create to test your viewer (consider something fun such as a robot or a cat), and we will also make up other data files to test your assignment.  Your program should work on all valid input files.  While it is nice for debugging to give meaningful error messages for invalid data files, you will not be graded on the ability of your program to handle invalid data files.

The data files can be any name that ends in ".data".  You must provide a mechanism in your application to load in new data files.  Consider using Java menus which are straightforward.  You can use code something like the following.  Be sure to use the java.awt.FileDialog class to make it easy for users to read in files.

	MenuBar menuBar = new MenuBar();
	Menu menu = new Menu("File");
	MenuItem item = new MenuItem("Load");
	item.addActionListener( ...)   // Action listener to respond to load command goes here
	menu.add(item);
	menuBar.add(menu);
	frame.setMenuBar(menuBar);

Note that you will have to use Java a bit more for this project to dynamically construct the interface based on the data model.  Just create a new Scrollbar and add it to a panel for every element you want to control.  Scrollbars use AdjustmentListeners to notify the application when the Scrollbar has been modified.  Be sure to include a Label showing what each Scrollbar is for.

Data File Format

The file format contains one line for each object or transform element.  Every line starts with a one-word label followed by the object, transform type, or stack command.  Each type then has a fixed number of type-specific parameters.  All object parameters are integers.  Transform numeric parameters can be either an integer, or an integer range separated by a '-'.  Integer ranges mean that the user should be able to modify the parameter with a Scrollbar.  Fixed transform parameters are not modifiable by the user. Stack commands are used to push or pop the transformation state.   A formal description of the file format follows:

<file> = <line>*
<line> = <comment>  | (<label> (<object> | <transform> | 'push' | 'pop'))
<label> = ([a-z] | [A-Z] | '-')+
<comment> = '#' .*
<object> = <box> | <sphere>
<transform> = <rotate> | <translate> | <scale>
<box> = 'box' x1 y1 z1 x2 y2 z2
<sphere> = 'sphere' centerx centery centerz radius
<rotate> = ('x' | 'y' | 'z') (number | <range>)
<translate> = (number | <range>) (number | <range>) (number | <range>)
<scale> = (number | <range>) (number | <range>) (number | <range>)
<range> = number '-' number

Sample Data File:

# Simple two-headed beast
# First make the body
body box 0 0 0 50 50 50
neck translate 0 50 50
# Then make the first head (with controllable rotation)
neck1-start push
neck1-bend rotate x 0-30
head box 0 0 0 20 20 -20
neck1-end pop
# Then make the second head (also with controllable rotation)
neck2-bend rotate x 0-30
head box 20 0 0 40 20 -20