Graphics Reference
In-Depth Information
void CDrawAndMouseHandler::OnMouseMove( unsigned int nFlags, int hwX, int hwY) {
.
// hardware (hwXY) -> deviceXY xform
A: HardwareToDevice(hwX, hwY, deviceX, deviceY);
// LMB click with Shift Key depressed
if (nFlags & MK _ SHIFT & MK _ LBUTTON) {
Source file.
DrawAndMouseHandler.cpp
file
.
// deviceXY -> WC Projection ray xform
B: DeviceToWorld(deviceX, deviceY, pt, ray);
// set projection ray in the CModel clss
C: theApp.GetModel().SetPickRay(pt, ray);
.
in
the WindowHan-
dler
folder
of
the
D3D _ CameraInvXform
project.
Listing 15.18. Mouse event service routine that defines the WC projection ray.
Figure 15.14 is a screenshot of running Tutorial 15.4. This tutorial appears and
works almost exactly the same as that of Tutorial 15.3. The only difference is
that the WC projection ray is created and displayed when the left mouse button is
depressed with the shift key. For example, similar to Tutorial 15.3, clicking and
dragging with the left mouse button orbits the camera. However, with the shift key
depressed, clicking and dragging in this tutorial does not manipulate the camera.
Instead, we are specifying a DC position for the creation of the projection ray.
With the shift key depressed, when you click and drag the left mouse button in
the main view, you will notice a yellow line being drawn in the main view. This
yellow line is the computed projection ray based on the mouse position in the
main view. We notice that the projection ray is not visible in the window where
the mouse is clicked. Recall that the projection ray is a line extending from the
camera position through the mouse-click position into the scene. In the window
in which the mouse is clicked, the projection ray is projected into a point and thus
is not visible. Now, release the shift key and the left mouse button. Notice that the
yellow line becomes stationary. We can now left mouse button click and drag in
the small view to examine the last WC projection ray that was defined in the main
view. Right mouse button click with the shift key depressed clears the yellow line.
The CModel class of Tutorial 15.4 has a m _ PickPt and a m _ PickRay that rep-
resent the WC projection ray origin and direction. These two values are set by the
corresponding mouse event service routines in the DrawAndMouseHandler class.
Listing 15.18 shows the details of the mouse event service routine. At label A,
the mouse click is transformed from hardware coordinate system,
Figure 15.14.
Tutorial
15.4.
(
hwX
,
hwY
)
,to
Search WWH ::




Custom Search