improve vive pro and vive focus 3 detection by utilizing optic resolution to distinguish them

This commit is contained in:
Mamadou Babaei
2024-08-16 16:26:06 +02:00
parent 27dddd1b03
commit 07995f23e2
4 changed files with 122 additions and 26 deletions
@@ -38,20 +38,107 @@
#include "Engine/Engine.h"
#include "IHeadMountedDisplay.h"
#include "IXRTrackingSystem.h"
#include "SGLog/SGLog.h"
FName FSGHeadMountDisplay::GetDeviceName()
{
if (GEngine->XRSystem.IsValid() && GEngine->XRSystem->IsHeadTrackingAllowed())
{
const IHeadMountedDisplay* Device{GEngine->XRSystem->GetHMDDevice()};
const FName DeviceName{Device->GetHMDName()};
return DeviceName;
if (Device)
{
const FName DeviceName{Device->GetHMDName()};
return DeviceName;
}
}
return NAME_None;
}
bool FSGHeadMountDisplay::IsHtcVivePro()
{
#if !PLATFORM_ANDROID
static const FName DeviceIdentifier{TEXT("Vive OpenXR: Vive SRanipal")};
const bool bIdentifierMatches = GetDeviceName() == DeviceIdentifier;
if (bIdentifierMatches)
{
if (GEngine->XRSystem.IsValid() && GEngine->XRSystem->IsHeadTrackingAllowed())
{
IHeadMountedDisplay* Device{GEngine->XRSystem->GetHMDDevice()};
if (Device)
{
IHeadMountedDisplay::MonitorInfo HmdMonitorInfo;
Device->GetHMDMonitorInfo(HmdMonitorInfo);
/// NOTE
// VIVE Pro:
// - Official Spec: 1440 x 1600 pixels per eye (2880 x 1600 pixels combined)
// - Unreal OpenXR Resolution: 4936 x 2740
// VIVE Focus 3:
// - Official Spec: 2448 x 2448 pixels per eye (4896 x 2448 pixels combined)
// - Unreal OpenXR Resolution: 5016 x 2508
if (HmdMonitorInfo.ResolutionX < 5000 && HmdMonitorInfo.ResolutionY > 2700)
{
return true;
}
}
}
}
#endif /* !PLATFORM_ANDROID */
return false;
}
bool FSGHeadMountDisplay::IsHtcViveFocus3()
{
static const FName DeviceIdentifier{TEXT("Vive OpenXR: Vive SRanipal")};
const bool bIdentifierMatches = GetDeviceName() == DeviceIdentifier;
#if PLATFORM_ANDROID
return bIdentifierMatches;
#else /* PLATFORM_ANDROID */
if (bIdentifierMatches)
{
if (GEngine->XRSystem.IsValid() && GEngine->XRSystem->IsHeadTrackingAllowed())
{
IHeadMountedDisplay* Device{GEngine->XRSystem->GetHMDDevice()};
if (Device)
{
IHeadMountedDisplay::MonitorInfo HmdMonitorInfo;
Device->GetHMDMonitorInfo(HmdMonitorInfo);
/// NOTE
// VIVE Pro:
// - Official Spec: 1440 x 1600 pixels per eye (2880 x 1600 pixels combined)
// - Unreal OpenXR Resolution: 4936 x 2740
// VIVE Focus 3:
// - Official Spec: 2448 x 2448 pixels per eye (4896 x 2448 pixels combined)
// - Unreal OpenXR Resolution: 5016 x 2508
if (HmdMonitorInfo.ResolutionX > 5000
&& (HmdMonitorInfo.ResolutionY > 2500 && HmdMonitorInfo.ResolutionY < 2700))
{
return true;
}
}
}
}
return false;
#endif /* PLATFORM_ANDROID */
}
ESGHeadMountDisplayDevice FSGHeadMountDisplay::GetDeviceType()
{
if (GEngine->XRSystem.IsValid() && GEngine->XRSystem->IsHeadTrackingAllowed())
{
IHeadMountedDisplay::MonitorInfo HmdMonitorInfo;
IHeadMountedDisplay* Device{GEngine->XRSystem->GetHMDDevice()};
Device->GetHMDMonitorInfo(HmdMonitorInfo);
const int32 ResX = HmdMonitorInfo.ResolutionX;
const int32 ResY = HmdMonitorInfo.ResolutionY;
SGLOG(HmdMonitorInfo.MonitorName, ResX, ResY, HmdMonitorInfo.DesktopX, HmdMonitorInfo.DesktopY,
HmdMonitorInfo.WindowSizeX, HmdMonitorInfo.WindowSizeY);
}
if (IsMetaQuest2())
{
return ESGHeadMountDisplayDevice::MetaQuest2;
@@ -67,15 +154,11 @@ ESGHeadMountDisplayDevice FSGHeadMountDisplay::GetDeviceType()
return ESGHeadMountDisplayDevice::MetaQuest3;
}
/// TODO
// WE NEED A MORE RELIABLE WAY TO DISTINGUISH VIVE Pro from VIVE Focus 3.
if (IsHtcVivePro())
{
return ESGHeadMountDisplayDevice::HtcVivePro;
}
/// TODO
// WE NEED A MORE RELIABLE WAY TO DISTINGUISH VIVE Pro from VIVE Focus 3.
if (IsHtcViveFocus3())
{
return ESGHeadMountDisplayDevice::HtcViveFocus3;
@@ -72,25 +72,8 @@ public:
return GetDeviceName() == DeviceIdentifier;
}
FORCEINLINE static bool IsHtcVivePro()
{
/// TODO
// WE NEED A MORE RELIABLE WAY TO DISTINGUISH VIVE Pro from VIVE Focus 3.
#if PLATFORM_ANDROID
return false;
#else /* PLATFORM_ANDROID */
static const FName DeviceIdentifier{TEXT("Vive OpenXR: Vive SRanipal")};
return GetDeviceName() == DeviceIdentifier;
#endif /* PLATFORM_ANDROID */
}
FORCEINLINE static bool IsHtcViveFocus3()
{
/// TODO
// WE NEED A MORE RELIABLE WAY TO DISTINGUISH VIVE Pro from VIVE Focus 3.
static const FName DeviceIdentifier{TEXT("Vive OpenXR: Vive SRanipal")};
return GetDeviceName() == DeviceIdentifier;
}
static bool IsHtcVivePro();
static bool IsHtcViveFocus3();
static ESGHeadMountDisplayDevice GetDeviceType();
};