# Due Thursday February 1st midnight

## An Overview

Height fields may be found in many applications of computer graphics. They are used to represent terrain in video games and simulations, and also often utilized to represent data in three dimensions. This assignment asks you to create a height field based on the data from an image which the user specifies at the command line, and to allow the user to manipulate the height field in three dimensions by rotating, translating, or scaling it. After the completion of your program, you will use it to create an animation.

## Why?

This assignment is intended as a hands-on introduction to OpenGL and programming in three dimensions. The starter code we provide is minimal, giving only the functionality to read and write a JPEG image and handle mouse and keyboard input. You must write the code to create a window, handle all camera transformations, perform any and all rendering, and handle any other functionality you may desire. We highly recommend the use of GLUT--please see the OpenGL Programming Guide for information, or, if you chose not to purchase this book, please see OpenGL.org and a page of OpenGL tutors or the on-line red book . You may use an alternate library (FLTK, GTK, etc) if you desire, but your submission must run in the graphics cluster, and we will likely be unable to provide support if you run into problems.

## Background Information

A height field is a visual representation of a function which takes as input a two-dimensional point and returns a scalar value ("height") as output. In other words, a function f takes x and y coordinates and returns a z coordinate.

Rendering a height field over arbitrary coordinates is somewhat tricky--we will simplify the problem by making our function piece-wise. Visually, the domain of our function is a two-dimensional grid of points, and a height value is defined at each point. We can render this data using only a point at each defined value, or use it to approximate a surface by connecting the points with triangles in 3D.

You will be using image data from a JPEG file to create your height field, such that the two dimensions of the grid correspond to the two dimensions of the image and the height value is a function of the image color. Image color has three intensity values, one each for red, green and blue, and you may use any function of these to obtain a height value as long as grey values (all color intensities equal) convert monotonically. The most straightforward way to do this is to pick one color channel and scale it linearly, ignoring the other two.

Starter code in C, a Makefile, and examples are located here. You may use another language if you wish, but your program must compile and run in the graphics cluster.

### Your program must:

• Handle at least a 256x256 image for your height field at interactive frame rates (>15fps with a window size of 640x480).
• Be able to render the height field as points, lines("wireframe"), or solid triangles (with keys for the user to switch between the three).
• Render as a perspective view, utilizing GL's depth buffer for hidden surface removal.
• Use input from the mouse to spin the heightfield around using glRotate.
• Use input from the mouse to move the heightfield around using glTranslate.
• Use input from the mouse to change the dimensions of the heightfield using glScale.
• Color the vertices using some smooth gradient.
• Be reasonably commented and written in an understandable manner--we will read your code.
• Be submitted along with JPEG frames for the required animation (see below).

### Animation Requirement

After finishing your program, you are required to submit an animation, represented by a series of JPEG images which are screenshots from your program. Functionality to output a screenshot is included in the starter code, and assumes you are using a window size of 640x480--your JPEG images must be this size. Please name your JPEG frames 00.jpg, 01.jpg, and so on, where 00.jpg is the first frame of your animation, and please do not exceed 100 frames. Expect a framerate of 15 frames per second. It's probably a good idea to test your animation by using animate ("man animate" for information) in the graphics cluster. This program takes a sequence of images and displays them as an animation, at your desired framerate.

The method of generating your frames is left up to you--there is a large amount of room for creativity. You may use any software you wish to generate the source images for your height fields. The GIMP is available on graphics cluster machines (type "gimp" at a terminal prompt). You may also use your animation to show off any extra features you choose to implement.

Your animation will receive credit based on its artistic content, whether pretty, funny, or just interesting in some manner.

## Submission

Please submit your code along with your makefile to /afs/andrew/scs/cs/15-462/turnin/your_andrew_id/, in a sub-directory called asst1. When we run "make" in this directory it should compile your program successfully. Within this directory, make a sub-directory called movie, and place the frames for your animation within, numbered as described above.

## Tips

• Familiarize yourself with GL's viewing transformations before attempting to render the height field itself. Try rendering a simple object first.
• Finish your program completely before worrying about the animation.
• Don't try to do this at the last minute. This assignment is supposed to be fun and relatively easy, but time pressure has a way of ruining that notion.
• Make sure you can log in right away. Notify us immediately if you have any problems.

## Extras

You may choose to implement any combination of the following for extra credit (max 10%).

• Experiment with material and lighting properties.
• Color the vertices based on color values taken from another image of equal size.
• Texturemap the surface with an arbitrary image.
• Allow the user to interactively deform the landscape.

For the brave or insane:

• Level of detail (mip mapping/trilinear) to allow heightfields of significantly higher resolution.
• Non-rectilinear geometry (not just by wiggling the points side to side).

## Examples

Below are some example images and the resultant height fields.