/**
			@brief	Create kinect sensor
		*/
		INuiSensor* KinectContext::Create(const OLECHAR* strInstanceId)
		{
			INuiSensor* sensor = NULL;
			HRESULT ret = ::NuiCreateSensorById(strInstanceId, &sensor);
			if (SUCCEEDED(ret)) {
				lock_.lock();
				int size = (int)kinects_.size();
				for(int i = 0; i < size; i++){
					if(0 == wcscmp(kinects_[i]->uniqueId_, sensor->NuiDeviceConnectionId())){
						std::wcout << "Kinect[" << kinects_[i]->index_ << "] is connected, Device Name:: " << sensor->NuiDeviceConnectionId() << "\n" << std::endl;
						lock_.unlock();
						return sensor;
					}
				}
				lock_.unlock();
			}
			return NULL;
		}
Пример #2
0
/// <summary>
/// Enumerate and construct all the sensors when the app starts up
/// </summary>
void CMainWindow::EnumerateSensors()
{
    int iCount = 0;
    HRESULT hr = NuiGetSensorCount(&iCount);
    if (FAILED(hr))
    {
        return;
    }

    for (int i = 0; i < iCount; ++i)
    {
        INuiSensor* pNuiSensor = nullptr;

        if (SUCCEEDED(NuiCreateSensorByIndex(i, &pNuiSensor)))
        {
            UpdateMainWindow(pNuiSensor->NuiDeviceConnectionId(), pNuiSensor->NuiStatus());
        }

        SafeRelease(pNuiSensor);
    }
}
		/**
			@brief	Create kinect sensor
		*/
		INuiSensor* KinectContext::Create(int index)
		{
			INuiSensor* sensor = NULL;
			HRESULT ret = ::NuiCreateSensorByIndex(index, &sensor);
			if (SUCCEEDED(ret)) {
				lock_.lock();
				int size = (int)kinects_.size();
				for(int i = 0; i < size; i++){
					if(kinects_[i]->index_ == sensor->NuiInstanceIndex()){
						std::wcout << "Kinect[" << kinects_[i]->index_ << "] is connected, Device Name:: " << sensor->NuiDeviceConnectionId() << "\n" << std::endl;
						lock_.unlock();
						return sensor;
					}
				}
				lock_.unlock();
			}
			return NULL;
		}