Difference between revisions of "Project2Fall12"

From Immersive Visualization Lab Wiki
Jump to: navigation, search
(2. Virtual Trackball (40 points))
(Project 2: Interactive Viewing)
Line 1: Line 1:
=Project 2: Interactive Viewing=
+
=Project 2: Viewing 3D Models=
  
This homework assignment consists of four parts, but only the first three are mandatory to get full credit (100 points). In the first part you will need to implement camera matrices and apply them to a simple scene. In the second part you will need to build a virtual trackball to rotate your 3D scene with the mouse. In the third part you will need to load 3D models files and display them with your viewer.
+
This homework assignment consists of three parts, but only the first two are mandatory to get full credit (100 points). In the first part you will need to implement camera matrices and apply them to a simple scene. In the second part you will need to load 3D models files and display them with your viewer. The third, optional part requires building a terrain map and allowing the user to fly over it.
  
 
This assignment is due on '''Friday, October 10'''.  
 
This assignment is due on '''Friday, October 10'''.  
 
It will be introduced by TA Sid on '''Monday, October 8th at 2:30pm''' in lab 260.
 
It will be introduced by TA Sid on '''Monday, October 8th at 2:30pm''' in lab 260.
  
==1. The Camera Matrix (30 Points)==
+
==1. The Camera Matrix (40 Points)==
  
 
===1a. Creating the Camera Matrix (20 Points)===
 
===1a. Creating the Camera Matrix (20 Points)===
Line 14: Line 14:
 
Add a method <tt>getValues</tt> to your camera class to access the components of the camera matrix <tt>C</tt> as an array of 16 values of type GLdouble in the order OpenGL expects them (column-major). You will need this in part 1b. ('''5 points''')
 
Add a method <tt>getValues</tt> to your camera class to access the components of the camera matrix <tt>C</tt> as an array of 16 values of type GLdouble in the order OpenGL expects them (column-major). You will need this in part 1b. ('''5 points''')
  
===1b. Testing (10 Points)===
+
===1b. Testing (20 Points)===
  
As a basis you can use your source code from last week. We provide [[house.cpp|source code]] to generate a simple scene with a house to test your camera matrix implementation.  
+
As a basis you can use your source code from last week. We provide [[house.cpp|source code]] to generate a simple scene with a house to test your camera matrix implementation. Add this code to render the house ('''10 points''').
  
 
Set OpenGL's projection matrix as it was in the Cube example from assignment 1 with the following code in GLUT's Reshape callback function:
 
Set OpenGL's projection matrix as it was in the Cube example from assignment 1 with the following code in GLUT's Reshape callback function:
Line 53: Line 53:
 
|}
 
|}
  
 
+
==2. Displaying 3D Models from Files (60 points)==
 
+
==3. Displaying Triangle Meshes from Files (30 points)==
+
  
 
The OBJ file format is a very simple ASCII text based file format for triangle meshes. In its basic form, an OBJ file contains a list of triangle vertices indicated by the letter <tt>v</tt>, followed by an array of indices to form triangles indicated by the letter <tt>f</tt>. We provide a [[Media:ObjReader.zip|C++ class that reads OBJ files]]. Add this code to your rendering engine. You have to write the necessary code to create OpenGL geometry out of the 3D data structure ('''20 points''').  
 
The OBJ file format is a very simple ASCII text based file format for triangle meshes. In its basic form, an OBJ file contains a list of triangle vertices indicated by the letter <tt>v</tt>, followed by an array of indices to form triangles indicated by the letter <tt>f</tt>. We provide a [[Media:ObjReader.zip|C++ class that reads OBJ files]]. Add this code to your rendering engine. You have to write the necessary code to create OpenGL geometry out of the 3D data structure ('''20 points''').  
Line 69: Line 67:
 
