Winoownto-Viewport Transformation: Order

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

21 0 Geometrica' Transformations

l'r11
Translate
Scale
Rotate
Scale (with =
:'W';j
Translate
ScaJc
Rutatc
Rl>lalt:
In rhese cases we need not he concerned about the order of matrix manipulation.
'
5 .4 THE WINOOWNTO-VIEWPORT TRANSFORMATION
Some graphics packages aUow rhe programmer ro specify output primitive in a
tloating-poim world-coordinate system. using whacever units are meaningful to rhe
application program: angstroms, light-years ) and so on. The rerrn
world is used because the application prngram b repre.!lenting a world rhm is being
<:rea ted or d to the user.
Given that output primitives are specified in world coordinates, the graphjcs subroutinl!
package must be rold how to map world omo screen coordinate!. (we use rhc
specific rerm screen coordinates to rclarc this discussion to SRGP, but lhat
hardcopy output devices might be in which case t.he term device coordinates wouid be
more appropriate). We could do this mapping by having the application programmer
provide the graphics package with a rransfomtation matrix to effect the mapping. A11other
way is to have the application programmer speeify a rectangular region in worltl
coordinate" caUcd the world-coordinate windnw, and a rectangular region in
screen coordinates, called the viewport. into which rhe world-coordinate window is to be
mapped. The transformation that maps the window imo the viewport is applied ro all of the
output primirives in world coordinates, rhus mapping them into screen coordinaces. Figure
5. lO shows rhis concept. As seen in rhb figure, tf the window and viewport do not have the
same heighr-to-width ratio, a tlOnunifonn scaling occurs. If the apptica(iOn program
changes the window or viewp()rt , then new oucput primitives drawn onto the screen will be
affected by the change. output primitives are not affected by a change.
The modifier world-coordinate is used with window to emphasize rhat we are not
discussing a which is a different and more recent and
[ill
L
Window
World coordjnates
Maximum range
ofscraen
coordinetes
Screen coordinates
Fig. 5.10 The wmdow in world coordinates and the v1ewport in screen coordinates
determine the mapping thac is applied to an che output primillves in world coordinates.
5.4
The Window-to Viewport Transformation 211
Window
World coordinates
Maximum rangP.
f-----------, of screen
lliJ
coordinates
ill]
Viewport 2
VIewport 1
Screen coordlnales
Fig. 5.11 The affect of drawing outpul primitives with two viewporls. Outpu1
primitives specifying 1he house ware firsl drawn with viewport 1, the viawporl was
changed to viewport 2, and than the application program agein called the graphics
package 10 draw 1he output pnmitivas.
which unfortunately has the same name. Whenever there is no ambiguity as to which type
of wsndow is meant, we wil1 drop the modifier.
!f SRGP were to provide world-coordinate ourput primitives, the viewport would be on
the current canvas, which defaulrs ro canvas 0, the screen. The apphcatton program would
be able to change the window or the viewport at any time, in which case subsequently
specified output would be subjected to a new transformation. If rhe change
included a different vjewport, then the new output VvUuld be located on the canvas
in posirions differem from those of the old ones, as shown iu Fig. 5.11.
A window manager might map SRGPs canvas 0 into !ess chan a fun-screen window. in
which not all of the canvas or even of the viewport would neccs'iarily be visible. In
Chaprer !0, we further discuss the relationships among world-coordinale windows,
viewports. and wmdow-manager windows.
Given a and viewporr, what is the cransformation matrix that maps the window
from world inco the vicwporr in conrrlinates? Tnis matrix can be
developed as a three-step transformation a!, suggested in Fig. 5. [ 2. The
Window 1n
worid coordinates
y
L---..&..--...... X
Window translated
to onglrt
....__..._ ___ ...,u
Window scaled to
size of viewport
v
(Umin 1 V m10}
Maximum
range
of screen
coordinates
......_ _____ ....... u
by (U min 1
v min) to frnar posjtion
Fig. 5.12 The steps in transforming a world-coordmate window into a viewport.
21 2 Geometrical Transformations
y
Window

World coordinates
v
Viewport
Maximum range
of screen
coordinates

Screen coordinates
Fig. 5.13 Output primi[ives in world coordinates are clipped against the wmdow.
Those that remain are displayed 1n the viewport .
window, specified by itl) and uppcr-righc comers. is first cranslated to the origin of
world coordinaces. Nexc, the size of the window is scaJed ro be equal to the size of the
viewport. Finally, a translation is used to position the viewport. The ovcraU macrix M..,v is:
Mwv =
T( . ) . s(r.imu - Umin vmu - vmin)
limtl\ V mm '
Xmu - Xmin Ymsx - Ymm
T(-Xmin - Ymm)
[g
0

ullla.'< - unun
0 0
. [g
0
-xm;']
-
1
Vnun
XmAX - Xrrun
v -
vmin l
- Yrnin
0
max
0
0 l
Ymax - Ymm
0 l
0 0
14!llall - Urrun
0 - xrmn
ufll<l'< - Umm +
llmm
Xw.a.oe - Xmm
Xrr.ax - Xmit.
Vma.\ - vmm v1T..1X
- vrrun
(5.33)
0
- ym1n +
Vrnin
}'IJ12X - Ymm Yrr:u: - Ymm
0 0
Mulrrp1ying P
= Mw\ tx
y I )
1
gives rhe expected resulr:
[
u - u
p = {.X - X J . . ,mm + U .
mn. X - X mJn
max rnm
\.' v .
(y -v ) mu mm+v
J rnJn Ymax - Y mm nul.
(5.34)
Many graphics packages combine che wjndow- viewport transfonnation wjrh clipping
of output primitives against the window. The concept of c1ipping was incroduced in Chapter
J; fig. 5. I 3 illusrrafes dipping in rhe comext of and viewports.
5.5 EFFICIENCY
The rnost general composicion of R, S. and T operations produces a macrix of che form
(5 .35)

You might also like