public SpellHandler.SpellType EndGesture() { //If the gesture was already ended if (lNextSample == -1 && rNextSample == -1) { return(SpellHandler.SpellType.NONE); } lNextSample = -1; rNextSample = -1; Gesture.GestureHand hands = currentGesture.GetCurHands(); //If there's only 1 node in one of the hands just delete the gesture and stop cause otherwise bad things happen during conversion if ((hands == Gesture.GestureHand.LEFT && currentGesture.NumNodes(Gesture.GestureHand.LEFT) < 2) || (hands == Gesture.GestureHand.RIGHT && currentGesture.NumNodes(Gesture.GestureHand.RIGHT) < 2) || (hands == Gesture.GestureHand.BOTH && (currentGesture.NumNodes(Gesture.GestureHand.LEFT) < 2 || currentGesture.NumNodes(Gesture.GestureHand.RIGHT) < 2))) { currentGesture = null; return(SpellHandler.SpellType.NONE); } currentGesture.ChangeNumNodes(samplesPerGesture); return(FindBestMatch(currentGesture)); }
//Returns the index of the best match in validGestures or -1 if none are close enough private SpellHandler.SpellType FindBestMatch(Gesture inputGesture) { SpellHandler.SpellType bestMatch = SpellHandler.SpellType.NONE; float matchDiff = 0; Gesture.GestureHand hands = inputGesture.GetCurHands(); if ((hands == Gesture.GestureHand.BOTH && (inputGesture.NumNodes(Gesture.GestureHand.LEFT) == 1 || inputGesture.NumNodes(Gesture.GestureHand.RIGHT) == 1)) || (hands != Gesture.GestureHand.BOTH && inputGesture.NumNodes(hands) == 1)) { return(bestMatch); } if (hands == Gesture.GestureHand.BOTH) { Debug.Log("both hands involved"); //If there's only 1 node just stop if (inputGesture.NumNodes(Gesture.GestureHand.LEFT) < 2 || inputGesture.NumNodes(Gesture.GestureHand.RIGHT) < 2) { return(bestMatch); } foreach (Gesture g in twoHandGestures) { float diff = g.AverageDifference(inputGesture, lengthAccuracyFactor, Gesture.GestureHand.LEFT) + g.AverageDifference(inputGesture, lengthAccuracyFactor, Gesture.GestureHand.RIGHT) / 2; //Debug.Log("diff = " + diff); if ((bestMatch == SpellHandler.SpellType.NONE && diff < accuracyPerSample) || diff < matchDiff) { bestMatch = g.GetSpell(); matchDiff = diff; } } } else { //If there's only 1 node just stop if (inputGesture.NumNodes(hands) < 2) { return(bestMatch); } foreach (Gesture g in oneHandGestures) { float diff = g.AverageDifference(inputGesture, lengthAccuracyFactor, hands); //Debug.Log("diff = " + diff); if ((bestMatch == SpellHandler.SpellType.NONE && diff < accuracyPerSample) || diff < matchDiff) { bestMatch = g.GetSpell(); matchDiff = diff; } } } return(bestMatch); }