Graphics Reference
In-Depth Information
1 range and will automat-
ically compute the M n 2 d (Equation (10.6)) operator for drawing the geometries
to the output device. In our library design, the M w 2 n operator is computed by
the WindowHandler class and loaded into the VIEW matrix processor ( M V )ofthe
D3D RC. Finally, we have seen that when defining the WC window, we must
ensure that the WC window aspect ratio is the same as that of the UI drawing
device. Otherwise, disproportional scaling will occur, resulting in images that
appear squeezed.
automatically clip away all geometries outside of the
±
10.5
Inverse Transformation
So far, we have concentrated on learning the output of geometric elements. To
build interactive applications, we must interact with the user. In particular, we
must understand how the added window coordinate system affects a user's picking
or selecting an on-screen object by clicking the mouse buttons (in DC space).
In the Tutorial 5.6 implementation of the ball-shooting program, we compared
mouse click positions with circles in the AllWorldBalls collection to locate the
selected one. Notice that this simple operation involves a comparison across two
distinct coordinate systems.
Hardware coordinate. Re-
call that the MFC API returns
mouse click positions in the
hardware coordinate system
where the top-left is the origin
with y -axis incrementing
downward and x -axis increase
rightward.
Mouse-click position ( pt dc ). This is a point on the display device (that the
user's mouse clicked on). In the case of MFC, this position is returned to us
in the hardware coordinate space. As described in Chapter 2 (Tutorial 2.4),
we flipped the y -axis by subtracting the y -value from the height of the de-
vice and thereby converting the point into the device coordinate space with
the origin at the lower-left corner. In all of the following discussions, we
assume that the hardware-to-device transform has already been performed
and we will work with points in DC space, pt dc .
Hardware-to-device
transform. This transfor-
mation is performed by
the HardwareToDevice()
function
defined
in
the
AllWorldBalls collection. This is the set of all geometries in the world.
By definition, these geometries are defined in the world coordinate (WC)
space.
WindowHandler class.
In the case of Tutorial 5.6, although we did not distinguish between these two
coordinate systems, the selection operation functioned correctly because we have
carefully defined the WC window to coincide exactly with the DC space. In gen-
eral, we must transform input mouse positions to the WC space before working
with them. For example, in the Tutorial 10.7 implementation of displaying the
Search WWH ::




Custom Search