Game Development Reference
In-Depth Information
hr = NuiInitialize(
NUI_INITIALIZE_FLAG_USES_DEPTH_AND_PLAYER_INDEX |
NUI_INITIALIZE_FLAG_USES_SKELETON |
NUI_INITIALIZE_FLAG_USES_COLOR );
Listing 2.1. Initializing the Kinect runtime.
Once the SDK is installed, we must build the connection between the Kinect
API and our target application. This is actually a fairly painless process, but it
requires some thought to be put into how the Kinect data is received and stored
for later use. There are two options provided by the runtime for getting access to
the data. The user can either poll the runtime to find out if new data is available,
or an event system can be used in which the runtime signals to the application
when new data is ready for processing. We will discuss the event-based model
since it is more ecient, and we will describe its implementation here.
2.4.1 Initialization and Acquisition
The first step in getting access to the Kinect data is to initialize the runtime.
This is done with a single function, NuiInitialize , whose arguments allow you
to specify which data streams you are interested in receiving. In Listing 2.1 we
request the three data streams that have been discussed earlier in this article:
the color-image stream, the depth-image stream with player index, and also the
skeletal player data stream.
After we tell the runtime what data we want, then we simply need to provide
a mechanism for the runtime to signal that the data is available for reading. This
is performed with a set of events, each of which is used to indicate that data is
available from one of the data streams. The application creates an event and then
passes it to the runtime when opening each data stream. In return we receive
a handle with which to identify the data stream. The resolution and format of
the data stream is configured during the opening of the stream. This process is
shown in Listing 2.2 for the depth-image stream.
m_hNextDepthFrameEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
hr = NuiImageStreamOpen(
NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX,
NUI_IMAGE_RESOLUTION_320x240,
0,
2,
m_hNextDepthFrameEvent,
&m_pDepthStreamHandle );
Listing 2.2. Opening a data stream.
 
Search Nedrilad ::




Custom Search