Graphics Reference
In-Depth Information
bool
UWBD3D
_
DrawHelper::
PushModelTransform
()
A:
Source file.
uwbgl
_
D3DDrawHelper3.cpp
file in the
D3D Files/
DrawHelper
subfolder of
the
UWBGL
_
D3D
_
Lib9
project.
m
_
pMatrixStack->Push();
pDevice->SetTransform(D3DTS
_
WORLD, m
_
pMatrixStack->GetTop());
bool
UWBD3D
_
DrawHelper::
PopModelTransform
()
m
_
pMatrixStack->Pop();
pDevice->SetTransform(D3DTS
_
WORLD, m
_
pMatrixStack->GetTop());
B:
bool
UWBD3D
_
DrawHelper::
InitializeModelTransform
()
m
_
pMatrixStack->LoadIdentity();
pDevice->SetTransform(D3DTS
_
WORLD, m
_
pMatrixStack->GetTop());
C:
bool
UWBD3D
_
DrawHelper::
AccumulateModelTransform
(trans, scale,
rotate, pivot)
D:
//
M
t
1
←
T
(
t
x
,
t
y
,
t
z
)
M
t
m
_
pMatrixStack->TranslateLocal( trans.x, trans.y, trans.z);
//
M
t
2
←
T
(
p
x
,
p
y
,
p
z
)
M
t
1
m
_
pMatrixStack->TranslateLocal(pivot.x, pivot.y, pivot.z);
//
M
t
3
←
R
(
θ
)
M
t
2
m
_
pMatrixStack->RotateAxisLocal(&z
_
axis, rotation
_
radians);
//
M
t
4
←
S
(
s
x
,
s
y
,
s
z
)
M
t
3
m
_
pMatrixStack->ScaleLocal(scale.x, scale.y, scale.z);
//
M
t
5
←
T
(
−
p
x
,−
p
y
,−
p
z
)
M
t
4
m
_
pMatrixStack->TranslateLocal(-pivot.x,-pivot.y,-pivot.z);
//
M
W
←
M
t
5
pDevice->SetTransform(D3DTS
_
WORLD,m
_
pMatrixStack->GetTop());
Listing 9.9.
Transformation functions
UWBD3D
_
DrawHelper
(
Lib9
).
the D3D
WORLD
matrix processor. This ensures the synchronization of the top of
the matrix stack with the
WORLD
processor. We see that at labels A and B, the
Push()
and
Pop()
functions save and restore the top of the matrix stack. At label
C, the
InitializeModelTransform()
function loads the matrix stack with the
identity matrix. At label
D
,the
AccumulateModelTransform()
function com-
putes a new operator at the top of the matrix stack. The transformation operator
being computed is
M
t
5
=
T
(
−
p
x
,−
p
y
)
M
t
4
=
T
(
−
p
x
,−
p
y
)
S
(
s
x
,
s
y
)
M
t
3
=
T
(
−
p
x
,−
p
y
)
S
(
s
x
,
s
y
)
R
(
θ
)
M
t
2
=
T
(
−
p
x
,−
p
y
)
S
(
s
x
,
s
y
)
R
(
θ
)
T
(
p
x
,
p
y
)
M
t
1
,
or
Search WWH ::
Custom Search