Game Development Reference
In-Depth Information
Orbit Camera
An orbit camera is one that orbits around a target object. The simplest way to im-
plement orbiting is to store the camera's position as an offset from the target, as
opposed to storing the world space position of the camera. That's due to the fact
that rotations are always applied with the assumption that the rotation is about the
origin (which hopefully you recall from Chapter 4 ). So if the camera position is
stored as an offset, any rotations applied will act as if the target object is at the
origin, which in the case of orbiting is precisely what we want. This type of orbit
camera is demonstrated in Figure 8.9 .
Figure 8.9 Orbit camera.
The typical control scheme for orbiting enables the player to both yaw and pitch,
but not roll. Because the input scheme will typically provide the yaw and pitch as
separate values, it's best to implement the orbiting as a two-part rotation. First, ro-
tate the camera up and then offset about the world up axis (for yaw), then rotate
the camera up and offset about the camera's left vector (for pitch). You need to
rotate the camera up in both rotations in order to get the correct behavior when the
camera is below the target.
As for how the rotation should be implemented, the system presented in Listing
8.2 uses quaternions, though it would be possible to implement it with matrices in-
stead. I should also note that there is an entirely different approach to implement-
Search WWH ::




Custom Search