Game Development Reference
In-Depth Information
Figure 8.7
Basic follow camera tracking a car.
Recall that to create a look-at matrix for the camera, three parameters are required:
the eye (or position of the camera), the target the camera is looking at, and the
camera's up vector. In the basic follow camera, the eye is going to be a set vertical
and horizontal offset from the target. Once this is calculated, we can then calculate
the remaining parameters to pass to
CreateLookAt
:
// tPos, tUp, tForward = Position, up, and forward
vector of target
// hDist = horizontal follow distance
// vDist = vertical follow distance
function
BasicFollowCamera(
Vector3
tPos
,
Vector3
tUp
,
Vector3
tForward
,
float
hDist
,
float
vDist
)
// Eye is offset from the target position
Vector3
eye
=
tPos
-
tForward
*
hDist
+
tUp
*
vDist