# Due Tuesday September 21st 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.

## Starter Code

You are given starter code which contains the following:

• Code to read an input jpeg into memory.
• Code to output a screenshot to a jpeg with a file name you specify.
• Code to diplay a simple menu when you right click. The menu provided simply contains an option to quit.
• Code to receive keyboard input. The starter code will cause the program to quit when the user presses 'q'.
• Code to capture mouse clicks and movement. The starter code will update the global transformation values (translate, rotate, scale) based on the input.
• Code to open a window and display a rectangle on the screen.
• Code to install all of the callbacks that you should need.

If you compile and run the starter code a window should appear with a colored rectangle. Although the input used for transforming the view is handled, and the transformation values are updated, it does not actually apply the transformations, so dragging the mouse will not cause any visible change.

The starter code maps the following inputs and transformations:

• Left Mouse Button = Rotate about X and Y.
• Middle Mouse Button = Rotate about Z.
• Ctrl + Left Mouse Button = Translate about X and Y.
• Ctrl + Middle Mouse Button = Translate about Z.
• Shift + Left Mouse Button = Scale about X and Y.
• Shift + Middle Mouse Button = Scale about Z.

You don't have to keep these mappings if you don't want to. However, you should provide documentation in your README that explains what inputs will cause what transformations.

• 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. (Depth buffering already provided in starter code.)
• Use GL's double buffering (already provided in starter code)
• 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/students/your_andrew_id/, in a sub-directory called asst1. Running "make" in this directory should compile your program successfully--if not, you've left out a necessary file. 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.
• Don't try to do this at the last minute. This assignment is supposed to be fun and relatively easy, but time pressure hasa way of ruining that notion.
• Make sure you can log in. Notify us immediately if you have any problems.
• To view your animation you can use the command `animate -delay 6 *.jpg`. You should do this in a directory that has all of your animation frames named as explained above, and no other jpegs.
• A simple way to make frames would be to bind a key to the savescreenshot function. Keep a count of how many frames you have saved, and generate a file name based off of that number. You can use `sprintf` to easily create the file name. Just position your heightfield where you want it for the next frame and hit the savescreenshot button.

## Extras

You may choose to implement any combination of the following for extra credit.

• Use a display list for the heightfield geometry.
• 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.
Click here for a tarball of simple animations of these two examples. (Warning - Large file: 13.2M)