// ジェスチャーを検出した void gesture_GestureRecognized(object sender, GestureRecognizedEventArgs e) { gestureStatus = GestureStatus.Recognized; // 手のトラッキングを開始する hands.StartTracking(e.EndPosition); }
void gestureGenerator_GestureRecognized(object sender, GestureRecognizedEventArgs e) { NiteKinectHandGestureEventData eventdata; switch (e.Gesture.ToLower()) { case "wave": handsGenerator.StartTracking(e.IdentifiedPosition); break; case "click": eventdata = new NiteKinectHandGestureEventData(new NiteKinectHandGestureData(0, NiteKinectHandState.GestureClick, this.depth.ConvertRealWorldToProjective(e.EndPosition))); if (DataReceived != null) { DataReceived(this, new DataReceivedEventHandler() { PluginData = eventdata }); } break; case "raisehand": eventdata = new NiteKinectHandGestureEventData(new NiteKinectHandGestureData(0, NiteKinectHandState.GestureRaiseHand, this.depth.ConvertRealWorldToProjective(e.EndPosition))); if (DataReceived != null) { DataReceived(this, new DataReceivedEventHandler() { PluginData = eventdata }); } break; default: break; } }
//called when data for any output pin is requested public void Evaluate(int SpreadMax) { if (FContext != null) { if (FDepthGenerator != null && FEnabledIn[0]) { FFov[0] = new Vector2D(FDepthGenerator.FieldOfView.HorizontalAngle, FDepthGenerator.FieldOfView.VerticalAngle); Update(); } if (FHandGenerator != null && FEnabledIn[0]) { FIsTrackedOut.SliceCount = FHandIdOut.SliceCount = FHandPositionOut.SliceCount = FStartPositionIn.SliceCount; //for every given StartPosition check if it is currently tracked lock (FHandTrackerLock) for (int i = 0; i < FStartPositionIn.SliceCount; i++) { if (FDoTrackStartPosition[i]) { //find userID in FTrackedStartPositions int userID = -1; foreach (var tracker in FTrackedStartPositions) { if (tracker.Value == FStartPositionIn[i]) { userID = tracker.Key; break; } } //if present return tracking info if (userID > -1) { FIsTrackedOut[i] = true; FHandIdOut[i] = userID; FHandPositionOut[i] = FTrackedHands[userID]; } //else start tracking else { FIsTrackedOut[i] = false; FHandIdOut[i] = -1; FHandPositionOut[i] = FStartPositionIn[i]; var p = new Point3D((float)(FStartPositionIn[i].x * 1000), (float)(FStartPositionIn[i].y * 1000), (float)(FStartPositionIn[i].z * 1000)); FHandGenerator.StartTracking(p); } } else { //find the userID corresponding to the StartPosition //and stop tracking it int userID = -1; foreach (var tracker in FTrackedStartPositions) { if (tracker.Value == FStartPositionIn[i]) { userID = tracker.Key; break; } } if (userID > -1) { FHandGenerator.StopTracking(userID); } FIsTrackedOut[i] = false; FHandIdOut[i] = -1; FHandPositionOut[i] = FStartPositionIn[i]; } } } else { FIsTrackedOut.SliceCount = FHandIdOut.SliceCount = FHandPositionOut.SliceCount = 0; } } }
//called when data for any output pin is requested public void Evaluate(int SpreadMax) { if (FContextChanged) { if (FContextIn.PluginIO.IsConnected) { if (FContextIn[0] != null) { try { // Create and Hands generator FHandGenerator = new HandsGenerator(FContextIn[0]); FHandGenerator.HandCreate += FHands_HandCreate; FHandGenerator.HandDestroy += FHands_HandDestroy; FHandGenerator.HandUpdate += FHands_HandUpdate; FHandGenerator.StartGenerating(); FContextChanged = false; } catch (Exception ex) { FLogger.Log(ex); } } } else { CleanUp(); FContextChanged = false; } } if (FHandGenerator != null) { if (FDoTrackStartPosition.IsChanged) { bool enable = false; for (int i = 0; i < FDoTrackStartPosition.SliceCount; i++) { enable |= FDoTrackStartPosition[i]; } //enable if any slice is 1 if (enable) { FHandGenerator.StartGenerating(); } else { FHandGenerator.StopGenerating(); } } if (FHandGenerator.IsDataNew) { FIsTrackedOut.SliceCount = FHandIdOut.SliceCount = FHandPositionOut.SliceCount = FStartPositionIn.SliceCount; //for every given StartPosition check if it is currently tracked for (int i = 0; i < FStartPositionIn.SliceCount; i++) { if (FDoTrackStartPosition[i]) { //find userID in FTrackedStartPositions int userID = -1; foreach (var tracker in FTrackedStartPositions) { var p = new Point3D((float)(FStartPositionIn[i].x * 1000), (float)(FStartPositionIn[i].y * 1000), (float)(FStartPositionIn[i].z * 1000)); if (tracker.Value.Equals(p)) { userID = tracker.Key; break; } } //if present return tracking info if (userID > -1) { FIsTrackedOut[i] = true; FHandIdOut[i] = userID; var p = FTrackedHands[userID]; FHandPositionOut[i] = new Vector3D(p.X / 1000, p.Y / 1000, p.Z / 1000); } //else start tracking else { FIsTrackedOut[i] = false; FHandIdOut[i] = -1; FHandPositionOut[i] = FStartPositionIn[i]; var p = new Point3D((float)(FStartPositionIn[i].x * 1000), (float)(FStartPositionIn[i].y * 1000), (float)(FStartPositionIn[i].z * 1000)); FHandGenerator.StartTracking(p); } } else { //find the handID corresponding to the StartPosition //and stop tracking it int userID = -1; foreach (var tracker in FTrackedStartPositions) { var p = new Point3D((float)(FStartPositionIn[i].x * 1000), (float)(FStartPositionIn[i].y * 1000), (float)(FStartPositionIn[i].z * 1000)); if (tracker.Value.Equals(p)) { userID = tracker.Key; break; } } if (userID > -1) { FHandGenerator.StopTracking(userID); } FIsTrackedOut[i] = false; FHandIdOut[i] = -1; FHandPositionOut[i] = FStartPositionIn[i]; } } } } else { FIsTrackedOut.SliceCount = FHandIdOut.SliceCount = FHandPositionOut.SliceCount = 0; } }