CMSC 435/634: Introduction to Computer Graphics
Assignment 5
Viewing Pipeline
Due November 4, 2002
The Assignment
For this assignment, you will be modifying your last assignment to drive an
amphibious vehicle on and around your island. You will replace the former
parallel projection with a perspective projection from the point of view of
the vehicle. You will replace the mouse motion handler with a new one that
maps horizontal mouse motion to turning left and right and vertical mouse
motion to moving the vehicle forward and backward in the direction it is
currently pointing. For a given x,z position of the vehicle, you will determine
its y position as a fixed distance above the island or sea at that point.
Finally, you will tilt the view to align with the surface at that point.
All aspects of the vehicle's view should be done on the OpenGL projection
matrix stack (glMatrixMode(GL_PROJECTION)). This could be done in
the mouse motion handler, but the extra credit will be easier if you set
view parameters in the mouse motion handler and create the projection matrix
in your draw function.
If your assignment 4 did not work, you can get a working sample version
from me or Dr. Rheingans after you have turned in your final version
of assignment 4. However, I would encourage you to start from your own assignment
4 code if at all possible.
You may find the following OpenGL calls helpful to complete the assignment:
- Reset the current matrix to a 4x4 identity matrix: glLoadIdentity()
- Set up perspective: glFrustum(left, right, bottom, top, near, far)
or gluPerspective(fov,aspect,near,far)
- Translate: glTranslatef(x,y,z)
- Rotate around an axis through the origin: glRotatef(degrees, axis_x,
axis_y, axis_z)
- Apply an arbitrary 4x4 transformation matrix: glMultMatrix(matrix)
- Push and pop matrix state: glPushMatrix(), glPopMatrix()
- Replace the current matrix with one of your own devising: glLoadMatrix(matrix)
Strategy
Plan ahead first. Know how you're going to find the position, height, and
orientation of the view. Don't forget to account for cases when the vehicle
is outside of the x/z region covered by the island or when the island surface
dips below sea level (in both cases, you should float above the water surface).
Once you have a plan, implement in stages. For example, you might get perspective
viewing working first, then add the steering, then movement, then find the
right height for your position, and finally tip the view to align with the
island slope.
Extra credit (for everyone)
Add some fun additional animated vehicle motion. Some possibilities are bobbing
up and down when on water, smoothly changing view orientation over several
frames as you move from triangle to triangle rather than abruptly snapping
from one orientation to another, or making the vehichle slide down in the
direction of steepest descent if it drives onto an area with slope steeper
than (say) 30 degrees. You're welcome to come up with other ideas too --
be creative.
You animate motion by making changes incrementally over several frames. Normally,
GLUT only calls your draw function if something changes. However, if you
call glutPostRedisplayinside 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. For example, to smoothly change view orientation, you might
have a current orientation and target orientation. If these don't match,
make a change limited to (say) no more than 10 degrees per frame. Draw with
the changed value, but if the current and target orientations are still not
the same, call glutPostRedisplay to take another step next frame.
635 required / 435 extra credit
Do all of the matrix manipulations yourself, using only one 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. As extra credit, this is worth a maximum of 5
points (yes, I know it's not very many points, but it's not very hard --
look at the man pages for the OpenGL transformation functions).
What to turn in
Turn in this assignment electronically as 'cs435 Proj5' (or after the due
date as Proj5late) using the submit mechanism:
submit cs435 Proj5 [files...]
The usual assignment boilerplate still applies -- submit all files
you've created or modified; we must be able to build and run on the GL systems
to grade, if you develop elsewhere leave sufficient time to port back; comments
are your friend and ours, they're a good idea and they can improve your grade.
In either case, you should all files that you created or modified.
References
As a reminder, the irix machines include all of the OpenGL man pages (you
don't have to be sitting at one, you can just 'ssh irix.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