Game Development Reference
In-Depth Information
/**
* Transform the given direction vector by the
* transformational inverse of this matrix.
*/
Vector3 transformInverseDirection(const Vector3 &vector) const
{
return Vector3(
vector.x * data[0] +
vector.y * data[4] +
vector.z * data[8],
vector.x * data[1] +
vector.y * data[5] +
vector.z * data[9],
vector.x * data[2] +
vector.y * data[6] +
vector.z * data[10]
);
}
};
These can be called in the same way as before:
Vector3 localToWorldDirn(const Vector3 &local, const Matrix4 &transform)
{
return transform.transformDirection(local);
}
and
Vector3 worldToLocalDirn(const Vector3 &world, const Matrix4 &transform)
{
return transform.transformInverseDirection(world);
}
9.4.6
C HANGING THE B ASIS OF A M ATRIX
There is one final thing we'll need to do with matrices that hasn't been covered yet.
Recall that we can think of a transformation matrix as converting between one basis
and another, one set of axes and another. If the transformation is a 3
×
4matrix,