Game Development Reference
In-Depth Information
return sqrt(x()*x() + y()*y() + z()*z());
}
float vector3::LengthSquared() const
{
return x()*x() + y()*y() + z()*z();
}
1.2.1.4Vector Normalization
A unit vector is a vector whose magnitude is one. It is often desirable to remove the mag-
nitude component of a vector but preserve its direction. We can do this by converting a
vector into a unit vector .
The vector is normalized by dividing the vector by its length.
vector4& vector4::Normalize()
{
const float inverseLength = 1.0f / Length();
return ((*this) *= inverseLength);
}
The Normalize function will multiply the components of the vector by the reciprocal of the
vector's magnitude. This has the effect of scaling the components of the vector so that the
overall vector magnitude becomes one. It will apply the normalization and return a refer-
ence to itself.
1.2.1.5Dot Product
Ingraphicsandgamedevelopment, thedotproductisoneofthemostusefuloperations we
can perform on a pair of vectors. Given two unit vectors u and v the dot product is defined
as:
The result is a scalar value that holds valuable information about the angular relationship
between the vectors u and v . The key things to remember are that if the angle between u
Search WWH ::




Custom Search