2

I am writing a program using the Surface SDK and .NET 4.0. I have to distinguish between multi-touch events and I'm having trouble distinguishing between gestures.

With two fingers I want to be able to zoom and rotate, but because generally the fingers are not moving in straight lines or perfect circles on the screen, the result is a combination of zoom and rotate. Could someone point out how this problem can be overcome? I am using some thresholds for ignoring small deviations, but these thresholds need to be manually tweaked and I couldn't find a good value for them.

I was thinking I could detect which kind of a gesture it is in the onManipulationStarting method and ignore the rest, but sometimes the gesture can start with just one finger on the screen and I'm identifying the wrong gesture.

I am including some code below:

private void OnManipulationDeltaHandler(object sender, ManipulationDeltaEventArgs mdea)
    {
         var zoomAmount = Math.Abs(mdea.DeltaManipulation.Scale.Length - Math.Sqrt(2));
                // ZOOM ACTION: 2 fingers and scaling bigger than a threshold
                if ((TouchesOver.Count() == 2) && (zoomAmount > scaleThreshold))
                {
                    if (ZoomCommand != null)
                    {
                       if (Math.Abs(zoomAmount - 0) > 0.1)
                        {
                            ZoomCommand.Execute((-zoomAmount).ToString());
                        }
                    }
                }
                else
                {
                    var rotateAmount = -mdea.DeltaManipulation.Rotation;
                    if ((TouchesOver.Count() == 2))
                    {
                        headValue += rotateAmount;
                        if (HeadRotationCommand != null)
                        {
                            HeadRotationCommand.Execute(new Orientation(pitchValue, headValue, rotateAmount));
                        }
                    }
                }               

        mdea.Handled = true;
        base.OnManipulationDelta(mdea);
   }

Can someone help? Thanks!

alex_and_ra
  • 219
  • 1
  • 16
  • the math performed by the manipulation APIs is not intended for you to selectively apply rotation or scaling. when you configure the API to calculate both, it assumes you will apply both. otherwise things will just feel really awkward for users. – Robert Levy Jun 18 '13 at 14:36
  • Hi, thanks for the reply. And how would you implement then support for rotation and scaling, when only one should be performed at one time? – alex_and_ra Jun 18 '13 at 17:50
  • 1
    i would not implement such a design *unless* there were specific spots on the control where users would need to touch to indicate whether they are doing a scale or rotate. in that case, you can simply toggle the CanScale/CanRotate properties of the ScatterViewItem based on where the user first touches it – Robert Levy Jun 19 '13 at 13:32

0 Answers0