Graphics Reference
In-Depth Information
A: void SetUpTranslationMatrix( float x, float y) {
LPDIRECT3DDEVICE9 pDevice = UWBD3D _ GraphicsSystem::GetSystem().GetD3DDevice();
D3DXMATRIX translate _ matrix;
D3DXMatrixTranslation(&translate _ matrix, x, y, 0);
pDevice->SetTransform(D3DTS _ WORLD , &translate _ matrix );
.
Source file. Model.cpp
file in the Model folder of
the D3D _ TranslateObjects
project.
B: void CModel::DrawModel() {
. draws the grid ... //
DrawGrid(m _ DrawHelper, m _ WorldBounds);
C: if (m _ bTransformCircle)
SetUpTranslationMatrix(m _ TranslateX, m _ TranslateY);
m _ Circle.Draw(lod, m _ DrawHelper);
D: SetUpTranslationMatrix(0,0);
if (!m _ bTransformCircle)
SetUpTranslationMatrix(m _ TranslateX, m _ TranslateY);
m _ Rectangle.Draw(lod, m _ DrawHelper );
SetUpTranslationMatrix(0,0);
.
Listing 8.5. The CModel::DrawModel() function of Tutorial 8.2.
This suggests that we can control the drawing of the circle and the rectangle
by loading the WORLD matrix either with the proper translation operator or with
the identity matrix. In Listing 8.5 at label A, the SetUpTranslationMatrix()
function computes the translation operator T , and the results are stored in trans
late _ marix . We see that this operator is loaded into the WORLD matrix processor
by the SetTransform() function. When the input parameters to this function are
(
, the computed results are the identity matrix. In the DrawModel() function
(B), when the “Control Circle” radio button is selected ( m _ bTransformCircle
is true), at label C we compute the translation operator T basedontheslider-bar
values. In this way, the circle is drawn according to the transform
0
,
0
)
T
(
t x ,
t y )
M w 2 n .
At label D, we compute and load the WORLD matrix processor with the identity
matrix, and the rectangle is drawn with translation being identity. That is why the
rectangle always remains at the origin when the “Control Circle” button is acti-
vated. When the “Control Circle” button is not selected, m _ bTransformCircle
is false, and the transformations experienced by the circle and the rectangle would
swap. From this tutorial, we see that it is possible to program the matrix proces-
sors and control the transformations for individual primitives we draw.
Search WWH ::




Custom Search