CS-511 - Assignment 2 (5%)

Surface Rendering

Due by: September 23, 2008

Assignment Specifications

In this assignment you need to write a simple surface viewer. The object to be rendered is read from an input file containing vertex and face information. After rendering the object keyboard keys may be used to move the camera around it. Your program should satisfy the following specifications:

  1. Input file format: The input text file describes one 3D object. Each line in that file describes either a vertex or a face. Empty lines, and lines beginning with a # should be ignored. The following are possible lines in the input file:

      # Specify a VERTEX:
      v <float-coord-x> <float-coord-y> <float-coord-z>
    
      # Specify a FACE (triangle):
      f <vertex-index-1> <vertex-index-2> <vertex-index-3>
    

  2. Object loading: Read vertex lines should be stored in a vertex array based on their order in the input file. Read face lines should be stored in a face array. Assume that all the faces are triangles. A face is specified by the indexes of three vertices in the vertex array.

  3. Object normalization: The coordinates of the loaded object should be scaled so that the larger side of its bounding box will have a length of one. The coordinates should be normalized so that the center of the bounding box of the object will be placed at the origin. The scaling/translation can be applied to the vertices directly or using the OpenGL modeling/viewing transformations.

  4. Lighting properties: Use one positional light source that is moved together with the camera. Use smooth shading. Enable the depth test. In order to obtain correct lighting of the object, for each drawn face (polygon) a normal vector should be specified. The normal vector is not provided and should be computed by you. A unique normal should be computed at each vertex by averaging the normals of the faces that intersect it (Compute a normal for each face and add it the existing normal of each of its vertices. Once the complete list of faces is traversed, normalize all the vertex normals).

  5. Moving the camera: after rendering the object, the user should be able to rotate the camera about the object (left/right/up/down) by using the arrow keys and zoom in/out by using the +/- keys. Instead of rotating the camera it is simpler to rotate the object. A simple way to implement the rotation is to store two rotation angles and modify them when the user presses the +/- keys. In this way, before rendering the object you execute two glRotate commands using the angles. Make sure not to combine the current rotation with that of a previous step.

  6. The vertex winding order: The vertex winding order in the provided objects is guarantied to be consistent within objects. It is not guaranteed to be consistent between objects. Test your program on the head and cow objects. Identifying whether the normals of an object need to be inverted due to a different winding order is not required in this assignment (Detecting an inverted winding order is simple. Given a point X on the surface with normal N, and given the center of mass of the object C, you can verify that $N\cdot(X-C)>0$, if it is smaller than zero you need to invert all the normals).

Implementation Notes

  1. You must use SVL/VL to compute the normal vector.

  2. Sample object files are available on the course's website. A sample function for reading the object file will be provided. Please note that the bunny object has holes at its bottom.

  3. Please follow the submission procedure of assignment 1.



Gady Agam 2008-09-09