Camera Lab

What's Happening

This lab allows you to "drive" a camera around inside a scene populated with random rectangles. Besides demonstrating camera manipulation, it also demonstrates techniques for handling keyboard input and updating the scene during the render event.

The left and right arrow keys rotate the camera around its "up" axis. The up and down arrow keys move forward and back. If the scene doesn't respond to keypresses, click on it with the mouse so it receives input focus.

Notice that you can move the camera foward while rotating. The camera transformations take place in the updateScene() function, which is called on render events. The keyboard events produced by the control keys are handled by the keyboard() function, which sets global flags to on or off, depending on whether the key was just depressed or released. These flags are then checked in updateScene().

There are two cameras in the scene: the main camera, and a rear camera, which simply always faces in the opposite direction of the main camera. Also, try changing the field of view (in degrees) with the selection box under the view window. Wide fields of view produce a wideangle effect, while narrow ones produce a zoom effect. You may also notice that a wide field of view makes the camera's front clipping plane more noticeable.

The Resume and Suspend radio buttons simply call the rear camera's resume() and suspend() methods. A camera's view automatically disappears when its suspend() method is called.

Key Methods Used

WTCamera::setViewRect, WTCamera::setOrientationVector, WTCamera::setRotation, WTCamera::setFieldOfView, WCamera::suspend, WCamera::resume, WT::setNotifyRenderEvent, WT::setNotifyKeyboardEvent

Points to Remember