Graphics Reference
In-Depth Information
Tutorials 8.3 and 8.4. The Scaling and Rotation Operators
Tutorial 8.3.
Project Name:
D3D _ ScaleObjects
Library Support:
UWBGL _ MFC _ Lib1
UWBGL _ D3D _ Lib8
Goals. Experience with scaling and rotation operators.
Approach.
Examine the drawing of primitives with the scaling/rotation
operators.
Tutorial 8.4.
Project Name:
D3D _ RotateObjects
Library Support:
UWBGL _ MFC _ Lib1
UWBGL _ D3D _ Lib8
Figures 8.21 and 8.22 are screen-shots of running Tutorials 8.3 and 8.4. These
two tutorials are structurally identical to Tutorial 8.2. The only difference is in
the transformation operator control, whereas in Tutorial 8.2 we allow user con-
trols translation, Tutorial 8.3 lets user controls the scaling, and Tutorial 8.4 lets
user controls the rotation operators. The behavior of the tutorials are also sim-
ilar, that depending on the radio control button settings, the slider bars control
one of the primitives. In the case of these two tutorials, we are interested in
examine the D3D function calls to compute the scaling/rotation operator.
List-
ing 8.6 shows the transformation-setting functions from Tutorials 8.3 and 8.4. At
label A, we see the D3D function D3DXMatrixScaling() , which computes the
scaling operator S
and stores the results in scale _ matrix . As in the case
of the translation operator in Listing 8.5, this operator is stored into the WORLD
matrix processor by the SetTransform() function call.
(
s x ,
s y )
If the parameters of
Figure 8.21.
Tutorial
SetUpScaleMatrix() are
, the result is the identity matrix. At label B, we
see the D3DXMatrixRotationZ() function, which computes the rotation opera-
tor R
(
1
,
1
)
8.3.
. Notice that the unit on the angle is in radians (and not degrees). As with
translation and scaling, the rotation operator is represented by rotate _ matrix ,
and this operator can be stored into the WORLD matrix processor. These tutorials
show us that we can load the WORLD matrix processor with any appropriate op-
erators (represented by a matrix) to accomplish desired transformations on the
primitive we wish to draw. We are now ready to learn the theory that allows us to
construct powerful transformation operators with matrices.
( θ )
Figure 8.22.
Tutorial
8.4.
Tutorial 8.3 : Model.cpp: working with the Scaling opeartor.
void SetUpScaleMatrix( float x, float y) {
LPDIRECT3DDEVICE9 pDevice =
UWBD3D _ GraphicsSystem::GetSystem().GetD3DDevice();
D3DXMATRIX scale _ matrix;
Source file. Model.cpp file
in
the Model
folder
of
the
A: D3DXMatrixScaling(&scale _ matrix, x, y, 0);
pDevice->SetTransform( D3DTS _ WORLD , &scale _ matrix );
D3D _ ScaleObjects
and D3D _ RotateObjects
projects.
}
Listing 8.6. The CModel::DrawModel() function of Tutorial 8.3 and 8.4.
Search WWH ::




Custom Search