Graphics Reference
In-Depth Information
bool
UWBD3D
_
DrawHelper::AccumulateModelTransform(
vec3
t,
vec3
s,
mat3
r,
vec3
p) {
.
A:
D3DXMATRIX
m;
// D3D matrix representation
m.
_
11=r[0][0]; m.
_
12=r[0][1]; ...
// convert math3d++ to D3D matrix
.
m
_
pMatrixStack->TranslateLocal(t.x,t.y,t.z);
//
M
t
1
=
T
(
t
)
M
t
m
_
pMatrixStack->TranslateLocal(p.x,p.y,p.z);
//
M
t
2
=
T
(
p
)
M
t
1
m
_
pMatrixStack->MultMatrixLocal(&m);
B:
//
M
t
3
=
RM
t
2
m
_
pMatrixStack->ScaleLocal(s.x,s.y,s.z);
//
M
t
4
=
S
(
s
)
M
t
3
Source file.
uwbgl
_
D3DDrawHelper8.cpp
file in the
D3D Files/
D3D_DrawHelper
m
_
pMatrixStack->TranslateLocal(-p.x,-p.y,-p.z);
//
M
t
5
=
T
(
−
p
)
M
t
4
.
//
M
W
←
M
t
5
subfolder
UWBGL
_
D3D
_
Lib16
of
the
project.
pDevice->SetTransform(D3DTS
_
WORLD,m
_
pMatrixStack->GetTop());
C:
Listing 16.10.
Setting matrix stack with rotation matrix.
friendly representation for the current orientation of our object. In this case, the
rotation slider bars are for users to adjust rotation and not set the current rotation.
For example, previously a user would manipulate the
x
-rotation slider bar to set
the current
x
-axis rotation to a certain degree. With the new matrix representation,
a user would manipulate the
x
-rotation slider bar to change the
x
-axis rotation by
a certain amount. We will examine the UI control support requirements in List-
ing 16.11. Listing 16.10 shows that the
D3D
_
DrawHelper
class is modified to
support the rotation matrix representation. At label A, the API-independent
mat3
is converted to the D3D-specific
D3DXMATRIX
data type. At label B, the con-
verted matrix is multiplied (pre-concatenated) onto the matrix stack representing
the rotation transformation. Label C shows, as previously, that the concatenated
transformation operator is loaded to the
WORLD
matrix processor. When compared
to Listing 15.6 (on p. 416), we see that instead of computing (Equation (15.1)),
R
z
R
y
R
x
T
(
−
p
)
S
(
s
)
(
θ
z
)
(
θ
y
)
(
θ
x
)
T
(
p
)
T
(
t
)
,
we now compute
T
(
−
p
)
S
(
s
)
RT
(
p
)
T
(
t
)
,
(16.3)
where
p
is the pivot position,
t
is the translation vector,
s
is the scaling factor,
(
θ
x
,
θ
y
,
θ
z
)
are the angles of rotations about the corresponding axes, and
R
is
a
general
rotation matrix. Notice the similarities between Equation (16.3) and
Equation (9.10) (on p. 249). The only difference is the parameter for rotation (
θ
).
Search WWH ::
Custom Search