CMSC 435: Introduction to Computer Graphics

Assignment 2

Modeling

Due March 2, 2005

Updated: Monday, Feb 21, 2005 - Added Visual Studio Project

The Assignment

For this assignment, you will be using OpenGL to create a simple interactive view of a procedurally modeled scene. You will create a landscape from a height field.   Your program will read an input file which contains a grid of heights, and generate the landscape accordingly. The landscape will be modeled using Bezier Patches, one patch for each height field entry. You must generate patches which are C1 continuous at each edge, and you must render the terrain without any cracking between patches. You will render the terrain by computing a grid of vertices at specified intervals along the patches, and connecting these vertices with triangles.

The landscape should be lit by one OpenGL distant light (simulating the sun or moon), and one ambient light (simulating bounce light and atmospheric scattering). For the lighting to work, you will need to compute surface normals at each vertex of your model. Compute these when you initially compute the landscape. The vertex normal should be the average of the normals for each face touching the vertex. Each face normal can be computed using the cross product of two of the edges on that face. Be careful to make sure your normals point up. A sample OpenGL application will be provided to get you started. You should use OpenGL's lighting functions to shade your scene. In order for the lighting to work correctly, you will need to compute normals as well as positions for each vertex you generate. You should use smooth shading glShadeModel(GL_SMOOTH).

For user interaction, your program should support rotation exactly as shown in the sample program. To match rotations to mouse motion on the screen, it adds a rotation around an axis perpendicular to the mouse motion in screen space, before the current transform. You should also adjust the viewing transformation so that the entire landscape can be seen. The easiest way to do this is to use an orthogonal projection (glOrtho) and set the width and height of the viewport equal to the width and height of your terrain.

The input file will be formatted as follows: The first two numbers are the number of patches that you will create in the X and Z directions. The remaining numbers form an X by Z grid of heights. Your program will create an X by Z grid of Bezier patches, and adjust the y values
of their control points according to the height field.

An example input file looks like this:
3 3
3 3 3
2 3.5 2
1 1 1

Each patch is represented by a 4x4 grid of control points. The four center control points should have heights equal to the height field value for the patch, and the four corner control points must have heights equal to the average height of all patches around them. The edge control points should be computed by averaging the corresponding center control points between neighboring patches. This will guarantee C1 continuity.

The zipped file can be downloaded here. The zipped file contains

The Windows Project can be downloaded here.


Using GLUT

Unfortunately, the only way to pass information between GLUT callback functions (the ones passed to GLUT through the glut*Func() calls) is by using global variables.

If you choose to code in C++, each of the GLUT callback functions must be a top-level function (not a class member function) declared extern "C". For example,

// declare
extern "C" void draw();

// define
extern "C" void draw() {
  // C++ code
}

Strategy

There are several ways you could program the procedural terrain. Those details are up to you. I do suggest planning your development with lots of intermediate milestones with visual results. Also, rendering itself can be a great way to debug visually.

What to turn in

Turn in this assignment electronically by submitting it using the 'submit' program on the GL systems 11:59 PM on March 2. Submit a readme.txt file telling us about your assignment. What (if any) help did you receive from books, web sites or people other than the instructor and TA? What did you do to make it look more realistic?

Also submit everything we need to run your submission. We should be able to run 'make' in your submission directory on the linux.gl systems to produce a running interactive OpenGL program. Submit your modified Makefile, any C/C++ files, and any other auxiliary files we might need. Screenshots and height fields for any terrains you think look good (At least 2). Be sure to comment your code! You will not be graded on the presence or quality of your comments, but we will look at your code and anything that helps us understand what you did (or were trying to do) can only help. In any case, your programs are expected to be robust and easy to understand.

Extra Credit:
For base credit, make your terrains as interesting looking as you can. Some things to try include color coding the terrain based on its elevation
(white at high altitudes, brown or green at lower altitudes), or adding random perturbations to your triangles to give the terrain a rougher, more
natural look. Extra points will be awarded based on creativity, effort, and appearance.
 

Working at home

Once again, if possible, I urge you to use the university computers for your work. I test things out on the gl systems and may or may not be able to help you if things don't work right for you at home. If you do work at home, your final submitted version must be able to run on the gl machines and must be electronically submitted there.

If you have a X server on your home machine (i.e. if you are running Linux, Mac with X11, or one of the Windows X11 packages), it is possible to run remotely, though interacting with the application is much harder when displaying remotely.

If you absolutely must work at home, you will need:

All of these libraries are cross-platform and run on both Unix and Windows. However, if there are no pre-built binaries for your platform, you may end up having to build them from the source downloads. Which brings me back to: if you don't have to work at home, don't.