Graphics Reference
In-Depth Information
void
UWB
_
WindowHandler::DeviceToWorld(
int
dcx,
int
dcy,
float
&wcx,
float
&wcy)
const
.
A:
GetDeviceSize(dcW, dcH);
// Get the UI drawing device dimension
vec3
center = m
_
WCWindow.GetCenter();
// Center position of the WC Window
float
wcW = m
_
WCWindow.Width();
// Width of the WC Window
float
wcH = m
_
WCWindow.Height();
// Height of the WC Window
B:
wcx = center.x + ((wcW/dcW)
*
(dcx - (dcW/2.0f)));
// implement Equation
10.17
wcy = center.y + ((wcH/dcH)
*
(dcy - (dcH/2.0f)));
// by computing Equation
10.19
Source file.
uwbgl
_
WindowHandler3.cpp
file in the
Common Files/ Win-
dowHandler
subfolder of the
UWBGL
_
D3D
_
Lib10
project.
Listing 10.14.
The
WindowHandler::DeviceToWorld()
implementation.
and
⎧
⎨
center
=(
cx
wc
,
cy
wc
)
,
WC window
=
width
=
W
wc
,
⎩
=
.
height
H
wc
Listing 10.14 shows the implementation of Equation (10.19) in the
DeviceTo
Tutorial 10.13.
Project Name:
D3D
_
BadMousePan
Library Support:
UWB
_
MFC
_
Lib1
UWB
_
D3D
_
Lib10
World()
transform function of the
UWB
_
WindowHandler
class in
D3D
_
UWB
_
Lib10
.
At label A, we obtain the dimension of the drawing device and the parameters for
the WC window. Label B is a direct implementation of Equation (10.19). In gen-
eral, we must transform all user mouse-click positions by Equation (10.17) before
comparing with points in the WC space.
Tutorial 10.14.
Project Name:
D3D
_
MousePan
Library Support:
UWB
_
MFC
_
Lib1
UWB
_
D3D
_
Lib10
Tutorials 10.13 and 10.14. Mouse Positions and Inverse Transforms
•
Goal.
Verify mouse positions and the need for device-to-world transforma-
tions.
•
Approach.
Extend Tutorial 10.12 to support moving of the small-view WC
window by dragging with the left mouse button in the main view.
Figure 10.23 is a screenshot of running Tutorials 10.13 and 10.14. In these tuto-
rials, left mouse button drag in the main view defines the center position for the
WC window of the small view. For example, from Figure 10.11 we know that the
nose position of the geometric person is
Figure 10.23.
Running
Tutorial 10.13 and 10.14.
in WC space. Now, if the user left
mouse button clicks at the nose position in the main view, our application will re-
act by moving the center of the small-view WC window to
(
20
,
30
)
(
20
,
30
)
. If the user left
mouse button drags towards the right-eye position,
, our application will
track the position by moving the center of the small-view WC window. Notice
(
22
,
32
)
Search WWH ::
Custom Search