Several hits in a loop after a break command
I have a weird problem. I am building a NUI for an application and I have attached some simple gestures to the right and left arrow. The problem is when I start the application. When I make a gesture for the first time, my application hits 2 times in a row. After that it works 100% as I want. The problem is just starting up.
I am adding two joints and a timestamp to my history structure which is put into an ArrayList
this._history.Add(new HistoryItem()
{
timestamp = timestamp,
activeHand = hand,
controlJoint = controlJoint
}
);
then in foreach loop I compare 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;
after that i clear the history of ArrayList
this._history.Clear();
So I don't get it. Why does it hit twice in a row after launch?
// edit
history ArrayList initialization
private List<HistoryItem> _history = new List<HistoryItem>(16);
in a loop
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 am breaking down here. Therefore, this code should not be called a second time in a row.
How does it clear something
// edit 2
I'll also add that the gestureStart flag must be set to true to access this part of the code. As you can see after hitting the "if" part, I set it to false. Therefore, it is impossible for the code to instantly get into this part
// edit 3 WORKING WORK
I created a workaround. I added time control. I am comparing the timestamp of the code call and the timestamp of the last gesture recognition. If its too fast (i meen a couple of ms, which is impossible to do), I don't let the arrow hit. I'm not sure if this is the perfect solution, but it is a working solution.
source to share