diff --git a/Sources/WpfApp/MainWindow.xaml b/Sources/WpfApp/MainWindow.xaml index 4ebe115..5e4a5e2 100644 --- a/Sources/WpfApp/MainWindow.xaml +++ b/Sources/WpfApp/MainWindow.xaml @@ -27,5 +27,7 @@ + + \ No newline at end of file diff --git a/Sources/WpfApp/MainWindow.xaml.cs b/Sources/WpfApp/MainWindow.xaml.cs index cf2c5a6..c3a4a84 100644 --- a/Sources/WpfApp/MainWindow.xaml.cs +++ b/Sources/WpfApp/MainWindow.xaml.cs @@ -24,7 +24,10 @@ namespace WpfApp private KinectSensor kinectSensor = null; private ColorFrameReader colorFrameReader = null; private WriteableBitmap colorBitmap = null; - + + private BodyFrameReader bodyFrameReader = null; + private Body[] bodies = null; + // Propriété publique pour le binding public WriteableBitmap ColorBitmap { @@ -53,6 +56,13 @@ namespace WpfApp // Gérer l'événement FrameArrived pour le flux de couleur this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived; + // Initialisation du BodyFrameReader + this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); + this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived; + + // Initialiser le tableau des corps + this.bodies = new Body[this.kinectSensor.BodyFrameSource.BodyCount]; + // Ouvrir la Kinect this.kinectSensor.Open(); } @@ -101,5 +111,63 @@ namespace WpfApp this.kinectSensor = null; } } + + private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e) + { + using (var bodyFrame = e.FrameReference.AcquireFrame()) + { + if (bodyFrame != null) + { + bodyFrame.GetAndRefreshBodyData(this.bodies); + + skeletonCanvas.Children.Clear(); // Nettoyer le canvas avant de dessiner + + foreach (var body in this.bodies) + { + if (body.IsTracked) + { + // Dessiner le squelette + DrawSkeleton(body); + } + } + } + } + } + + private void DrawSkeleton(Body body) + { + foreach (JointType jointType in body.Joints.Keys) + { + Joint joint = body.Joints[jointType]; + if (joint.TrackingState == TrackingState.Tracked) + { + // Convertir les coordonnées du joint en coordonnées de l'écran + Point point = new Point(); + ColorSpacePoint colorPoint = this.kinectSensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position); + point.X = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X; + point.Y = float.IsInfinity(colorPoint.Y) ? 0 : colorPoint.Y; + + // Dessiner le joint + DrawJoint(point); + } + } + + // Dessinez les os ici si nécessaire + } + + private void DrawJoint(Point point) + { + Ellipse ellipse = new Ellipse + { + Width = 10, + Height = 10, + Fill = new SolidColorBrush(Colors.Red) + }; + + Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2); + Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2); + + skeletonCanvas.Children.Add(ellipse); + } } }