From 28b03623508139fff136c8dc8f4719dc5e0d400d Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Fri, 27 Mar 2020 19:17:36 +0100 Subject: [PATCH] Set up WebXR Room Scale sizes (#3065) --- app/src/main/cpp/DeviceDelegate.h | 1 + app/src/main/cpp/ExternalVR.cpp | 6 ++++++ app/src/main/cpp/ExternalVR.h | 1 + .../oculusvr/cpp/DeviceDelegateOculusVR.cpp | 18 ++++++++++++++-- app/src/wavevr/cpp/DeviceDelegateWaveVR.cpp | 21 ++++++++++++++++++- 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/DeviceDelegate.h b/app/src/main/cpp/DeviceDelegate.h index 48b8ed5bb..a943f87f6 100644 --- a/app/src/main/cpp/DeviceDelegate.h +++ b/app/src/main/cpp/DeviceDelegate.h @@ -39,6 +39,7 @@ class ImmersiveDisplay { const double aBottomDegrees) = 0; virtual void SetEyeOffset(const device::Eye aEye, const float aX, const float aY, const float aZ) = 0; virtual void SetEyeResolution(const int32_t aWidth, const int32_t aHeight) = 0; + virtual void SetStageSize(const float aWidth, const float aDepth) = 0; virtual void SetSittingToStandingTransform(const vrb::Matrix& aTransform) = 0; virtual void CompleteEnumeration() = 0; }; diff --git a/app/src/main/cpp/ExternalVR.cpp b/app/src/main/cpp/ExternalVR.cpp index d911f0780..3123d828b 100644 --- a/app/src/main/cpp/ExternalVR.cpp +++ b/app/src/main/cpp/ExternalVR.cpp @@ -299,6 +299,12 @@ ExternalVR::SetEyeResolution(const int32_t aWidth, const int32_t aHeight) { m.system.displayState.eyeResolution.height = aHeight; } +void +ExternalVR::SetStageSize(const float aWidth, const float aDepth) { + m.system.displayState.stageSize.width = aWidth; + m.system.displayState.stageSize.height = aDepth; +} + void ExternalVR::SetSittingToStandingTransform(const vrb::Matrix& aTransform) { memcpy(&(m.system.displayState.sittingToStandingTransform), aTransform.Data(), sizeof(m.system.displayState.sittingToStandingTransform)); diff --git a/app/src/main/cpp/ExternalVR.h b/app/src/main/cpp/ExternalVR.h index caba1edac..8f1cf7301 100644 --- a/app/src/main/cpp/ExternalVR.h +++ b/app/src/main/cpp/ExternalVR.h @@ -45,6 +45,7 @@ class ExternalVR : public ImmersiveDisplay { const double aBottomDegrees) override; void SetEyeOffset(const device::Eye aEye, const float aX, const float aY, const float aZ) override; void SetEyeResolution(const int32_t aX, const int32_t aY) override; + void SetStageSize(const float aWidth, const float aDepth) override; void SetSittingToStandingTransform(const vrb::Matrix& aTransform) override; void CompleteEnumeration() override; // ExternalVR interface diff --git a/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp b/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp index e6ffdeada..df7594314 100644 --- a/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp +++ b/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp @@ -227,6 +227,18 @@ struct DeviceDelegateOculusVR::State { } } + void UpdateBoundary() { + if (!ovr || !Is6DOF()) { + return; + } + ovrPosef pose; + ovrVector3f size; + vrapi_GetBoundaryOrientedBoundingBox(ovr, &pose, &size); + if (immersiveDisplay) { + immersiveDisplay->SetStageSize(size.x * 2.0f, size.z * 2.0f); + } + } + void AddUILayer(const OculusLayerPtr& aLayer, VRLayerSurface::SurfaceType aSurfaceType) { if (ovr) { vrb::RenderContextPtr ctx = context.lock(); @@ -669,9 +681,10 @@ DeviceDelegateOculusVR::RegisterImmersiveDisplay(ImmersiveDisplayPtr aDisplay) { m.GetImmersiveRenderSize(width, height); m.immersiveDisplay->SetEyeResolution(width, height); m.immersiveDisplay->SetSittingToStandingTransform(vrb::Matrix::Translation(kAverageOculusHeight)); - m.immersiveDisplay->CompleteEnumeration(); - + m.UpdateBoundary(); m.UpdatePerspective(); + + m.immersiveDisplay->CompleteEnumeration(); } void @@ -1199,6 +1212,7 @@ DeviceDelegateOculusVR::EnterVR(const crow::BrowserEGLContext& aEGLContext) { m.UpdateDisplayRefreshRate(); m.UpdateClockLevels(); m.UpdateTrackingMode(); + m.UpdateBoundary(); } // Reset reorientation after Enter VR diff --git a/app/src/wavevr/cpp/DeviceDelegateWaveVR.cpp b/app/src/wavevr/cpp/DeviceDelegateWaveVR.cpp index 5fb7ebdbe..45d2614c5 100644 --- a/app/src/wavevr/cpp/DeviceDelegateWaveVR.cpp +++ b/app/src/wavevr/cpp/DeviceDelegateWaveVR.cpp @@ -28,6 +28,7 @@ #include #include #include +#include namespace crow { @@ -331,6 +332,22 @@ struct DeviceDelegateWaveVR::State { } } + void UpdateBoundary() { + if (!immersiveDisplay) { + return; + } + WVR_Arena_t arena = WVR_GetArena(); + if (arena.shape == WVR_ArenaShape_Rectangle && + arena.area.rectangle.width > 0 && + arena.area.rectangle.length > 0) { + immersiveDisplay->SetStageSize(arena.area.rectangle.width, arena.area.rectangle.length); + } else if (arena.shape == WVR_ArenaShape_Round && arena.area.round.diameter > 0) { + immersiveDisplay->SetStageSize(arena.area.round.diameter, arena.area.round.diameter); + } else { + immersiveDisplay->SetStageSize(0.0f, 0.0f); + } + } + void UpdateHaptics(Controller& controller) { vrb::RenderContextPtr renderContext = context.lock(); if (!renderContext) { @@ -442,8 +459,9 @@ DeviceDelegateWaveVR::RegisterImmersiveDisplay(ImmersiveDisplayPtr aDisplay) { m.immersiveDisplay->SetCapabilityFlags(flags); m.immersiveDisplay->SetEyeResolution(m.renderWidth, m.renderHeight); m.immersiveDisplay->SetSittingToStandingTransform(vrb::Matrix::Translation(kAverageHeight)); - m.immersiveDisplay->CompleteEnumeration(); + m.UpdateBoundary(); m.InitializeCameras(); + m.immersiveDisplay->CompleteEnumeration(); } void @@ -590,6 +608,7 @@ DeviceDelegateWaveVR::ProcessEvents() { case WVR_EventType_DeviceResume: { VRB_WAVE_EVENT_LOG("WVR_EventType_DeviceResume"); m.reorientMatrix = vrb::Matrix::Identity(); + m.UpdateBoundary(); } break; case WVR_EventType_DeviceRoleChanged: {