Ejemplo n.º 1
0
        /* public bool IsAbove(JointType joint1, JointType joint2) {
         *   return GetJointPosition(joint1, ScreenSpace.World).Y > GetJointPosition(joint2, ScreenSpace.World).Y;
         * }*/

        /// <summary>
        ///     Returns the screen position of the target joint.
        /// </summary>
        /// <param name="joint">The joint to return position data for.</param>
        /// <param name="skeleton">If not set then the first available skeleton will be selected.</param>
        /// <returns>The joint position.</returns>
        public static Vector3 GetJointPosition(JointType joint, ScreenSpace type, CustomSkeleton skeleton = null)
        {
            if (instance == null)
            {
                return(Vector3.Zero);
            }

            // If the skeleton provided is null then grab the first available skeleton and use it:
            if (skeleton == null && instance.Skeletons != null && instance.Skeletons.Count > 0)
            {
                skeleton =
                    instance.Skeletons.FirstOrDefault(
                        o => o.Joints.Count > 0 && o.State == SkeletonTrackingState.Tracked);
            }
            else
            {
                return(Vector3.Zero);
            }

            if (type == ScreenSpace.Screen)
            {
                return(skeleton.ScaleTo(joint, Screen.Width, Screen.Height));
            }
            return(skeleton.ScaleTo(joint, Screen.Width, Screen.Height));
            //  return skeleton.ScaleTo(joint, World.Width, World.Height);
        }
Ejemplo n.º 2
0
        public void DrawSkeleton(CustomSkeleton skeleton)
        {
            if (skeleton == null)
            {
                return;
            }

            DrawJointConnection(skeleton, JointType.Head, JointType.ShoulderCenter);
            DrawJointConnection(skeleton, JointType.ShoulderCenter, JointType.ShoulderRight);
            DrawJointConnection(skeleton, JointType.ShoulderRight, JointType.ElbowRight);
            DrawJointConnection(skeleton, JointType.ElbowRight, JointType.HandRight);
            DrawJointConnection(skeleton, JointType.ShoulderCenter, JointType.ShoulderLeft);
            DrawJointConnection(skeleton, JointType.ShoulderLeft, JointType.ElbowLeft);
            DrawJointConnection(skeleton, JointType.ElbowLeft, JointType.HandLeft);
            DrawJointConnection(skeleton, JointType.ShoulderCenter, JointType.HipCenter);
            DrawJointConnection(skeleton, JointType.HipCenter, JointType.HipRight);
            DrawJointConnection(skeleton, JointType.HipRight, JointType.KneeRight);
            DrawJointConnection(skeleton, JointType.KneeRight, JointType.FootRight);
            DrawJointConnection(skeleton, JointType.HipCenter, JointType.HipLeft);
            DrawJointConnection(skeleton, JointType.HipLeft, JointType.KneeLeft);
            DrawJointConnection(skeleton, JointType.KneeLeft, JointType.FootLeft);
        }
Ejemplo n.º 3
0
        private void OnSkeletonUpdated(object sender, SkeletonFrameReadyEventArgs e)
        {
            // The live feed returns updates from the camera:
            var skeletonFrame = e.OpenSkeletonFrame();

            if (skeletonFrame == null)
            {
                return;
            }

            // Add smoothing to prevent glitching in the skeletons' movements:
            var raw = new Skeleton[6];

            skeletonFrame.CopySkeletonDataTo(raw);
            for (var i = 0; i < raw.Length; i++)
            {
                if (raw[i] == null)
                {
                    continue;
                }

                if (Skeletons.Count <= i || Skeletons[i] == null)
                {
                    // If this skeleton was just added then set it:
                    var newSkeleton = new CustomSkeleton();
                    newSkeleton.Set(raw[i]);
                    Skeletons.Add(newSkeleton);
                    continue;
                }

                if (Smoothing > 0f)
                {
                    // Set the state of the skeleton:
                    Skeletons[i].State = raw[i].TrackingState;

                    // Add smoothing interpolation to each point:
                    foreach (Joint joint in raw[i].Joints)
                    {
                        var pos = new Vector3();
                        pos.X = Interpolate(Skeletons[i].Joints[joint.JointType].X, joint.Position.X, Smoothing);
                        pos.Y = Interpolate(Skeletons[i].Joints[joint.JointType].Y, -joint.Position.Y, Smoothing);
                        pos.Z = Interpolate(Skeletons[i].Joints[joint.JointType].Z, joint.Position.Z, Smoothing);

                        Skeletons[i].Joints[joint.JointType] = pos;
                    }
                }
                else
                {
                    // Store the raw data for the skeleton:
                    Skeletons[i].Set(raw[i]);
                }
            }

            skeletonFrame.Dispose();

            if (raw != null && raw.Any(o => o.TrackingState == SkeletonTrackingState.Tracked))
            {
                SkeletonActive = true;
                Debug_Skeleton = "Skeleton Found";
            }
            else
            {
                SkeletonActive = false;
                Debug_Skeleton = "No Skeleton Found";
            }
        }
Ejemplo n.º 4
0
        protected Vector2 jointToVector(CustomSkeleton skeleton, JointType type, int Width, int Height)
        {
            var position = skeleton.ScaleTo(type, Width, Height);

            return(new Vector2(position.X, position.Y));
        }
Ejemplo n.º 5
0
 protected Vector2 jointToVector(CustomSkeleton skeleton, JointType type)
 {
     return(jointToVector(skeleton, type, World.Width, World.Height));
 }
Ejemplo n.º 6
0
 public void DrawJointConnection(CustomSkeleton skeleton, JointType joint1, JointType joint2)
 {
     DrawLine(Renderer, 4, Color.Blue, jointToVector(skeleton, joint1), jointToVector(skeleton, joint2));
 }