playMaker

Author Topic: Touch: Pinch zoom [SOLVED]  (Read 6691 times)

doppelmonster

  • Full Member
  • ***
  • Posts: 157
    • Grinder Games
Touch: Pinch zoom [SOLVED]
« on: May 20, 2013, 06:51:08 PM »
Hello,
im trying to get a pinch zoom working with playmaker. Im already able to track two fingers and get the distance between them and store it in a float var. Now im stuck because i dont know how to read out if the distance is getting larger or smaller (zoom in/out). So i need the delta of the distance variable. Is there an action in playmaker that can provide me this?

Thanks,
Matthias
« Last Edit: May 25, 2013, 05:37:33 PM by Alex Chouls »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Touch: Pinch zoom
« Reply #1 on: May 21, 2013, 02:16:03 AM »
Hi,

 If you are storing touch positions in vector3, then yes, simply get the magnitude of the vector ( Touch2-touch1) and that's your zoom value


If you are using vector2 variables, you can do the same but you'll need some custom actions:

https://hutonggames.fogbugz.com/default.asp?W1004

you are on the right path tho, you need to get the delta value of the gesture, that's the likely way to get what you want, if you get just the magnitude, you will struggle using that variable to do anything meaningfull.

 getting the delta is also simple, simply store the previous magnitude and substract it with the fresh one and override the previous magnitude, do that everyframe and you have your delta pinch value.

bye,

 Jean

doppelmonster

  • Full Member
  • ***
  • Posts: 157
    • Grinder Games
Re: Touch: Pinch zoom
« Reply #2 on: May 22, 2013, 08:02:55 AM »
Hi Jean,
you got me on the right track. But i didnt understood how to do this:

Quote
getting the delta is also simple, simply store the previous magnitude and substract it with the fresh one and override the previous magnitude, do that everyframe and you have your delta pinch value.

This was my initial question. How would you set up an FSM for that?


I tried to use the delta from "get touch info".
But i was not able to extract the magnitude (or length?) from the delta vector3.
"Get vector3 length" and "Vector3 Operator" both didnt work.


So finaly i used the delta of "Touch info" but used the independent floats of x and y. This works fine, but maybe there is a simpler solution?

http://www.evernote.com/shard/s239/sh/80bbdbd0-a6e8-43f3-a315-1bc4d90ec417/ea7b30528eee9a4160e868cea0826bb3

http://www.evernote.com/shard/s239/sh/5dec8e7f-61ee-4f1d-8151-417f122a8534/96974b98e59b55ceeb2824697d47a3e7

http://www.evernote.com/shard/s239/sh/8a5e84e5-3448-484a-91d8-942a37c7dfee/41ba0e61b247ccb406a96ea1f5ff3388

xhidnoda

  • Full Member
  • ***
  • Posts: 231
Re: Touch: Pinch zoom
« Reply #3 on: May 22, 2013, 10:31:58 AM »
this..is interesting ;) Come on Jean!  :P :P :P :P :P Send a picture of FSM  ;D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Touch: Pinch zoom
« Reply #4 on: May 23, 2013, 02:22:09 AM »
Hi,

 I have better than a screenshot :)

 I made a small working example on how to catch a pinch gesture, extract the positions, and get the delta pinch.

 Warning. this is not bullet proof, the way I check touches are sequential, so it works in most case, only fail if you start releasing the first finger and pressing again.

 If you want a bullet proof pinch, I suggest you use a library like Input.touches, it has everything you need, and more, including full support for pinch gesture with proper feedback and all.
 
If you still want to do it all in playmaker, I would go for ArrayMaker, and store the touch Ids in an array, then, the second touch is not hard coded, and when the first touch is released, the id it removed from the array, which then will work for any cases.

bye,

 Jean

doppelmonster

  • Full Member
  • ***
  • Posts: 157
    • Grinder Games
Re: Touch: Pinch zoom
« Reply #5 on: May 23, 2013, 02:53:28 AM »
Thank you so much,  Jean.
That is very usefull information.

So its the "distance" operation in Vector3 operator i totaly overlooked.

The vector 3 Operator has much more interesting operations that i dont understand. Sadly its not in the manual. Maybe this is basic knowledge for a programmer? I will try to find out more.

ArrayMaker is another beast i have to tackle later. For now sequential check is enough for my game.



jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Touch: Pinch zoom [solved]
« Reply #6 on: May 23, 2013, 03:23:45 AM »
Hi,

 yes, Likely it would have been better to use "vector length" action, but that action only works once, not everyframe, so using vector operator is the trick to get there without having to write or get any custom actions.

yes, first get confortable with PlayMaker as is, then ArrayMaker will be a natural progression.

bye,

 Jean

xhidnoda

  • Full Member
  • ***
  • Posts: 231
Re: Touch: Pinch zoom [solved]
« Reply #7 on: May 24, 2013, 10:18:50 AM »
Jean...you are the FFFFFUUUUUU hero!  :P :P

orenfridman

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Touch: Pinch zoom [SOLVED]
« Reply #8 on: May 26, 2016, 06:05:40 AM »
An old topic, go far back in time to 2013 : ) Now tested 2016, and the results work fine at delta pitch. The project example posted by: jeanfabre

i did try my best to copy the delta pitch to a new variable float add, it seems to be not working from some reason i can't understand, the float add is clamp in sum point at increase/decrease! Any help will be appreciated..

« Last Edit: May 26, 2016, 08:05:32 AM by orenfridman »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Touch: Pinch zoom [SOLVED]
« Reply #9 on: August 10, 2016, 03:23:39 AM »
Hi,

 Sorry, it's an old post, but going through my list...

 Have you been able to work it out?

Bye,

 Jean