Game Development Reference
In-Depth Information
D3DXMATRIXC=A*B;//C=AB
Another important operator of the D3DXMATRIX class is the parenthe-
sis operator, which allows us to conveniently access entries in the
matrix. Note that when using the parenthesis operator, we index start-
ing into the matrix starting at zero like a C-array. For example, to
access entry ij = 11 of a matrix, we would write:
D3DXMATRIX M;
M(0, 0) = 5.0f; // Set entry ij = 11 to 5.0f.
The D3DX library also provides the following useful functions that set a
D3DXMATRIX to the identity matrix, take the transpose of a
D3DXMATRIX , and find the inverse of a D3DXMATRIX :
D3DXMATRIX *D3DXMatrixIdentity(
D3DXMATRIX *pout
// The matrix to be set to the identity.
);
D3DXMATRIX M;
D3DXMatrixIdentity( &M ); // M = identity matrix
D3DXMATRIX *D3DXMatrixTranspose(
D3DXMATRIX *pOut,
// The resulting transposed matrix.
CONST D3DXMATRIX *pM
// The matrix to take the transpose of.
);
D3DXMATRIX A(...);
// initialize A
D3DXMATRIX B;
D3DXMatrixTranspose( &B, &A ); // B = transpose(A)
D3DXMATRIX *D3DXMatrixInverse(
D3DXMATRIX *pOut,
// returns inverse of pM
FLOAT *pDeterminant,
// determinant, if required, else pass 0
CONST D3DXMATRIX *pM
// matrix to invert
);
The inverse function returns null if the matrix that we are trying to
invert does not have an inverse. Also, for this topic we can ignore the
second parameter and set it to 0 every time.
D3DXMATRIX A(...);
// initialize A
D3DXMATRIX B;
D3DXMatrixInverse( &B, 0, &A ); // B = inverse(A)
Basic Transformations
When programming using Direct3D, we use 4 4 matrices to represent
transformations. The idea is this: We set the entries of a 4 4 matrix X
to describe a specific transformation. Then we place the coordinates of
a point or the components of a vector into the columns of a 1 4row
Search WWH ::




Custom Search