Difference between revisions of "Project2Fall12"

From Immersive Visualization Lab Wiki
Jump to: navigation, search
(1b. Testing (10 Points))
(1b. Testing (10 Points))
Line 25: Line 25:
 
** Up vector 0, 1, 0.5
 
** Up vector 0, 1, 0.5
  
Compare your implementation to the test images shown below. If you can accurately re-create the images you will receive '''5 points''' for each image. Note that the images below were rendered with OpenGL's lighting set to 'off' (<tt>glDisable(GL_LIGHTING)</tt>).
+
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 <tt>glDisable(GL_LIGHTING)</tt>.
  
 
<center>
 
<center>

Revision as of 23:29, 4 October 2012

Contents

Project 2: Interactive Viewing

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 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 (30 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 (10 points).

1b. Testing (10 Points)

We provide source code to generate a simple scene to test your camera matrix implementation. Set the object transformation matrix (model matrix) to the identity matrix and render two images of the scene using these two sets of parameters:

  • 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.png
Image 1

House2.png
Image 2

2. Virtual Trackball (50 points)

Implement a virtual trackball which allows a user to rotate an object interactively with the mouse. Your solution should translate clicking and dragging of the mouse into a rotation matrix, which you then use to rotate the scene. Rotations around all three coordinate axes should be supported. A sample executable demonstrating the trackball functionality is available for Windows and Linux. If the executable does not work on your computer, here is a video of it. To access mouse coordinates, you will need to use GLUT's callback functions glutMouseFunc() and glutMotionFunc(). Note that successive trackball rotations must build on previous ones; at no point should the model snap back to a previous or default position.

The figure below illustrates how to translate mouse movement into a rotation axis and angle. m0 and m1 are consecutive 2D mouse positions. These positions define two locations v and w on a 3D virtual sphere that fills the rendering window. Use their cross product as the rotation axis a = v x w, and the angle between v and w as the rotation angle.

Trackball.jpg

Horizontal mouse movement in the middle of the window should result in a rotation around the y-axis. Vertical mouse movement in the middle of the window should result in a rotation around the x-axis. Mouse movements along the boundary (horizontal and vertical) should result in rotations at least partially around the z-axis.


You will notice that you can either rotate the camera around a static object space, or the object space with respect to a stationary camera. We recommended (but not required) using a stationary camera and rotating the object space.

You get points for the following accomplishments:

  • The object space rotates about its origin (20 points).
  • The trackball rotates correctly with regards to mouse movement (e.g., mouse to the right -> object rotates to the right) (25 points).
  • Clicking and dragging anywhere in the window, including close to the edge or corners of the window, does not crash the application (5 points).

3. Displaying Triangle Meshes from Files (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 v, followed by an array of indices to form triangles indicated by the letter f. We provide a C++ class that reads .obj files. You should add this code to your rendering engine. The .zip file also contains a code sample that demonstrates the use of this class. You have to add the routines to create OpenGL geometry out of the 3D data structure (4 points). Add support for a command line parameter to specify the name of the .obj file to load (1 point).

One problem is that you don't know the extent of the object stored in the file. The stored triangle coordinates may be too small or too large for your rendering window. To fix this, calculate the minimum and maximum coordinates in all three dimensions (5 points), and find out what size objects your rendering window allows. Based on these values you need to create a translation matrix (5 points) and a uniform scale matrix (5 points) which, together, transform the object so that it fills the rendering window.

Here are a few sample .obj files for testing. Make sure they all work, because you will be asked to show some of them during homework grading.


4. 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