Firstly let me start by  showcasing a little game I made using the Kinect sensor and Adobe AIR.

If you would like to make a game using Skeletal Tracking and  full body interaction, read on!

In this tutorial series I will be explaining how to get the Microsoft Kinect sensor installed on your desktop PC and ready to use with Adobe AIR.
I will cover the installation of the Kinect sensor, installation of the AS3NUI API (used to interface with the Kinect) –  as well as providing a basic Skeletal tracking example.

To follow on you are required to have a Microsoft Kinect sensor with the PC USB kit.
Note, the USB cable may not come with the Kinect if purchased in an Xbox bundle. If you purchase it separately it comes with a cable.

STEP 1- Download and install the Kinect Drivers

The first thing you want to do is download the official Kinect SDK, it will give you all the required drivers.  You can also get the required Kinect drivers by downloading OpenNI  .However I recommend getting the Kinect SDK from Microsoft.
Get it here http://www.microsoft.com/en-us/kinectforwindowsdev/Start.aspx.

Download the latest SDK as indicated by the red outline below.
Do not yet plugin your Kinect. If you did, you may find that the Kinect doesn’t show any lights flashing and is not functional.

kinect setup for pc

Step 2: Plug in your Kinect Via the USB cable

Plug in the device using  special USB cable kit provided in the Kinect bundle. If all went correctly,  you should see the green light on the device start flashing.

Step 3:  Download the AS3NUI ANE

https://github.com/AS3NUI/airkinect-2-core/raw/master/bin/airkinect-2-core-mssdk.ane

After downloading the ANE, the easiest way to get up and running is to setup in Flash Pro and use it as a compiler. You can use Flash Builder, FlashDevelop, or your fav development environment, but I will only be covering Flash Pro IDE for now.

Open flash and create a new project

  1. Go the File > Actionscript settings.
  2. On the Library Path tab, click on the “Browse to a Native Extension (ANE)” button (button to the right of the SWC button)
  3. Choose the ane file you just downloaded.

Step 4 : Simple Example

microsoft kinect joints

Create a document class and paste in the following source

package
{
import com.as3nui.nativeExtensions.air.kinect.constants.CameraResolution;
import com.as3nui.nativeExtensions.air.kinect.data.SkeletonJoint;
import com.as3nui.nativeExtensions.air.kinect.data.User;
import com.as3nui.nativeExtensions.air.kinect.events.CameraImageEvent;
import com.as3nui.nativeExtensions.air.kinect.events.DeviceErrorEvent;
import com.as3nui.nativeExtensions.air.kinect.events.DeviceEvent;
import com.as3nui.nativeExtensions.air.kinect.events.DeviceInfoEvent;
import com.as3nui.nativeExtensions.air.kinect.frameworks.mssdk.data.MSSkeletonJoint;
import com.as3nui.nativeExtensions.air.kinect.Kinect;
import com.as3nui.nativeExtensions.air.kinect.KinectSettings;
import flash.display.Bitmap;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.StageDisplayState;
import flash.events.Event;

/**
* ...
* @author John Stejskal
*  Johnstejskal@gmail.com
*  www.johnstejskal.com
*/
public class Main extends Sprite
{

private var kinect:Kinect;
private var cameraBitmap:Bitmap;
private var skeletonHolder:Sprite;

public function Main():void
{

stage.displayState = StageDisplayState.FULL_SCREEN

//check if the kinect is supported
if (Kinect.isSupported())
{
//establish the kinect device
kinect = Kinect.getDevice();

//declare bitmap that will hold the camera data
cameraBitmap = new Bitmap();
addChild(cameraBitmap);

//Create an empty spite which will hold out joins/bones
skeletonHolder = new Sprite();
addChild(skeletonHolder);

//add a kinect rbg update listener (this fires every time the camera frame updates)
kinect.addEventListener(CameraImageEvent.RGB_IMAGE_UPDATE, rbg_update, false, 0, true);

//listen to when the kinect is ready
kinect.addEventListener(DeviceEvent.STARTED, kinectStarted);

//Core settings, these will determin how the device behaves, what it see's and what it ignores.
var settings:KinectSettings = new KinectSettings();
settings.rgbEnabled = true;
settings.rgbResolution = CameraResolution.RESOLUTION_1280_960;
settings.depthEnabled = true;
settings.depthResolution = CameraResolution.RESOLUTION_1280_960;
settings.depthShowUserColors = true;
settings.skeletonEnabled = true;
kinect.start(settings);

//add the main loop in which the skeleton updates
addEventListener(Event.ENTER_FRAME, on_enterFrame, false, 0, true);
}
else
{
trace("device is not supported");
}
}

private function on_enterFrame(e:Event):void
{
//clear all dots to make way for new ones
skeletonHolder.graphics.clear();

//loop through all skeletons in frame, up to 2 with as3Nui.
for each(var user:User in kinect.usersWithSkeleton)
{
skeletonHolder.graphics.beginFill(0x00ccff);

for each(var joint:MSSkeletonJoint in user.skeletonJoints)
{

trace("joints :"+joint.name)

//Draw a circle on all the joints
skeletonHolder.graphics.drawCircle(joint.position.depth.x, joint.position.depth.y, 15 );
}

//-------------------o
//Points for tracking

/*
user.leftHand.position.depth;
user.rightHand.position.depth;

user.head.position.depth;

user.rightHip.position.depth;
user.leftHip.position.depth;

user.rightShoulder.position.depth;
user.leftShoulder.position.depth;

user.leftElbow.position.depth;
user.rightElbow.position.depth;

user.neck.position.depth;
*/

//-------------------o
//Some other useful info

//trace(user.hasSkeleton);
//trace(user.position.world);

}
}

//udates the camera feed
private function rbg_update(event:CameraImageEvent):void {
cameraBitmap.bitmapData = event.imageData;
}

private function kinectStarted(e:DeviceEvent):void
{
trace("kinect has started")

}

}

}

Here is a list of some useful points which can be retrieved through the user object.

user.leftHand.position.depth;
user.rightHand.position.depth;

user.head.position.depth;

user.rightHip.position.depth;
user.leftHip.position.depth;

user.rightShoulder.position.depth;
user.leftShoulder.position.depth;

user.leftElbow.position.depth;
user.rightElbow.position.depth;

user.neck.position.depth;

Once you are tracking the above points, you can do so much cool stuff – like tracking a fist hitting a flash MC, overlay MCs to move with body parts.. etc,  Get creative with it.

I have provided a simple functional template of the above code on my github, grab it here:
https://github.com/johnstejskal/as3NuiKinect_template

For easily compiling use the src/main.fla with  Flash CS6.

In upcoming posts I will do some tutorials on how top make some simple games with Kinect.

Bye for now!