COMP 15 Project #2: Robot parade

COMP15 Spring 20XX
Due: Thursday, February 17, 11:00PM


Object-orientation is a natural approach to computer graphics. Graphical scenes consist of objects that are instantiated from one or more classes. Often, multiple objects of a specific type are instantiated from the same class. An object may consist of subparts where each subpart is an instance (object) of some other class. In this case, there is a part-of relationship from the child (subordinate object) to the parent object. (The part-of relationship is similar to the has-a relationship, which is used by some object-oriented design methods.) The part-of relationships in a scene can be described in a "scene graph," which is a directed-acyclic graph (DAG) with the scene at the root of the DAG and graphical primitives at the leaves of the DAG.

The part-of relationship is usually accompanied by a spatial, geometric relationship between parent and child (a subpart of the parent.) The child must be scaled, oriented and placed with respect to the coordinate space of the parent. This is accomplished in PostScript using the scale, rotation and translation transformations, respectively. The PostScript transformation stack allows concatenation and nesting of transformations such that parent-child (part-subpart) geometric relationships are easily applied and managed.


The objectives for this project are:

The principles underlying this project are fundamental to the field of computer graphics. The notion of a scene graph is used in OpenGL modelling and game engines.

What needs to be done

Your program must draw a scene with four robots. Each of the robots may be an instance of a single Robot class. The scene, generally, has the following (sub)parts:

Each kind of part must be a separate class. Instances of parts must be created by defining the appropriate objects. Each class should follow the common design pattern discussed in class (i.e., rules for scene structure, use of draw_me functions and the rules for placing and drawing subcomponents.) Parts should be positioned, scaled and oriented using PostScript geometric transformations.

What you draw is up to you, as long as it is tasteful. Before programming, draw a scene and lay out your parts on graph paper. Then translate your geometry into classes, objects, graphical primitives and transformations. Only the "leaves" of the scene (the bottom-most parts) may use graphical primitives (i.e., line, circle, rect.) Interior components of the scene may only create, scale, orient and place instances of other robot parts.

Three files are being provided to start this project: psfile.h, psfile.cpp and an incomplete makefile. The files are located in the /g/15/class/project2 directory. The two C++ source files, psfile.h and psfile.cpp, implement the PostscriptFile class that performs simple, PostScript-based graphics. The application programming interface (API) for this class is described in the technical note:

PostScript file API
You must complete the makefile in order to build your program using the make utility. The name of your executable program must be robot_parade and the name of the PostScript output file must be

You should test as thoroughly as possible. Identify and test any special cases. Add comments to the source code to describe your approach and solution. Don't forget to provide a header comment with your name, section and e-mail address in each file.

All programs must build and execute correctly on the Linux cluster assigned to our course:
Do not assume that your program will build and run correctly on the cluster even if you have the same version of g++ on your own machine. Many have tried and many have failed.

Previewing the PostScript file

The robot_parade program will produce a PostScript file. You will need to use a PostScript previewer to display the PostScript file. You may preview the finished PostScript file using the GhostScript previewer (called "gs" on Linux and "gsview" on Sun Solaris) or print the file to get hard-copy. GhostScript is an open source PostScript interpreter and previewer. It is available for Macintosh and Windows. The Mac OS X Previewer is able to display PostScript files under Panther (v10.3 or later.)

Extra credit

Here are two problems to consider:

Extra challenges are always above the call of duty and are for extra credit.

On-line resources

If you would like to learn more about PostScript, be sure to read the on-line tutorials on PostScript. Take the "PostScript tutorial" link from the COMP15 schedule page. The PostScript write-up has links to the Adobe PostScript tutorial/cookbook and reference manuals (the "blue book" and the "red book.") The Adobe books are particularly well-written and have many examples in case you want to extend the PostscriptFile interface.

Submitting your work

Use the provide system to submit the finished program:

    provide comp15 p2 makefile psfile.h psfile.cpp ...
Be sure you are completely satisfied with your work before submitting! You must submit your makefile, psfile.h and psfile.cpp along with all of the include and source files needed to draw your scene.

Yep, that's a lot of stuff and please be careful to make sure that no pieces and parts are missing! Remember, you can use *nix wildcards to specify files to be submitted, e.g., "*.h *.cpp."

You may also want to consider creating a simple shell script to submit your code. A shell script is just a *nix file that contains shell commands in it. Simply edit a file to contain your provide command, change the permissions on the file to make it executable, and then run the script by entering the name of the file as if it were a command or executable program. If you're unsure about how to do this, try writing a shell script that does an ls to display the names of all of your .h and .cpp files and the makefile:

  1. Create a file, called scriptfile, with the command "ls *.h *.cpp makefile" in it.
  2. Change the permissions on the file to make it executable using the command "chmod 0755 scriptfile".
  3. Enter the name of the file as if it were a command, i.e., just type ./scriptfile at the shell prompt.
  4. See if the shell script displays the names of your C++ source files and the makefile.
If everything looks good to go, change the ls to the necessary provide stuff and you're ready to submit.

Copyright © 2004-2013 Paul J. Drongowski