Graphics Reference
In-Depth Information
Because the display transformation is attached to the canvas, it operates on
the entire scene, no matter how large or complex. At this point our scene is a
single primitive, but as we continue developing this application and the scene
becomes more complex, the value of this display transformation will be more
apparent.
Inline Exercise 2.1: Performing the scale before the translate is one way to
accomplish this display transformation; however, the reverse order will work
as well, with different values for the numeric properties. Using the laboratory,
visit V.03 and edit the XAML code to reverse the order of the two transforms.
First, change the order without adjusting the numeric properties, notice how the
rendered scene changes, and then change the properties as needed to restore the
desired target rendering.
Inline Exercise 2.2: Note that the circle is “hugging” the top and left side of
the canvas. Edit V.03 to move the circle 1
8
of an inch down, to give it some “breathing room.” Here again, the correct
numeric values will depend on the order of the transforms.
/
8 of an inch to the right and 1
/
Inline Exercise 2.3: Edit V.03 to add a small blue dot to act as the 12:00
marker.
In Inline Exercise 2.1, you noted the order dependency of a transformation
sequence: Scale followed by translate doesn't yield the same results as translate
followed by scale. The reason for the order dependency is based on laws of linear
algebra. As you will discover in Chapter 12, each transformation, like rotation and
translation, is represented internally by a matrix. Sequencing a number of trans-
formations is implemented via matrix multiplication, a noncommutative opera-
tion. Thus, it should be no surprise that the order of sequential transformations is
important.
2.4.6 Creating and Using Modular Templates
These same transformation utilities are also used for the purpose of construct-
ing a scene by positioning and adjusting copies of reusable stencils called control
templates. 6 Unlike physical templates that cannot change their size, graphics tem-
plates can be rotated, translated, and scaled.
52
y
1
x
Consider how we might approach defining the hour and minute clock hands.
We would like both to share a similar shape, but we'd like the hour hand to be
shorter and stouter, a variation that can be achieved via a nonuniform scaling of
the same polygon that generates the minute hand. So let's consider how we might
construct and place those two hands by defining and using the template shown in
Figure 2.15.
y 5 9
y
Figure
2.15:
Geometry
of
our
6. WPF's use of the word “control” in its template nomenclature refers to a typical use of
this kind of template: the construction of reusable custom GUI controls.
clock-hand template.
 
 
 
Search WWH ::




Custom Search