예제 #1
0
        private void DrawBodyGP(GesturePak.Frame Frame, IDictionary <JointType, Point> jointPoints, DrawingContext drawingContext)
        {
            try
            {
                var joints = (IReadOnlyDictionary <JointType, Joint>)Frame.Joints;

                CurrentJointPoints = (Dictionary <JointType, Point>)jointPoints;

                // Draw the bones

                //// Torso
                DrawBoneGP(joints, jointPoints, JointType.Head, JointType.Neck, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.Neck, JointType.SpineShoulder, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.SpineShoulder, JointType.SpineMid, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.SpineMid, JointType.SpineBase, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.SpineShoulder, JointType.ShoulderRight, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.SpineShoulder, JointType.ShoulderLeft, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.SpineBase, JointType.HipRight, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.SpineBase, JointType.HipLeft, drawingContext);

                //// Right Arm
                DrawBoneGP(joints, jointPoints, JointType.ShoulderRight, JointType.ElbowRight, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.ElbowRight, JointType.WristRight, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.WristRight, JointType.HandRight, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.HandRight, JointType.HandTipRight, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.WristRight, JointType.ThumbRight, drawingContext);

                //// Left Arm
                DrawBoneGP(joints, jointPoints, JointType.ShoulderLeft, JointType.ElbowLeft, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.ElbowLeft, JointType.WristLeft, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.WristLeft, JointType.HandLeft, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.HandLeft, JointType.HandTipLeft, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.WristLeft, JointType.ThumbLeft, drawingContext);

                //// Right Leg
                DrawBoneGP(joints, jointPoints, JointType.HipRight, JointType.KneeRight, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.KneeRight, JointType.AnkleRight, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.AnkleRight, JointType.FootRight, drawingContext);

                //// Left Leg
                DrawBoneGP(joints, jointPoints, JointType.HipLeft, JointType.KneeLeft, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.KneeLeft, JointType.AnkleLeft, drawingContext);
                DrawBoneGP(joints, jointPoints, JointType.AnkleLeft, JointType.FootLeft, drawingContext);

                // Draw the joints
                var Gesture = Frame.Parent;
                foreach (JointType jointType in joints.Keys)
                {
                    drawJoint(Gesture.JointTrackOptions[(int)jointType], jointPoints[jointType], drawingContext);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #2
0
        /// <summary>
        /// High-level code to call when you really only want to draw one body frame at a time.
        /// </summary>
        /// <param name="Frame"></param>
        void drawBodyFromFrame(GesturePak.Frame Frame)
        {
            try
            {
                var mapper = KinectSensor.GetDefault().CoordinateMapper;

                using (DrawingContext dc = this.drawingGroup.Open())
                {
                    // Draw a transparent background to set the render size
                    dc.DrawRectangle(Brushes.Transparent, null, new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));

                    // draw the body
                    var joints = (Dictionary <JointType, Joint>)Frame.Joints;


                    Dictionary <JointType, Point> jointPoints = new Dictionary <JointType, Point>();
                    foreach (JointType jointType in joints.Keys)
                    {
                        DepthSpacePoint depthSpacePoint = mapper.MapCameraPointToDepthSpace(joints[jointType].Position);
                        jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y);
                    }

                    var args = new DrawingFrameEventArgs(Frame, jointPoints, dc);

                    OnDrawingFrame(args);

                    this.DrawBodyGP(Frame, jointPoints, dc);

                    // just draw the hands
                    if (DrawHandsEnabled == true)
                    {
                        this.DrawHand(Frame.LeftHandState, jointPoints[JointType.HandLeft], dc);
                        this.DrawHand(Frame.RightHandState, jointPoints[JointType.HandRight], dc);
                    }

                    OnFrameDrawn(args);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #3
0
 /// <summary>
 /// Moves to the previous frame
 /// </summary>
 public void ShowPreviousFrame()
 {
     if (animationFrames == null)
     {
         return;
     }
     if (!drawing)
     {
         drawing = true;
         if (animationIndex == 0)
         {
             SetAnimationIndex(animationFrames.Count - 1);
         }
         else
         {
             SetAnimationIndex(animationIndex - 1);
         }
         GesturePak.Frame thisFrame = animationFrames[animationIndex];
         drawBodyFromFrame(thisFrame);
         drawing = false;
     }
 }
예제 #4
0
 /// <summary>
 /// Move to a particular frame
 /// </summary>
 /// <param name="FrameNumber"></param>
 public void SetFrameNumber(int FrameNumber)
 {
     if (animationFrames == null)
     {
         return;
     }
     if (FrameNumber >= animationFrames.Count)
     {
         return;
     }
     if (FrameNumber <= 0)
     {
         return;
     }
     if (!drawing)
     {
         drawing = true;
         SetAnimationIndex(FrameNumber - 1);
         GesturePak.Frame thisFrame = animationFrames[animationIndex];
         drawBodyFromFrame(thisFrame);
         drawing = false;
     }
 }
 public DrawingFrameEventArgs(GesturePak.Frame Frame, Dictionary <JointType, Point> JointPoints, DrawingContext dc)
 {
     this.Frame       = Frame;
     this.JointPoints = JointPoints;
     this.dc          = dc;
 }