Game Development Reference
With our camera control code in place, we can manipulate its position by simply
modifying the three new variables and calling UpdateCamera() to perform the re-
quired math for us. However, this isn't useful without some way of gathering input
and making the necessary changes to the aforementioned variables.
Gathering user input
FreeGLUT allows us to gather input using the Keyboard() and Special() call-
back functions. Remember that Keyboard() is called whenever FreeGLUT detects
that a generic keyboard key has been pressed, such as letters, numbers, and so
on. Meanwhile, the Special() function is called for special keys such as the arrow
keys, Home , End , Page Up / Page Down , and so on.
In this chapter's source code, we've used both of these functions to grab different
types of user input, and employed them to modify our camera's pitch, yaw, and
zoom distance (recall that the roll is always calculated using an up vector that never
changes). Each time the values are modified by a key press, we perform the math-
ematical calculations necessary to reposition the camera based on this updated in-
formation. Note that these functions are repeatedly called while a key is still held
down, allowing the camera to continue moving as long as the key is pressed.
Within our application, we can now zoom and rotate the camera with the arrow keys,
Z , and X . Here is our box viewed from a different angle and distance: