Graphics Reference
In-Depth Information
9.4
Programming Transformations with
Graphics APIs
Tutorial 9.1. Concatenation of Matrices
Tutorial 9.1.
Project Name:
D3D _ TranslateScaleObj
Library Support:
UWB _ MFC _ Lib1
UWB _ D3D _ Lib8
Goals. Understand graphics APIs' support for concatenation of transfor-
mation operators (matrices).
Approach. Use simple translation and scaling as examples to examine how
concatenation can be implemented.
Figure 9.10 is a screenshot of running Tutorial 9.1. This tutorial implements and
visualizes the concatenated results of scaling and translation matrices:
V i S
(
s x
,
s y
)
T
(
t x
,
t y
) ,
where V i are the vertices of a rectangle. In this case,
V a
=(
0
,
0
) ,
Figure 9.10.
Tutorial
V b =(
2
,
0
) ,
9.1.
rectangle vertices:
V c =(
2
,
3
) ,
V d =(
0
,
3
) .
Because V a is the origin, from our discussion, we know that the scaling operation
will be carried out with respect to V a . In this case, we would expect the rectangle
to be scaled by
(
,
)
with the left and bottom edges being stationary and the
scaled rectangle to be translated by
s x
s y
. By manipulating the slider bars, we can
verify this behavior and that each of the four slider bars controls the corresponding
displacements or scaling factors.
Listing 9.1 shows the CModel class of this tutorial. At label A are the functions
that the slider-bar event service functions will call to set the corresponding values
for the displacements (i.e., t x , t y ) and/or scaling factors (i.e., s x , s y ) at label B. The
rectangle we see in the application window is defined at label C. Listing 9.2 is the
function that computes and draws the rectangle. At label A, we see the declaration
of three transformation operators (matrices). It is important to note that all three
operators are of the same D3DXMATRIX data type (all transformation operators are
matrices). At label B, as we saw in tutorials from the previous chapter, these
two functions compute the translation and scaling matrices. At label C, we call
the function D3DXMatrixMultiply() to concatenate the translation and scaling
operators into the combined _ matrix operator. At this point, combined _ matrix
( M a ) implements
(
t x
,
t y
)
M a =
S
(
s x ,
s y )
T
(
t x ,
t y ) .
(9.6)
Search WWH ::




Custom Search