Graphics Reference
In-Depth Information
two contact-point translations. We could translate so as to preserve the lower-left
contact point, whether it's the first or the second, on the grounds that for right-
handed people, this is likely to be the thumb contact. We'll choose the second, but
there's a good argument to be made for each of the others. The only way to decide
conclusively is through user testing.
Now we have a complete problem definition: We'll translate the photo so that
the midpoint of the two contacts moves as specified, and we'll scale it about that
midpoint by the ratio of the contact distance after to the contact distance before.
The mathematical portion of the solution is now straightforward: We first scale
the object about the initial midpoint, and then translate that midpoint to its new
location.
21.3.2 Building the Program
To place our photo manipulator in context, we'll assume that there are several
photos in a scene, represented by a very simple scene graph: a “background,”
representing an infinite canvas on which the photos are placed, with a global
translate-and-scale transformation, and n photos, each with its own translate-and-
scale transformation (see Figure 21.6). We “see” the parts of the photos that, after
transformation, are visible in the unit square 0
1. When we manipulate a
particular photo (or the background), we will alter its transformation and none of
the others.
x , y
Figure 21.6: The background
canvas (yellow rectangle) has
its own scale-and-translate view
transformation (the top red
ellipse), and each photo (blue
square) has a scale-and-translate
as well.
We'll assume that the manipulation is to be done in the form of callbacks, one
for each contact event, where a contact is the touch of a digit to the interaction sur-
face: We get informed when there's a new contact, a contact drag, and a contact
release. When two contacts move at once (as in the move-and-resize action), we'll
get a callback for each one (in no particular order). Each callback will identify the
contact with which it's associated. And at the start of the photo-manipulator appli-
cation, the program will register with the operating system to receive callbacks for
all such interactions.
When, for instance, a touch and drag begins, the application's new-contact
callback will be invoked; it handles this by creating an Interaction object to
handle the remainder of the interaction sequence. That interaction object registers
for subsequent callbacks, and after receiving each and processing it, marks it as
having been handled so that no other registrants like the application itself get
that callback. When the interaction is completed (by a contact-release event), the
interactor can unregister itself, and subsequent callbacks will once again go to the
application (see Figure 21.7).
21.3.3 The Interactor
The interactor, at initialization, must do the following.
1. Identify which photo is being manipulated (and if the contact is not within
a photo, record that the background is being manipulated).
2. Record the initial point of contact.
3. Record the initial transformation T 0 for the photo or background.
4. Keep a reference to the transformation for the selected photo (or back-
ground) in the scene graph. (Because we do the same thing whether a
photo or the background is selected, we'll refer to the selected photo from
now on.)
 
 
 
Search WWH ::




Custom Search