CS 445 / 645 Introduction to Computer Graphics
Spring 2004
Assignment 2: Sutherland-Hodgman Clipping
Due: 5:00 Tuesday, February 24th
URL: http://www.cs.virginia.edu/~gfx/Courses/2004/Intro.Spring.04/ProgrammingAssignments/Exercise2
Synopsis
Your program will load a polygonal object, clip the polygonal object with two clipping planes, and use OpenGL to render it. You will write code to clip the model to the two arbitrary clipping planes using the Sutherland-Hodgman algorithm. Your FLTK/Boost/OpenGL program will provide debugging aids and an intuitive user-interface. Grad students, note that your program must also support interactive repositioning of the clipping planes.
Relevant reading/files/software
Collaboration and Use of Materials on the Web
Unlike previous assignments for this course, you cannot use any graphics code related to clipping. Code segments for the tasks in the assignment are probably floating around the web and it is inappropriate to use any of them. As per the earlier assignments, you can still talk to your classmates about your work, but you cannot look at each other's code or work side-by-side to generate your code. You can use outside resources to learn about OpenGL, FLTK, and Boost.
Specifics
We are providing a Visual Studio 7.1 Solution file and C++ skeleton files. The skeleton files will set up lighting so that front-facing polygons will be drawn one color and back-facing polygons another. You will modify the functions in the skeleton code, adding additional user interface widgets and core functionality. Take full advantage of available C++ data structures to avoid making mistakes by reimplementing your own. Some special things to notice about the code:
modelname.poly
A B C D
E F G HWhere the .poly file is defined according to these rules. We will be using these .poly files to test your code. The skeleton code includes a .poly loader. Think about the data structure you wish to use to store the model's vertices. Link lists are reconfigurable but perhaps less usable in other ways.
A B C D are the four doubles that define the parameters of the first implicit plane equation: Ax + By + Cz + D = 0. Clip away all geometry found in the negative half space formed by this plane
E F G H are the four doubles that define the parameters of the second implicit plane equation: Ex + Fy + Gz + H = 0. Clip away all geometry found in the negative half space formed by this plane
(10 points) The user must be able to navigate through the world using three slider bars, one to set rotation amounts about each of the x, y, and z axes. Label your sliders. Also provide a dial to control the zoom into the scene. Try rotating 180 degrees about x and then rotate about y to see if you can accomplish Gimbal Lock.
Add a toggle to select one of three Clipping modes (all three of which you must implement)
(25 points) Use the Sutherland-Hodgman 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. Take advantage of the large memory your computer has by storing the clipped vertices in a data structure rather than re-clip with each screen redraw. Graduate students - think about what conditions will merit re-clipping (only when the clipping planes move). Also, make an executive decision to either render n-sided polygons or to convert all n-gons into triangles before rendering.
(15 points) Use the plane equations to determine which polygons of the model are intersected (sliced) by the clipping planes. Don't actually perform any clipping, just change the color of these polygons so you can easily see what polygons will have to be altered by the clipping process.
(10 points) OpenGL has direct support for clipping to arbitrary planes. Use the OpenGL clipping implementation instead of your Sutherland-Hodgeman implementation to render the model clipped to the two planes.
(5 points) Add a toggle that switches between Wireframe and Solid Shading. The polygons should then be rendered according to the selected rendering mode.
(5 points) Add a checkbox that turns on/off rendering of the clipping plane normals. The normal vectors should have one endpoint on the point of their respective plane that is closest to the origin.
(5 points) Add a checkbox that turns on/off rendering of the world coordinate axes.
(10 points) Add a checkbox that turns on/off rendering of the clipping planes. The clipping plane should be rendered as a unit square and its center should be located on the point of the plane closest to the origin. One edge of the square must be parallel to the x-z plane of the world. We'll discuss this in class.
(5 points) Turn in your assignment according to the instructions.
(Grad students only) Use the center mouse button to interactively select one of the clipping planes. Once selected, allow the user the freedom to reposition the selected clipping plane. Translation is all that I require, but rotation would be nice.
(Grad students only) Create a more intuitive user interface for navigating around the rendered model. Use the virtual trackball described in Angle 4.10.2.
Left button + drag = rotating the camera around the polygonal model. The camera should remain a constant distance from the model, but the translation of the mouse should correspond to longitudinal and latitudinal rotations of the camera about the model. Picture the way you use a trackball. Try rotating 180 degrees about x and then rotate about y to see if you can accomplish Gimbal Lock.
Right button + drag = zooming in and out of the model. Forward movements of the mouse move the camera closer to the model's center and Downward movements move the camera away from the model.
Extra Credit