Interactive 3D Using OpenGL

Exercise 2

Implement an interactive 3D viewer using the OpenGL API. Here are the specifications:

  1. The program is invoked with two file names. The first file contains the 3D object to be viewed. The second file contains the viewing and screen parameters.
    The format of these files is as follows (the // indicate explanatory comments not in the file; words in boldface appear as they are):

    object file (ending with .msh):
    Object name // the name of the object, one word
    Diffuse r g b // this is the diffuse material color for the object. r,g,b are in [0,255]
    Specular r g b n // the color of the specular highlights and the specular exponent
    n // n is the number of vertices (integer)
    V0x V0y V0z N0x N0y N0z // vertex coordinates + vertex normal (real numbers)
    ...
    V(n-1)x V(n-1)y V(n-1)z N(n-1)x N(n-1)y N(n-1)z
    m // m is the number of triangular faces (integer)
    t00 t01 t03 // vertex numbers (integers)
    ...
    t(m-1)0 t(m-1)1 t(m-1)2
    k // k is the number of quadrilateral faces (integer)
    q00 q01 q03 q04// vertex numbers (integers)
    ...
    q(m-1)0 q(m-1)1 q(m-1)2 q(m-1)4

    view file (ending with .viw):
    Camera cx cy cz // world coordinates of the camera position (real numbers)
    LookAt lx ly lz // world coordinates of the center of interest (real numbers)
    Up ux uy uz // the "up vector" (real numbers)
    Fov a // horizontal field-of-view angle in degrees (real number)
    Resolution w h // width and height of screen window in pixels (integers)
    Lights n // The number of light sources to be used
    L0x L0y L0z L0w // light source position (or direction, if 4th coordinate is 0)
    ...
    L(n-1)x L(n-1)y L(n-1)z L(n-1)w

    Exercises which will not handle the formats correctly will not be graded.
    When the coordinates of the normals of all vertices of a face are all zero, it means you should compute a normal to the whole face.


  2. The program opens a screen window of size (w,h) and displays the 3D object in this window.
    The object should be displayed with shading and hidden surface removal.
  3. If no view file name is given, the program automatically computes an appropriate view and uses it. The view is such that the object is fully seen from its widest side and occupies about 3/4 of the screen window. Hint: use the mesh's bounding box.
  4. The program should also find a pair of good clipping planes for the view.
  5. The program enables the user to:
  6. Double buffering should be used for smooth object motion.
  7. Clicking the `r' key resets the view to its initial state.
  8. Clicking the `q' key terminates the program.
  9. Clicking the `x', `y', and `z' keys constrains the rotation to be around the screen's x, y and z axes, respectively. These clicks operate as toggles (i.e., the next click on any of them gets out of constrained mode).
  10. You should create interesting object files and submit them with your program.
  11. Use a clear, well modularized programming style. There is no need for code documentation, only in special cases. Provide a short documentation for each module.

The exercise should be submitted by 8/6/98. All the files should be in a directory ~you/graphics/ex2. The directory should also contain a README file saying who are the people submitting the exercise, which files are there, and document any modifications you have made to the specification. E-mail the README file + the name of the directory containing the source and run files to: BODEK

Libraries and example files are on sunshine. An example source code which uses OpenGl and Makefile are available: Example source file: bounce.c ,
Makefile: Makefile .

In order that your application would run properly you should run the following command before running application.

setenv LD_LIBRARY_PATH /usr/local/Mesa-2.6/lib:$LD_LIBRARY_PATH

This command should be executed only once.

We are aware of the fact that this specification may be incomplete. If you have any questions or problems, e-mail the TA, and stay tuned to future modifications and corrections.