Graphics Reference
In-Depth Information
void
CDrawAndMouseHandler::OnMouseButton(
bool
down,
unsigned int
nFlags,
int
hwX,
int
hwY)
// variable for point in DC space
A:
int
dcX, dcY;
Source file.
DrawAndMouseHandler.cpp
file
// variable for point in WC space
float
wcX, wcY;
// Transform from hardware space (hwX,hwY) to DC (dcX, dcY)
in
the
WindowHan-
dlers
folder
of
the
D3D
_
SceneNodePicking
project.
B:
HardwareToDevice(hwX, hwY, dcX, dcY);
// Transform from DC (dcX,dcY) to WC (wcX,wcY)
DeviceToWorld(dcX, dcY, wcX, wcY);
if
(MK
_
LBUTTON && down)
// if left mouse button is clicked
// Calls the
PickNodeAt()
function with mouse click in WC
theApp.GetModel().PickNodeAt(wcX,wcY)
C:
Listing 11.17.
The mouse-click service routine of Tutorial 11.7.
get
pSearchNode
. In this way, the
bbox
returned will be the WC bounding box of
the currently selected scene node. Because all positions are in the WC space, we
can perform the simple containment test at label D to determine if
pick
_
point
is
within the bounds of
bbox
. Listing 11.17 shows the mouse event service routine
implemented in
CDrawAndMouseHandler.cpp
. In this case, we can see that the
mouse-click position is forwarded to the service routine in hardware coordinate
space,
(
hwX
,
hwY
)
. At label B, the mouse-click position is transformed into DC
space,
. At label C, we see that
when the left mouse button is clicked, the
CModel::PickNodeAt()
function is
called with the mouse-click position in the WC space.
(
dcX
,
dcY
)
, and then to WC space,
(
wcX
,
wcY
)
11.4.2
Collision
In Section 7.5, we discussed the issues involved with colliding primitives. Our
conclusion is that it is more efficient to approximate collisions with intersections
of simple volumes that bound the colliding primitives. The
UWB
_
BoundingVolume
class (Listing 7.15 on p. 185) was introduced to approximate primitive collision.
In the previous section, we learned how to compute WC bounding boxes for scene
node objects based on the
UWB
_
BoundingBox
class to support mouse-click selec-
tion. We can now approximate the collision between scene nodes based on the
intersection of their corresponding bounding boxes.
Tutorial 11.8.
Project Name:
D3D
_
SceneNodeCollision
Library Support:
UWB_MFC_Lib1
UWB_D3D_Lib12
Tutorial 11.8. Collision Detection
•
Goal.
Demonstrate colliding scene node objects based on the WC bounding
boxes.
Search WWH ::
Custom Search