Graphics Reference
In-Depth Information
void CModel::DrawModel() {
.
A: D3DXMatrixTranslation(&translate _ matrix, m _ TranslateX, m _ TranslateY, 0);
D3DXMatrixScaling( &scale _ matrix, m _ ScaleX, m _ ScaleY, 1);
B: if (!m _ bTranslateFirst)
// computes M a = ST
D3DXMatrixMultiply(&combined _ matrix, &scale _ matrix, &translate _ matrix);
else
// computes M b =
TS
D3DXMatrixMultiply(&combined _ matrix, &translate _ matrix, &scale _ matrix);
.
Source file. Model.cpp file
in the Model folder of the
D3D _ MatrixMultipleOrder
project.
C: pDevice->SetTransform(D3DTS _ WORLD, &combined _ matrix);
D: m _ Rectangle.Draw(lod, m _ DrawHelper);
}
Listing 9.3. The CModel::DrawModel() function of Tutorial 9.2.
the concatenated results from combined _ matrix (C), and the drawing of the rect-
angle (D). In this case, depending on the radio button selected, at label B we either
compute the M a or the M b operator and store the result in combined _ matrix for
loading into the WORLD matrix.
Graphics API Matrix Stacks
The concatenation of matrices we experienced in the previous tutorials is a fre-
quently performed operation in interactive computer graphics applications. In
addition, as we will see in Chapter 11, we often need to save and restore transfor-
mation matrices. Modern graphics APIs typically define a matrix stack to support
these operations. A matrix stack is a push-down stack where the basic element
of the stack is a transformation matrix. In other words, the matrix stack supports
the pushing and popping of an entire transformation matrix onto/off a stack. Fur-
thermore, the matrix stack typically supports operations for concatenating trans-
formation matrices with the top of the stack element. For example, the Direct3D
API defines the ID3DXMatrixStack to support the following functions.
Push() . Duplicates the top of the stack matrix and then performs a typical
stack push operation. In this way, the top of the stack matrix is duplicated,
and as programmers, we have a copy of the top stack matrix to work with.
This operation is important for saving transformation matrices.
Search WWH ::




Custom Search