Files
UnrealEngineUWP/Engine/Plugins/Runtime/WindowsMixedReality/Source/WindowsMixedRealityHMD/Private/WindowsMixedRealityFunctionLibrary.cpp
fieldsJacksonG e1b4c13b7e Unshelved from pending changelist '18540094':
PR #8767: Deprecate WMR (Contributed by fieldsJacksonG)

#preflight 18625839
#rb jeff.fisher
#jira UE-138625

#ROBOMERGE-AUTHOR: steve.smith
#ROBOMERGE-SOURCE: CL 18668535 in //UE5/Release-5.0/... via CL 18668690 via CL 18668769
#ROBOMERGE-BOT: UE5 (Release-Engine-Test -> Main) (v901-18665521)

[CL 18668796 by fieldsJacksonG in ue5-main branch]
2022-01-19 18:42:21 -05:00

238 lines
7.0 KiB
C++

// Copyright (c) Microsoft Corporation. All rights reserved.
#include "WindowsMixedRealityFunctionLibrary.h"
#include "EngineGlobals.h"
#include "Engine/Engine.h"
#include "WindowsMixedRealityHMD.h"
#if WITH_WINDOWS_MIXED_REALITY
#include "MixedRealityInterop.h"
#include "WindowsMixedRealityInteropUtility.h"
#endif
#include <functional>
UDEPRECATED_WindowsMixedRealityFunctionLibrary::UDEPRECATED_WindowsMixedRealityFunctionLibrary(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
WindowsMixedReality::FWindowsMixedRealityHMD* GetWindowsMixedRealityHMD() noexcept
{
if (GEngine->XRSystem.IsValid() && (GEngine->XRSystem->GetSystemName() == FName("WindowsMixedRealityHMD")))
{
return static_cast<WindowsMixedReality::FWindowsMixedRealityHMD*>(GEngine->XRSystem.Get());
}
return nullptr;
}
FString UDEPRECATED_WindowsMixedRealityFunctionLibrary::GetVersionString()
{
WindowsMixedReality::FWindowsMixedRealityHMD* hmd = GetWindowsMixedRealityHMD();
if (hmd == nullptr)
{
return FString();
}
return hmd->GetVersionString();
}
void UDEPRECATED_WindowsMixedRealityFunctionLibrary::ToggleImmersive(bool immersive)
{
WindowsMixedReality::FWindowsMixedRealityHMD* hmd = GetWindowsMixedRealityHMD();
if (hmd == nullptr)
{
return;
}
hmd->EnableStereo(immersive);
}
bool UDEPRECATED_WindowsMixedRealityFunctionLibrary::IsCurrentlyImmersive()
{
WindowsMixedReality::FWindowsMixedRealityHMD* hmd = GetWindowsMixedRealityHMD();
if (hmd == nullptr)
{
return false;
}
return hmd->IsCurrentlyImmersive();
}
bool UDEPRECATED_WindowsMixedRealityFunctionLibrary::IsDisplayOpaque()
{
WindowsMixedReality::FWindowsMixedRealityHMD* hmd = GetWindowsMixedRealityHMD();
if (hmd == nullptr)
{
return true;
}
return hmd->IsDisplayOpaque();
}
void UDEPRECATED_WindowsMixedRealityFunctionLibrary::LockMouseToCenter(bool locked)
{
WindowsMixedReality::FWindowsMixedRealityHMD* hmd = GetWindowsMixedRealityHMD();
if (hmd == nullptr)
{
return;
}
hmd->LockMouseToCenter(locked);
}
bool UDEPRECATED_WindowsMixedRealityFunctionLibrary::IsTrackingAvailable()
{
#if WITH_WINDOWS_MIXED_REALITY
WindowsMixedReality::FWindowsMixedRealityHMD* hmd = GetWindowsMixedRealityHMD();
if (hmd == nullptr)
{
return false;
}
return hmd->IsTrackingAvailable();
#else
return false;
#endif
}
FPointerPoseInfo UDEPRECATED_WindowsMixedRealityFunctionLibrary::GetPointerPoseInfo(EControllerHand hand)
{
FPointerPoseInfo info;
info.TrackingStatus = GetControllerTrackingStatus(hand);
#if WITH_WINDOWS_MIXED_REALITY
WindowsMixedReality::FWindowsMixedRealityHMD* hmd = GetWindowsMixedRealityHMD();
if (hmd == nullptr)
{
return info;
}
WindowsMixedReality::PointerPoseInfo p;
hmd->GetPointerPose(hand, p);
info.Origin = FVector(p.origin.x, p.origin.y, p.origin.z);
info.Direction = FVector(p.direction.x, p.direction.y, p.direction.z);
info.Up = FVector(p.up.x, p.up.y, p.up.z);
info.Orientation = FQuat(p.orientation.x, p.orientation.y, p.orientation.z, p.orientation.w);
#endif
return info;
}
bool UDEPRECATED_WindowsMixedRealityFunctionLibrary::IsButtonClicked(EControllerHand hand, EHMDInputControllerButtons button)
{
#if WITH_WINDOWS_MIXED_REALITY
WindowsMixedReality::FWindowsMixedRealityHMD* hmd = GetWindowsMixedRealityHMD();
if (hmd == nullptr)
{
return false;
}
return hmd->GetPressState((WindowsMixedReality::HMDHand)hand, (WindowsMixedReality::HMDInputControllerButtons)button) == WindowsMixedReality::HMDInputPressState::Pressed;
#endif
return false;
}
bool UDEPRECATED_WindowsMixedRealityFunctionLibrary::IsButtonDown(EControllerHand hand, EHMDInputControllerButtons button)
{
#if WITH_WINDOWS_MIXED_REALITY
WindowsMixedReality::FWindowsMixedRealityHMD* hmd = GetWindowsMixedRealityHMD();
if (hmd == nullptr)
{
return false;
}
return hmd->GetPressState((WindowsMixedReality::HMDHand)hand, (WindowsMixedReality::HMDInputControllerButtons)button, false) == WindowsMixedReality::HMDInputPressState::Pressed;
#endif
return false;
}
bool UDEPRECATED_WindowsMixedRealityFunctionLibrary::IsGrasped(EControllerHand hand)
{
return IsButtonDown(hand, EHMDInputControllerButtons::Grasp);
}
bool UDEPRECATED_WindowsMixedRealityFunctionLibrary::IsSelectPressed(EControllerHand hand)
{
return IsButtonDown(hand, EHMDInputControllerButtons::Select);
}
EHMDTrackingStatus UDEPRECATED_WindowsMixedRealityFunctionLibrary::GetControllerTrackingStatus(EControllerHand hand)
{
#if WITH_WINDOWS_MIXED_REALITY
WindowsMixedReality::FWindowsMixedRealityHMD* hmd = GetWindowsMixedRealityHMD();
if (hmd == nullptr)
{
return EHMDTrackingStatus::NotTracked;
}
return (EHMDTrackingStatus)hmd->GetControllerTrackingStatus((WindowsMixedReality::HMDHand)hand);
#endif
return EHMDTrackingStatus::NotTracked;
}
void UDEPRECATED_WindowsMixedRealityFunctionLibrary::SetFocusPointForFrame(FVector position)
{
#if WITH_WINDOWS_MIXED_REALITY
WindowsMixedReality::FWindowsMixedRealityHMD* hmd = GetWindowsMixedRealityHMD();
if (hmd == nullptr)
{
return;
}
hmd->SetFocusPointForFrame(position);
#endif
}
// Temporary CVAR api for FocusPoint
// The blueprint function to run a ConsoleCommand can be used to issue this each frame.
// The command string would be something like:
// vr.SetFocusPointForFrame 102.4 -850.3 21.7
static void SetFocusPointForFrame(const TArray<FString>& Args, UWorld*, FOutputDevice& Ar)
{
Ar.Logf(ELogVerbosity::Error, TEXT("SetFocusPointForFrame DEPRECATED: please switch to using the SetFocusPointForFrame blueprint function in this library instead. This command will be removed in 4.25."));
const int ArgsNum = Args.Num();
if (ArgsNum != 3)
{
Ar.Logf(ELogVerbosity::Error, TEXT("SetFocusPointForFrame command parameter expects 3 parameters not %i. Ignoring command."), ArgsNum);
}
FVector Position;
for (int i = 0; i < 3; ++i)
{
if (!FCString::IsNumeric(*Args[i]))
{
Ar.Logf(ELogVerbosity::Error, TEXT("SetFocusPointForFrame command parameter %i, '%s' is not numeric. Ignoring command."), i, *Args[i]);
return;
}
const float Value = FCString::Atof(*Args[i]);
check(i >= 0 && i <= 2);
Position[i] = Value;
}
WindowsMixedReality::FWindowsMixedRealityHMD* hmd = GetWindowsMixedRealityHMD();
if (hmd == nullptr)
{
Ar.Logf(ELogVerbosity::Error, TEXT("SetFocusPointForFrame command called but not WindowsMixedRealityHMD found. Ignoring command."));
return;
}
//Ar.Logf(TEXT("WindowsMixedReality SetFocusPointForFrame setting to %0.2f,%0.2f,%0.2f."), Position.X, Position.Y, Position.Z);
hmd->SetFocusPointForFrame(Position);
}
#define LOCTEXT_NAMESPACE "WindowsMixedReality"
static FAutoConsoleCommand CSetFocusPointForFrameCmd(
TEXT("vr.SetFocusPointForFrame"),
*LOCTEXT("CVarText_SetFocusPointForFrame", "Set the reference point for the stabilization plane on hololens 2. You must set it each frame to activate the feature for that frame. DEPRECATED: please switch to using the SetFocusPointForFrame blueprint function in this library instead.").ToString(),
FConsoleCommandWithWorldArgsAndOutputDeviceDelegate::CreateStatic(SetFocusPointForFrame));
#undef LOCTEXT_NAMESPACE