Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: calbar on October 16, 2013, 07:59:03 PM

Title: How do you find the center of all touches for multi-touch gesture calculations?
Post by: calbar on October 16, 2013, 07:59:03 PM
I'm looking to refactor my Unity Input stuff to do it the NGUI way, but I'm a little stumped with my pinch and rotate methods.

With Unity Input it's fairly straight forward because in a single method I just iterate through Input.touches, average their positions, and do some math to compare relative movement of all the touches around that center point.

With NGUI you're working with UICamera.currentTouch and UICamera.currentTouchID, which of course pertains to a single touch point. I'm not quite sure how to make touches collaborate when they are all triggering methods separately.

So I have two questions:
1. Will OnDrag be called multiple times on a single object in a single update, but with a different currentTouch, if there are multiple fingers dragging on it?
2. How would you suggest I find the center of all the current touches for my gesture methods?

Thanks for your help!
Title: Re: How do you find the center of all touches for multi-touch gesture calculations?
Post by: calbar on October 18, 2013, 09:55:08 AM
I'm still not sure how best to combine touches into an average.

Off the cuff, I'm thinking about constantly caching touch positionings based on ID and keeping a continually updated "center point" from these values... but that's rather involved.

Is there an easier way to do this..?
Title: Re: How do you find the center of all touches for multi-touch gesture calculations?
Post by: ArenMook on October 18, 2013, 04:29:31 PM
Each touch is separate, so if you're dragging multiple things, expect multiple OnDrag events.

My question is why are you doing this integration? You can just keep using your own system that relies on Input touches for pinch and rotate. I'm pretty sure this is what FingerGestures does as well, and it doesn't conflict with NGUI.
Title: Re: How do you find the center of all touches for multi-touch gesture calculations?
Post by: calbar on October 19, 2013, 07:05:38 PM
Oh, from reading around the forums I got the impression using Unity touch + NGUI touch was a bad idea...

Ok, well if you don't think it would be an issue to use them both, I'll take that into account when I consider refactoring. Thanks!
Title: Re: How do you find the center of all touches for multi-touch gesture calculations?
Post by: ArenMook on October 19, 2013, 08:30:42 PM
It's not a good idea to do your own press / click logic, but for things NGUI doesn't handle -- such as pinching and rotation, all is fair game.