Game Development Reference
In-Depth Information
From this vector we can determine the direction and we are also able to calculate the dis-
tance betweenthetwopoints.Onesituationinwhichwemaywanttodothisistocalculate
the direction we want to aim the camera in order to look at some point in space. By per-
forming vector subtraction from the point of interest and the camera's position, we get the
direction vector to which we should orient the camera.
1.2.1.3Vector Length
A vector represents both a direction and a magnitude, often we need to measure the length
(magnitude) of a vector. The length of a vector will be denoted by:
Given a vector
The length of the vector is computed with the Euclidean norm:
Which aswewill see,happenstobethesquarerootofthedotproductofthevector against
itself.
Itisnotalwaysnecessarytocalculatethepreciselengthofavector,particularlywhenwhat
is necessary is only to know if a vector is longer than another vector. In this case we can
skip computing the square root and use the squared length for comparison. Most math lib-
raries provide two length functions.
float vector3::Length() const
{
Search WWH ::




Custom Search