Transformations and Projections
Due: April 9, 1999
The goal of Assignment 1 is to familiarize yourself with the concepts of
Transformations and Projections in 3D Graphics. It will also help to introduce
the OpenGL graphics library that we will be using throughout this course.
The assignment is in two parts, each of which is worth 10% of your final
grade. Eight out of a possible ten points will be awarded for a full implementation
of the specifications given below. The final two points will be awarded
on each part of the assignment for creative use of 3D graphics to enhance
the quality and the effectiveness of the resulting program. That is, if
the implementation of the assignments are exceptional (beyond what the
basic assignment calls for), then a full 10 points will be awarded. Computer
graphics is about using creative ideas to view complex geometry in interesting
ways, so now is a good time to start thinking along these lines.
Part 1
You are to implement a program that uses perspective and orthographic parallel
viewing to display a 2D animated image of 3D objects. Your program
should display an image of a spinning object (spinning about its center
of mass). The geometry of the object is specified through an input file.
The user should be able to interact with the object through GLUT menus.
When perspective is used parts of the object that are further away should
appear smaller than those that are closer (perspective foreshortening).
The objects should be able to be rotated (rotation centered about the
objects center of mass) around the three principal axes (X, Y, Z) in any
combination (for example, the objects should be able to be rotated about
both the X and the Y axes at the same time). Your program should provide
the user with a menu of options that will enable them to turn on/off the
rotation about the three principal axes independently, as well as providing
menu options to turn off all rotation with one selection, reset the object
to a standard orientation, switch between parallel and perspective projections,
and to exit the program.
The file format for the object geometry should be a simple file of one
or more lines, with each line containing the specification for a single
triangle. The triangle format should be of the format x1 y1 z1 x2 y2 z2
x3 y3 z3 where x1 y1 z1 represents the first vertex of the triangle etc.
Your program should be able to handle an arbitrary number of triangles.
To implement the program you should use OpenGL and the GLUT library.
A skeleton of a simple GLUT program that does nothing but display a window
on the screen will be provided (see the directory /home/dcs/bdc659/Graphics/Assignment1/Example
for the source code and a Makefile to build the program). For this assignment,
you will only be able to use the 2D OpenGL line primitive to draw the animated
cube. The point of the assignment is to give you experience with implementing
geometric transformations and 3D projections, so you will not be allowed
to use any of the following OpenGL functionality:
-
OpenGL matrix functions
-
OpenGL 3D primitives
-
OpenGL 3D projection
In fact, the only OpenGL calls that you should have for drawing geometry
on the screen are to glClear(), glBegin(GL_LINES), glEnd(), glVertex2f(),
and glColor(). OpenGL and GLUT functions related to your user interface
are allowed, but there should be NO OpenGL 3D functionality used in this
program. If you have any doubts or questions about which functions you
are allowed to use please come and see me, as the use of the wrong calls
will cost you marks. It is necessary to be strict about this, as the OpenGL
3D functionality makes this assignment trivial.
A simple example program will be available for you as a basic implementation
(home/dcs/bdc659/Graphics/Assignment1/Part1). It is a basic implementation
and it should by no means limit your imagination in what you attempt
to implement. A full implementation of the above specification will give
you 8/10 of the full points available, but further points will be given
for "imaginative extensions" to the assignment. How can you view simple
3D geometry more effectively on a 2D screen?
Part 2
In part two of the assignment, you are to write a program that reads in
a set of 3D spheres and a set of 3D lines from an input file and displays
them on the screen using OpenGL 3D functionality. Your 3D scene should
contain two light sources (positioned at a location chosen by you), each
of which the user should be able to turn on or off interactively. The user
should be able to change the orientation of the geometry (rotate) in the
same manner as in Part 1 of this assignment. If you can design a better
user interface for rotating the geometry, feel free to implement it. As
long as it is functionally equivalent to the capabilities of the rotations
in Part 1 (or better) it will be acceptable. Novel implementations of a
user interface for rotating the 3D scene will again make it possible to
receive the full ten points for this part of the assignment. Other extensions
that increase the quality of the final product will also be eligible for
extra points.
For each object you should at least use diffuse shading for display.
The input file format that your program will be required to read is very
simple. It consists of a set of lines containing simple text, the first
line in the file gives the number of spheres (s), the second line gives
the number of lines (l), followed by s lines describing the sphere information
and l lines describing the line information. A sphere's description will
be in the format x y z r R G B, where x, y, and z are
the 3D coordinates of the center of the sphere, r is the radius,
and R, G, and B are the RGB triple that defines the color of the sphere.
A lines description will be in the format x1 y1 z1 x2 y2 z2 R
G B, where x1 y1 z1 is the start point of the line, x2 y2
z2 is the end point of the line, and R G B is the color description
of the line. An example file would look like this:
3
2
0.0 0.0 0.0 10.0 1.0 0.0 0.0
0.0 0.0 10.0 4.0 0.0 1.0 0.0
0.0 0.0 -10.0 4.0 0.0 0.0 1.0
0.0 0.0 0.0 0.0 0.0 10.0 1.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 -10.0 0.0 0.0 1.0
This 3D scene consists of three spheres, one a red sphere of radius 10
centered at the origin, one a green sphere of radius 4 centered at 0,0,10
and one a blue sphere of radius 4 centered at 0,0,-10. It also contains
two lines, a red line from 0,0,0 to 0,0,10 and a blue line from 0,0,0 to
0,0,-10. When viewing the scene, the "look at position" (and the point
that you should rotate around) should be located at the "centroid" of the
set of spheres (we will define the centroid as the average of the x, y,
and z coordinates of the sphere centers).
Program Submission
To simplify submission of the assignment, everyone should create a directory
called Graphics in their home directory on the SGI machines in the Computational
Science and Engineering Lab. For each of the assignments for this course,
you should create a subdirectory beneath the Graphics directory with the
name AssignmentN where N is the assignment number (for Assignment 1 the
subdirectory should be called Assignment1). Within each Assignment directory,
you should have a subdirectory for each part of the assignment called PartM
(where M is either 1 or 2 in this case). Within each of those directories,
you should have all of the source code (C and header files), a Makefile
that will build your programs, and an executable program for me to mark
(it should be named PartM as well, where M is 1 or 2). The modification
times on the source code files, the Makefile, and the executables should
not be later than the submission deadline. On or before the submission
deadline, you should print out all of the relevant source code files (c
and h files) as well as the Makefile you used and give them to the me or
slide them under my door (CSIT Room N328). Your code should be well documented
and readable (marks will be deducted for code that is not understandable).
The executable file for marking must be executable by "other" and the directory
tree up to and including the directory that contains the executable must
be readable and executable by "other". You can protect the source code
files from being read, but they must be in the directory and the directory
must be readable by "other". In some cases, I may want to look at the source
code directly and perhaps even recompile the program. Late assignments
will be docked 1 mark per day for each day that they are late.