Sunday, February 10, 2013

Pinch Zoom

For doing pinch zoom, remember to include object origin (or other relevant point) in calculations.

Take starting touch positions t1' and t2".
Take next touch positions t2' and t2".
Calculate distances from start positions d1 and from next positions d2.
Calculate scale factor d2 / d1.
Apply scale factor by multiplication operation to global scale factor.

Calculate new positions for object o (o is referred as upper left point of object):
newPos1 = t2' - (t1' - o) * scaleFactor
newPos2 = t2" - (t1" - o) * scaleFactor

Take midpoint from newPos1 and newPos2, M.
Point M should be new upper left point for object 0.

It works as described in this blog
http://adtsai.blogspot.com/2010/09/pinch-zooming-using-xna4-on-wp7-getting.html

Scaling:
http://en.wikipedia.org/wiki/Scaling_%28geometry%29

No comments:

Post a Comment