Graphics Reference
In-Depth Information
Source file. Model.cpp
file in the Model folder of
the D3D _ PivotedRotation
project.
void CModel::DrawModel() {
.
A:
pMatrixStack->LoadIdentity();
pMatrixStack->Push()
if (m _ bPivotAtObjectCenter)
// center of the rectangle
pivot = vec3 (1.0, 1.5, 0.0);
B:
else
// default pivot position is the lower left corner
pivot = vec3 (0.0, 0.0, 0.0);
// M t 1 T ( t x , t y , 0 ) M t
pMatrixStack->TranslateLocal(m _ TranslateX, m _ TranslateY, 0.0f);
// M t 2 T ( p x , p y , 0 ) M t 1
pMatrixStack->TranslateLocal(pivot.x, pivot.y, 0.0f);
// M t 3 R ( θ ) M t 2
pMatrixStack->RotateAxisLocal( &z _ axis, m _ RotateAngleRadians );
// M t 4 S ( s x , s y , 1 ) M t 3
pMatrixStack->ScaleLocal(m _ ScaleX, m _ ScaleY, 1.0f);
// M t 5 T ( p x ,− p y , 0 ) M t 4
pMatrixStack->TranslateLocal(-pivot.x, -pivot.y, 0.0f);
// M W M t 5
C:
pDevice->SetTransform(D3DTS _ WORLD, pMatrixStack->GetTop());
m _ Rectangle.Draw(lod, m _ DrawHelper);
.
D:
Listing 9.5. The CModel::DrawModel() function of Tutorial 9.4.
to be the pivot position, we would perform two translation operations with zero
displacements and effectively compute M c of Equation (9.8). Lastly at label D,
the computed matrix is loaded into the WORLD matrix processor, and the rectangle
is drawn. Notice the correspondence between the ordering of operators in Equa-
tion (9.9) and the sequence of function calls at label C: T
is the rightmost
operator, and the corresponding TranslateLocal(m _ TranslateX, m _ Trans
lateY) is the function that is called first . Remember that for D3D Local trans-
form functions, concatenation of operators is always to the left side of the top of
the matrix stack. For this reason, to implement a concatenated transformation op-
erator, we should begin by calling the function that corresponds to the rightmost
operator and sequence to the left.
In this tutorial, we see that by understanding and analyzing the required trans-
form operator carefully, the actual implementation can be rather straightforward.
(
t x ,
t y )
Search WWH ::




Custom Search