Graphics Reference
In-Depth Information
Pop() . Pops off the current top of the stack. This is a typical stack pop
operation, where the current top of the stack is eliminated from the stack.
This operation is important for restoring previous transformation matrices.
Concatenation. The ID3DXMatrixStack defines many transformation op-
erators (e.g., TranslateLocal() , ScaleLocal() ) where the results of the
transformation operation is concatenated with the top of the stack matrix.
Tutorial 9.3. Working with the D3D Matrix Stack.
Tutorial 9.3.
Project Name:
D3D _ MatrixStack
Library Support:
UWB _ MFC _ Lib1
UWB _ D3D _ Lib8
Goals. Understand the matrix stack utility for concatenating, saving, and
restoring of transformation matrices.
Approach. Experience using the D3D matrix stack in a simple application;
in this case, we will re-implement Tutorial 9.2 based on the D3D matrix
stack utility.
Figure 9.12 is a screenshot of running Tutorial 9.3. The behavior of this tutorial is
identical to that of Tutorial 9.2. The only difference between these two tutorials
is in the implementation of the CModel::DrawModel() function. In this case,
instead of computing and loading transformation matrices explicitly, we take ad-
vantage of the D3D matrix stack utility. Listing 9.4 shows that, at label A, we
request D3D to create a ID3DXMatrixStack object, pMatrixStack . At label B1,
we load an identity matrix to the top of the stack and perform a Push() operation
to duplicate this identity matrix for later use. At this point, the pMatrixStack has
two elements, and both are identity matrices. Depending on the GUI radio button
selection, either the operations at label C or D will be performed. In either case,
the TranslateLocal() and ScaleLocal() functions compute the appropriate
operator and concatenate the operator to the top of the pMatrixStack . At label
E, we call the GetTop() function to access and load the concatenated matrix to
the WORLD matrix processor. With the WORLD matrix processor properly loaded, at
label F we send the rectangle vertices to the D3D RC for drawing. Recall that at
label B1, we have pushed and saved a copy of the identity matrix on the stack.
Now at label B2, we pop off the concatenated matrix that we no longer need and
re-initialize the WORLD matrix with the saved identity matrix at label G.
It is important to understand the order of concatenation for the matrix stack
transformation function calls, that
Figure 9.12.
Tutorial
9.3.
pMatrixStack->TranslateLocal( ... )
Search WWH ::




Custom Search