// Update the queue, assuming that Left and Right Hand Gesture Control isn't Null private void UpdateQueue() { // Debug.Log ("Updating Queue"); // pop out obsolete items // --------------------- A potentialbug --------------------------- // if we use pause or something, since here it's Time.time that isn't affected by the time scale. // A short inresponse may happen (because previous items are pop out) // ---------------------------------------------------------------- float currentTime = Time.time; while (leftHandList.Count >= 2 && currentTime - leftHandList.First.Value.InsertTime > obsoleteTime) { leftHandList.RemoveFirst(); } while (rightHandList.Count >= 2 && currentTime - rightHandList.First.Value.InsertTime > obsoleteTime) { rightHandList.RemoveFirst(); } // insert new gesture HandActionItem lhai = new HandActionItem(LeftHandGC.bufferedGesture(), currentTime, LeftHandPalm.forward, LeftHandPalm.position); HandActionItem rhai = new HandActionItem(RightHandGC.bufferedGesture(), currentTime, RightHandPalm.forward, RightHandPalm.position); if (leftHandList.Count == 0 || HandActionItem.CompareTwoHandActionItem(leftHandList.Last.Value, lhai) > newItemDelta) { leftHandList.AddLast(lhai); // Debug.Log ("left add news"); } if (rightHandList.Count == 0 || HandActionItem.CompareTwoHandActionItem(rightHandList.Last.Value, rhai) > newItemDelta) { rightHandList.AddLast(rhai); // Debug.Log ("right add news"); } }
public bool isMatch(ref LinkedListNode <HandActionItem> currentAction) { if (currentAction == null || currentAction.Value == null) { return(false); } HandActionItem action = currentAction.Value; // gesture position match if (_posLock) { // Get current palm pos Vector3 curPos = GameObject.Find("Hand_l").transform.Find("palm").position; if ((curPos - action.PalmPos).magnitude > 0.05f) { return(false); } } // gesture name match int i = 0; for (i = 0; i < _gesturenames.Length; ++i) { if (action.Gesture == _gesturenames [i]) { break; } } if (i >= _gesturenames.Length) { return(false); } // duration time match if (_duration > .0f) { float lastTime = (currentAction.Next != null) ? currentAction.Next.Value.InsertTime : Time.time; if (lastTime - action.InsertTime < _duration) { return(false); } } // palm normal vector match, here uses 30 degrees. if (_palmNorm != Vector3.zero) { // Debug.Log ("Palm check:" + _palmNorm + " the action:" + action.PalmNorm); if (Vector3.Dot(action.PalmNorm.normalized, _palmNorm) < 0.866f) // 0.866 = cos(30 degree) { return(false); } } return(true); }
public static float CompareTwoHandActionItem(HandActionItem a, HandActionItem b) { float palmNormalScore = Vector3.Dot(a.PalmNorm, b.PalmNorm); // use a quatratic function as a score function for the dot of palm normals. (x - 1)^2 palmNormalScore = (palmNormalScore - 1) * (palmNormalScore - 1); float palmPosScore = (a.PalmPos - b.PalmPos).magnitude; // gesture score, a constant float gestureScore = 0; if (a.Gesture != b.Gesture) { gestureScore = 5; } return(gestureScore + palmNormalScore + palmPosScore); }
public bool isMatch(ref LinkedListNode <HandActionItem> currentAction) { if (currentAction == null || currentAction.Value == null) { return(false); } if (fromGestures == null || toGestures == null) { return(false); } // try to fit this pattern HandActionItem action = currentAction.Value; int i = 0; for (i = 0; i < toGestures.Length; ++i) { if (action.Gesture == toGestures [i]) { break; } } if (i >= toGestures.Length) { return(false); } if (toNormal != Vector3.zero) { if (Vector3.Dot(toNormal, action.PalmNorm.normalized) < 0.866f) { return(false); } } // try to jump over time to match pattern LinkedListNode <HandActionItem> prev = currentAction; while (prev != null && prev.Value != null) { prev = prev.Previous; if (prev == null || prev.Value == null) { break; } HandActionItem prevact = prev.Value; if (action.InsertTime - prev.Next.Value.InsertTime > timeSpan) { return(false); } // try to match this for (i = 0; i < fromGestures.Length; ++i) { if (prevact.Gesture == fromGestures [i]) { break; } } if (i >= fromGestures.Length) { continue; } if (fromNormal != Vector3.zero) { if (Vector3.Dot(fromNormal, prevact.PalmNorm.normalized) < 0.866f) { continue; } } // find it currentAction = prev.Next; return(true); } return(false); }