Back to basics with a Basic XNA and Kinect SDK sample

Sign in to queue

Description

Every so often it's good to take a step back and review some basics, to look at something a little less complex, to revel in simplicity. That and I liked how this sample used XNA...

BTW, no this isn't a Windows Phone related sample in any way, but I recent received that WP7 Foam Guy and I had major bed head, so... Wink

Basic XNA and Kinect SDK Sample

This past week I have spent a little bit of time playing with the Kinect SDK and trying to get to grips with how it all works. My biggest interest is to use the Kinect SDK along with Microsoft’s XNA Framework for games development so I made a sample project using these technologies. I’ve posted a link to this project at the end of the article.

The idea of this project was pretty simple. I wanted to get the RGB camera stream of me goofing around and use it as the background in an XNA application. I also wanted to try out some skeleton tracking functionality to test when my hands are intersecting with hot spots (represented as semi-transparent squares) on the screen. As it turns out, this project was pretty simple and quick to make and overall I’m really quite impressed with how the SDK is to use.

This project makes use of a couple of simple extension methods I created and ...

Project Information URL: http://jason-mitchell.com/2011/06/28/basic-xna-and-kinect-sdk-sample/

Project Source URL: http://jason-mitchell.com/Uploads/XNA_And_Kinect-28_06_11.zip

SNAGHTML5be4df88

image

private void SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
    SkeletonFrame skeletonFrame = e.SkeletonFrame;
    ResetSquareColors();

    foreach (SkeletonData data in skeletonFrame.Skeletons)
    {
        if (data.TrackingState == SkeletonTrackingState.PositionOnly)
        {
            foreach (Joint joint in data.Joints)
            {
                if (joint.ID == JointID.HandRight || joint.ID == JointID.HandLeft)
                {
                    Vector2 jointPosition = joint.GetScreenPosition(kinectRuntime, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
                    Rectangle rectangle = new Rectangle((int)jointPosition.X - (JointIntersectionSize / 2), (int)jointPosition.Y - (JointIntersectionSize / 2), JointIntersectionSize, JointIntersectionSize);

                    foreach (TextureInstance texture in hotSpots)
                    {
                        if (texture.CalculateBoundingRectangle().Intersects(rectangle))
                            texture.Color = Color.LimeGreen;
                    }
                }
            }
        }
    }
}

protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);

    spriteBatch.Begin();

    kinectRGBVideo.Draw(spriteBatch);

    foreach (TextureInstance texture in hotSpots)
        texture.Draw(spriteBatch);

    spriteBatch.End();

    base.Draw(gameTime);
}

Contact Information:

The Discussion

Add Your 2 Cents