/*#region INetworkObserver public void MessageReceived(String message) { if (message.Equals("back")) { Back(); } } #endregion */ /// <summary> /// Registers a gesture workspace for this state machine. The /// hand is only considered to be in the correct pose if it /// is within this area. Workspace will be adjusted since, /// unlike the default workspace, we want interaction to take /// place a bit further back from the phone. Otherwise the user /// would have to reach too far and this also poses finger /// tracking problems. /// </summary> public new void RegisterWorkspace(GestureSpace workspace) { Rectangle space = workspace.GetRectangle(); int bottom = GestureSpace.Height / 2; int top = bottom - GestureSpace.Height; GestureSpace adjustedSpace = new GestureSpace(space.Left, top, space.Right, bottom); base.RegisterWorkspace(adjustedSpace); }
/// <summary> /// Check for group switches based on the /// position of the given hand. Returns true /// if a group switch has taken place. /// </summary> /* private bool ProcessGroups(Hand hand) { int midZ = base.workspace.MidZ(); float palmZ = hand.PalmPosition.z; // Determine which group we're in int g = (palmZ <= midZ) ? 1 : 2; if (activeSet.HasGroups) { if (activeGroup != g) { GroupLeave(activeGroup); GroupEnter(g); return true; } } return false; }*/ private void ShowEdges(GestureSpace space, int group, Hand hand, List<Finger> fingers) { if (hand == null || fingers == null || fingers.Count == 0) return; Vector avgPos = AveragePos(fingers); int midZ = space.MidZ(); int z = (int) hand.PalmPosition.z; int edgeToShow = 0; if (z > midZ - EDGE_THRESHOLD && group == 1) { edgeToShow = 4; } else if (z < midZ + EDGE_THRESHOLD && group == 2) { edgeToShow = 2; } foreach (IParentObserver observer in observers) { if (observer is ICountObserver) { ICountObserver ic = (ICountObserver)observer; if (workspace != null) { ic.CursorUpdate(workspace.Normalise(avgPos), fingers.Count, edgeToShow); } } } }
// private int activeGroup; public CountDetector(LeapInterface leap, GestureSpace space) { // Initialise state machines state = CountState.Idle; selectionState = CountSelectionState.Idle; activeHandId = -1; discardedFrames = 0; ignoredFrames = 0; this.leap = leap; /* // Initialise groups and ROIs activeGroup = 0; */ // Initialise list of observers observers = new List<IParentObserver>(); // Initialise selection metadata countStart = DateTime.Now; // Register gesture workspace this.RegisterWorkspace(space); // Register this gesture detector for frame updates and keep reference of the LeapMotion controller this.leap.RegisterFrameListener(this); GestureDetector.DEBUG = false; }