CSCI 1300
Introduction to Computer Science
Homework 10: Orthogonal 3D Display

Due Date

You must submit your program called ortho.cxx by 10pm on Friday, Dec 2. Submit the programming work online to http://culearn.colorado.edu. Late work is accepted until 10am on the following Monday with no penalty. If you have not already used your two very late submissions, then you may submit this until 11:59pm on Wednesday, Dec 7 with a 13-point penalty.

Working Alone

You may talk with other students and instructors about the assignments, but you may not look at or copy code written by others. The penalty for violating this code is an F for the entire semester.

Programming Style

As always, all your work must follow these ten essential style items. See www.cs.colorado.edu/~main/style.html.

The Assignment


I found a file that contains data for a wire-frame model of a space shuttle in a file called shuttle.dat from Apostolos Tolis at Stanford University. I'm not sure how good it is, because I haven't yet seen it displayed except for a simple view called an orthogonal projection. For this week's assignment, you will write a program that displays this simple view. Next week we will add perspective and the ability to rotate your model.

You must use a careful incremental development and testing for this project, and each separate task must be done by a well-designed function or functions. Here are the steps that your program will follow:

  1. Open and read the data file (always called shuttle.dat for this program) into a data structure that I'll describe below.
  2. Display the model in a winbgi screen whose size is S times S (in pixels). Your world coordinate system should go from wmin to wmax in each dimension. The number wmin is 1.2 times the smallest x or y coordinate in the file, and wmax is 1.2 times the largest. (The file also contains z-coordinates, but those do not effect wmin and wmax.)
  3. Wait for the user to press a key before the program closes.

The Format of the Data File

How to Store the Data

You must store the vertices in a two-dimensional array declared this way:
double data[M][3];
You must use exactly this declaration in your main program (otherwise the TAs won't be able to grade your work). The idea is that the x, y and z coordinates of point number i will always be stored in data[i-1][0], data[i-1][1] and data[i-1][2].

You must store the edges and their colors in two separate arrays declared this way:

unsigned int vertex[N];
int color[N];
For example, if the first edge goes to vertex number 522 and the color of that first edge is specified as 0, then vertex[0] will be 522 and color[0] will be 0. Note: The first edge in the file is guaranteed to have color number 0, so that the first movement that's made when you draw the image is always a moveto (rather than a lineto). Note that the vertex numbers in the vertex array range from 1 to the number of vertices. I must subtract one from this number before I use it as a row index for the data array!

How to Draw the Data

When you draw an edge, convert its x and y coordinates to pixels and draw a line in the appropriate color. For now, we are ignoring the z-coordinates (which results in a drawing format that's called an orthogonal projection).