public static void startRecognizer(ArrayList pointArray, musicPlayback player) { // main recognizer function pointArray = optimizeGesture(pointArray, maxPoints); Vector2 center = calcCenterOfGesture(pointArray); Vector2 v = (Vector2)pointArray[0]; float radians = Mathf.Atan2(center.y - v.y, center.x - v.x); pointArray = RotateGesture(pointArray, -radians, center); pointArray = ScaleGesture(pointArray, sizeOfScaleRect); pointArray = TranslateGestureToOrigin(pointArray); gestureMatch(pointArray, player); }
// -------------------------------- GESTURE OPTIMIZING DONE ---------------------------------------------------------------- // -------------------------------- START OF THE MATCHING PROCESS ---------------------------------------------------------------- static void gestureMatch(ArrayList pointArray, musicPlayback player) { float tempDistance = Mathf.Infinity; int count = 0; for (int i = 0; i < GestureTemplates.Templates.Count; ++i) { float distance = calcDistanceAtOptimalAngle(pointArray, (ArrayList)GestureTemplates.Templates[i], -angleRange, angleRange); if (distance < tempDistance) { tempDistance = distance; count = i; } } float HalfDiagonal = 0.5f * Mathf.Sqrt(Mathf.Pow(sizeOfScaleRect, 2) + Mathf.Pow(sizeOfScaleRect, 2)); float score = 1.0f - (tempDistance / HalfDiagonal); // print the result // Debug.Log("RESULT: " + GestureTemplates.TemplateNames[count] + " SCORE: " + score); // // for (int i = 0; i < pointArray.Count; i++) { // Debug.Log ("Point Array: " + pointArray[i]); // } if (score < 0.7f) { // Debug.Log("NO MATCH " + score ); } else { // Debug.Log("RESULT: " + GestureTemplates.TemplateNames[count] + " SCORE: " + score); if (player != null) { player.skipCurrent(); } } }