Home | | Syllabus | | Assignments | | Documentation

    Solution to Assignment 5


    Problem 1a: Walking through a scene.

    C code for solution to the scene Walk-through problem


    Problem 1b: Questions about walking through a scene.

    1. If you used glFrustum(xmin, xmax, ymin, ymax, near, far) instead of gluPerspective() in your program, what values of xmin, xmax, ymin and ymax would give you the same clipping volume as specified in the program?
    The gluPerspective(fovy, aspect, near, far) function sets up a frustum clipping volume whose near and far planes along the Z axis are as specified by the parameters, near and far. The frustum is symmetrical about the x and y axes, with the angular field of view along the y axis given by fovy. In our problem fovy = 45deg. Thus the vertical edges of the clipping volume will be defined by lines in the y-z plane at +/- 22.5 deg from the z axis, as shown in the figure.

    The parameters ymin and ymax are defined at the near Z plane, (which is at Z = -1), so we have the following equations:

    ymin = -1*tan(22.5) = -.414

    ymax = 1*tan(22.5) = .414

    Because the aspect ratio (width/height) is 1.0, and because the horizontal edges of the frustum are also symmetrical about the plane x = 0, we have:

    xmin = ymin = -0.414

    xmax = ymax = 0.414

    So, the entire function call would be:

    glFrustum(-.414, .414, -.414, .414, 1.0, 400.0);

    2. Why did you set the initial camera position with vz = 250.0? What would happen if you had set it to vz = 0.0?
    The initial camera position is at position Z = 0.0, which is also the middle of the object we defined. We need to shift the camera backward (to z = 250) in order to get a view of the front of the pyramid. If we did not move the camera back to vz = 250, the initial view would have been from inside the pyramid!

    3. When you hit the lowercase 'z' key, the vz component is decremented, but the pyramid appears to move toward the camera (i.e. it gets bigger), as if it is moving in a positive Z direction. Why is this?
    When you hit lowercase z, you decrement the position of the camera. This is equivalent to incrementing the position of the pyramid while holding the camera stationary (and in fact, that is what happens in openGL). Thus a decrement of camera position, causes an increment in object position. The object moves closer to the camera and thus appears bigger.

    4. If you hold down the uppercase Z for a long time, the pyramid appears to move away from the camera (i.e. it gets smaller). After a while, the top of the pyramid gets flattened. As the pyramid moves further away, the top gets flatter. Why does this happen?
    The top of the pyramid gets flattened because the pyramid is moving outside the clipping volume. The clipping volume is defined with respect to the camera position. As we "move the camera", openGL actually holds the camera stationary and moves the object in the opposite direction. When you hold down uppercase Z, the object moves away. When the position of the top of the pyramid reaches Z = -400.0, it is aligned with the back of the clipping volume. Because the pyramid surfaces slant backwards, the top gets clipped off first. You can only see this clearly when you are looking straight on at one of the faces of the pyramid. When you are looking at the pyramid along an edge (as was the case if you stopped the spinning of the pyramid), the top is still flattened, but the projections of the faces are still triangular so you cannot see the flattening.


    Problem 2: Drawing a pyramid with a shadow.

    C code for creating the pyramid with a shadow.


    Home | | Syllabus | | Assignments | | Documentation


    Constance Royden--croyden@mathcs.holycross.edu
    Computer Science 384
    Date Created: August 17, 1999
    Last Modified: November 5, 2003
    Page Expires: August 17, 2004