Game Development Reference
In-Depth Information
Figure 8.12 Camera blocked by an object (a), and camera moved up so it's no
longer blocked (b).
Another consideration is what should be done when the camera becomes too close
to the target object. Recall that the near plane of the camera is a little bit in front of
the eye, which means a close camera could cause part of the target object to dis-
appear. A popular solution to this problem is to hide or alpha out the target if the
camera gets too close.
The alpha solution sometimes is also applied to the general problem of the camera
being blocked by an object. So rather than moving the camera forward, the game
may just alpha out the object that's blocking it. Several third-person action games
utilize this method.
Picking
Picking is the capability to click or tap to select an object in the 3D world. Picking
is commonly used in RTS games, such as the tower defense game in Chapter
14 , Sample Game: Tower Defense for PC/Mac .” In that particular game, picking
is implemented in order to enable selection of the various towers (and locations
where towers can be placed) in the game world. Although picking is not strictly a
camera algorithm, it does tie in with the camera and projection.
Recall that to transform a given point in world space into projection (or screen)
space, it must be multiplied by the camera matrix followed by the projection mat-
rix. However, the position of the mouse (or touch) is expressed as a 2D point in
screen space. What we need to do is take that 2D point that's in screen space and
transform it back into world space, which is known as an unprojection . In order
to perform an unprojection, we need a matrix that can do the opposite transforma-
tion. For a row-major representation, this means we need the inverse of the camera
matrix multiplied by the projection matrix:
unprojection = ( camera × projection ) -1
Search WWH ::




Custom Search