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:
- Open and read the data file (always called shuttle.dat for this
program)
into a data structure that I'll
describe below.
- 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.)
- Wait for the user to press a key before the program closes.
The Format of the Data File
-
-
The first line of the data file contains the number of 3-dimensional
points that define the model. We call these points the vertices
of the model.
For this model, the number is exactly 522. Please read
this number and check (using an assert statement) that it is equal to a global named constant that
you've defined:
const size_t M = 522;
(In the future, you might use vectors to allow varying numbers of
vertices, but NOT NOW PLEASE!)
- Let's suppose there are M vertices. Then the next M lines of
the data file contain the x, y and z-coordinates of those vertices
(with one set of x, y and z-coordinates on each line). Note: We will
number these vertices from vertex number 1 to number M.
-
The next line of data contains the number of pen movements to draw
the model.
For this model, the number is exactly 891. Please read
this number and check (using an assert statement) that it is equal to another global named constant that
you've defined:
const size_t N = 891;
- Let's suppose there are N pen movements. Then the next N lines of
the data file contain two numbers each. The first number on each line
is a vertex number (from 1 to M). The second number is a color to use
when drawing a line to that vertex (except that color 0 means to move
the pen to vertex without drawing a line). Note: You will use the
lineto function to draw a line to a vertex, and use the moveto
function to move the pen without drawing a line. For this particular
file, all of the drawn lines are white, but your program should work
correctly even if the TAs change the colors of some or all lines.
- The data file might have more information after the pen movements,
but you can ignore that info!
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).