Homework 8
22C:151 Introduction to Computer Graphics
Due Thursday, November 20, 2003
25 points
Implement BSP-tree (binary space partition tree) construction and drawing
algorithms and use them to render scenes of convex texture-mapped polygons.
Your program should take a file name as input. The file
will contain a description of a set of convex polygons to render (see below
for format details).
Your program should allow interactive viewing of the set of
texture-mapped polygons.
Only the proper visible portions of the polygons should be drawn
and this should be accomplished via BSP-tree traversal rather
than use of OpenGL's depth buffering capabilities.
Interactive viewing will be accomplished using view manipluation
and keyboard/mouse movement code that will be provided for you:
README (documentation for hw7viewing.c),
hw8viewing.c, rgbimage.h (needed to
read the texture image files). Three test files are also available:
test.txt, test2.txt,
test3.txt. Finally, the following three image files are
used in the three test examples: tabletop.rgb,
brick.rgb, paper.rgb.
Thus, the basic steps are:
- read the polygon scene file (and the referenced texture files)
- construct a BSP tree for the scene. You do not have to
use any techniques that attempt to construct a "good" BSP tree.
Any correct BSP tree will be fine.
- As the user changes viewpoint, the polygons should be
properly rendered.
Based on the current viewpoint and the
BSP tree, traverse the BSP tree, generating OpenGL polygon
drawing commands, including texture mapping code, as you go.
Input file format
The first line of the input file will contain an integer indicating
the number of polygons described in the file. The rest of the file
will describe the individual polygons.
A polygon with n vertices will be described in n+1 lines in the file.
The first line of a polygon description will contain 1 integer, indicating
the number of vertices in the polygin,
and the name of the texture file to use for texture mapping this
polygon. The remaining n lines will each contain five
floating point numbers giving the world x, y, and z coordinates and
u and v texture coordinates of each vertex of the polygon.
The vertices will be listed in counterclockwise order.
For example, the following describes 2 polygons:
2
4 brick.rgb
1.0 1.0 1.0 0.0 0.0
2.0 1.0 1.0 1.0 0.0
2.0 1.0 0.0 1.0 1.0
1.0 1.0 0.0 0.0 1.0
3 ground.rgb
-1.0 0.0 0.0 0.0 0.0
-1.0 0.0 2.0 1.0 0.0
-0.5 3.0 1.0 0.5 1.0
Results
Say something in your README file about what
your results. Does BSP rendering seem good? Is it faster
than using the depth buffer? Would there be much
more work to do to make it robust and complete? Etc.
Submitting your program
Submit your assignment according to the guidelines on the class WWW home page. For the
on-line part of the submission, respond 'hw8' to the ``Location:''
request.