CMSC 435/634: Introduction to Computer Graphics

Assignment 3
Viewing
Due October 14, 2004

The Assignment

For this assignment, you will be modifying your last assignment to drive over your random landscape. You will replace the former parallel projection with a perspective projection from the point of view of a person sitting in a vehicle approximately 1 meter above the ground. You will replace the mouse motion handler with a new one that maps horizontal mouse motion to looking left and right and vertical mouse motion to speeding up and slowing down your motion. The view should tip to align with the landscape as you move.

To figure out the vertical position for your vehicle and the up-vector for the view, you will first need to locate the current position in x/y, the figure out which triangle you are in, and finally interpolate to find the height and components of the up vector within the triangle.

Perspective projection should be applied in the OpenGL projection matrix stack (glMatrixMode(GL_PROJECTION)), while viewing transformations should be applied in the OpenGL model/view matrix stack (glMatrixMode(GL_MODELVIEW)). It is probably easiest to move the view matrix setup into your draw function and just update state in your motion function.

You animate motion by making changes each frame then redrawing. Normally, GLUT only calls your draw function if something it knows about changes. However, if you call glutPostRedisplay inside your draw function, it will cause GLUT to call your draw function again for a new frame as soon as the current frame is complete (the mouse motion handler does this). To animate continuous motion, decide your speed in meters per second, figure out how much time has elapsed using gettimeofday(), then move your viewpoint an appropriate distance forward.

634 required

Do all of the matrix manipulations yourself, using only glLoadMatrix to set the final result. I would recommend getting the base project working using the OpenGL matrix functions, then replace them incrementally. You will get more credit for a working program that makes partial use of glLoadMatrix or glMultMatrix than a completely non-working program that uses only glLoadMatrix. This should not be too difficult if you use the man pages for the OpenGL transformation functions as reference.

Extra credit (for everyone)

Add some fun additional animated vehicle motion. Be creative — think about what kinds of motion a vehicle might have, then figure out how they'd break down into per-frame steps.

Strategy

Plan ahead first. Know how you're going to find the position and view vector. Once you have a plan, implement in stages that each produce a visible result. While it is not part of the assigned project, it may also be useful to set up extra keys to show debugging results. For example, a key that switches from the perspective view to an 'assignment 2' view with the vehicle postion marked by a gluSphere could be helpful if you are having trouble debugging your position code.

If your assignment 2 did not work, you can get a working sample version from me after you have turned in your final version of assignment 2. However, I would encourage you to start from your own assignment 2 code if at all possible. Problems with your assignment 2 will not count against your assignment 3 grade, but you should at least have some landscape height and smooth per-vertex normals.

You may find the following OpenGL calls helpful to complete the assignment:

What to turn in

Turn in this assignment electronically by checking it into your Assn3 CVS directory by 11:59 PM on the day of the deadline. We will use a dated checkout for grading, so you will be graded on whatever has been checked in as of 11:59 PM. 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 interesting motions did you add?

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. 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.

References

As a reminder, gl machines include all of the OpenGL man pages (you don't have to be sitting at one, you can just 'ssh gl.umbc.edu'). Just try 'man glFrustum', etc. to find out more about any function used in the assignment that sparks your curiosity. Also, the OpenGL 1.1 Programmers Guide (the "OpenGL red book") is available online, and is a good reference