多命中中圈突破命令后 [英] multiple hits in loop after the break command

查看:188
本文介绍了多命中中圈突破命令后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题。我创建了一个应用程序,并NUI我绑定了一些简单的手势,以左,右箭头。问题是,当我启动应用程序。当我做的手势,第一次我的应用程序更是创下连续2次。之后,它作为我想要的工作100%。只有启动的问题。

I've got a strange problem. I'm creating a NUI for application and I binded some simple gestures to right and left arrow. The problem is when I start application. When I make gesture for the first time my application is hitting 2 times in a row. After that it works 100% as I want. Only the start is the problem.

我添加两个关节和时间戳到我的历史结构被放入的ArrayList

I'm adding two Joints and timestamp to my history struct which is put into the ArrayList

        this._history.Add(new HistoryItem()
            {
                timestamp = timestamp,
                activeHand = hand,
                controlJoint = controlJoint
            }
        );



然后foreach循环,我的数据进行比较

then in foreach loop I'm comparing data

if (Math.Abs((hand.Position.X - item.controlJoint.Position.X)) < MainWindow.treshold && Math.Abs((hand.Position.Y - item.controlJoint.Position.Y)) < MainWindow.verticalTreshold)

如果它点击我立刻断绝与

If it hits I instantly break the lopp with

break;



之后,我清除历史记录的ArrayList

after that I clear the history ArrayList

this._history.Clear();



所以,我不明白这一点。为什么开始后它击中两次在一排?

So I don't get it. Why after the start it hits two times in a row ?

//修改

历史ArrayList的初始化

history ArrayList initialization

private List<HistoryItem> _history = new List<HistoryItem>(16);

在环

foreach (HistoryItem item in this._history)
        {
         if ((hand.Position.X - item.controlJoint.Position.X) < MainWindow.treshold)
                            {
                                float tmp = (hand.Position.X - controlJoint.Position.X);
                                MainWindow.slideNumber++;
                                this._logger.Log("Next slide: " + MainWindow.slideNumber);
                                this._logger.Log(hand.Position.X + " - " + controlJoint.Position.X + " = " + tmp + " | " + MainWindow.treshold);
                                this.startTime = 0;
                                this.gestureStart = false;
                                answerFlag = true;
                                System.Windows.Forms.SendKeys.SendWait("{Right}");
                                break;
                            }
                }

现在。正如你可以看到我打破这里。所以这个代码不应该连续

Now. As you can see i'm breaking here. So this code shouldn't be invoked second time in a row

被调用第二次这怎么清除的东西。

How this clears something

//编辑2

我还要补充一点,进入这个部分的代码gestureStart标志必须设置为true。正如你可以进入'如果'的一部分在这里我将它设置为假后看到。所以这是不可能的,代码即刻可以得到这部分

I'll also add that to get into this part of code the gestureStart flag need to be set to true. As you can see after getting into the 'if' part here I'm setting it to false. So it is impossible that the code instantly can get to this part

//编辑3 工作替代方法

我创建了一种变通方法。我已经添加了时间控制。我比较援引去年手势识别的代码和时间戳的时间戳。如果它的速度太快(我meen几毫秒就不可能使这)我不允许打一个箭头。我不知道如果它是一个完美的解决方案,但它是一个可行的解决方案。

I've created kind of workaround. I've added time control. I'm comparing timestamp of invoking the code and timestamp of last gesture recognition. If its too fast ( i meen couple of ms which it impossible to make ) I don't allow to hit an arrow. I'm not sure if it's a perfect solution but it is a working solution

推荐答案

好吧我的问题是代码。 OFC一个小bug在调试untracable。我使用的一个功能来分析帧的历史。

Ok my problem was the code. Ofc a small bug untracable in the debug. I used one function to analyse a history of frames.

的方法,是在2种模式工作的。 I`ve脱离了创造2不同势方法,每个方法为每个任务,现在,它的伟大工程

The method was working in 2 modes. I`ve detached that and created 2 diffrent methods, each for each task and now it works great

这篇关于多命中中圈突破命令后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