![]() |
Lab 4: Navigation
|
![]() |
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, you 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 view 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 program Lab4Navigation.zip. This program
is similar to what you did on Lab 3:
|
In this part of the lab, you will implement the fly through keyboard controls. Look for the "TO DO" comments in the code.
Begin by implementing the calcUVN
function. It calculates the initial value of viewRotation.
To do this, first compute u, v, n based on the values of VPN and VUP.
Then use u, v, n to construct the viewRotation matrix.
Next, implement the calcViewMat
function. It calculates
and returns the View matrix: V = viewRotation * EyeTranslation
. You will
need to use the variable "eye" to
generate the EyeTranslation matrix. This method will be called
from render() (in render_scene.js) to calculate the initial value
of the view matrix (viewMat).
Implement the fly-through controls in the function keyAction
case
statement (in Camera.js). Look for the "IMPLEMENT" comments
in the code. The needed controls are:
The keyAction
function is called from the setKeyEventHandler
function
(in eventHandlers.js). You don't need to make any changes to setKeyEventHandler
, but take a look at it so you see what it is doing.
In class, we will go over how to calculate the actions 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 mouse controls
for dolly, tumble, and track that are found in
the motion
function in Camera.js
:
The mouse controls are set up as follows:
In class, we will open up Maya to see how they work. The Track and Dolly are quite easy. The Tumble is difficult and will take a bit of thinking!
By the beginning of lab on the due date above, be ready to demonstrate your finished program.