Graphics Reference
In-Depth Information
void
CModel::DrawModel() {
.
// reference to a matrix stack
A:
ID3DXMatrixStack
*
pMatrixStack;
// Creates a matrix stack object
Source file.
Model.cpp
file
in
the
Model
folder
of
the
D3DXCreateMatrixStack(0, &pMatrixStack);
// Loads identity to the top of stack
B1:
pMatrixStack->LoadIdentity();
// duplicate the top of the stack and push
pMatrixStack->Push();
if
(!m
_
bTranslateFirst)
// concatenate translation
C:
pMatrixStack->TranslateLocal(m
_
TranslateX,m
_
TranslateY);
// and scaling with top of stack
pMatrixStack->ScaleLocal(m
_
ScaleX, m
_
ScaleY);
else
D:
pMatrixStack->ScaleLocal(m
_
ScaleX, m
_
ScaleY);
pMatrixStack->TranslateLocal(m
_
TranslateX, m
_
TranslateY);
// Load WORLD with top of stack
E:
pDevice->SetTransform(D3DTS
_
WORLD, pMatrixStack->GetTop());
// Draw the rectangle
F:
m
_
Rectangle.Draw(lod, m
_
DrawHelper);
// pop-off computed transform and restore the saved identity matrix
B2:
pMatrixStack->Pop();
// Load identity in to WORLD
G:
pDevice->SetTransform( D3DTS
_
WORLD, pMatrixStack->GetTop() );
.
D3D
_
MatrixStack
project.
Listing 9.4.
The
CModel::DrawModel()
function of Tutorial 9.3.
computes
top of stack matrix
=
TM
t
,
where
M
t
is the current matrix at the top of the stack. The important detail is
that the operator
T
is concatenated on the left of
M
t
. This concatenation on the
left side of the top of stack matrix is true for all
Local
transformations functions
in D3D. For example, at label C, after the
TranslateLocal()
function call, the
computed top of stack matrix
M
t
1
is
M
t
1
=
TM
t
,
Search WWH ::
Custom Search