Game Development Reference
In-Depth Information
User input and camera control
We will now learn how to gather keyboard input from FreeGLUT and use it to interact
with our world. This will take the form of rotating our camera around the center of our
world (and hence, our box).
Continue from here using the Chapter2.3_UserInputAndCameraControl
project files.
Implementing camera control
We created a basic camera earlier in this chapter, but it is currently stationary. In order
to verify that our world is truly three-dimensional, it would help if we could rotate our
camera around a central pivot point. There's a lot of 3D mathematics that goes into
controlling camera movement (particularly when it comes to rotation), which is beyond
the scope of this topic. So, if some of what is covered here seems confusing, know
that pretty much any topic or blog that covers 3D mathematics and rendering as a
whole should cover these topics.
To begin, we will need three new variables for our camera. These will store the current
values for the camera's rotation and zoom:
float m_cameraDistance; // distance from the
camera to its target
float m_cameraPitch; // pitch of the camera
float m_cameraYaw; // yaw of the camera
Significant changes are required in our UpdateCamera() code to calculate the new
camera position based on the previous variables. The additions to this function are
liberally commented to explain the process, so we won't consume space explaining
them here.
Search WWH ::

Custom Search