Project 3: mini-OpenGL
Due: 11/11/00 at 11:59PM.
Overview
In this project you will implement a simple graphics pipeline system similar
to OpenGL. To allow you focus on the nuts and bolts of the assignment,
we supply supporting code that provides a user interface, file i/o, the
general pipeline structure, and many of the data structures
you'll need. Data is read from files in .ply format.
What You Have to Do
The assignment is worth 20 points. The following is a list of features
that you may implement. The number in parentheses corresponds to how many
points it is worth. Options in bold are mandatory.
-
(5) Scan-line algorithm: Implement
the scan-line algorithm using flat shading, color mode, and orthographic
projection. No z-buffering is necessary at this point.
-
(1) Smooth shading: Modify your
scan-line to support smooth shading in addition to flat shading.
-
(2) z-Buffering: Implement the
z-buffering algorithm.
-
(2) Clipping: Implement 3D
polygon clipping.
-
(1) Transforms: Implement
transforms for rotation, scaling and translation based on user input.
-
(1) Perspective Projection:
Modify your implementation to support perspective projection as specified
by the user.Notes on perspective projection are here .
-
(3) Lighting: Add support for ambient and diffuse lighting
. You'll need to compute the "average" normal for each vertex.
-
(1) Implement anti-aliasing.
-
(1) Implement texture mapping. Code to support texture mapping can be found here .
-
(1) Implement specular lighting..
-
(1) Implement back-face culling.
-
(3) Implement Bresenham's algorithm for scan converting line segments with
the out-code clipping algorithm.
By implementing all the required features, you get 15 points. There are
many ways to get more points:
-
(as listed above) implementing optional features,
-
(1) submitting 3D models you constructed,
-
(1) submitting images for the art contest,
(1) submitting a .mpeg movie with a sequence of images resulting from
a moving object,
-
(2) winning the art contest.
It is possible to get more than 20 points. However, after 20 points, each
point is divided by 2, and after 22 points, each point is divided by 4.
Getting Started
You should use the code available at /cs/cs155/proj3/src, on the graphics
machines, as a starting point for your assignment. We provide you with:
-
main.[cpp/h] manages initialization.
-
menu[cpp/h] builds and manages the menus.
-
setup[cpp/h] builds and manages system paramters such as type of projection,
shading model, current transforation matrix, current projection matrix,
etc.
-
Vertex.[cpp/h] provides a vertex class, matrix class and supporting routines.
A vertex is a 3D point in homogenous coordinates (hence 4D) plus RGB-color
values.
-
Polygon.[cpp/h] provides a polygon class and supporting routines.
A polygon is a sequence of vertices listed in counter-clockwise order.
-
Mesh.[cpp/h] provides a mesh class to organize a collection of polygons.
-
myply.[cpp/h] and ply.[cpp/h] are utilities to read a ply file and build
the corresponding Mesh data structure.
-
LineSeg.[cpp/h] provides classes and supporting routines for the edge table
and active edge table.
-
buffer.[c/h] provide classes and supporting routines for the frame buffer
and z-buffer.
After you copy the provided files to your directory, the first thing to
do is compile the program.
In either case an executable called myOpenGL will be created.
How the Program Works
The program provides a user interface with a display window. Menu
options allow the user to enter a input file (.ply) which contains the
description of some object. After rendering, the contents of the
frame buffer will be displayed. Other menu options allow the user
choose the type of projection (perspective or orthographic),
the shading model (flat or smooth), and the color model (color vs.
lighting). The user may also enter model transformations to be applied
to the object.
Do not change
Do not change main.[cpp/h], myply.[cpp/h], or ply.[cpp/h]. We
will use OUR version of this code when we test your code. If you
think that modifications are needed, let me know. If I agree, I'll implment
the changes and make them
available to the class.
What you should change
Scan-line algorithm:
-
mySetUp::
The constructor needs to be modified to define the projection matrix,
CPM, for orthographic projection. Use the Matrix class in Vertex.[cpp/h].
The standard frustum is already defined. DO NOT CHANGE the definition
of the standard frustum.
Mesh::render:
This routine steps through the polygon mesh, creating a copy of each
polygon, and calling the polygon renderer on the copy. Modify this
routine to set up the vertex colors correctly for flat shading.
-
Polygon::render:
This routine processes the polygon through the rendering pipeline.
Modify this routine to project the vertices, apply the appropriate viewport
transformation to the vertices, and call the scanConvert. The routine
Vertex::xfm(Matrix* M) multiplies a vertex on the left by the (transformation)
matrix M.
-
Polygon::scanConvert:
This routine scan coverts the polygon. Implement the scan line
algorithm. Initially ignore z-Buffering. You need to
construct the edge table (et) and active edge table (aet) for the polygon's
line segments. Use the lineSegment and EdgeTable classes in lineSeg.h.
-
LineSeg.[cpp/h]:
Modify the lineSeg constructor to intialize lineSeg values correctly.
You may find it useful for debugging to assign each line segment a unique
identifier segNum. Implement the increment function, which updates
currX_ and currY_ as you increment scan lines. The Edge Table class
holds an array of linked lists of lineSegs. Facilities are provided
to step through a list and add and delete lineSegs from a list.
Smooth Shading:
-
Mesh.render:
Modify this routine to fix the colors for smooth shading.
-
LineSeg.[cpp/h]
Modify the constructor and the increment function to compute interpolated
color values along the line segment.
-
Polygon::scanConvert:
Modify scanConvert function to interpolate color values along the scan
line.
z-Buffering:
-
Mesh::render:
This routine should create and initialize the z-buffer before rendering
the mesh. Be sure to destroy the z-buffer when you are done.
-
Polygon::scanConvert
Incorporate z-buffering.
Clipping:
-
Polygon::clip:
Implement the polygon clipping algorithm discussed in class; i.e. clip
each edge of the polygon against one plane of the frustum. Repeat
for remaining planes. A plane class is provided in Vertex.[cpp/h]
to help you get started.
-
plane::plane
Implement the constructor for the plance class; i.e. compute the equation
of the plane given three vertices on the plane. The vertices are
specified in counter-clockwise direction.
-
plane::whichSide:
Implement this routine which tests whether a vertex is in front of
or behind a plane. The direction is defined by the normal to the
plane <A,B,C>.
Transforms:
-
menu.cpp
Modify to multiply the CTM by the appropriate transformation matrix.
Both left and right multiply routines are provided in the Matrix class.
-
Polygon::render
Modify to multiply vertices by the CTM to transform them to world coordinates.
Perspective Projection:
-
menu.cpp
Modify to allow user to change projection type.
-
setup.cpp
Define the projection matrix for perspective projection.
-
Polygon::clip
Modify to clip against the frustum for perspective projection.
-
Polygon::render
Normalize the vertices after projection.
What to Submit
You should submit:
-
the complete source code with a Makefile,
-
any *.ply files you created (optional),
-
links for the .mpeg movie for the movie feature (optional),
-
links for the images for the art contest (optional), and
-
a writeup.
The writeup should be a HTML document called assignment3.html
which may include other documents or pictures. It should be brief, describing
what you have implemented, what works and what doesn't, how you created
the art contest images and/or movies, and any relevent instructions on
how to run your interface. Make sure that any linked images/movies are
world readable.
Make sure the source code compiles on the graphics machines. If
it doesn't, you will have to attend to a grading session with a TA, and
your grade will suffer.
Remember our standing late policy and collaboration policy.
Hints:
Last update: 10/24/01
11.05 PM