Graphics Reference
In-Depth Information
PhotoApp
buttonPress
Create interactor
Interactor
mouseMove
mouseMove
mouseMove
Mouse events
routed to
Interactor
...
Destroy interactor
buttonRelease
Mouse events
again handled
by PhotoApp
Figure 21.7: Callbacks to the application result in the creation of an interactor, which
handles subsequent callbacks until done.
Let's imagine, for the time being, that the interaction is a simple single-finger
click and drag, with no scaling involved. Then our strategy for implementing the
interaction during dragging is as follows.
1. At each drag, compute the offset d between the current contact and the
initial contact.
2. Let T be the transformation which is translation-by- d .
3. Replace the transformation for the selected photo with T T 0 (i.e., first do
whatever transformations were done previously, and then translate by T ).
Notice that rather than accumulate incremental motions, we use the offset from
the original point. Accumulating increments can also work, but numerical prob-
lems may make the sum of the increments different from the total motion for long
drag sequences, making the photo appear to “slip” around the contact point that's
being dragged. We discuss this further in the case of virtual sphere rotation.
Note that in either case—accumulated incremental motions, or a single trans-
lation determined from the start point and current point—the translation is com-
posed with the existing transformations on the photo, and thus should be described
as a “relative” transformation rather than an absolute one.
At the end of the interaction, when the contact is broken, we need only destroy
the interactor.
The code outline,
in an informal approximation of C#,
is shown in
Listing 21.1.
Listing 21.1: Outline of interaction code for photo manipulation application.
1
2
3
4
5
6
7
8
Application:
main()
build scene graph for photos and display the scene register newContact, dragContact,
releaseContact callbacks
public newContactCallback(Scene s, Contact c)
Interaction ii = new Interactor(c)
 
Search WWH ::




Custom Search