Assignment 3: render a grid in 3D with OpenGL 1.x

Update your code for the previus assignment to render a grid terrain in 3D. Implement the usual translate/rotate movements on key press:

u/d: for up/down 
l/r: for left/right 
f/b: for forward/backward
x/X: for rotation around X-axis
y/Y: for rotation around Y-axis
z/Z: for rotation around Z-axis
c: cycle though the various color maps 
q: quit 
In addition:

3D rendering

To render 3D shapes the steps are the following:
  1. set up a projection transofrmation in your main() function:
      gluPerspective(60, 1 /* aspect */, 1, 10.0); 
      /* by default camera is at (0,0,0) looking along negative y axis;  
          the frustrum is from z=-1 to z=-10 
  2. Enable hidden surface removad in OpenGL when you set up:
    Make sure your display mode contains depth:
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); 
    and when you clear in display function, make sure you clear the depth buffer as well:
  3. In your display function, set up transformations to map your grid into the [-1,1]x[-1,1] window; and then render the triangles in the grid being careful to specify the correct z-coordinate of each vertex using
    The display function will look like this:
    glLoadIdentity(); //clear the matrix 
    //viewing transformation 
    //first keypress motion: translate then rotate , for e.g. 
    glTranslatef(pos[0], pos[1], pos[2]);  
    glRotatef(theta[0], 1,0,0); 
    glRotatef(theta[1], 0,1,0);  
    glRotatef(theta[2], 0,0,1);  
    //now map the terrain to [-1,1]x[-1,1] window 
    glScale(..); //scale [0,0]x [nrows,ncols] to [-1,1]x[-1,1]
    glTranslatef(-ncols/2.0, -nrows/2.0, -2);  //center it 
    //draw the grid 

For documentation on GL check the Reddbook, especially chapter 3 (Viewing) here. Below are some excerpts from the book:

As we can attest, it's all too easy to achieve the well-known black-screen effect. Although any number of things can go wrong, often you get this effect - which results in absolutely nothing being drawn in the window you open on the screen - from incorrectly aiming the "camera" and taking a picture with the model behind you. A similar problem arises if you don't choose a field of view that's wide enough to view your objects but narrow enough so they appear reasonably large.

If you find yourself exerting great programming effort only to create a black window, try these diagnostic steps.

Submitting your work

Make a folder called render3d in your svn folder on microwave, and update it with your work.