Implementing Firefox's Pinch Zoom Gesture

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
AuahDark
Party member
Posts: 107
Joined: Mon Oct 23, 2017 2:34 pm
Location: Indonesia
Contact:

Implementing Firefox's Pinch Zoom Gesture

Post by AuahDark »

Hello, I'm trying to implement zoom gesture for my game. I tried various methods on implementing this but no avail. My quick guess is to do it in love.touchmoved callback but I have no idea how. Any help is appreciated.

This is the gesture I wanted. You can see both of my fingers as black large dots.


I only need the basic concept/explanation how to do it. Code snippet that uses gamera is plus point but not necessary.
Profile. Do you encounter crashes in LÖVE Android and wanna send me logcats? Please hit me up in LÖVE Discord and send the full logcat file!
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Implementing Firefox's Pinch Zoom Gesture

Post by pgimeno »

AuahDark wrote: Mon Sep 27, 2021 11:35 am I only need the basic concept/explanation how to do it. Code snippet that uses gamera is plus point but not necessary.
I've written a library to handle pinch gestures. It's incomplete because I'm stuck at something and I don't know how to solve it, but my library handles zoom, pan and rotation, all of them optional. I can hand you the WIP library if you think it can be useful for you. It produces values for a Löve transform, with position, rotation, scale and origin but no shear. I'm not sure how easy or hard will it be to adapt that to gamera. It should be simple to adapt it to cam11.

For pure zoom, the basics are as follows. Calculate the ratio between the initial distance between the fingers and the initial zoom, and use that to determine the final zoom as the distance between fingers varies via a simple cross-multiplication (the ratio should remain constant).

Panning is more complex. My library offers several options for what to use as hook, but the most straightforward one is the middle point between the fingers. You transform the initial middle point between both fingers to world coordinates and store that position; then, as the fingers move and the centre moves, you need to work backwards from the new position of the centre between the fingers, such that when transforming it to world coordinates, it produces the same initial point.

I assume you don't need rotation.
User avatar
AuahDark
Party member
Posts: 107
Joined: Mon Oct 23, 2017 2:34 pm
Location: Indonesia
Contact:

Re: Implementing Firefox's Pinch Zoom Gesture

Post by AuahDark »

It took me few days, but thanks I finally got it right.
Profile. Do you encounter crashes in LÖVE Android and wanna send me logcats? Please hit me up in LÖVE Discord and send the full logcat file!
Post Reply

Who is online

Users browsing this forum: No registered users and 41 guests