The objective of this assignment is for you to implement an algorithm that will clip an arbitrary polygonal model to a set of planes, given only the model data and plane equations.
You will use OpenGL for the rendering and GLUT mouse and keyboard callbacks for
the interface.
Sample program
Ewen has kindly put together a sample program
that implements some (not all) of the required features. This uses
built-in OpenGL clipping and should give you a feeling for what these models
look like when clipped. Note that sometimes it's easier to see what's
going on in wireframe (hit 's' in Ewen's program to toggle wireframe/shaded).
Specifics
The student will be responsible for the following features:
- The program must be able to load 3D models provided in the very simple
".poly" format, of which a few examples can be found
here. This format
is simple enough that you can (and should) construct some simple one- or
few-polygon models as test cases. Look at the "icos-unit.poly" file in a
text viewer to see what this format looks like: number of vertices, number of
polygons, a list of vertices, and a list of polygons expressed as indices into
the list of vertices. The most important thing to notice about the .poly format
is that the indices of vertices (references by the list of faces) start at
1, not 0. If your model looks like a big mush of polygons, it
may be because you're indexing the vertices wrong. Also note that it is
possible to specify polygons with any number of vertices in this format.
- The user must be able to rotate and zoom the view around the center of the
model (may not equal the origin).
- The program must support at least two clip
planes.
- There must be a toggle allowing the user to switch between four different clipping modes (which the student is required to implement):
- None: No clipping
- Software: Use the Sutherland-Hodgeman algorithm to clip all polygons that penetrate, or fall within, the negative half spaces of either (or both) of the clipping planes. If a polygon is partially clipped, compute the new polygon that is within the positive half space. Also, make an executive decision to either render n-sided polygons or to convert all n-gons into triangles before rendering
(we promise that all incoming polygons will be convex).
- Hardware: Use OpenGL's built-in support for arbitrary clipping
planes to perform the clipping.
- Highlight: Use the plane equations to determine which polygons intersect the planes (and so would be divided), and change the color of these polygons so they can be easily seen.
I recommend you implement the hardware and highlight modes first, as having them as references will help make debugging far simpler.
- Add a toggle that switches between solid and wireframe shading.
- Implement a way of directly editing the A, B, C, and D values for each of the two plane equations (e.g.
the user presses a key in GLUT and then types the equations into the windows
console).
- For extra credit, perform the projection-matrix multiply yourself (thus
transforming the vertices into normalized device coordinates, i.e. x,y
ä [-1,+1],
z
ä
[0,1]) and clip the resulting vertices directly in homogeneous
coordinates. The resulting clipped vertices should then be rendered using
an identity (orthographic) projection matrix.
- Implement a method of rotating/sliding the clipping planes around with mouse
and/or keyboard controls, in addition to the manual entry.
- (Required for CS 645, Extra Credit for CS 445) Draw each of the clipping planes as partially transparent surfaces in the viewport.
- The fastest correct clipping implementations for
each course (445/645) will receive extra credit.
Turn-In Instructions
As usual: write a web page describing what you did, including your entry (can just be
a screenshot) for the art contest.
Your web page should contain a link to a .zip file that contains ALL of the source code that your TA will need to build your assignment. It is your responsibility to make sure that the zip file is complete. We are not going to fix compile errors or fill in missing pieces of assignments.
Please e-mail a link to your submission to the TA. Please, PLEASE check to
make sure the link works. Never, NEVER e-mail the TA anything except a URL when submitting. In particular, do NOT e-mail your .zip file or any images as attachments.
Be sure to keep all assignments up on your web space for the entire
semester. Sometimes we have to go back and re-download assignments.