Graphics Reference
In-Depth Information
Source
file.
Model.h
file
class
CModel {
// ... similar to Tutorial
11.6
...
in
the
Model
folder
of
the
D3D
_
SceneNodePicking
project.
public
:
// sets the currently selected scene node
A:
void
SetActiveSceneNode(UWB
_
SceneNode
*
);
// test if (wcX, wcY) is inside the WC Bbox of the currently
// selected scene node
B:
void
PickNodeAt(
float
wcX,
float
wcY);
private
:
// root of the enture human model hierarchy
UWB
_
SceneNode m
_
Body;
// pointer to the scene node that is selected in the
// SceneTreeControl GUI element
C:
UWB
_
SceneNode
*
m
_
pActiveNode;
.
D:
};
Listing 11.15.
The
CModel
class of Tutorial 11.7.
Source file.
Model.cpp
file in the
Model
folder of
the
D3D
_
SceneNodePicking
project.
void
CModel::PickNodeAt(
float
worldX,
float
worldY)
// bbox of the currently selected scene node
UWB
_
BoundingBox bbox;
// mouse click position in WC
vec3
pick
_
point(worldX, worldY, 0);
// initialize matrix stack for OC-to-WC computation
A:
m
_
DrawHelper.InitializeModelTransform();
// compute WC bbox for the selected scene node
B:
m
_
Body.GetNodeBounds(m
_
pActiveNode, bbox ...);
// test if bbox contains the mouse click position
C:
if
(bbox.ContainsPoint( pick
_
point ) )
.
// all positions are in WC space
sets bbox draw color and prints appropriate message
D:
Listing 11.16.
The implementation
CModel
class of Tutorial 11.7.
initialized at label B for the proper concatenation of the OC-to-WC transformation
matrix. At label C, we call the
GetNodeBounds()
function on the
m
_
Body
node.
As illustrated in Listing 11.14, the
GetNodeBounds()
function will maintain a
correct OC-to-WC transformation matrix on the matrix stack while traversing the
hierarchy in search of the target node. In this case, the
m
_
pActiveNode
is the tar-
Search WWH ::
Custom Search