CS 381  >  Week 7 Review Problems

CS 381, Fall 2003
Week 7 Review Problems

Below are some problems related to the material covered in class recently. Answers are in the Answers section, below. Do not turn these in. We may certainly discuss any of these problems in class, if you want.

You can expect Test 2 (on Friday, November 7) to contain problems similar to some of these.

Problems

Note: On the test you will be expected to do problems like these without books or notes.
  1. Express the vector (1, 2, 3) in homogeneous form.
     
  2. Convert the following points from homogeneous form back to ordinary 3-D. a. (5, 2, 7, 1). b. (8, 4, 1, 4).
     
  3. What does homogeneous form allow us to do that is difficult or impossible with ordinary 3-D points/vectors?
     
  4. How does OpenGL store transformations internally?
     
  5. List two kinds of 3-D transformations that cannot be performed using multiplication of a 3×3 matrix by a 3-D vector.
     
  6. What matrices does OpenGL use to represent the transformations generated by each of the following function calls?
    1. glTranslated(7., 8., 9.);
    2. glScaled(7., 8., 9.);

     
  7. Fill in the blank:
    Representing transformations as matrices is particularly convenient, because a single matrix can represent a ________ of transformations.

     
  8. What does “HSR” stand for?
     
  9. We wish to add HSR, using depth buffering, to a simple, well-written GLUT program. What 3 things do we need to do? In your answer, include both the required code and its effect.
     
  10. a. How does OpenGL distinguish between the front and back sides of a polygon? b. Why do we care? Don’t polygons appear identical from the front and the back?
     
  11. Suppose you are given a function drawsphere, having no parameters, that draws a sphere with radius 1, centered at the origin. Write some C++ code that uses this function to draw a sphere of radius 5, centered at (2, 3, 4). You may assume that the matrix mode is GL_MODELVIEW. You are to make no permanent changes to the model/view matrix.
     
  12. We have discussed 5 things that occur in the “vertex operations” portion of the OpenGL geometry pipeline. What are they, and in what order do they occur?
     
  13. Why does your instructor insist that “all graphics is 2-D graphics”? Aren’t we studying 3-D graphics in this class?
     
  14. Bitmap text does not work well in a 3-D scene. Explain.
     
  15. In a perspective projection, we often think of the near clipping plane as representing the screen. And we generally want to draw bitmap text directly on the screen. What problem might occur if we try to draw text on the near clipping plane?
     
  16. How can the proper use of transformations greatly reduce the amount of code required when drawing a complex scene full of many similar objects?
     
  17. The glScale* command scales the world, leaving the origin (0, 0, 0) fixed. Suppose you want to scale the world by a factor of 2, leaving the point (1, 2, 3) fixed. Write C++/OpenGL code (transformation commands only!) that does this.
     
  18. Occasionally, we need to do “glEnable(GL_NORMALIZE);” a. Underwhat circumstances do we need to do this? b. Why? That is, what facts about the OpenGL pipeline make this command necessary?
     
  19. You friend Egbert says that GL_MODELVIEW mode is pointless. He says, “I can do all my transformations with the projection matrix.” To demonstrate, he shows you a program containing the following code.
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-1., 1., -1., 1., 1., 10.);
    glTranslated(0.5, 0.5, -3.);
    When you try this program, you find that it seem to work: you get a perspective view of an object drawn with center (0.5, 0.5, -3.). Still, Egbert’s reasoning has a flaw. What is it?
     

Answers

  1. (1, 2, 3, 1).
    1. (5, 2, 7).
    2. (2, 1, 1/4). [Or (2, 1, 0.25).]
  2. Expressing points & vectors in homogeneous form allows us to express all of the most common transformations in a common format (see next answer).
  3. OpenGL stores transformations as 4×4 matrices of floating-point values.
  4. 3-D matrix-vector multiplication cannot do: Such multiplication can be used to perform scaling, rotation about a line through the origin, and orthogonal projection.
    1. (
       1  0  0  7
      0 1 0 8
      0 0 1 9
      0 0 0 1
      ) .
    2. (
       7  0  0  0
      0 8 0 0
      0 0 9 0
      0 0 0 1
      ) .
  5. Representing transformations as matrices is particularly convenient, because a single matrix can represent a sequence of transformations.
  6. HSR = Hidden Surface Removal.
  7. We need to do the following
    1. OpenGL distinguishes between the front and back sides of a polygon by whether the vertices appear in counterclockwise or clockwise order. (By default, the front side is the one from which the vertices appear in counterclockwise order.)
    2. When there is no lighting, front or back makes little difference (although you can still cull one and not the other!). However, OpenGL can light the front and back differently.
  8. glPushMatrix();
        glTranslated(2., 3., 4.);
        glScaled(5., 5., 5.);
        drawsphere();
    glPopMatrix();
    Depending on the context, you may also wish to do “glLoadIdentity();” just before the transformation commands above.
  9. Here are the five operations we have discussed, in order. Actually, we have discussed two more: 4th-coordinate division and culling. 4th-coordinate division occurs after the projection and before view-frustum clipping, and culling occurs after the viewport transformation.
  10. “All graphics is 2-D graphics” because graphics is the generation of 2-D images to be viewed by eyes with 2-D retinas. What we call “3-D graphics” is really the rendering of 2-D images based on 3-D scenes.
  11. Bitmap text does not work well in 3-D, because bitmaps (along with more general raster images) are copied to the screen pixel by pixel, and are thus affected by transformations differently from geometric objects.
  12. If we draw bitmap text exactly on the near clipping plane, then it may be discarded during view-frustum clipping. One way to solve this is to draw the text just a bit behind the near plane. (This problem is closely related to the reason we avoid using operator== for floating-point values.)
  13. To reduce the amount of code required for such a scene, write a single function to draw the object in a “standard” form (positioned at the origin, no color information given, etc.). Then repeatedly call this function, setting up various OpenGL states (transformations, in particular) beforehand. This lets a single function draw all of the similar objects.
  14. We first move the point (1, 2, 3) to the origin, then scale, then move point back. Since transformation commands are given in the code in reverse order, we want the following.
    glTranslated( 1.,  2.,  3.);
    glScaled(2., 2., 2.);
    glTranslated(-1., -2., -3.);
    1. We need to do “glEnable(GL_NORMALIZE); when we are doing both (1) lighting, and (2) scaling.
    2. OpenGL lighting computations assume that normals are unit vectors. But normals go through the model/view transformation (with translations removed). Thus, if scaling is done, normals may come out of model/view with non-unit length. Normalization fixes this.
  15. The flaw with Egbert’s reasoning is how his program would deal with lighting. Most lighting computations occur between the model/view and projection transformations. Thus, even though model/view and projection affect vertex coordinates as if they were one big transformation, these two transformations affect lighting differently. So Egbert’s program may draw an unlit scene correctly, but it would not draw a lit scene correctly.


CS 381, Fall 2003: Week 7 Review Problems / Last update: 4 Nov 2002 / Glenn G. Chappell / ffggc@uaf.edu