Viewer Movement in OpenGL

Tom Kelliher, CS 320

Mar. 30, 2005

Administrivia

Announcements

New project handout.

Assignment

Read Chapter 5.

From Last Time

Linear algebra basis for computer graphics transformations.

Outline

  1. Understanding clipping volumes and their specifications.

  2. Projections.

  3. Movements in 3-D.

  4. Toward a better movement model.

Coming Up

Movement through a room. (?)

Preliminary: Viewing Volumes

Are our viewing volume coordinates relative or absolute?

Consider:

  1. By default, the eye is at looking down the -z axis.

  2. What does
    glOrtho(-10.0, 10.0, -5.0, 5.0, -2.0, 2.0);
    
    mean?

  3. Other viewing modes:
    1. glFrustum: same parameters as glOrtho. What's a frustum? Truncated pyramid.

    2. gluPerspective: fovy, aspect ratio, zNear, and zFar.

    znear and zfar need to be positive.

Moving and Positioning the Eye

View specification:

  1. One way of specifying eye position and viewing angle:
    1. Specify position of eye.

    2. Specify center of field of view.

    3. Specify ``up.''

  2. Use of gluLookAt() in cubeview.c:
    void display(void)
    {
    
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    /* Update viewer position in modelview matrix */
    
       glLoadIdentity();
       gluLookAt(viewer[0],viewer[1],viewer[2], 0.0, 0.0, 0.0,
                 0.0, 1.0, 0.0);
    
    /* rotate cube */
    
       glRotatef(theta[0], 1.0, 0.0, 0.0);
       glRotatef(theta[1], 0.0, 1.0, 0.0);
       glRotatef(theta[2], 0.0, 0.0, 1.0);
    
        colorcube();
    
       glutSwapBuffers();
    }
    
    Note order of matrix multiplications: view, then model transformations.

  3. Is it really necessary to have view and model transformations?

Example Runs

  1. P1: Stock viewcube using frustum. Demonstrate clipping, invisibility when up vector is parallel to line of sight, walking through the cube.

  2. P2: Perspective view with fovy 45, near 2, and far 20.

  3. P3: Perspective view with fovy 135, near 0.1, far 100.

A Movement Model

Problems with viewer movement in cubeview:

  1. Must specify movement in global coordinate values.

  2. Can't speak of left, right, forward, backward, etc.

Consider this model:

  1. What should the radius of the circle be?

  2. Given x, y, and , what's and ?

  3. How do we handle left, right, forward and backward?

  4. Suppose, to see the ``big picture,'' I wanted to elevate on the Z-axis. What should I do with center? Is that easy to do?



Thomas P. Kelliher
Wed Mar 30 09:35:37 EST 2005
Tom Kelliher