Draft for solutions to the exam in TSBK05 050607

1. OpenGL programming

a) Draft code, mark the code telling what does whhat part of the transformation pipeline. The question wants you to show that you know how theory and practice fits together. Note that it is no problem at all if you don't remember the exact names of OpenGL calls! API names are unimportant, you look them up when you need them.

// May be part of "redraw" or "display" or done in user interface parts // World coordinates to camera coordinates (camera placement) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(...) // Part of the "display" function in GLUT or similar // Model coordinates to world coordinates (place model in world) glMatrixMode(GL_MODELVIEW); glPushMatrix(); // Preserve the camera placement glTranslate...(...); glRotate...(...) draw model glPopMatrix(); // Not mandatory for solution: // May be part of "redraw" function in GLUT or similar // Camera coordinates to projected coordinates glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum()

b) GLUT (like SDL) is a library that hides the system dependent parts of OpenGL under a cross-platform interface. If such an API is not used, we must do some tasks using system dependent libraries, that is GLX (Unix, X-Windows), WGL (MS Windows), AGL (Macintosh). (GLU was mentioned as a side-track and is irrelevant to the question.)

Notes: OpenGL questions generally focuses on transformations (like a), with minor questions on system-level issues (like b). As noted above, mis-spellings of OpenGL calls are generally accepted as long as it is clear what function you

2. Transformations

a) This is really not one of the best transformation problems, since it isn't very well founded in practicval problems. On the other hand, it is pretty easy: Translate a vertex to origin, rotate and mirror, translate to the new position of that vertex. Most problems should be formulated to that we do the more interesting transform to origin - transform - transforma back sequence.

Full matrices should be given (see the book), angles in rotations should be properly derived from geometry. The full transformation multiplication sequence should be given in the proper order.

b) This is the look-at problem, covered by the book, section 7-3 and 7-4. Note that a "forward vector" is in the opposite direction to the view-plane normal vector. The final reult should be equivalent of formula 7-4.

3. Curve generation

a) This question demand that you reformulate the Bresenham line drawing algorithm to a strict midpoint algorithm, a nice and easy variant of all the more tedious ellipse and circle algorithms.

A line can be formulated as y = mx + b. Rewrite to f1(x, y) = m*x
+ b - y. This is a function which is positive above the line and
negative below. But, it is not integers. With one end point
x_{0}, y_{0} and total lengths Æx and Æy, m = Æy/Æx
and b = y _{0} - x_{0} * Æy / Æx. Multiply by Æx and
everything are integers! Then we get:

f2(x, y) = x*Æy - y*Æx - x_{0}*Æy + y_{0}*Æx

The curve should be 8-connected so the possible steps should be
(1, 0) and (1, 1), putting the midpoint in x_{k}+1,
y_{k}+1/2. But when we insert this midpoint in f2 we find
that the half step causes non-integer values. We fix that by
multiplting with 2, which gives us the final curve function

f(x, y) = 2(x*Æy - y*Æx - x_{0}*Æy + y_{0}*Æx)

Using p_{k} = f(x_{k}+1, y_{k}+1/2) we
calculate p_{k+1} - p_{k}

for diagonal and horizontal moves. As expected they come out as 2Æy-2Æx and 2Æy, respectively.

Finally we calculate the starting value: f(x0 + 1, y0 + 1/2) = 2Æy - Æx

Same result, other (more general) method.

b) If you get the result above, this is obviously true, but how
can you prove it without having the Bresenham algorithm available?
You should do its very first part, calculating d_{upper} and
d_{lower}, and find that their difference multiplied with Æx
results in the same thing.

c) Note how each pair of update steps supports a limited direction interval. The figure you draw should mark which part uses which pair of update steps and the point where you need to switch. See the section in the book about ellipse drawing.

4. Miscellaneous

a) Ray-triangle intersection.

First derive the formula for the intersection by inserting the line equation in the plane equation.

Then describe how the intersection is placed in the triangle, and how we can use barycentric coordinates or some equivalent method for checking that we are in the triangle. See the supplement.

b) Problem 1: Heavy stack use. Problem 2: Massive numbers of function calls. Problem 3: No stopping rule that guarantees that it ends.

5. Mapping techniques.

a) See the supplement. (The book also covers this but IMHO not as well.)

b) Resolution pyramid for textures, in order to reduce aliasing. The cost is 33% more memory for each texture (that is, it is cheap).

6. Collission detection

a) Sorting, for example linear sorting, quad trees or octrees,

b) See the supplement, two figures with colliding polyhedra. The tests involved are containment tests and edge-polygon intersection tests.

7. Visible surface detection

a) First: z^{-1} is linear in screen space, which z is
not. Second, z^{-1} gives higher resolution near the camera,
which is highly desirable for the Z-buffer.

b) It is the set of polygons that need to be drawn from one specific cell to rennder the scene properly. It can be rendered by rendering the entire world as polygon indices (rather than textures and shades). All polygons for which there are indices in the resulting images are part of the PVS. By rendering in all directions from several positions in a cell we get a good approximation of the perfect PVS.

c) Decomposition, building of tree: See the book and the supplement. It will be correctly rendered since we choose branch in real-time depending on vieweing direction.

8. Light, shading and ray-tracing

a) Yes. The Phong model can be used for calculating shades per vertex with support for specular reflections. Phong shading can be used without using the specular reflection component in the three-component model; nothing stops us from interpolating normals and calculating light per pixel even if the object is diffuse.

b) The rays start at the camera, and are traced until they reach a diffuse surface or max search depth.

c) E_{k} is emitted light from light sources,
p_{k} the reflectivity, B _{k} is the total emitted
light and F _{k} the form factor. If you know that, the
calculations should be easy.