Graphics Reference
In-Depth Information
mation computation starting from the body node. In our implementation, the an-
cestor's transformation matrices are concatenated on the top of the matrix stack.
Listing 11.14 shows the implementation of the GetNodeBounds() function de-
signed to compute the WC bounding box of a branch of the scene hierarchy rooted
at pSearchNode . As in all cases, the OC-to-WC transformation is maintained at
the top of the matrix stack (at label B) while the hierarchy is traversed in search
of the target pSearchNode (at label B1). When the target node is found at label
A, the WC bounding box rooted at this node is computed by the GetBounds()
function. At this point, all the transformations of the ancestors of this target node
are concatenated at the top of the matrix stack. For this reason, it is possible to
correctly compute the WC bounding box. The PopModelTransform() function
call at label C ensures that the proper matrix stack is maintained.
Tutorial 11.7. Mouse-Hit Detection
Tutorial 11.7.
Project Name:
D3D _ SceneNodePicking
Library Support:
UWB_MFC_Lib1
UWB_D3D_Lib12
Goal. Demonstrate the coordinate transformations and proximity tests com-
putations involved to support the implementation of mouse-click selection.
Approach. Support mouse-click selection of scene nodes in the human
model from Figure 11.13.
Figure 11.22 is a screenshot of running Tutorial 11.7. As in previous tutorials, this
tutorial allows the user to select a current scene node via the SceneTreeControl
GUI element. In addition, this tutorial computes and shows the WC bounding
box of the branch of the hierarchy that is rooted at the currently selected scene
node. For example, in Figure 11.22, the user has selected the left arm node in
SceneTreeControl , and the WC bounding box drawn is the branch of the hier-
archy rooted at the left arm, including that of the child, the left palm node. Finally,
this tutorial is capable of determining if a mouse click is within the currently high-
lighted WC bound. Notice that the WC bounding box is an axis-aligned rectangle,
which may include significant void spaces. Listing 11.15 shows the definition of
the CModel class of Tutorial 11.7. The function SetActiveNode() at label A se-
lects a currently active scene node. This function is called when the user clicks in
the SceneTreeControl GUI element to activate a different scene node to work
with. Recall that the currently active scene node is the one that we compute
the WC bounding box for. The PickNodeAt() function at label B accepts the
(
Figure 11.22.
Tutorial
11.7.
point in WC space and determines if the point is within the bounds of
the currently selected scene node. The m _ Body at label C is the root node of the en-
tire human model hierarchy, whereas the m _ pActiveNode is the currently selected
scene node. Listing 11.16 shows the implementation of the PickNodeAt() func-
tion. Local variables for this function are defined at label A. The matrix stack is
wcX
,
wcY
)
 
Search WWH ::




Custom Search