From 34b45d55ee9e5ab9fce3effabdee8de048cc7878 Mon Sep 17 00:00:00 2001 From: Sebi <pape@vr.rwth-aachen.de> Date: Fri, 18 Mar 2022 14:18:20 +0100 Subject: [PATCH] Deactivating tracking for non-simulator launch --- README.md | 5 +++++ Source/HMDSimulator/Public/HMDSimulationManager.h | 2 ++ Source/HMDSimulatorHMD/Private/SimulatedHMD.cpp | 15 +++++++++------ .../Private/SimulatedMotionController.cpp | 5 +++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 29d5150..362b5f1 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ The HMD Simulator uses the keyboard and mouse to grab the input that is needed t Do a [VR Preview launch](Resources/VRLaunch.png) and you will see something similar to this:  Currently, the HMD Simulator emulated the two controllers and the position of the HMD. +If SteamVR is running and a real HMD is detected it is used instead. If you want to explicitly use the HMDSimulator, switch off your HMD or unplug it and close SteamVR. Then restart Unreal und do a [VR Preview launch](Resources/VRLaunch.png). + ### Camera Movement You can move around with the Mouse + WASD @@ -33,3 +35,6 @@ You can select a controller to control with either LeftShift (Left Controller) o The emulated controllers also offer 3 virtual buttons at the moment. The Trigger, Grab and Menu Button. These can be controlled with T, G or M respectively. If you select a controller (or more) and press one of these keys the controller sends a respective button press to Unreal, that you can use in your Blueprints (ideally via ActionMappings, see Configuration). If setup correctly you can e.g. Grab objects in the world and move them:  + +### Packaging +The HMD Simulator can be packed together with your game and only turns on, if you launch your game in VR mode (commandline parameter `-vr`) and additionally provide the `-hmd-simulator` parameter. diff --git a/Source/HMDSimulator/Public/HMDSimulationManager.h b/Source/HMDSimulator/Public/HMDSimulationManager.h index 6b13b3a..3442d0c 100644 --- a/Source/HMDSimulator/Public/HMDSimulationManager.h +++ b/Source/HMDSimulator/Public/HMDSimulationManager.h @@ -48,6 +48,8 @@ public: virtual void OnBeginPlay(FWorldContext& InWorldContext, bool EnableInThisPlay); //Called by simulated HMD virtual void OnEndPlay(FWorldContext& InWorldContext); //Called by simulated HMD + bool IsCurrentlyEnabled(){return CurrentlyEnabled;} + private: void BindInputEvents(); void UnbindInputEvents(); diff --git a/Source/HMDSimulatorHMD/Private/SimulatedHMD.cpp b/Source/HMDSimulatorHMD/Private/SimulatedHMD.cpp index 2877c55..be34eb1 100644 --- a/Source/HMDSimulatorHMD/Private/SimulatedHMD.cpp +++ b/Source/HMDSimulatorHMD/Private/SimulatedHMD.cpp @@ -44,12 +44,12 @@ bool FSimulatedHMD::IsHMDConnected() /* Always connected */ return true; } -bool FSimulatedHMD::IsHMDEnabled() const /* Always enabled */ +bool FSimulatedHMD::IsHMDEnabled() const { - return true; + return HMDSimulationManager && HMDSimulationManager->IsCurrentlyEnabled(); } -void FSimulatedHMD::EnableHMD(bool){} /* Always enabled */ +void FSimulatedHMD::EnableHMD(bool){} /* Enabled/Disabled automatically (see CheckActivation) */ bool FSimulatedHMD::GetHMDMonitorInfo(MonitorInfo& MonitorDesc) { @@ -93,7 +93,7 @@ void FSimulatedHMD::OnBeginPlay(FWorldContext& InWorldContext) { const bool Activation = CheckActivation(); - UE_LOG(LogTemp, Warning, TEXT("HMDSimulator Activated: %d"), Activation); + UE_LOG(LogHMDSimulatiorHMD, Log, TEXT("HMDSimulator Activated: %d"), Activation); HMDSimulationManager->OnBeginPlay(InWorldContext, Activation); } @@ -104,7 +104,8 @@ void FSimulatedHMD::OnEndPlay(FWorldContext& InWorldContext) bool FSimulatedHMD::EnumerateTrackedDevices(TArray<int32>& OutDevices, EXRTrackedDeviceType Type) { - if (Type == EXRTrackedDeviceType::Any || Type == EXRTrackedDeviceType::HeadMountedDisplay) + if (HMDSimulationManager && HMDSimulationManager->IsCurrentlyEnabled() && + (Type == EXRTrackedDeviceType::Any || Type == EXRTrackedDeviceType::HeadMountedDisplay)) { OutDevices.Add(HMDDeviceId); return true; @@ -122,6 +123,8 @@ float FSimulatedHMD::GetInterpupillaryDistance() const bool FSimulatedHMD::GetCurrentPose(int32 DeviceId, FQuat& CurrentOrientation, FVector& CurrentPosition) { + if(!HMDSimulationManager || !HMDSimulationManager->IsCurrentlyEnabled()) return false; + if(DeviceId == HMDDeviceId) { HMDSimulationManager->GetHeadPose(CurrentOrientation, CurrentPosition); @@ -410,7 +413,7 @@ void FSimulatedHMD::PreRenderViewFamily_RenderThread(FRHICommandListImmediate&, bool FSimulatedHMD::IsActiveThisFrame(class FViewport* InViewport) const { - return GEngine && GEngine->IsStereoscopic3D(InViewport); + return GEngine && GEngine->IsStereoscopic3D(InViewport) && HMDSimulationManager && HMDSimulationManager->IsCurrentlyEnabled(); } FSimulatedHMD::FSimulatedHMD(const FAutoRegister& AutoRegister) diff --git a/Source/HMDSimulatorInput/Private/SimulatedMotionController.cpp b/Source/HMDSimulatorInput/Private/SimulatedMotionController.cpp index 12f94a3..d11236c 100644 --- a/Source/HMDSimulatorInput/Private/SimulatedMotionController.cpp +++ b/Source/HMDSimulatorInput/Private/SimulatedMotionController.cpp @@ -57,6 +57,8 @@ void FSimulatedMotionController::SetChannelValues(int32, const FForceFeedbackVal void FSimulatedMotionController::EnumerateSources(TArray<FMotionControllerSource>& SourcesOut) const { + if(!HMDSimulationManager || !HMDSimulationManager->IsCurrentlyEnabled()) return; + SourcesOut.Add(FMotionControllerSource(LeftHandSourceId)); SourcesOut.Add(FMotionControllerSource(RightHandSourceId)); } @@ -69,6 +71,8 @@ FName FSimulatedMotionController::GetMotionControllerDeviceTypeName() const bool FSimulatedMotionController::GetControllerOrientationAndPosition(const int32, const EControllerHand DeviceHand, FRotator& OutOrientation, FVector& OutPosition, float) const { + if(!HMDSimulationManager || !HMDSimulationManager->IsCurrentlyEnabled()) return false; + switch(DeviceHand) { case EControllerHand::Left: @@ -83,6 +87,7 @@ bool FSimulatedMotionController::GetControllerOrientationAndPosition(const int32 ETrackingStatus FSimulatedMotionController::GetControllerTrackingStatus(const int32, const EControllerHand) const { + if(!HMDSimulationManager || !HMDSimulationManager->IsCurrentlyEnabled()) return ETrackingStatus::NotTracked; return ETrackingStatus::Tracked; } -- GitLab