Game Development Reference

In-Depth Information

tmp.y * data[5] +

tmp.z * data[9],

tmp.x * data[2] +

tmp.y * data[6] +

tmp.z * data[10]

);

}

};

which is called like this:

Vector3 worldToLocal(const Vector3 &world, const Matrix4 &transform)

{

return transform.transformInverse(world);

}

Recall from chapter 2 that vectors can represent positions as well as directions.

This is a significant distinction when it comes to transforming vectors. So far we have

looked at vectors representing positions. In this case converting between local and

object coordinates is a matter of multiplying by the transform matrix, as we have

seen.

For direction vectors, however, the same is not true. If we start with a direction

vector in object space, for example, the Z-axis direction vector

⎡

⎤

0

0

1

⎣

⎦

and multiply it by a transformation matrix—for example, the translation only

⎡

⎤

1001

0100

0010

⎣

⎦

we end up with a direction vector, that of

⎡

⎣

⎤

⎦

1

0

1