Graphics Reference
In-Depth Information
points. Whenever this number changes, we'll restart our tracking. Listing 21.2
shows the differences, except for what happens when a contact moves.
Listing 21.2: Handling the varying number of contact points.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Interactor:
private Contact c1, c2;
private Transform2 initialXform
private Point2 startPoint
private FrameworkElement controlled
private PhotoDisplay photoDisplay
private Vector2 startVector
public Interactor(Scene s, Contact c)
c1 = c; c2 = null;
startPoint = c1.getPoint()
initializeInteraction()
...
// if there's only one contact so far, add a second.
public void addContact(Contact c)
if (c2 == null)
c2 = newContact(e);
initializeInteraction();
private void initializeInteraction()
initialFform = controlled.GetTransform();
if (c2 == null)
startPoint = c1.getPosition();
else
startPoint = midpoint of two contacts
startVector = c2.getPosition() - c1.getPosition();
public removeContact(Contact c)
if only one contact, remove this interactor
otherwise remove one contact and reinitialize interaction
When a contact point moves, we have to adjust the transformation for the
relevant photo. Listing 21.3 gives the details.
Listing 21.3: Handling motion of contact points.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public void contactMoved(Contact c, Point p)
if (c2 == null)
Vector v = p - startPoint;
TransformGroup tg = new TransformGroup();
tg.Children.Add(initialTransform);
tg.Children.Add(new TranslateTransform(v.X, v.Y));
controlled.SetTransform(tg);
else
// two-point motion.
// scale is ratio between current diff-vec and old diff-vec.
// perform scale around starting mid-point.
// translation = diff between current midpoint and old
Point pp = getMidpoint(); // in world coords.
Point qq = startPoint;
pp = photoDisplay.TranslatePoint(pp, (UIElement) controlled.Parent);
 
Search WWH ::




Custom Search