Graphics Reference
In-Depth Information
Figure 4.9.
Window, normalized view-
port, and pixel space.
the dots of the electron beam for the CRT may not be “square.” The hardware ratio
is usually expressed in the form a = ya/xa with the operating system supplying the
values xa and ya. In Microsoft Windows, one gets these values via the calls
(
)
xa
=
GetDeviceCaps hdc ASPECTX
,
;
(
)
ya
=
GetDeviceCaps hdc ASPECTY
,
;
where hdc is a “device context” and ASPECTX and ASPECTY are system-defined
constants.
To take the aspect ratios into account and to allow more generality in the defini-
tion of the viewport, Blinn ([Blin92]) suggests using normalized device coordinates
(NDC) for the viewport that are separate from pixel coordinates. The normalized
viewport in this case will be the rectangle [-1,1] ¥ [-a,a], where a is the hardware
aspect ratio. If N x and N y are the number of pixels in the x- and y-direction of our
picture in pixel space, then Figure 4.8 becomes Figure 4.9.
We need to explain the “-e” terms in Figure 4.9. One's first reaction might be that
[0,N x - 1] ¥ [0,N y - 1] should be the pixel rectangle. But one needs to remember our
discussion of pixel coordinates in Section 2.8. Pixels should be centered at half
integers, so that the correct rectangle is [-0.5,N x - 0.5] ¥ [-0.5,N y - 0.5]. Next, the map
from NDC to pixel space must round the result to the nearest integer. Since rounding
is the same thing as adding 0.5 and truncating, we can get the same result by mapping
[-1,1] ¥ [-a,a] to [0,N x ] ¥ [0,N y ] and truncating. One last problem is that a +1 in the
x- or y-coordinate of a point in NDC will now map to a pixel with N x or N y in the
corresponding coordinate. This is unfortunately outside our pixel rectangle. Rather
than looking for this special case in our computation, the quickest (and satisfactory)
solution is to shrink NDC slightly by subtracting a small amount e from the pixel
ranges. Smith suggests letting e be 0.001.
There is still more to the window and viewport story, but first we need to talk
about clipping.
Search WWH ::




Custom Search