Before you start

This assignment uses the OpenGL graphics library together with a cross-platform OpenGL windowing library called GLFW and an OpenGL extension manager called GLEW. It also uses CMake for building. Download any of these that you do not already have. It should be possible to do this project on Windows, Mac or Linux. If using Linux, you may also need to download a driver for your GPU from the GPU manufacturer, if the generic driver does not support the features we need.

The base code has been pushed to a GLapp directory in your class repository. This includes cmake files to try to find GLFW and GLEW. If you install them in your user directory or a place it can't find, be sure to set the GLEWDIR, GLFW_LOCATION environment variables before running cmake. There is a GUI for cmake, but I always run from the command line (Windows, Mac or Linux, all starting in the GLapp directory):

Linux (or Mac using Makefiles)

mkdir build
cd build
cmake ..

Windows Visual Studio

mkdir build
chdir build
cmake -G "Visual Studio 15 2017 Win64" ..

Mac Xcode

mkdir build
cd build
cmake -G Xcode ..
open GLapp.xcodeproj

Try the sample code well before the assignment due date to make sure you can get it to run.

The Assignment

For this assignment, you will be using OpenGL to create a simple interactive view of a scene. The sample OpenGL application creates a terrain on a rectangular grid based on data from an image, and has viewing controls to orbit around it.

You will modify this program to interactively walk over the landscape using typical game keyboard and mouse controls. Motion should use four keys: holding 'w' should move you in whatever direction you are currently pointing, 's' should move you backwards, 'a' and 'd' should move you to the left and right. Moving the mouse left, right, up and down should rotate your view and motion direction around your current position. All motions should be computed in terms of rates (per second or per millisecond), then scaled by the elapsed time between frames. This is the typical first-person keyboard and mouse motion control scheme.

During any motion, the view should remain a constant height above the landscape. To figure out the height of your viewpoint, consider just your horizontal (x,y) position. From that position, find your triangle and your 2D barycentric position within that triangle. Use barycentric interpolation of the vertex elevations to compute the surface height at your position, then add a constant offset to place your viewpoint above the surface.

You should stop the motion if you reach the edge of the terrain, and would no longer be above any terrain triangle

634 only

Also align the view with a barycentric interpolation of the surface normal. This (without the 'a' and 'd' strafing keys, is the beginning of a vehicle control scheme

Extra credit

The simplest way to do this assignment is to check every triangle for the current position. For up to 20 points of extra credit, use the half-edge data structure to directly track the view position. Using this data structure, when you leave one triangle through one edge, you should immediately know exactly which triangle to check next.

Extra credit is only available if you submit by the original deadline or use your free late. If you submit late with the late penalty, you will not be eligible for any extra credit points.

You are also only eligible for extra credit if you tell us you did the extra credit in your assn3.txt and where to find the mesh data structure definitions and code.


Plan ahead first. Know how you are going to find the position and view vector. Once you have a plan, implement in stages that each produce a visible, testable result. While it is not part of the assignment, it may be useful to add extra keys for debugging. For example, a key that switches between the perspective view and a top-down view with a simple object at the current position could help debug your position code.

What to turn in

Turn in this assignment electronically by pushing your source code to your class git repository by 11:59 PM on the day of the deadline and tagging the commit assn3. Do your development in the GLapp directory where the sample code was provided.

Also include an assn3.txt file telling us about your assignment. Include your name and campus ID at the top of this file. Do not forget to tell us what (if any) help you received from books, web sites or people other than the instructor and TA.

Commit along the way with useful commit messages. We will be looking at your development process, so a complete and perfectly working ray tracer submitted in a single checkin one minute before the deadline will NOT get full credit. Individual checkins of complete files one at a time just before the deadline will also NOT get full credit. Do be sure to check in all of your source code, assn3.txt, and updated .gitignore file, but no build files, log files, generated images, zip files, libraries, or other non-code content.