CMSC 435/634: Introduction to Computer Graphics

Assignment 4
Modeling
Due November 7, 2012

The Assignment

This assignment builds on the previous terrain driving assignment. You may either use your own Assignment 3 code, or start from my code (in ~olano/public/drive on gl), or look at my code to help fix your own.

For this assignment, you will be loading a car model from a file and drawing it at your current position as you drive over the terrain. The car can be found in ~olano/public/drive/mini.obj and ~olano/public/drive/mini.mtl. The format is a subset of the OBJ model format (described below). You should load the model once when your program starts, then use the data structures you create to render that model along with the terrain each frame. Scale, translate and transform the car model to draw it at the current vehicle position.

Modify your viewing code to toggle between two modes with the 'v' key. In the first mode, your view should be inside the car from the drivers seat. Mouse motion in this mode should rotate your view from the drivers seat. In the second mode, your view should be outside the car. Mouse motion in this mode should orbit your view around the car in a "third person" view. In both modes, the driving keys should still turn and accelerate the car.

Format

The obj format is a simple text model format, commonly used for model interchange. Details on the complete format can be found on Wikipedia (among other sources). The file you have to load only uses a subset of the complete format, and this subset is all you need to be able to read correctly.

Treat lines starting with '#' or any line you don't recognize as a comment.

Lines in the format 'v %f %f %f' specify a vertex. The general format allows 4-element xyzw vertices, but the file you are given does not have any of these. Lines in the format 'vn %f %f %f' specify a vertex normal. The general format also allows texture coordinate lines beginning 'vt' but your file does not have any of these, so you do not need to support them.

These vertices are connected together into faces with lines of the form 'f %d//%d %d//%d %d//%d'. The first pair of numbers give the indices (starting at 1) for the first vertex and normal in this triangle, the second pair of numbers gives the indices for the second vertex and normal, and the third pair gives the indices for the third vertex and normal. In your file, each pair of numbers will be the same, so the first vertex always matches up with the first normal.

For example, a file containing a single triangle might look like this:

    v 0 0 1
    v 1 0 0
    v 0 1 0
    vn 1 1 1
    vn 1 1 1
    vn 1 1 1
    f 1//1 2//2 3//3
  

In addition, your file contains material specifications, with a line 'mtllib mini.mtl', which says to find material descriptions in the mini.mtl file. Then there are 'usemtl %s' lines that specify a specific material to be used for subsequent geometry.

The material definitions in mini.mtl consist of lines of the form 'newmtl %s' defining a new material name, followed by a line giving the ambient color 'Ka %f %f %f %f' and diffuse color 'Kd %f %f %f %f'.

You can have one vertex array and one normal array, but you should draw the faces for each material type separately to allow you to change colors.

634 only

Add additional obj features necessary to also load bunny.obj and drive the bunny around the terrain instead. Note that this bunny model does not have a material definition. In this case, you should have a reasonable default material. In addition, it has texture coordinates, and does not use the same index for the vertex position, texture coordinate, and normal. You will need to associate a new index with each unique v/vt/vn triple, and construct new vertex position, texture coordinate, and normal arrays in this order. I recommend looking into the capabilities of STL map for this.

Strategy

Plan ahead first. Start with a third-person view and a placeholder object like glutSolidSphere or glutWireSphere. With glutWireSphere, you can test and debug the first-person view controls. Then start working on model loading. First construct a simpler file like a tetrahedron or cube before you take on the full 40k triangle model.

What to turn in

Turn in this assignment electronically by checking your source code into your assn4 CVS directory by 11:59 PM on the day of the deadline. Do your development in the assn4 directory so we can find it. As always, double check that you have submitted everything we need to build and run your submission, but not any generated files. In particular, no executables, or any of the other files xcode or visual studio generate (if it is binary, leave it out!). This time you will lose up to 10 points of your total grade if you check in unnecessary files.

For grading, be sure your program does run on Linux, and be sure to include a Makefile that will build your project when we run 'make'. Also, include a readme.txt file telling us about your assignment. Do not forget to tell us what (if any) help did you receive from books, web sites or people other than the instructor and TA, details about how you implemented the extra credit (if attempted).