Graphics Reference
In-Depth Information
ject. If we modify the
XformInfo
operator of selective nodes in a scene hierarchy
during each timer update, then a continuous animation will be observed by the
user.
Tutorial 11.9. Animating the
SceneNodes
Tutorial 11.9.
Project Name:
D3D
_
SceneNodeAnimation
Library Support:
UWB_MFC_Lib1
UWB_D3D_Lib12
•
Goal.
Demonstrate that simple animation of scene nodes can be imple-
mented by modifying the
XformInfo
operators of scene nodes during timer
events.
•
Approach.
Continuously update the palm nodes' rotation operator in the
human model from Figure 11.13.
Figure 11.25 is a screenshot of running Tutorial 11.9. This tutorial runs and be-
haves very similar to that of Tutorial 11.8. The only difference is that the two
palms on the human model and the palm of the arm bullet spin continuously. List-
ing 11.21 shows that in order to create the spinning animation of the palms on the
human model, the rotation value in the
XformInfo
operator of the left and right
palm nodes must be incremented during each timer update. We see that at label A,
a copy of the left palm
XformInfo
node is obtained; at label B, the rotation value
is incremented; and at label C, the new rotation value is copied back to the left
palm node. With the increased rotation value, the next redraw will rotate the left
palm with an additional angle from its original position. In this way, during timer
events, the rotation value is continuously incremented, and the incremented value
shows up as additional rotation when the palm is drawn, resulting in an apparent
spinning animation of the palm node.
Figure 11.25.
Tutorial
11.9.
Source file.
Model
_
Siumulation.cpp
file in the
Model
folder of the
D3D
_
SceneNodeAnimation
project.
void
CModel::UpdateSimulation() {
// ... similar to Listing
11.20
...
// XformInfo operator of the left arm node
UWB
_
XformInfo xform = m
_
pLeftPalmNode->GetXformInfo();
// get the current rotation value
A:
B:
float
rotation = xform.GetRotationInDegrees();
rotation += 10;
// increase the rotation value
if
(rotation > 360) rotation -= 360.0f;
// avoid overflows
// set the new rotation value to
C:
xform.SetRotationDegrees( rotation );
// the XformInfo operator of the scene node
m
_
pLeftPalmNode->SetXformInfo( xform );
D:
// Repeat the above for the Right Palm scene node
}
Listing 11.21.
The
CModel::UpdateSimulation()
function of Tutorial 11.9.
Search WWH ::
Custom Search