More Transformations and Triangle Clipping in Homogeneous Coordinates
COMP-236: Homework #2 : Spring 2000

Demo executable: PC, SGI
Demo source code (without clipper, includes matric/vector modules)
 


Quad clipped in eye space

Quad clipped in NDC space

Teapot clipped in eye space

Teapot clipped in NDC space
Problem 1 (10 points)

Derive the OpenGL glRotate matrix for rotations of a radians about an arbitrary axis [x y z] from the primary axis rotations derived in the tech report. The direction of positive rotation is determined by the right-hand rule. Clearly show each of the transformation matrices that make up the final composite, and give a brief description of what each transformation is doing. You do not have to give the final form of the composite matrix; just show the concatenation of your individual transformations.
 

Problem 2 (40 points)

Show how to derive the OpenGL perspective transformation matrix from the glFrustum definition of a viewing frustum (see the OpenGL redbook). Explain what happens to the z values and why linear interpolation of depth in screen space correctly preserves the visibility relationships between polygons in the scene. Why is this even a consideration?

The perspective transformation matrix is defined as follows:

Your goal is derive the elements of this 4x4 matrix from the frustum definition and obtain a clear understanding of what is happening here geometrically. You should break apart the transformation into several simpler transformations (hint: decouple what happens to the x and y components from the z components; both will rely on w). One of the transformations will be a simple projection similar to what we derived in class from similar triangles with the addition of some normalization. The other transformation performs the perspective depth transformation.

The following steps will make the derivation easier.

Problem 3 (50 points)

Implement 3D clipping of a convex polygon in homogeneous coordinates using the Sutherland-Hodgeman algorithm. The polygon must first be transformed by the perspective matrix derived in question (2).

INPUT: the 4D vertices of a CONVEX polygon that has undergone the perspective transformation.

OUTPUT: a clipped polygon that is inside the view frustum (including the boundary). The vertices are still defined in homogeneous coordinates. A perspective divide on the resulting polygon vertices should give the desired screen space clipped triangles in NDC space. You can use the supplied OpenGL demo program to show that this is working correctly.

Clearly document your code and use generic data structures for maximum portability (packed float arrays, etc).

Function header:

//----------------------------------------------------------------------------
// Clips a 4D homogeneous convex polygon defined by the packed array of float InPts.
// to the viewing frustum defined by w components of the verts. The clipped polygon is
// put in OutPts (which must be a different location than InPts) and the number
// of vertices in the clipped polygon is returned. InPts must have NumInPts*4
// floats (enough to contain poly). Regular orthographic NDC clipping can be
// achieved by making the w coordinate of each point be 1. OutPts will be
// allocated and return filled with the clipped polygon.
//----------------------------------------------------------------------------
int ClipPolyToFrustum(float *InPts, const int NumInPts, float* &OutPts);
Turn in this function, all supporting routines, and the include file named homoclip.*pp. with a simple driver program (main.cpp) that clearly tests its correctness numerically. Use the provided matrix/vector modules provided with the demo source code. Explain your test cases. Also, give several reasons for doing homogeneous clipping in the first place. Will it handle non-convex? Why or why not?