Game Development Reference
In-Depth Information
HRESULT hr = NuiImageStreamGetNextFrame(
m_pDepthStreamHandle,
0,
&pImageFrame );
INuiFrameTexture * pTexture = pImageFrame ->pFrameTexture;
NUI_LOCKED_RECT LockedRect;
pTexture->LockRect( 0, &LockedRect, NULL, 0 );
if ( LockedRect.Pitch != 0 ) {
BYTE * pBuffer = (BYTE*) LockedRect.pBits;
if ( m_pSysMemDepthBuffer != NULL ) {
USHORT * pBufferRun = (USHORT*) pBuffer;
for ( int y=0;y<240;y++){
for ( int x=0;x<320;x++){
USHORT s = *pBufferRun;
USHORT RealDepth = (s & 0xfff8) >> 3;
USHORT Player = s & 7;
pBufferRun++;
USHORT* pDestBuff =
(USHORT*)(&(m_pSysMemDepthBuffer[(x+320*y)*2]));
*pDestBuff = RealDepth;
}
}
m_DepthFrameTimer.Update();
m_pSysMemDepthBuffer = NULL;
}
}
NuiImageStreamReleaseFrame( m_pDepthStreamHandle, pImageFrame );
Listing 2.3. Acquiring a depth frame from the Kinect runtime.
What we have set up here is the mechanism for the runtime to let us know
when the next depth image frame is ready. The passed-in event will be triggered
when the frame is ready, and the handle is used to refer to the depth frame later
on. Once the runtime signals that a frame is ready for reading, the application
must acquire access to it using runtime methods. To complete this event-based
system, we utilize a separate processing thread that simply waits for the event to
be signaled and then copies the frame data as necessary. This process is depicted
in Listing 2.3, once again for the depth data stream.
Getting the data from the runtime consists of four general steps. First, we
acquire the frame using the NuiImageStreamGetNextFrame function. This returns
a structure that contains an INuiFrameTexture pointer, which holds the actual
frame data. Next we lock this texture interface, read the raw frame data out,
and finally release the frame after we are finished with it. The actual bit format
 
Search Nedrilad ::




Custom Search