Camera controls enable a user to navigate around the 3D scene. There are various ways of doing this. For example, a "fly-through" allows the user to move through a scene as though one was at the controls of an airplane. Another approach is to allow the user to "dolly, tumble, and track" which are the typical navigation tools used in Maya. In this assignment, will first implement the fly-through controls using keyboard presses. You will then implement dolly, tumble, and track using mouse controls.
In class, we will talk about the matrix transform (called V) which transforms vertices from World to Camera coordinates. This is the product of a rotation and translation. In the code, the global variable "viewRotation" is the rotation component of V. It is initialized in the calcUVN method based on the values of VPN and VUP. The variable called "eye" is the location of the camera in World coordinates which can be used to generate the translational component of V:
In the display method, you need to initialize model view matrix (mv) to the value of V.
All of the camera controls (key or mouse) operate by updating only two variables: the camera location stored in the variable "eye" and the camera orientation, stored in "viewRotation"!
![]() |
Download the Car Navigation Codeblocks Project. This program
has a single car that can move forward or backward (press f or b). Coordinate axes are included to help you
see the effect of the transformations. There is a white box that always sits in the middle of the
window. The purpose of this will be more clear when you implement the tumble control.
In the project folder, you will see the executable CarNavigationComplete.exe. If you double click on it, you can run the full working version of the code. The black console lists the different key and mouse controls that are available. If you compile and run the source code that is provided, none of the camera navigation controls work. Your task for this lab is to implement these camera controls. |
Remarks on the code:
Begin by implementing the calcUVN() method. It calculates the initial value of viewRotation. To do this, first compute u, v, n based on the values of VPN and VUP, similar to what you did in the ray tracing lab. Then use u, v, n to construct the viewRotation matrix.
In the display() method, calculate the View matrix: V = viewRotation * EyeTranslation
. You will
need to use the variable "eye" to
generate the EyeTranslation matrix. Once V is computed, set the starting value of mv
(the modelview matrix) to V.
Implement the fly-through controls in the keySpecial() method. Look for the "NEED TO IMPLEMENT" comments in the code. The needed controls are:
The choice of key controls for each of these operations can be seen in the printControls() method. In class, we will go over how to calculate these by updating the eye and viewRotation variables. Each control only requires a couple of lines of code. If you understand the concepts, the coding should be easy.
In this part of the lab, you will implement the dolly, tumble, and track:
The mouse controls are set up as follows:
In class, we will open up Maya to see how they work (or run CarNavigationComplete.exe). The Track and Dolly are quite easy. The Tumble is difficult and will take a bit of thinking!
No later 5pm on Thurs, Oct 25, demonstrate your program in lab and submit your code via WISE Assignments.