draft-draft-draft-draft-draft-draft-draft-draft-draft-draft-draft-draft
Goals
- Understand the camera projection matrix.
- Understand the camera view matrix.
- Understand how to implement a camera “fly-through” (as might be found in a game)
- Understand how to implement the Dolly, Pan, and Tumble camera controls (as are found in Maya).
Overview
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:
View matrix: V = viewRotation * EyeTranslationIn 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”!
Sample Code
Download from the fileshare the Lab07 CarNavigation Code. 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:
- Code restructure from previous labs: Note the shape objects have been moved to a separate class and the shader and other variables have been placed in a header file called Globals.h so they can be shared among multiple cpp files.
- Callback functions: Callback functions have been added for mouse controls (mouse() and motion()) and special key controls (keySpecial()), e.g. for keyboard controls using the arrow keys. The GLUT callbacks are established in the main() method.
Part 1: Fly Through Controls
- 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:
- move the camera forward/backward
- turn the camera up/down
- turn the camera left/right
- roll the camera left/right
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.
Part 2: Maya
In this part of the lab, you will implement the dolly, tumble, and track:
- Track (slides camera horizontally or vertically)
- Dolly (moves camera forward/back – similar to what was done in keySpecial, but here you do this with a mouse rather than key presses)
- Tumble (rotate around a “center of interest”). You should be able to choose (toggle t) whether you want the “center of interest” to be the origin of the world coordinate system or a point that is a fixed distance in front of the camera (i.e. where the white box sits). Be careful. Moving the mouse up and down rotates in a direction parallel to the Camera’s x-axis, while moving the mouse left/right rotates the camera around the World’s y-axis. These are very different operations which take place in different coordinate systems and thus at different points in the transformation sequence.
The mouse controls are set up as follows:
- Right mouse drag up/down, left/right to Track
- Left mouse drag up/down, left/right to Tumble
- Middle mouse drag to Dolly
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 noon on Thurs, Week 8, demonstrate your program in lab and submit your code via the fileshare.