* [http://ivl.calit2.net/wiki/files/bunny.obj Bunny]
 
* [http://ivl.calit2.net/wiki/files/bunny.obj Bunny]
  
You will notice that without further measures, the objects in the OBJ files may be too small or too large for your rendering window. To automatically accommodate for different sizes, calculate the minimum and maximum coordinates in all three dimensions ('''3 points'''), and find out approximately what size objects your rendering window allows. Based on these values you need to create a translation matrix ('''3 points''') and a uniform scale matrix ('''3 points''') which, multiplied with the object matrix, transform the object so that it fills the rendering window. If you implemented the trackball from part 2, allow the user to rotate the object with the mouse by multiplying the object matrix with the trackball rotation matrix.
+
You will notice that without further measures, the objects in the OBJ files may be too small or too large for your rendering window. To automatically accommodate for different sizes, calculate the minimum and maximum coordinates in all three dimensions ('''3 points'''), and find out approximately what size objects your rendering window allows. Based on these values you need to create a translation matrix ('''3 points''') and a uniform scale matrix ('''3 points''') which, multiplied with the object matrix, transform the object so that it fills the rendering window.  
  
 
<!-- To upload the above files, I had to upload them directly to the Wiki server! -->
 
<!-- To upload the above files, I had to upload them directly to the Wiki server! -->
  
==4. Optional Project: Height Map (10 points)==
+
==3. Optional Project: Height Map (10 points)==
  
 
Generate and display a 3D mesh out of a 2D height map image. Wikipedia has a great [http://en.wikipedia.org/wiki/Heightmap description of this topic]. Allow the user to interactively fly over the height map, similar to a simple flight simulator, using keyboard or mouse. You can use the height map image from the Wikipedia page, which you will also find below, or create your own with a paint program or another method of your choice.  
 
Generate and display a 3D mesh out of a 2D height map image. Wikipedia has a great [http://en.wikipedia.org/wiki/Heightmap description of this topic]. Allow the user to interactively fly over the height map, similar to a simple flight simulator, using keyboard or mouse. You can use the height map image from the Wikipedia page, which you will also find below, or create your own with a paint program or another method of your choice.  

Revision as of 01:23, 5 October 2012

Contents

Project 2: Viewing 3D Models

This homework assignment consists of three parts, but only the first two are mandatory to get full credit (100 points). In the first part you will need to implement camera matrices and apply them to a simple scene. In the second part you will need to load 3D models files and display them with your viewer. The third, optional part requires building a terrain map and allowing the user to fly over it.

This assignment is due on Friday, October 10. It will be introduced by TA Sid on Monday, October 8th at 2:30pm in lab 260.

1. The Camera Matrix (40 Points)

1a. Creating the Camera Matrix (20 Points)

As described in the lecture slides, create a camera class Camera with member variables for a 'center of projection' e, a 'look at point' d, and an 'up vector' up (10 points). The class should have an internal camera matrix C, derived from e, d and up (5 points).

Add a method getValues to your camera class to access the components of the camera matrix C as an array of 16 values of type GLdouble in the order OpenGL expects them (column-major). You will need this in part 1b. (5 points)

1b. Testing (20 Points)

As a basis you can use your source code from last week. We provide source code to generate a simple scene with a house to test your camera matrix implementation. Add this code to render the house (10 points).

Set OpenGL's projection matrix as it was in the Cube example from assignment 1 with the following code in GLUT's Reshape callback function:

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glFrustum(-10.0, 10.0, -10.0, 10.0, 10, 1000.0);
  glTranslatef(0, 0, -20);

In your GLUT Display callback, set OpenGL's model-view matrix to your camera matrix C.

  glMatrixMode(GL_MODELVIEW);
  glLoadMatrixf(camera.getCameraMatrix().getValues());

Render two images of the scene using these two sets of parameters for your camera matrix:

  • Image 1:
    • Center of projection: 0, 10, 10
    • Look at point: 0, 0, 0
    • Up vector 0, 1, 0
  • Image 2:
    • Center of projection: -15, 5, 10
    • Look at point: -5, 0, 0
    • Up vector 0, 1, 0.5

Compare your implementation to the correct result images shown below. If you can accurately re-create the images you will receive 5 points for each image. Note that you need to set OpenGL's lighting to 'off' with glDisable(GL_LIGHTING).

House1-half.png House2-half.png
Image 1 Image 2

2. Displaying 3D Models from Files (60 points)

The OBJ file format is a very simple ASCII text based file format for triangle meshes. In its basic form, an OBJ file contains a list of triangle vertices indicated by the letter v, followed by an array of indices to form triangles indicated by the letter f. We provide a C++ class that reads OBJ files. Add this code to your rendering engine. You have to write the necessary code to create OpenGL geometry out of the 3D data structure (20 points).

Add support for a command line parameter to specify the name of the .obj file to load (1 point). Note that you can access the file name passed on the command line by evaluating argv[1] in your main() function (look here for further information on command line arguments).

Here are five sample OBJ files for testing. Make sure they all work, because you will be asked to show them during homework grading.

You will notice that without further measures, the objects in the OBJ files may be too small or too large for your rendering window. To automatically accommodate for different sizes, calculate the minimum and maximum coordinates in all three dimensions (3 points), and find out approximately what size objects your rendering window allows. Based on these values you need to create a translation matrix (3 points) and a uniform scale matrix (3 points) which, multiplied with the object matrix, transform the object so that it fills the rendering window.


3. Optional Project: Height Map (10 points)

Generate and display a 3D mesh out of a 2D height map image. Wikipedia has a great description of this topic. Allow the user to interactively fly over the height map, similar to a simple flight simulator, using keyboard or mouse. You can use the height map image from the Wikipedia page, which you will also find below, or create your own with a paint program or another method of your choice.

Heightmap.png
Height map image from Wikipedia

To get full credit you need to implement the following features:

  • Load the height map image and create a 3D mesh out of it (4 points). You can either read the Wikipedia PNG image file with your own reader, or read this PGM image file with this piece of C code.
  • Use a color gradient from blue (water) to yellow (sand), green (grass), grey (rock) and white (snow) to color the terrain polygons, depending on their height (2 points).
  • Create a separate navigation mode apart from that of the trackball, in which the user can navigate by steering left/right, up/down, and change the velocity of the flight (3 points). Scale the terrain up to a size appropriate for a flight simulator scenario (1 point).

If you use the Wikipedia height map, the resulting terrain should look similar to this, except that it needs to be colored as described above:

Heightmap rendered.png
3D terrain generated from height map