Kinect::Kinect() { NuiSetDeviceStatusCallback( &KinectSdk::deviceStatus, this ); init(); for ( int32_t i = 0; i < NUI_SKELETON_COUNT; i++ ) { mSkeletons.push_back( Skeleton() ); } }
// when the instance is first created, it will create an initial // set of sensor objects void SensorManager::Initialize() { AutoLock sensorLock( m_csSensorLock ); AutoLock handleLock( m_csHandleLock ); CreateListOfAvailableSensors(); // Set the sensor status callback NuiSetDeviceStatusCallback( NuiStatusCallback, this ); }
Device::Device() { NuiSetDeviceStatusCallback( &MsKinect::deviceStatus, this ); init(); for ( int32_t i = 0; i < NUI_SKELETON_COUNT; ++i ) { mSkeletons.push_back( Skeleton() ); } App::get()->getSignalUpdate().connect( bind( &Device::update, this ) ); }
HRESULT KinectManager::initialize() { INuiSensor * nui; int nuiCount = 0; HRESULT hr; NuiSetDeviceStatusCallback(OnSensorStatusChanged, NULL); hr = NuiGetSensorCount(&nuiCount); if ( FAILED(hr)) { return hr; } // Look at each kinect sensor for (int i = 0; i < nuiCount; i++) { // Create the sensor so we can check status, if we can't create it, move on. hr = NuiCreateSensorByIndex(i, &nui); if (FAILED(hr)) { continue; } // Get the status of the sensor, and if connected, then we can initialize it. hr = nui->NuiStatus(); if (S_OK == hr) { nuiList.push_front(nui); } // This sensor was not okay, so we release it (into the wild!) since we're not using it. nui->Release(); } return hr; }
/// <summary> /// Handle windows messages for a class instance /// </summary> /// <param name="hWnd">Window message is for</param> /// <param name="uMsg">Message</param> /// <param name="wParam">Message data</param> /// <param name="lParam">Additional message data</param> /// <returns>result of message processing</returns> LRESULT CMainWindow::DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: { // Bind application window handle m_hWnd = hWnd; // Set device status callback to monitor all sensor changes NuiSetDeviceStatusCallback(StatusChangeCallback, reinterpret_cast<void*>(hWnd)); InitializeResource(); } break; case WM_CTLCOLORSTATIC: case WM_CTLCOLORDLG: return (LRESULT)GetStockObject(WHITE_BRUSH); case WM_NOTIFY: switch (LOWORD(wParam)) { case IDC_MOREINFOLINK: OnClickMoreInfoLink(lParam); break; case IDC_KINECTSENSORLIST: return m_pSensorListControl->HandleNotifyMessage(hWnd, (LPNMLISTVIEW)lParam); case IDC_STATUSLOGLIST: return m_pStatusLogListControl->HandleNotifyMessage(hWnd, (LPNMLISTVIEW)lParam); } break; // If the titlebar X is clicked, destroy the app case WM_CLOSE: { m_pKinectWindowMgr->CloseAllKinectWindows(); DestroyWindow(hWnd); } break; // Quit the main message pump case WM_DESTROY: PostQuitMessage(0); break; // Handle the Kinect sensor status change case case WM_UPDATEMAINWINDOW: { UpdateMainWindow((PCWCHAR)wParam, (HRESULT)lParam); UpdateLayoutAndShowStatus(); } break; // If the kinect window is closed, notify Kinect window manager case WM_CLOSEKINECTWINDOW: m_pKinectWindowMgr->ResetKinectWindow((PCWSTR)wParam); break; case WM_SIZE: Resize(); break; case WM_PAINT: DrawBreakLine(); break; case WM_GETMINMAXINFO: { POINT minTrackSize = {m_minTrackWidth, 0}; auto pMinMaxInfo = (PMINMAXINFO)lParam; pMinMaxInfo->ptMinTrackSize = minTrackSize; } break; } return FALSE; }
/// <summary> /// Handle windows messages for the class instance /// </summary> /// <param name="hWnd">window message is for</param> /// <param name="uMsg">message</param> /// <param name="wParam">message data</param> /// <param name="lParam">additional message data</param> /// <returns>result of message processing</returns> LRESULT CALLBACK CBackgroundRemovalBasics::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: { HRESULT hr; // Bind application window handle m_hWnd = hWnd; // Create NuiSensorChooser UI control RECT rc; GetClientRect(m_hWnd, &rc); POINT ptCenterTop; ptCenterTop.x = (rc.right - rc.left)/2; ptCenterTop.y = 0; // Create the sensor chooser UI control to show sensor status m_pSensorChooserUI = new NuiSensorChooserUI(m_hWnd, IDC_SENSORCHOOSER, ptCenterTop); // Set the sensor status callback NuiSetDeviceStatusCallback(StatusChangeCallback, reinterpret_cast<void*>(m_hWnd)); // Init the sensor chooser to find a valid sensor m_pSensorChooser = new NuiSensorChooser(); // Init Direct2D D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pD2DFactory); // Create and initialize a new Direct2D image renderer (take a look at ImageRenderer.h) // We'll use this to draw the data we receive from the Kinect to the screen m_pDrawBackgroundRemovalBasics = new ImageRenderer(); hr = m_pDrawBackgroundRemovalBasics->Initialize(GetDlgItem(m_hWnd, IDC_VIDEOVIEW), m_pD2DFactory, m_colorWidth, m_colorHeight, m_colorWidth * cBytesPerPixel); if (FAILED(hr)) { SetStatusMessage(L"Failed to initialize the Direct2D draw device."); } // Look for a connected Kinect, and create it if found hr = CreateFirstConnected(); if (FAILED(hr)) { return FALSE; } // Create the sream that does background removal and player segmentation hr = CreateBackgroundRemovedColorStream(); if (FAILED(hr)) { return FALSE; } } break; // If the titlebar X is clicked, destroy app case WM_CLOSE: DestroyWindow(hWnd); break; case WM_DESTROY: // Quit the main message pump PostQuitMessage(0); break; // Handle button press case WM_COMMAND: // If it was for the near mode control and a clicked event, change near mode if (IDC_CHECK_NEARMODE == LOWORD(wParam) && BN_CLICKED == HIWORD(wParam)) { // Toggle out internal state for near mode m_bNearMode = !m_bNearMode; if (NULL != m_pNuiSensor) { // Set near mode based on our internal state m_pNuiSensor->NuiImageStreamSetImageFrameFlags(m_pDepthStreamHandle, m_bNearMode ? NUI_IMAGE_STREAM_FLAG_ENABLE_NEAR_MODE : 0); } } break; case WM_NOTIFY: { const NMHDR* pNMHeader = reinterpret_cast<const NMHDR*>(lParam); if (pNMHeader->code == NSCN_REFRESH && pNMHeader->idFrom == IDC_SENSORCHOOSER) { // Handle refresh notification sent from NSC UI control DWORD dwChangeFlags; HRESULT hr = m_pSensorChooser->TryResolveConflict(&dwChangeFlags); if (SUCCEEDED(hr)) { UpdateSensorAndStatus(dwChangeFlags); } } return TRUE; } break; case WM_SENSORCHANGED: { if (NULL != m_pSensorChooser) { // Handle sensor status change event DWORD dwChangeFlags = 0; HRESULT hr = m_pSensorChooser->HandleNuiStatusChanged(&dwChangeFlags); if (SUCCEEDED(hr)) { UpdateSensorAndStatus(dwChangeFlags); } } } break; } return FALSE; }