Graphics Reference
In-Depth Information
16
17
18
19
20
21
22
23
24
25
26
qq = photoDisplay.TranslatePoint(qq, (UIElement) controlled.Parent);
Vector motion = pp - qq;
Vector contactDiff = c2.getPosition() - c1.getPosition();
double scaleFactor = contactDiff.Length / startVector.Length;
TransformGroup tg = new TransformGroup();
tg.Children.Add(initialTransform);
tg.Children.Add(new ScaleTransform(scaleFactor, scaleFactor, qq.X,qq.Y));
tg.Children.Add(new TranslateTransform(motion.X, motion.Y));
controlled.SetTransform(tg);
This code uses several WPF conventions that deserve explanation. First, a
TransformGroup is a sequence of transformations that are applied in order; thus,
in the if clause, we first perform the initial transformation to the photo, and then
translate it. Second, the line
pp = photoDisplay.TranslatePoint(pp, (UIElement) controlled.Parent)
transforms the point pp from the world coordinate system (that of the
PhotoDisplay ) to the coordinate system of the parent of the current photo (the
background canvas). In the case where the background canvas is being manipu-
lated, it transforms the point to the coordinate system of background's parent, that
is, the PhotoDisplay. Thus, the computed translation qq-pp is the one to apply
after the photo has been scaled, but before it is further transformed by the transfor-
mation associated to the background. It's essential that the point pp start in world
coordinates for this to work properly. If it were, say, in the coordinate system of
the photo, we'd have to transform it to the photo's parent.
21.4 Mouse-Based Object Manipulation in 3D
The same general approach—build an interactor that handles a click-and-drag
sequence by editing the transformation on a target object—works in 3D as well.
A closely related idea is that the relationship of object to view is symmetric: In
a view of a scene with only a single object, we can move the object to the right,
or the camera to the left, and get the same change in the eventual image. Thus, a
slightly modified version of the interaction we use for object manipulation can be
used for camera manipulation.
21.4.1 The Trackball Interface
In the trackball model, we imagine that an object is suspended in a transparent
solid ball with center C that can be rotated by the user; a click and drag on the
ball's surface, from a starting point A to an endpoint B , defines a rotation: The ball
is rotated in the plane of A , B , and C , with C as the center of rotation, so as to
move A to B . (This is also called the virtual sphere model.)
Inline Exercise 21.1: In terms of A , B , and C , describe the axis of the rotation,
and the angle.
 
 
 
 
Search WWH ::




Custom Search