void SensorSkeletonFrameReady(AllFramesReadyEventArgs 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 (!_gestureMaps.ContainsKey(sd.TrackingId)) { var mapstate = new GestureMapState(_gestureMap); _gestureMaps.Add(sd.TrackingId, mapstate); } var keycode = _gestureMaps[sd.TrackingId].Evaluate(sd, false, _bitmap.Width, _bitmap.Height); GetWaitingMessages(_gestureMaps); if (keycode != VirtualKeyCode.NONAME) { rtbMessages.AppendText("Gesture accepted from player " + sd.TrackingId + "\r"); rtbMessages.ScrollToCaret(); rtbMessages.AppendText("Command passed to System: " + keycode + "\r"); rtbMessages.ScrollToCaret(); InputSimulator.SimulateKeyPress(keycode); _gestureMaps[sd.TrackingId].ResetAll(sd); } // 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; if (_bitmap != null) { _bitmap = AddSkeletonToDepthBitmap(sd, _bitmap, true); } } } }
void SensorSkeletonFrameReady(AllFramesReadyEventArgs 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 (!_gestureMaps.ContainsKey(sd.TrackingId)) { var mapstate = new GestureMapState(_gestureMap); _gestureMaps.Add(sd.TrackingId, mapstate); } var keycode = _gestureMaps[sd.TrackingId].Evaluate(sd, false, _bitmap.Width, _bitmap.Height); GetWaitingMessages(_gestureMaps); if (keycode != VirtualKeyCode.NONAME) { //Another method //InputSimulator.SimulateKeyPress(keycode); switch (keycode) { case VirtualKeyCode.RBUTTON: p.DoPunch(Direction.Right); break; case VirtualKeyCode.LBUTTON: p.DoPunch(Direction.Left); break; default: break; } _gestureMaps[sd.TrackingId].ResetAll(sd); } p.SetPosition(new Vector2(sd.Joints[JointType.HipCenter].Position.X, p.pos.Y)); // 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; if (_bitmap != null) { _bitmap = AddSkeletonToDepthBitmap(sd, _bitmap, true); } } } }
void SensorSkeletonFrameReady(AllFramesReadyEventArgs 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 (!_gestureMaps.ContainsKey(sd.TrackingId)) { var mapstate = new GestureMapState(_gestureMap); _gestureMaps.Add(sd.TrackingId, mapstate); } var keycode = _gestureMaps[sd.TrackingId].Evaluate(sd, false, _bitmap.Width, _bitmap.Height); GetWaitingMessages(_gestureMaps); if (keycode == VirtualKeyCode.ACCEPT) { var kneer = sd.Joints[JointType.KneeRight]; var shoulderr = sd.Joints[JointType.ShoulderRight]; var d = distance(kneer, shoulderr); mInstructions.Text = "d: " + d; //if (d > (d + (d * .1))) //if (d > 0.66) //{ rtbMessages.AppendText("READY TO GOOOOOOOO " + sd.TrackingId + "\r"); rtbMessages.ScrollToCaret(); _gestureMaps[sd.TrackingId].ResetAll(sd); _readyGestureDetected = true; mInstructions.Text = "2. In order to display the next slide, move your right wrist above your right hip and put it down." + "To display the previous slide, do the same with your left wrist\r" + "3. To disable futher processing, pass your left Knee to the left of your left shoulder\r"; _armr = new Pen(Color.Green, 5); _arml = new Pen(Color.Green, 5); //} } else if (keycode == VirtualKeyCode.CANCEL) { rtbMessages.AppendText("DISABLING!! " + sd.TrackingId + "\r"); rtbMessages.ScrollToCaret(); _gestureMaps[sd.TrackingId].ResetAll(sd); _readyGestureDetected = false; _armr = new Pen(Color.Red, 5); _arml = new Pen(Color.Red, 5); } else if (keycode != VirtualKeyCode.NONAME && _readyGestureDetected) { rtbMessages.AppendText("Gesture accepted\r"); rtbMessages.ScrollToCaret(); rtbMessages.AppendText("Command passed to System: " + keycode + "\r"); rtbMessages.ScrollToCaret(); InputSimulator.SimulateKeyPress(keycode); _gestureMaps[sd.TrackingId].ResetAll(sd); if (keycode == VirtualKeyCode.NEXT) { _armr = new Pen(Color.DeepSkyBlue, 10); _arml = new Pen(Color.Green, 5); } else if (keycode == VirtualKeyCode.PRIOR) { _arml = new Pen(Color.DeepPink, 10); _armr = new Pen(Color.Green, 5); } } // 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; if (_bitmap != null) { _bitmap = AddSkeletonToDepthBitmap(sd, _bitmap, true); } } } }
void SensorSkeletonFrameReady(AllFramesReadyEventArgs e) { SerialPort serialPort1 = new SerialPort("COM8", 9600); 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 (!_gestureMaps.ContainsKey(sd.TrackingId)) { var mapstate = new GestureMapState(_gestureMap); _gestureMaps.Add(sd.TrackingId, mapstate); } var keycode = new VirtualKeyCode(); try { keycode = _gestureMaps[sd.TrackingId].Evaluate(sd, false, _bitmap.Width, _bitmap.Height); GetWaitingMessages(_gestureMaps); } catch (NullReferenceException nre) { Console.WriteLine(nre.Message); } if (keycode != VirtualKeyCode.NONAME) { rtbMessages.AppendText("Gesture accepted from player " + sd.TrackingId + "\r"); rtbMessages.ScrollToCaret(); rtbMessages.AppendText("Command passed to System: " + keycode + "\r"); rtbMessages.ScrollToCaret(); //InputSimulator.SimulateKeyPress(keycode); _gestureMaps[sd.TrackingId].ResetAll(sd); serialPort1.Open(); if (serialPort1.IsOpen) { try { serialPort1.WriteLine(keycode.ToString().Substring(3, 1)); rtbMessages.AppendText("Command passed to Arduino: " + keycode.ToString().Substring(3, 1) + "\r"); } catch (ArgumentOutOfRangeException aoore) { Console.WriteLine(aoore.Message); } } else { rtbMessages.AppendText("Failed to pass command to Arduino.\r"); } serialPort1.Close(); } // 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; if (_bitmap != null) { _bitmap = AddSkeletonToDepthBitmap(sd, _bitmap, true); } } } }