CMSC 435/634: Introduction to Computer Graphics

Assignment 3 Viewing Due March 12, 2014

The Assignment

For this assignment, you are given a program that uses OpenGL to render a hilly terrain. 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. During any motion, you should remain a constant height above the landscape. All motions should be computed in terms of rates (per second or per millisecond), then scaled by the elapsed time between frames.

To figure out the height of your viewpoint, consider just the horizontal position of your character. From that position, you will compute which triangle you are above, 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 you above the surface.

Make the landscape effectively infinite by rendering a 3x3 grid of nine offset copies of the base terrain. You can turn on fog to hide the repetition with the 'f' key. You can play with the fog function in terrain.frag to balance local visibility while still hiding the distant repetition. If your character walks out of the central square, move their position back to the opposite edge. This jump should not be visible when the fog is enabled, since the terrain edges match and the distant changes will be hidden.

634 only

Also align the view with a barycentric interpolation of the surface normal.

Extra credit

For up to 10 points of extra credit, add the ability to jump when the user presses space. For full credit, if the user jumps while moving, they should continue in the current direction regardless of any additional presses of 'a', 's', 'd' or 'w' while in the air, and when they land, they should do so based on the terrain elevation at the landing point. In addition, they should only be able to jump if on the ground, no double-jump.

For up to 15 points of extra credit, add a look-at transform to Mat and MatPair and use it in implementing your view instead of just translations and rotations. For full credit, you should support both viewing using translation and rotation, and viewing using your look-at transform, with a key to toggle between them.

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

Strategy

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 copy of the light marker object at the current position could help debug your position code.

Development options

The sample code will run on the UMBC PCs in the GAIM lab, ENG 005a. This is the corner lab on the bottom floor of the Engineering building with PCs and XBoxes, not the visual arts Mac lab next door in 005b. You will also need to download the pre-built GLFW and GLEW libraries from umbc.box.com/glfw-glew. Unzip the files, and run the envset script you find there before opening the project in Visual Studio.

There are limited PCs in this lab, so you may want to try working at home. The same code and instructions should work on your own PC assuming you have Visual Studio (as a UMBC student you can get it for free from Microsoft at dreamspark.com).

It should also work on Mac if you have Mac OS 10.9. You will need XCode, and CMake, and will need to download and build GLEW and GLFW yourself from source and install into /usr/local. If you are not familiar with building packages from source, post a question on piazza. You can either use the provided Makefile to build and run on the command line in a terminal, or use XCode. If you use XCode, you will also need to edit the "Scheme" settings to set the execution working directory to be the directory containing the ppm files.

You may also be able to run it on Linux. In addition to installing GLEW and GLFW, you will also need a vendor-provided video driver (the generic driver that comes with many Linux distributions will not support the features we need). Note that AMD and NVIDIA do have recent drivers with sufficient support, but Intel does not. If you have Intel graphics, you will probably be able to use it from Windows, but not Linux.

If you use your own system, you may find it useful to check out your cvs directory directly on your own computer. This will allow you to work locally, then check changes back in directly without having to copy the files back onto the gl systems. You can either use a command-line cvs client, a GUI client, or one that's integrated into the OS. For Mac or Linux, I usually use the command line client, but for Windows I use TortoiseCVS. In the command-line CVS, you use ssh to access the repository by adding <user>@gl.umbc.edu: to the beginning of the repository path. For example, to check out a copy on my Mac, I'd use

cvs -d olano@gl.umbc.edu:/afs/umbc.edu/users/o/l/olano/pub/435 checkout -d my435 olano

In Tortoise CVS, these you would enter the parts of this in separate boxes of the checkout dialog. Set the type to :ssh:, enter your username, gl.umbc.edu, and /afs/umbc.edu/users/o/l/olano/pub/435 in the appropriate boxes on the left hand side of the checkout dialog, and your username again in the "Module" box on the right hand side of the dialog.

What to turn in

Turn in this assignment electronically by checking your source code into your assn3 CVS directory by 11:59 PM on the day of the deadline. Do your development in the assn3 directory so we can find it. As always, double check that you have submitted everything we need to build and run your submission, but not any generated files. In particular, no executables, or any of the other files xcode or visual studio generate beyond the ones already checked in.

Be sure to include the details of the system you used for the assignment in your README in case we have problems.