Game Development Reference
In-Depth Information
multiply each vector by one matrix that contains all three transforma-
tions combined. This saves a significant amount of vector-matrix
multiplication operations.
Some Functions to Transform Vectors
The D3DX library provides the following two functions for transform-
ing points and vectors, respectively. The
D3DXVec3TransformCoord
function transforms points and assumes the fourth component of the
vector is an understood 1. The
D3DXVec3TransformNormal
function
transforms vectors and assumes the fourth component of the vector is
an understood 0.
D3DXVECTOR3 *D3DXVec3TransformCoord(
D3DXVECTOR3* pOut,
// Result.
CONST D3DXVECTOR3* pV,
// The point to transform.
CONST D3DXMATRIX* pM
// The transformation matrix.
);
D3DXMATRIX T(...); // initialize a transformation matrix
D3DXVECTOR3 p(...); // initialize a point
D3DXVec3TransformCoord( &p, &p, &T); // transform the point
D3DXVECTOR3 *WINAPI D3DXVec3TransformNormal(
D3DXVECTOR3 *pOut,
// Result.
CONST D3DXVECTOR3 *pV,
// The vector to transform.
CONST D3DXMATRIX *pM
// The transformation matrix.
);
D3DXMATRIX T(...); // initialize a transformation matrix
D3DXVECTOR3 v(...); // initialize a vector
D3DXVec3TransformNormal( &v, &v, &T); // transform the vector
Note:
The D3DX library also provides
D3DXVec3Transform-
CoordArray
and
D3DXVec3TransformNormalArray
for transforming
an array of points and an array of vectors, respectively.
Planes (Optional)
A plane can be described with a vector
n
and a point on the plane
p
0
.
The vector
n
is called the plane's
normal vector
and is perpendicular to
the plane (see Figure 11).
Figure 11: A plane defined by a normal vector
n
and a point on the plane
p
0
Search WWH ::
Custom Search