Page 3 of 3
Drawing a Bone
it should be obvious that what we have to do next is draw a line between ShoulderCenter and Spine. Clearly this is just a repeat of what we have already done so this suggests another helper function:
void DrawBone(JointID j1,
Point p2 = GetJoint(j2, data);
g.DrawLine(Pens.Red, p1, p2);
This will draw a line between the two specified Joints. So to draw the body all we need is:
JointID.ShoulderCenter, data, g);
JointID.Spine, data, g);
This is all we need!
If you run the program now you will see lines following the body.
Now that you have seen this much adding two legs should be easy:
JointID.KneeLeft, data, g);
JointID.AnkleLeft, data, g);
JointID.FootLeft, data, g);
JointID.KneeRight, data, g);
JointID.AnkleRight, data, g);
JointID.FootRight, data, g);
All we have left to do is to add the two arms:
JointID.ShoulderLeft, data, g);
JointID.ElbowLeft, data, g);
JointID.WristLeft, data, g);
JointID.HandLeft, data, g);
JointID.ShoulderRight, data, g);
JointID.ElbowRight, data, g);
JointID.WristRight, data, g);
JointID.HandRight, data, g);
Now if you run the program you will see a complete skeleton plot.
You can argue that there are better ways to organize the code but you have to have a list of the joints you want to draw lines between somewhere.
If you want to try taking it further why not change the drawing of the head for an ellipse and a rectangle for the body. It is all fairly easy.
Articles on the Microsoft Kinect SDK
- Getting started with Microsoft Kinect SDK
- Player index
- Depth and Video space
- The Full Skeleton (this article)
Next Time: Audio
You can download the code for the Windows Forms version of this program from the CodeBin (note you have to register first).
or email your comment to: firstname.lastname@example.org
To be informed about new articles on I Programmer, subscribe to the RSS feed, follow us on Google+, Twitter, Linkedin or Facebook or sign up for our weekly newsletter.