Exemplo n.º 1
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     
     #line 6 "..\..\..\MainWindow.xaml"
     ((KinectPowerPointControl.MainWindow)(target)).Closed += new System.EventHandler(this.MainWindow_Closed);
     
     #line default
     #line hidden
     return;
     case 2:
     this.skeletonCanvas1 = ((KinectPowerPointControl.KinectSkeleton)(target));
     return;
     case 3:
     this.videoImage = ((System.Windows.Controls.Image)(target));
     return;
     case 4:
     this.ellipseLeftHand = ((System.Windows.Shapes.Ellipse)(target));
     return;
     case 5:
     this.ellipseRightHand = ((System.Windows.Shapes.Ellipse)(target));
     return;
     case 6:
     this.ellipseHead = ((System.Windows.Shapes.Ellipse)(target));
     return;
     }
     this._contentLoaded = true;
 }
Exemplo n.º 2
0
        //void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            if (sensor == null || !sensor.IsRunning || !((KinectSensor)sender).SkeletonStream.IsEnabled)
                return;
            Skeleton closestSkeleton;
            #region Find Skeleton
            using (var skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame == null)
                    return;

                if (skeletons == null ||
                    skeletons.Length != skeletonFrame.SkeletonArrayLength)
                {
                    skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                }

                skeletonFrame.CopySkeletonDataTo(skeletons);

                closestSkeleton = (from s in skeletons
                                            where s.TrackingState == SkeletonTrackingState.Tracked &&
                                                  s.Joints[JointType.Head].TrackingState == JointTrackingState.Tracked
                                            select s).OrderBy(s => s.Joints[JointType.Head].Position.Z)
                                                    .FirstOrDefault();

                if (closestSkeleton == null)
                    return;

                #region default paint
                var head = closestSkeleton.Joints[JointType.Head];
                var rightHand = closestSkeleton.Joints[JointType.HandRight];
                var leftHand = closestSkeleton.Joints[JointType.HandLeft];

                if (head.TrackingState != JointTrackingState.Tracked ||
                    rightHand.TrackingState != JointTrackingState.Tracked ||
                    leftHand.TrackingState != JointTrackingState.Tracked)
                {
                    //Don't have a good read on the joints so we cannot process gestures
                    return;
                }

                SetEllipsePosition(ellipseHead, head, false);
                SetEllipsePosition(ellipseLeftHand, leftHand, isBackGestureActive);
                SetEllipsePosition(ellipseRightHand, rightHand, isForwardGestureActive);

                ProcessForwardBackGesture(head, rightHand, leftHand);
                #endregion default paint
            }
            #endregion Find Skeleton

            if (closestSkeleton != null)
            {
                using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame())
                {
                    #region depth_image
                    skeletonCanvas = this.skeletonCanvas1;                   
                    if (depthImageFrame != null)
                    {
                        skeletonCanvas.ShowBones = true;//this.ShowBones;
                        skeletonCanvas.ShowJoints = true;//this.ShowJoints;
                        skeletonCanvas.ShowCenter = true;//this.ShowCenter;

                        // Transform the data into the correct space
                        // For each joint, we determine the exact X/Y coordinates for the target view
                        foreach (Joint joint in closestSkeleton.Joints)
                        {
                            Point mappedPoint = this.GetPosition2DLocation(depthImageFrame, joint.Position);
                            jointMapping[joint.JointType] = new JointMapping
                            {
                                Joint = joint,
                                MappedPoint = mappedPoint
                            };
                            if (joint.TrackingState != 0)
                            {
                                //MessageBox.Show("Find someone's Skeleton!");
                                Console.WriteLine("Find someone's Skeleton!");
                            }
                        }
                        Point centerPoint = this.GetPosition2DLocation(depthImageFrame, closestSkeleton.Position);

                        // Scale the skeleton thickness
                        // 1.0 is the desired size at 640 width
                        double scale = this.RenderSize.Width / 640;

                        skeletonCanvas.RefreshSkeleton(closestSkeleton, jointMapping, centerPoint, scale);
                    }

                    #endregion depth_image
                }
            }
        }