Ejemplo n.º 1
0
//Newer version, without the failing
void URealSenseTask::HandProducerTick()
{
	if (!HandsEnabled)
		return;

	//Data is up to date from earlier
	if (collector->handData == nullptr)
		return;
	
	if (!collector->handTickDataRead)
		return;

	collector->handTickDataRead = false;

	PXCHandData* handData = collector->handData;
	
	collector->numberOfDetectedHands = handData->QueryNumberOfHands();

	for (pxcI32 i = 0; i < collector->numberOfDetectedHands; i++)
	{
		//get hand information
		PXCHandData::IHand* hand;

		if (handData->QueryHandData(PXCHandData::AccessOrderType::ACCESS_ORDER_BY_TIME, i, hand) == PXC_STATUS_NO_ERROR)
		{
			//Store hand data
			collector->tempHandData[i] = hand;

			//Iterate Joints - lambda capture works...
			PXCHandData::JointData jointData;
			for (int j = 0; j < PXCHandData::NUMBER_OF_JOINTS; j++)
			{
				hand->QueryTrackedJoint((PXCHandData::JointType)j, jointData);

				collector->tempJointData[i][j] = jointData;
				collector->jointDataReady[i][j] = true;

				//This event should also emit if a frame is missed by caching the latest input
				/*RunLambdaOnGameThread([&, jointData]()
				{
					PXCHandData::JointData tempJointData = jointData;

					tempJoint->setFromRealSenseJoint(&tempJointData);
					if (collector->interfaceDelegate != nullptr)
						IRealSenseInterface::Execute_JointMoved(collector->interfaceDelegate, tempJoint);
					//}
				});*/
			}
		}
	}
}
Ejemplo n.º 2
0
void URealSenseTask::HandProducerTickOld()
{
	if (!HandsEnabled)
		return;

	//Data is up to date from earlier
	if (collector->handData == nullptr)
		return;

	PXCHandData* handData = collector->handData;

	for (pxcI32 i = 0; i < handData->QueryNumberOfHands(); i++)
	{
		//get hand information
		PXCHandData::IHand* hand;

		if (handData->QueryHandData(PXCHandData::AccessOrderType::ACCESS_ORDER_BY_TIME, i, hand) == PXC_STATUS_NO_ERROR)
		{

			{
				FScopeLock lock(&JointCriticalSection);
				collector->tempHandData[i] = hand;
			}

			//Hand data
			RunLambdaOnGameThread([&, i]()
			{
				{
					FScopeLock lock(&JointCriticalSection);

					if (!collector->handDataRead[i])
					{
						tempHand->setFromRealSenseHand(hand);//tempHandData[i]);
						if (collector->interfaceDelegate != nullptr)
							IRealSenseInterface::Execute_HandMoved(collector->interfaceDelegate, tempHand);

						//clear it
						collector->handDataRead[i] = true;
					}
				}
			});

			//Iterate Joints
			PXCHandData::JointData jointData;
			for (int j = 0; j < PXCHandData::NUMBER_OF_JOINTS; j++)
			{
				hand->QueryTrackedJoint((PXCHandData::JointType)j, jointData);

				//Copy data only if it hasn't been read
				{
					FScopeLock lock(&JointCriticalSection);
					if (collector->jointDataRead[i][j])
					{
						collector->tempJointData[i][j] = jointData;
						FVector vect = FVector(jointData.positionWorld.x, jointData.positionWorld.y, jointData.positionWorld.z);
						//UE_LOG(RealSensePluginLog, Log, TEXT("Copied Joint: %s"), *vect.ToString());

						collector->jointDataRead[i][j] = false;
					}

				}

				//This event should also emit if a frame is missed by caching the latest input
				RunLambdaOnGameThread([&, i, j]()
				{
					//{
						//FScopeLock lock(&JointCriticalSection);

						if (!collector->jointDataRead[i][j])
						{
							//FVector vect = FVector(tempJointData[i][j].positionWorld.x, tempJointData[i][j].positionWorld.y, tempJointData[i][j].positionWorld.z);
							//UE_LOG(RealSensePluginLog, Log, TEXT("Reading Joint: %s"), *vect.ToString());


							tempJoint->setFromRealSenseJoint(&collector->tempJointData[i][j]);
							if (collector->interfaceDelegate != nullptr)
								IRealSenseInterface::Execute_JointMoved(collector->interfaceDelegate, tempJoint);

							//clear it
							collector->jointDataRead[i][j] = true;
						}
					//}
				});
			}
		}

	}
}
Ejemplo n.º 3
0
void URealSenseTask::GestureProducerTick()
{
	PXCHandData* handData = collector->handData;
	PXCHandData::GestureData gestureData;

	for (pxcI32 i = 0; i < handData->QueryNumberOfHands(); i++)
	{
		//get hand information
		PXCHandData::IHand* hand;
		
		if (handData->QueryHandData(PXCHandData::AccessOrderType::ACCESS_ORDER_BY_TIME, i, hand) == PXC_STATUS_NO_ERROR)
		{
			//spread fingers
			if (!GesturesEnabled)
				return;

				//FScopeLock lock(&GestureCriticalSection);
				//tempHand->setFromRealSenseHand(hand);
				//URealSenseHand* copyHand = DuplicateObject(tempHand, nullptr);

			if (handData->IsGestureFired(L"spreadfingers", gestureData))
			{
				runGestureOnGameThread(gestureData.handId, hand->QueryUniqueId(), [&]()
				{
					tempHand->setFromRealSenseHand(hand);
					IRealSenseInterface::Execute_SpreadFingersGestureDetected(collector->interfaceDelegate, tempHand);
				});
			}

			//fist
			if (handData->IsGestureFired(L"fist", gestureData))
			{
				runGestureOnGameThread(gestureData.handId, hand->QueryUniqueId(), [&]()
				{
					tempHand->setFromRealSenseHand(hand);
					IRealSenseInterface::Execute_FistGestureDetected(collector->interfaceDelegate, tempHand);
				});
			}

			//tap
			if (handData->IsGestureFired(L"tap", gestureData))
			{
				runGestureOnGameThread(gestureData.handId, hand->QueryUniqueId(), [&]()
				{
					tempHand->setFromRealSenseHand(hand);
					IRealSenseInterface::Execute_TapGestureDetected(collector->interfaceDelegate, tempHand);
				});
			}

			//thumb_down
			if (handData->IsGestureFired(L"thumb_down", gestureData))
			{
				runGestureOnGameThread(gestureData.handId, hand->QueryUniqueId(), [&]()
				{
					tempHand->setFromRealSenseHand(hand);
					IRealSenseInterface::Execute_ThumbDownGestureDetected(collector->interfaceDelegate, tempHand);
				});
			}

			//thumb_up

			if (handData->IsGestureFired(L"thumb_up", gestureData))
			{
				//If the gesture was fired by the same hand
				runGestureOnGameThread(gestureData.handId, hand->QueryUniqueId(), [&]()
				{
					tempHand->setFromRealSenseHand(hand);
					IRealSenseInterface::Execute_ThumbUpGestureDetected(collector->interfaceDelegate, tempHand);
				});
			}


			//two_fingers_pinch_open
			if (handData->IsGestureFired(L"two_fingers_pinch_open", gestureData))
			{
				runGestureOnGameThread(gestureData.handId, hand->QueryUniqueId(), [&]()
				{
					tempHand->setFromRealSenseHand(hand);
					IRealSenseInterface::Execute_TwoFingersPinchOpenGestureDetected(collector->interfaceDelegate, tempHand);
				});
			}

			//v_sign
			if (handData->IsGestureFired(L"v_sign", gestureData))
			{
				runGestureOnGameThread(gestureData.handId, hand->QueryUniqueId(), [&]()
				{
					tempHand->setFromRealSenseHand(hand);
					IRealSenseInterface::Execute_VSignGestureDetected(collector->interfaceDelegate, tempHand);
				});
			}


			//full_pinch
			if (handData->IsGestureFired(L"full_pinch", gestureData))
			{
				runGestureOnGameThread(gestureData.handId, hand->QueryUniqueId(), [&]()
				{
					tempHand->setFromRealSenseHand(hand);
					IRealSenseInterface::Execute_FullPinchGestureDetected(collector->interfaceDelegate, tempHand);
				});
			}

			//swipe
			if (handData->IsGestureFired(L"swipe", gestureData))
			{
				runGestureOnGameThread(gestureData.handId, hand->QueryUniqueId(), [&]()
				{
					tempHand->setFromRealSenseHand(hand);
					IRealSenseInterface::Execute_SwipeGestureDetected(collector->interfaceDelegate, tempHand);
				});
			}

			//wave
			if (handData->IsGestureFired(L"wave", gestureData))
			{
				runGestureOnGameThread(gestureData.handId, hand->QueryUniqueId(), [&]()
				{
					tempHand->setFromRealSenseHand(hand);
					IRealSenseInterface::Execute_WaveGestureDetected(collector->interfaceDelegate, tempHand);
				});
			}
		}
	}
}