Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 跳跃动作会在不同的手势类型之间混淆。如何优化?_C#_Visual Studio 2015_Gestures_Leap Motion - Fatal编程技术网

C# 跳跃动作会在不同的手势类型之间混淆。如何优化?

C# 跳跃动作会在不同的手势类型之间混淆。如何优化?,c#,visual-studio-2015,gestures,leap-motion,C#,Visual Studio 2015,Gestures,Leap Motion,未优化向左、向右、向上和向下的滑动手势。如果必须使用向上滑动来执行任务,则会将其与左滑动混淆并仍在执行。请向我建议要优化的参数以区分滑动。或用于完美滑动识别的命令 此外,它还与圆圈和滑动相混淆。 我已经添加了我的代码。在一个单独的帧中,只应检测到一个手势。我如何在这里限制这一点 public MainWindow() { InitializeComponent(); this.controller = new Controller(); this.listen

未优化向左、向右、向上和向下的滑动手势。如果必须使用向上滑动来执行任务,则会将其与左滑动混淆并仍在执行。请向我建议要优化的参数以区分滑动。或用于完美滑动识别的命令 此外,它还与圆圈和滑动相混淆。 我已经添加了我的代码。在一个单独的帧中,只应检测到一个手势。我如何在这里限制这一点

public MainWindow()
{
InitializeComponent();

        this.controller = new Controller();

        this.listener = new LeapListener(this);
        controller.AddListener(listener);

        for (int iCount = 1; iCount < 23; iCount++)
        {
            images[iCount] = new BitmapImage();
            images[iCount].BeginInit();
            images[iCount].UriSource = new Uri("Images/" + iCount + ".png", UriKind.Relative);
            images[iCount].EndInit();
        }
        image.Source = images[1];
    }



    delegate void LeapEventDelegate(string EventName);




    public void LeapEventNotification(string EventName)
    {
        if (this.CheckAccess())
        {
            switch (EventName)
            {
                case "onInit":

                    break;
                case "onConnect":

                    this.connectHandler();
                    break;
                case "onFrame":

                    this.checkGestures(this.controller.Frame());

                    break;
            }
        }
        else
        {
            Dispatcher.Invoke(new LeapEventDelegate(LeapEventNotification
                ), new object[] { EventName });
        }
    }

    public void connectHandler()
    {
        controller.EnableGesture(Gesture.GestureType.TYPE_SWIPE);
        this.controller.EnableGesture(Gesture.GestureType.TYPE_CIRCLE);
        this.controller.EnableGesture(Gesture.GestureType.TYPE_KEY_TAP);
        this.controller.EnableGesture(Gesture.GestureType.TYPE_SCREEN_TAP);


        // controller.Config.SetFloat("Gesture.Swipe.Speed", 4000.0f);
        controller.Config.SetFloat("Gesture.Swipe.MinVelocity", 750f);
        controller.Config.SetFloat("Gesture.Swipe.MinLength", 200f);

        controller.Config.SetFloat("Gesture.KeyTap.MinDownVelocity", 40.0f);
        controller.Config.SetFloat("Gesture.KeyTap.HistorySeconds", .2f);
        controller.Config.SetFloat("Gesture.KeyTap.MinDistance", 40.0f);

        controller.Config.SetFloat("Gesture.Circle.MinRadius", 15.0f);
        controller.Config.SetFloat("Gesture.Circle.MinArc", 15f);

        controller.Config.SetFloat("InteractionBox.Width", 1600.0f);
        controller.Config.SetFloat("InteractionBox.Height", 1600.0f);

        controller.Config.Save();
    }


    public void checkGestures(Frame frame)
    {


        GestureList gestures = frame.Gestures();
        foreach (Gesture gesture in gestures)
        {

            // For Image 1
            if (image.Source.Equals(images[1]))
            {



                if (gesture.Type == Gesture.GestureType.TYPE_SWIPE)
                {

                    SwipeGesture swipe = new SwipeGesture(gesture);
                    if (swipe.State == Gesture.GestureState.STATE_START && swipe.Direction.x > 0 && Math.Abs(swipe.Direction.y) < 5)
                    {

                        image.Source = images[2];
                        //   Console.WriteLine("Second");
                    }

                }

            }

            // For Image 2
            else if (image.Source.Equals(images[2]))
            {

                if (gesture.Type == Gesture.GestureType.TYPE_SWIPE)
                {
                    SwipeGesture swipe = new SwipeGesture(gesture);

                    if (swipe.State == Gesture.GestureState.STATE_START && swipe.Direction.y > 0)

                    {
                        image.Source = images[3];
                    }
                   else  if (swipe.State == Gesture.GestureState.STATE_START && swipe.Direction.x > 0 && Math.Abs(swipe.Direction.y) < 5)
                    {
                        image.Source = images[7];
                    }
                }
                 if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP)
                {
                    KeyTapGesture TapGesture = new KeyTapGesture(gesture);
                    image.Source = images[1];
                    Console.WriteLine("Circle");
                }
            }
            // For Image 3
            else if (image.Source.Equals(images[3]))
            {

                if (gesture.Type == Gesture.GestureType.TYPE_SWIPE)
                {
                    SwipeGesture swipe = new SwipeGesture(gesture);

                    if (swipe.State == Gesture.GestureState.STATE_START && swipe.Direction.y < 0)

                    {
                        image.Source = images[4];
                    }
                 else   if (swipe.State == Gesture.GestureState.STATE_START && swipe.Direction.x < 0 && Math.Abs(swipe.Direction.y) < 5)
                    {
                        image.Source = images[16];
                    }

                }
                if (gesture.Type == Gesture.GestureType.TYPE_KEY_TAP)
                {
                    KeyTapGesture TapGesture = new KeyTapGesture(gesture);
                    image.Source = images[1];

                }
            }

            }//foreach
        }
    }
}
public主窗口()
{
初始化组件();
this.controller=新控制器();
this.listener=新的LeapListener(this);
controller.AddListener(监听器);
对于(int-iCount=1;iCount<23;iCount++)
{
图像[iCount]=新的位图图像();
图像[iCount].BeginInit();
images[iCount].UriSource=newURI(“images/”+iCount+“.png”,UriKind.Relative);
图像[iCount].EndInit();
}
image.Source=图像[1];
}
委托无效LeapEventDelegate(字符串EventName);
公共void LeapEventNotification(字符串EventName)
{
if(this.CheckAccess())
{
开关(EventName)
{
案例“onInit”:
打破
案例“onConnect”:
这个.connectHandler();
打破
案例“onFrame”:
this.checksignals(this.controller.Frame());
打破
}
}
其他的
{
Dispatcher.Invoke(新的LeapEventDelegate(LeapEventNotification
),新对象[]{EventName});
}
}
public-void-connectHandler()
{
控制器.启用手势(手势.手势类型.类型\u滑动);
this.controller.enableSpirate(手势.GestureType.TYPE\u圆圈);
this.controller.enableShipt(手势.GestureType.TYPE\u键\u点击);
this.controller.enableShipt(手势.GestureType.TYPE\u屏幕\u点击);
//controller.Config.SetFloat(“手势.滑动.速度”,4000.0f);
controller.Config.SetFloat(“signature.Swipe.MinVelocity”,750f);
controller.Config.SetFloat(“signature.Swipe.MinLength”,200f);
controller.Config.SetFloat(“signature.KeyTap.MinDownVelocity”,40.0f);
controller.Config.SetFloat(“signature.KeyTap.HistorySeconds”,.2f);
controller.Config.SetFloat(“signature.KeyTap.MinDistance”,40.0f);
controller.Config.SetFloat(“手势.圆圈.最小半径”,15.0f);
controller.Config.SetFloat(“signature.Circle.MinArc”,15f);
controller.Config.SetFloat(“InteractionBox.Width”,1600.0f);
controller.Config.SetFloat(“InteractionBox.Height”,1600.0f);
controller.Config.Save();
}
公共无效检查手势(框架)
{
手势列表手势=frame.signatures();
foreach(手势中的手势)
{
//对于图1
if(image.Source.Equals(images[1]))
{
如果(手势.Type==手势.GestureType.Type\u滑动)
{
SwipeGesture swipe=新SwipeGesture(手势);
如果(swipe.State==sipple.GestureState.State_START&&swipe.Direction.x>0&&Math.Abs(swipe.Direction.y)<5)
{
image.Source=图像[2];
//控制台。写入线(“第二”);
}
}
}
//对于图2
else if(image.Source.Equals(images[2]))
{
如果(手势.Type==手势.GestureType.Type\u滑动)
{
SwipeGesture swipe=新SwipeGesture(手势);
如果(swipe.State==signature.GestureState.State\u START&&swipe.Direction.y>0)
{
image.Source=图像[3];
}
else如果(swipe.State==sipple.GestureState.State_START&&swipe.Direction.x>0&&Math.Abs(swipe.Direction.y)<5)
{
image.Source=图像[7];
}
}
如果(手势.Type==手势.GestureType.Type\u键\u点击)
{
按键手势=新的按键手势(手势);
image.Source=图像[1];
控制台写入线(“圆圈”);
}
}
//对于图3
else if(image.Source.Equals(images[3]))
{
如果(手势.Type==手势.GestureType.Type\u滑动)
{
SwipeGesture swipe=新SwipeGesture(手势);
if(swipe.State==signature.GestureState.State\u START&&swipe.Direction.y<0)
{
image.Source=图像[4];
}
else if(swipe.State==sipple.GestureState.State_START&&swipe.Direction.x<0&&Math.Abs(swipe.Direction.y)<5)
{
image.Source=图像[16];
}
}
如果(手势.Type==手势.GestureType.Type\u键\u点击)
{
按键手势=新的按键手势(手势);
image.Source=图像[1];
}
}
}//弗雷奇
}
}
}

开箱即用的手势在3.x(Orion)中被弃用,因为它们不可靠。 最好的办法是理解SDK,只需创建自己的手势,就可以超越现成的功能,更可靠。
一切都与3d定位有关,因此请注意您的Y、X、Z,使用调试手或创建您自己的调试系统来查看其行为。

您使用的是什么版本的Leap Motion软件?软件版本2.3.1+31549