Files
UnrealEngineUWP/Engine/Source/Runtime/HeadMountedDisplay/Private/IXRTrackingSystem.cpp
jeff fisher 5dac39ce5d UE-147360 VR Preview w. Net Mode Play As Client doesn't function as intended
-Previous code said that the first PIE world was allowed to track the HMD.  However sometimes the first PIE world is a dedicated server.  Now the first non-dedicated-server PIE world gets HMD tracking.
-This fix is a bit ugly to fit with hotfix rules.  I think it would be better to cache this value somewhere, but didn't see anywhere that was not a public header.
#jira UE-147360
[REVIEW]
#rb Arciel.Rekman
#preflight none

#ROBOMERGE-AUTHOR: jeff.fisher
#ROBOMERGE-SOURCE: CL 19929072 in //UE5/Release-5.0/... via CL 19930613
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v943-19904690)

[CL 19932812 by jeff fisher in ue5-main branch]
2022-04-26 20:14:45 -04:00

57 lines
1.8 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "IXRTrackingSystem.h"
#include "IHeadMountedDisplay.h"
#include "EngineGlobals.h"
#include "Engine/Engine.h"
#include "Kismet/GameplayStatics.h"
void IXRTrackingSystem::GetHMDData(UObject* WorldContext, FXRHMDData& HMDData)
{
HMDData.bValid = true;
HMDData.DeviceName = GetHMDDevice() ? GetHMDDevice()->GetHMDName() : GetSystemName();
HMDData.ApplicationInstanceID = FApp::GetInstanceId();
bool bIsTracking = IsTracking(IXRTrackingSystem::HMDDeviceId);
HMDData.TrackingStatus = bIsTracking ? ETrackingStatus::Tracked : ETrackingStatus::NotTracked;
APlayerCameraManager* CameraManager = UGameplayStatics::GetPlayerCameraManager(WorldContext, 0);
if (CameraManager)
{
HMDData.Rotation = CameraManager->GetCameraRotation().Quaternion();
HMDData.Position = CameraManager->GetCameraLocation();
}
//GetCurrentPose(0, HMDVisualizationData.Rotation, HMDVisualizationData.Position);
}
bool IXRTrackingSystem::IsHeadTrackingAllowedForWorld(UWorld& World) const
{
#if WITH_EDITOR
// For VR PIE only the first instance uses the headset
// This implementation is constrained by hotfix rules. It would be better to cache this somewhere.
if (!IsHeadTrackingAllowed())
{
return false;
}
if (World.WorldType != EWorldType::PIE)
{
return true;
}
// If we are a pie instance then the first pie world that is not a dedicated server uses head tracking
const int32 MyPIEInstanceID = World.GetOutermost()->GetPIEInstanceID();
for (const FWorldContext& WorldContext : GEngine->GetWorldContexts())
{
if (WorldContext.WorldType == EWorldType::PIE && WorldContext.RunAsDedicated == false && WorldContext.World())
{
return WorldContext.World()->GetOutermost()->GetPIEInstanceID() == MyPIEInstanceID;
}
}
return false;
#else
return IsHeadTrackingAllowed();
#endif
}