Exemplo n.º 1
0
void FSteamVRHMD::GetCurrentPose(FQuat& CurrentOrientation, FVector& CurrentPosition, uint32 DeviceId, bool bForceRefresh /* = false*/)
{
	if (VRSystem == nullptr)
	{
		return;
	}

	check(DeviceId >= 0 && DeviceId < vr::k_unMaxTrackedDeviceCount);

	if (bForceRefresh)
	{
		// With SteamVR, we should only update on the PreRender_ViewFamily, and then the next frame should use the previous frame's results
		check(IsInRenderingThread());

		TrackingFrame.FrameNumber = GFrameNumberRenderThread;

		vr::TrackedDevicePose_t Poses[vr::k_unMaxTrackedDeviceCount];
		VRCompositor->WaitGetPoses(Poses, ARRAYSIZE(Poses));

		for (uint32 i = 0; i < vr::k_unMaxTrackedDeviceCount; ++i)
		{
			TrackingFrame.bDeviceIsConnected[i] = Poses[i].bDeviceIsConnected;
			TrackingFrame.bPoseIsValid[i] = Poses[i].bPoseIsValid;

			FVector LocalCurrentPosition;
			FQuat LocalCurrentOrientation;
			PoseToOrientationAndPosition(Poses[i].mDeviceToAbsoluteTracking, LocalCurrentOrientation, LocalCurrentPosition);

			TrackingFrame.DeviceOrientation[i] = LocalCurrentOrientation;
			TrackingFrame.DevicePosition[i] = LocalCurrentPosition;

			TrackingFrame.RawPoses[i] = Poses[i].mDeviceToAbsoluteTracking;
		}
	}
	
	// Update CurrentOrientation and CurrentPosition for the desired device, if valid
	if (TrackingFrame.bPoseIsValid[DeviceId])
 	{
		CurrentOrientation = TrackingFrame.DeviceOrientation[DeviceId];
		CurrentPosition = TrackingFrame.DevicePosition[DeviceId];
 	}
}
Exemplo n.º 2
0
void FGearVR::GetCurrentPose(FQuat& CurrentHmdOrientation, FVector& CurrentHmdPosition, bool bUseOrienationForPlayerCamera, bool bUsePositionForPlayerCamera)
{
	check(IsInGameThread());

	auto frame = GetFrame();
	check(frame);

	if (bUseOrienationForPlayerCamera || bUsePositionForPlayerCamera)
	{
		// if this pose is going to be used for camera update then save it.
		// This matters only if bUpdateOnRT is OFF.
		frame->EyeRenderPose[0] = frame->CurEyeRenderPose[0];
		frame->EyeRenderPose[1] = frame->CurEyeRenderPose[1];
		frame->HeadPose = frame->CurSensorState.Predicted.Pose;
	}

	frame->PoseToOrientationAndPosition(frame->CurSensorState.Predicted.Pose, CurrentHmdOrientation, CurrentHmdPosition);
	//UE_LOG(LogHMD, Log, TEXT("CRPOSE: Pos %.3f %.3f %.3f"), CurrentHmdPosition.X, CurrentHmdPosition.Y, CurrentHmdPosition.Z);
	//UE_LOG(LogHMD, Log, TEXT("CRPOSE: Yaw %.3f Pitch %.3f Roll %.3f"), CurrentHmdOrientation.Rotator().Yaw, CurrentHmdOrientation.Rotator().Pitch, CurrentHmdOrientation.Rotator().Roll);
}