public void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame()) { if (skeletonFrameData == null) { return; } var allSkeletons = new Skeleton[skeletonFrameData.SkeletonArrayLength]; skeletonFrameData.CopySkeletonDataTo(allSkeletons); foreach (Skeleton sd in allSkeletons) { // If this skeleton is no longer being tracked, skip it if (sd.TrackingState != SkeletonTrackingState.Tracked) { continue; } // If there is not already a gesture state map for this skeleton, then create one if (!userMap.ContainsKey(sd.TrackingId)) { var user = new GestureStateUser(gestures); userMap.Add(sd.TrackingId, user); } // WSRConfig.GetInstance().logDebug("GESTURE", "Skeleton " + sd.Position.X + "," + sd.Position.Y + "," + sd.Position.Z); Gesture gesture = userMap[sd.TrackingId].Evaluate(sd); if (gesture != null) { WSRConfig.GetInstance().logInfo("GESTURE", "Active User Gesture complete: " + gesture.Description); // Store the Gesture matching the most components if (match == null || match.Components.Count <= gesture.Components.Count) { match = gesture; } // Do not fire immediatly, wait a little bit } // This break prevents multiple player data from being confused during evaluation. // If one were going to dis-allow multiple players, this trackingId would facilitate // that feat. playerId = sd.TrackingId; } } // Reset threshold if ((DateTime.Now - threshold).TotalMilliseconds > 1000){ threshold = DateTime.Now; // Fire the latest matching gesture on threshold if (match != null) { fireGesture(match); userMap[playerId].ResetAll(); match = null; } } }
public Gesture CheckGestures(Skeleton[] skeletons) { // Clean Prefetch Skeleton = null; if (null == skeletons) { return(null); } foreach (Skeleton sd in skeletons) { // Too large array if (sd == null) { continue; } // If this skeleton is no longer being tracked, skip it if (sd.TrackingState != SkeletonTrackingState.Tracked) { continue; } // Prefetch some Prefetch(sd); // Validate all joints some data if (!Viewport(sd)) { continue; } Skeleton = sd; // If there is not already a gesture state map for this skeleton, then create one if (!userMap.ContainsKey("P_" + sd.TrackingId)) { var user = new GestureStateUser(gestures); userMap.Add("P_" + sd.TrackingId, user); } Gesture gesture = userMap["P_" + sd.TrackingId].Evaluate(sd); if (null != gesture) { // Store the Gesture matching the most components if (match == null || match.Components.Count <= gesture.Components.Count) { match = gesture; } // Do not fire immediatly, wait a little bit Gesture g = MatchGesture(); if (g != null) { return(g); } } break; // The skeleton match } // At last return gesture or null return(MatchGesture()); }
public Gesture CheckGestures(Skeleton[] skeletons) { // Clean Prefetch Skeleton = null; if (null == skeletons) { return null; } foreach (Skeleton sd in skeletons) { // Too large array if (sd == null) { continue; } // If this skeleton is no longer being tracked, skip it if (sd.TrackingState != SkeletonTrackingState.Tracked) { continue; } // Prefetch some Prefetch(sd); // Validate all joints some data if (!Viewport(sd)) { continue; } Skeleton = sd; // If there is not already a gesture state map for this skeleton, then create one if (!userMap.ContainsKey("P_"+sd.TrackingId)) { var user = new GestureStateUser(gestures); userMap.Add("P_"+sd.TrackingId, user); } Gesture gesture = userMap["P_" + sd.TrackingId].Evaluate(sd); if (null != gesture) { // Store the Gesture matching the most components if (match == null || match.Components.Count <= gesture.Components.Count) { match = gesture; } // Do not fire immediatly, wait a little bit Gesture g = MatchGesture(); if (g != null) { return g; } } break; // The skeleton match } // At last return gesture or null return MatchGesture(); }