Lab Assignment 3: The Exploding Barn
In this assignment, you finally have the chance to transform a 3-D
world to 2-D and draw the transformed objects as a wire frame by
drawing just the edges of each face. More specifically, you are to
write a program that draws the exploding barn as shown below.
You will also create an original scene and draw that one, too.
To accomplish this, your program must perform the
following steps:
- Read in a vertex list and a face list.
- Calculate outward-directed normal vectors for each face.
- Read in the view reference point, vrp, a point to look at,
lookat, a guess at an up vector, up, and the location
of the eye, e along the n axis.
- Read in the specifications for the window, front and back
planes, and the viewport, a total of 10 numbers.
- Calculate u, v, and n.
- Calculate M, the matrix that performs the entire
3-D to 2-D perspective transformation.
- Transform all vertices.
- Draw all face edges.
- Draw all normal vectors as a line from the center of each face to
another point along the normal direction. Experiment with the length
of the normal vectors you draw until you find a length that is easily
visible but not too long. Remember, you cannot simply transform
the normal vector with M. M is applied to points, not
vectors. You must apply M to the two endpoints of each
normal vector, then draw the vector between the transformed points.
Also draw a little disk at the end of the normal vector away from the
face. Your normal vectors will look like little pins stuck into the
barn.
- No clipping needs to be performed. Therefore, the placement of
the front and back planes are irrelevant, but include them in the view
file and in your
construction of the transformation matrix. We will use them in future
assignments
Optional Graphical User Interface
You may use the GUI that has been created for this class. The needed
files are xparms.h and xparms.c. You might also find this makefile handy. It illustrates how to write a
makefile to link correctly to X-window libraries on multiple systems.
Check In
First, make sure your program displays the exploding barn correctly
using this lab3.scene file and this
lab3.view file.
Then create a scene file of your own that contains at least 10 faces, each
containing at least three vertices. Also create a view file the
produces a nice view of your lovely creation.
To check this assignment in, check in a tar file of all of the
following files:
- your source code (do not hand in
xparms.c or xparms.h),
- your scene file containing the vertices and faces for your
original object,
- your view file for viewing your original object,
- a file named
readme.txt that describes how to compile your
program and a short description of what you original scene is,
- optionally, a
makefile for compiling and linking your program.
We will grade your program by compiling it and running it with our
barn data and with your original scene and view files.
Debugging Help
Using the above scene and data files and and adding a lot of print
statements to your program, you should see output like this:
-> lab3 -fg black -bg white
Using X11 server PseudoColor visual depth 24, colormap size 256
Using default color map
Read 34 vertices and 10 faces from scene file.
In process_parm_text vrp 2 .6 0.8
lookat 1 0.5 0.5
up 0 1 0
e 10
window -1.2 -1 1.2 1.4
front 1
back -5
viewport 0 0 1 1
u 0.287348 -0.000000 -0.957826
v -0.091325 0.995444 -0.027398
n 0.953463 0.095346 0.286039
T(-r)
1.00 0.00 0.00 -2.00
0.00 1.00 0.00 -0.60
0.00 0.00 1.00 -0.80
0.00 0.00 0.00 1.00
R'(u,v,n)
0.29 -0.00 -0.96 0.00
-0.09 1.00 -0.03 0.00
0.95 0.10 0.29 0.00
0.00 0.00 0.00 1.00
Mper
1.00 0.00 0.00 0.00
0.00 1.00 0.00 0.00
0.00 0.00 1.00 0.00
0.00 0.00 -0.10 1.00
Mnorm
0.42 0.00 0.00 0.50
0.00 0.42 0.00 0.42
0.00 0.00 -0.22 -0.25
0.00 0.00 0.00 1.00
Mdevice
441.00 0.00 0.00 0.00
0.00 -441.00 0.00 441.00
0.00 0.00 1.00 0.00
0.00 0.00 0.00 1.00
M
31.78 -2.10 -182.31 304.05
-7.75 -185.37 -2.32 385.82
-0.19 -0.02 -0.06 0.19
-0.10 -0.01 -0.03 1.22
Dumping window ID 0x5800036... (as a result of clicking on "File")
Window dump is in window.xwd
and you should see this picture in your graphics window: