|
I have a problem with my current code, it works to detect the zoom, and i think my code detects the difference between rotation and pinch, but if i put two fingers down and swipe it still zooms. How do i detect this and stop it? I also have to accomodate for users being sloppy when pinching and zoom and move fingers sideways a little bit (probably defining a variable that can be changed) Here is my current code: How do i edit this to detect if a user swipe with two fingers and pinches to zoom? (i also have to take into account a user can have the pinch horizontal, vertical, or a combo of the two diagonally which i tried doing with the midpoint code.
(comments are locked)
|
|
first, whining never helps, it won't get you pity or sympathy. You're asking for help from people who have no reason to help you and do not stand to benefit in any way from doing so; you're entitled to nothing. Remember that. That said, I'll attempt to help anyway this time, despite your attitude, because I do understand your frustration. This is basically a variation of the standard mouse dragging vs clicking problem, and the same solution ought to work. What you need is some state information. in Idle state: check for a two-finger touch. If you get one, remember the finger positions and calculate and store the distance between them, and change state to TwoFingerTouch. in TwoFingerTouch state: If one or both touches have ended: compare their final positions to their originals. If they've both moved in the same general direction, and moved far enough to qualify as a swipe, ... do a swipe, and go back to the Idle state. If they moved different directions, or not far enough, go back to Idle state. If both touches are still there, calc the current distance between them. If it's reduced enough, transition to PinchZoom state. in PinchZoom state: Calculate the new distance between the fingers, and apply zoom level based on this relative to original distance between them. If one or both fingers released, return to Idle state. state machine As for how to implement this simple state machine, there are many ways, a search for State Machines will probably find you many examples. Here's one very simple way it could be done: Btw the first statement makes all forum posters seem selfish and makes this system seem very one way, where ppl expect help but never give it. Sorry about "whining" but this question was up long enough for people to see and yet they chose not to respond to such an easy question, which kinda concerns me. And i wasnt lookkng for sympathy. Its a forum. Asking questions why others dont post is acceptabke (obviously to a point). Second, i would prefer using code i have. If i wanted to use state machines i would have posted elsewhere and wouldnt have posted code. I also would have used playmaker rather than code the fsm in a script. How can i modify my code to not zoom while swiping with both fingers.
Nov 21 '11 at 05:53 PM
1337GameDev
very simple reason people were ignoring the question. Try typing "pinch zoom," "swipe," or "flick" into the search box at the top, you get pages and pages of people asking this same question. If the only acceptable answer is one that specifically involves someone fixing your specific code, then you're in the wrong place anyway. FAQ rules clearly state, answer must be reasonably interesting or useful to at least one person besides you; if the only answer you want is how to fix your specific code, your question doesn't meet that criteria.
Nov 21 '11 at 05:56 PM
WillTAtl
And also, to add thanks for helping. I just am curious how to do this with code i have rather than resort to FSM for everything, i have this coded this way otherwise it wont fit my OOD i wish to have.
Nov 21 '11 at 05:59 PM
1337GameDev
Most people who i have searched use a similar code, so i assumed people would be able to help with the code that seems pretty common. Obiously it is interesting to others besides just me, or people wouldn't be posting the question using code similar to mine (and not using FSM's)
Nov 21 '11 at 06:01 PM
1337GameDev
you don't need to rewrite the code to use enums or switches; you just need to add a minimal amount of state info. Basically, what you're doing now is using a series of If(condition..) statements, where the condition tries to identify which state you're in for you. The problem with this is that it can and will detect pinch and flick in the same updates. All you have to do is add a new variable, isPinching. When pinch is first detected, set isPinch to true, and when a pinch ends (one or both fingers releases), set it back to false. Then add !isPinch to the condition for swipe, so it will not swipe if it's detected a pinch. It's really not that different from what you're doing, but you absolutely are going to require at least this minimal amount of state information. And I must say, despite what you think, using states will actually make it far easier to extend the code if you wanted to add more input types later, like three-finger swipes or two- or three-finger taps. The problem you're having is trying to explicitly and absolutely differentiate one from the other without any kind of state information. As illustrated by the other answer, this problem doesn't exist at all if you're only doing pinch, and it will get exponentially worse the more the more cases you add.
Nov 21 '11 at 10:24 PM
WillTAtl
(comments are locked)
|
|
Since I'm not sure what your question is, I'll go with the title and give you my C# script that will detect pinch. This is extracted from a 342 lines of code bloated script, so I'm sorry if I'm missing something. Just let me know and I'll dig deeper to fix it: Hope this is enough to help you! This code just handles punching to zoom, but dies not take into account if i swipe with two fingers, same as my code. I do like that you calculated the distance between fingers and set the position of camera closer or further depending on that. My camera uses fov, because i am planning on having it rotate and want to avoid complex circle math, so i used fov of the camera and used mathf. Clamp to limit its value to a certain degree value. (fov is field of view, a property of camera object that uses degrees)
Nov 21 '11 at 10:16 PM
1337GameDev
Yes, I did consider what you said about swiping. But if this is not enough that means I don't understand what you meant. In this code, if you put two fingers down and swipe, it won't do anything, as long as you swipe it in equal distance. And you can increase "minPinchDistance" to reduce sensibility of detecting the pinch. In other words, a higher value will require a higher distance between fingers to trigger the pinch. Here, if you can try it on android see if this is what you want: http://www.p3d.com.br/android
Nov 22 '11 at 12:27 PM
Cawas
(comments are locked)
|

Does somebody know this answer? This is covered all the time by people's projects, but why doesn't NOBODY want to give insight into how THEY did it? I have spent over 2 weeks on this code and concept....
Dude, chill. Try reducing your question. Picture yourself trying to answer a question this big. Go to http://stackexchange.com/sites pick your favorite topic, one you're an expert on, and try to answer the biggest questions there. At least 100 lines like yours, with something dense to read. Code reviews are always a pain to do, specially when the code is this big and unfiltered.
ok ill structure my questions better and break them down. Im just getting used to this being viewed and posting using my galaxy tab10. 1. The main question is defined in the title tho. I just need a way to discern pinching from two finger swiping, as my code zooms if i swipe (obviously im not pinching to zoom and other apps supports those gestures).
Actually, your other question on the same topic is much better already: http://answers.unity3d.com/questions/182757/two-finger-swipe-vs-pinch-and-zoom-problem.html which is indeed much more a question about logic than Unity3D or C#.