/// <summary>
        /// Draws the specified body.
        /// </summary>
        /// <param name="body">The body to draw.</param>
        /// <param name="jointRadius">The size of the joint ellipses.</param>
        /// <param name="jointBrush">The brush used to draw the joints.</param>
        /// <param name="boneThickness">The thickness of the bone lines.</param>
        /// <param name="boneBrush">The brush used to draw the bones.</param>
        public void DrawBody(Body body, double jointRadius, Brush jointBrush, double boneThickness, Brush boneBrush)
        {
            if (body == null || !body.IsTracked)
            {
                return;
            }

            BodyVisual visual = _bodyVisuals.Where(b => b.TrackingId == body.TrackingId).FirstOrDefault();

            if (visual == null)
            {
                visual = BodyVisual.Create(body.TrackingId, body.Joints.Keys, jointRadius, jointBrush, boneThickness, boneBrush);

                foreach (var ellipse in visual.Joints.Values)
                {
                    canvas.Children.Add(ellipse);
                }

                foreach (var line in visual.Bones.Values)
                {
                    canvas.Children.Add(line);
                }

                _bodyVisuals.Add(visual);
            }

            foreach (var joint in body.Joints)
            {
                if (joint.Key != JointType.Head)
                {
                    Point point = GetPoint(joint.Value.Position);

                    visual.UpdateJoint(joint.Key, point);
                }
            }

            foreach (var bone in visual.CONNECTIONS)
            {
                Point first  = GetPoint(body.Joints[bone.Item1].Position);
                Point second = GetPoint(body.Joints[bone.Item2].Position);

                visual.UpdateBone(bone, first, second);
            }
        }
        /// <summary>
        /// Creates a new BodyVisual object with the specified parameters.
        /// </summary>
        /// <param name="trackingId">The tracking ID of the corresponding body.</param>
        /// <param name="joints">The joint types of the body.</param>
        /// <param name="jointRadius">The desired joint size.</param>
        /// <param name="jointBrush">The desired joint brush.</param>
        /// <param name="boneThickness">The desired line thickness.</param>
        /// <param name="boneBrush">The desired line brush.</param>
        /// <returns>A new instance of BodyVisual.</returns>
        public static BodyVisual Create(ulong trackingId, IEnumerable <JointType> joints, double jointRadius, Brush jointBrush, double boneThickness, Brush boneBrush)
        {
            BodyVisual bodyVisual = new BodyVisual
            {
                TrackingId = trackingId
            };

            foreach (var joint in joints)
            {
                bodyVisual.AddJoint(joint, jointRadius, jointBrush);
            }

            foreach (var bone in bodyVisual.CONNECTIONS)
            {
                bodyVisual.AddBone(bone, boneThickness, boneBrush);
            }

            return(bodyVisual);
        }
示例#3
0
        /// <summary>
        /// Creates a new BodyVisual object with the specified parameters.
        /// </summary>
        /// <param name="trackingId">The tracking ID of the corresponding body.</param>
        /// <param name="joints">The joint types of the body.</param>
        /// <param name="jointRadius">The desired joint size.</param>
        /// <param name="jointBrush">The desired joint brush.</param>
        /// <param name="boneThickness">The desired line thickness.</param>
        /// <param name="boneBrush">The desired line brush.</param>
        /// <returns>A new instance of BodyVisual.</returns>
        public static BodyVisual Create(ulong trackingId, IEnumerable<JointType> joints, double jointRadius, Brush jointBrush, double boneThickness, Brush boneBrush)
        {
            BodyVisual bodyVisual = new BodyVisual
            {
                TrackingId = trackingId
            };

            foreach (var joint in joints)
            {
                bodyVisual.AddJoint(joint, jointRadius, jointBrush);
            }

            foreach (var bone in bodyVisual.CONNECTIONS)
            {
                bodyVisual.AddBone(bone, boneThickness, boneBrush);
            }

            return bodyVisual;
        }