Graphics Reference
In-Depth Information
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Interactor:
private Contact c1
private Transform2 initialXform
private Point2 startPoint
private FrameworkElement controlled
private PhotoDisplay photoDisplay
public Interactor(Contact c)
c1=c
intialPoint = c1.getPoint()
controlled = the photo (or background) that's at initialPoint
initialXform = controlled.getTransform()
register for all contact callbacks
public dragContactCallback(Contact c)
if c1 != c { signal an error }
Vector2 diff = c.getPoint() - initialPoint
Transform2 T = new Translation(diff)
s.setTransform(o, initialXform * T)
redisplay scene
public releaseContactCallback(Contact c)
if c1 != c { signal an error }
unregister this interactor for callbacks
We're assuming here that we have point, vector, and transformation classes,
and that composition of transformations is represented by the overloaded * oper-
ator, in which S * T is the transformation that applies S and then T . Furthermore,
we assume that each object (photo or background) stores its own transformation,
rather than the transformations being stored in a scene-graph object.
All of these assumptions hold in WPF, and a WPF implementation of this
photo manipulator is available on this topic's website. Rather than using actual
multitouch contacts, which may not be available to all readers, the program sim-
ulates them by letting the user right-click to create or destroy a “contact” (shown
as a small marker) and then left-click and drag to move contacts.
WPF also provides pick correlation—a report of which object in a scene is
visible at the pixel where the user clicks, as needed at line 19 in Listing 21.1.
What changes must be made to allow for two-contact interaction? When the
second contact happens, we'll treat the first contact's click-and-drag sequence as
having terminated (i.e., we'll start from the current photo's current transformation,
and forget that we ever had an initial transformation or contact point).
For a two-contact interaction, we'll (a) treat the midpoint of the two contacts
as pinned to the photo so that when the midpoint moves, the photo moves, and (b)
scale the photo relative to the distance between the fingers so that if the fingers
move together the photo is unscaled, and if they widen the photo enlarges, etc.
We'll record the midpoint and vector difference of the contacts at the start, and
at each update we'll build an appropriate scale-and-translate transformation. In
other words, we'll do just what we did for the single-contact click and drag, but
now we'll do it by remembering the initial positions of two contact points, and we
will include scaling.
Because the interaction sequence might look like “touch with one finger, drag
to the right, touch with the thumb as well, drag farther to the right and widen the
distance of the finger to the thumb,” we must also track the number of contact
 
 
Search WWH ::




Custom Search