From 4d5fb757292035cee66f09473f5c5cde6ef5eb29 Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Fri, 22 Mar 2019 15:52:41 +0100 Subject: [PATCH] Set WebVR sittingToStanding transform. Enabled WebVR neck model for 3DOF devices. (#1036) --- .../googlevr/cpp/DeviceDelegateGoogleVR.cpp | 5 +-- app/src/main/cpp/Device.h | 1 + app/src/main/cpp/DeviceDelegate.h | 1 + app/src/main/cpp/ExternalVR.cpp | 8 +++++ app/src/main/cpp/ExternalVR.h | 1 + app/src/main/cpp/moz_external_vr.h | 35 +++++++++++-------- .../oculusvr/cpp/DeviceDelegateOculusVR.cpp | 7 +++- app/src/wavevr/cpp/DeviceDelegateWaveVR.cpp | 13 +++++-- versions.gradle | 2 +- 9 files changed, 52 insertions(+), 21 deletions(-) diff --git a/app/src/googlevr/cpp/DeviceDelegateGoogleVR.cpp b/app/src/googlevr/cpp/DeviceDelegateGoogleVR.cpp index 3be388944..b696483ca 100644 --- a/app/src/googlevr/cpp/DeviceDelegateGoogleVR.cpp +++ b/app/src/googlevr/cpp/DeviceDelegateGoogleVR.cpp @@ -27,6 +27,7 @@ namespace { +static const vrb::Vector kAverageHeight(0.0f, 1.7f, 0.0f); static const int32_t kMaxControllerCount = 2; struct Controller { @@ -391,7 +392,8 @@ DeviceDelegateGoogleVR::RegisterImmersiveDisplay(ImmersiveDisplayPtr aDisplay) { } m.immersiveDisplay->SetDeviceName("Daydream"); - m.immersiveDisplay->SetCapabilityFlags(device::Position | device::Orientation | device::Present); + m.immersiveDisplay->SetCapabilityFlags(device::Position | device::Orientation | device::Present | device::StageParameters); + m.immersiveDisplay->SetSittingToStandingTransform(vrb::Matrix::Translation(kAverageHeight)); gvr_sizei size = m.GetImmersiveModeSize(); m.immersiveDisplay->SetEyeResolution(size.width / 2, size.height); m.immersiveDisplay->CompleteEnumeration(); @@ -469,7 +471,6 @@ DeviceDelegateGoogleVR::ProcessEvents() { void DeviceDelegateGoogleVR::StartFrame() { - static const vrb::Vector kAverageHeight(0.0f, 1.7f, 0.0f); gvr_clock_time_point when = GVR_CHECK(gvr_get_time_point_now()); // 50ms into the future is what GVR docs recommends using for head rotation prediction. when.monotonic_system_time_nanos += 50000000; diff --git a/app/src/main/cpp/Device.h b/app/src/main/cpp/Device.h index 68713b411..37df2cf1c 100644 --- a/app/src/main/cpp/Device.h +++ b/app/src/main/cpp/Device.h @@ -16,6 +16,7 @@ const CapabilityFlags AngularAcceleration = 1 << 5; const CapabilityFlags LinearAcceleration = 1 << 6; const CapabilityFlags StageParameters = 1 << 7; const CapabilityFlags MountDetection = 1 << 8; +const CapabilityFlags PositionEmulated = 1 << 9; enum class Eye { Left, Right }; enum class RenderMode { StandAlone, Immersive }; const int32_t EyeCount = 2; diff --git a/app/src/main/cpp/DeviceDelegate.h b/app/src/main/cpp/DeviceDelegate.h index ff99625e6..d8b98d0f8 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 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 a881e771c..633acdf40 100644 --- a/app/src/main/cpp/ExternalVR.cpp +++ b/app/src/main/cpp/ExternalVR.cpp @@ -256,6 +256,9 @@ ExternalVR::SetCapabilityFlags(const device::CapabilityFlags aFlags) { if (device::MountDetection & aFlags) { result |= static_cast(mozilla::gfx::VRDisplayCapabilityFlags::Cap_MountDetection); } + if (device::PositionEmulated & aFlags) { + result |= static_cast(mozilla::gfx::VRDisplayCapabilityFlags::Cap_PositionEmulated); + } m.deviceCapabilities = aFlags; m.system.displayState.capabilityFlags = static_cast(result); m.system.sensorState.flags = m.system.displayState.capabilityFlags; @@ -292,6 +295,11 @@ ExternalVR::SetEyeResolution(const int32_t aWidth, const int32_t aHeight) { m.system.displayState.eyeResolution.height = aHeight; } +void +ExternalVR::SetSittingToStandingTransform(const vrb::Matrix& aTransform) { + memcpy(&(m.system.displayState.sittingToStandingTransform), aTransform.Data(), sizeof(m.system.displayState.sittingToStandingTransform)); +} + void ExternalVR::PushSystemState() { Lock lock(m.data.systemMutex); diff --git a/app/src/main/cpp/ExternalVR.h b/app/src/main/cpp/ExternalVR.h index 5011c3d97..00dc7f0c2 100644 --- a/app/src/main/cpp/ExternalVR.h +++ b/app/src/main/cpp/ExternalVR.h @@ -44,6 +44,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 SetSittingToStandingTransform(const vrb::Matrix& aTransform) override; void CompleteEnumeration() override; // ExternalVR interface void PushSystemState(); diff --git a/app/src/main/cpp/moz_external_vr.h b/app/src/main/cpp/moz_external_vr.h index ecd4bea64..760435fc7 100644 --- a/app/src/main/cpp/moz_external_vr.h +++ b/app/src/main/cpp/moz_external_vr.h @@ -34,7 +34,7 @@ enum class GamepadCapabilityFlags : uint16_t; #endif // MOZILLA_INTERNAL_API namespace gfx { -static const int32_t kVRExternalVersion = 6; +static const int32_t kVRExternalVersion = 7; // We assign VR presentations to groups with a bitmask. // Currently, we will only display either content or chrome. @@ -88,26 +88,26 @@ enum class ControllerCapabilityFlags : uint16_t { /** * Cap_Position is set if the Gamepad is capable of tracking its position. */ - Cap_Position = 1 << 1, + Cap_Position = 1 << 1, /** * Cap_Orientation is set if the Gamepad is capable of tracking its * orientation. */ - Cap_Orientation = 1 << 2, + Cap_Orientation = 1 << 2, /** * Cap_AngularAcceleration is set if the Gamepad is capable of tracking its * angular acceleration. */ - Cap_AngularAcceleration = 1 << 3, + Cap_AngularAcceleration = 1 << 3, /** * Cap_LinearAcceleration is set if the Gamepad is capable of tracking its * linear acceleration. */ - Cap_LinearAcceleration = 1 << 4, + Cap_LinearAcceleration = 1 << 4, /** * Cap_All used for validity checking during IPC serialization */ - Cap_All = (1 << 5) - 1 + Cap_All = (1 << 5) - 1 }; #endif // ifndef MOZILLA_INTERNAL_API @@ -117,12 +117,12 @@ enum class VRDisplayCapabilityFlags : uint16_t { /** * Cap_Position is set if the VRDisplay is capable of tracking its position. */ - Cap_Position = 1 << 1, + Cap_Position = 1 << 1, /** * Cap_Orientation is set if the VRDisplay is capable of tracking its * orientation. */ - Cap_Orientation = 1 << 2, + Cap_Orientation = 1 << 2, /** * Cap_Present is set if the VRDisplay is capable of presenting content to an * HMD or similar device. Can be used to indicate "magic window" devices that @@ -130,7 +130,7 @@ enum class VRDisplayCapabilityFlags : uint16_t { * meaningful. If false then calls to requestPresent should always fail, and * getEyeParameters should return null. */ - Cap_Present = 1 << 3, + Cap_Present = 1 << 3, /** * Cap_External is set if the VRDisplay is separate from the device's * primary display. If presenting VR content will obscure @@ -138,31 +138,36 @@ enum class VRDisplayCapabilityFlags : uint16_t { * un-set, the application should not attempt to mirror VR content * or update non-VR UI because that content will not be visible. */ - Cap_External = 1 << 4, + Cap_External = 1 << 4, /** * Cap_AngularAcceleration is set if the VRDisplay is capable of tracking its * angular acceleration. */ - Cap_AngularAcceleration = 1 << 5, + Cap_AngularAcceleration = 1 << 5, /** * Cap_LinearAcceleration is set if the VRDisplay is capable of tracking its * linear acceleration. */ - Cap_LinearAcceleration = 1 << 6, + Cap_LinearAcceleration = 1 << 6, /** * Cap_StageParameters is set if the VRDisplay is capable of room scale VR * and can report the StageParameters to describe the space. */ - Cap_StageParameters = 1 << 7, + Cap_StageParameters = 1 << 7, /** * Cap_MountDetection is set if the VRDisplay is capable of sensing when the * user is wearing the device. */ - Cap_MountDetection = 1 << 8, + Cap_MountDetection = 1 << 8, + /** + * Cap_PositionEmulated is set if the VRDisplay is capable of setting a + * neck model in position even if still doesn't support 6DOF tracking. + */ + Cap_PositionEmulated = 1 << 9, /** * Cap_All used for validity checking during IPC serialization */ - Cap_All = (1 << 9) - 1 + Cap_All = (1 << 9) - 1 }; #ifdef MOZILLA_INTERNAL_API diff --git a/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp b/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp index 5d95a363a..cb55edd60 100644 --- a/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp +++ b/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp @@ -572,6 +572,8 @@ class OculusLayerEquirect: public OculusLayerBaseSetEyeResolution(width, height); + m.immersiveDisplay->SetSittingToStandingTransform(vrb::Matrix::Translation(kAverageOculusHeight)); m.immersiveDisplay->CompleteEnumeration(); m.UpdatePerspective(); @@ -1116,9 +1119,11 @@ DeviceDelegateOculusVR::StartFrame() { if (m.immersiveDisplay) { m.immersiveDisplay->SetEyeOffset(device::Eye::Left, -ipd * 0.5f, 0.f, 0.f); m.immersiveDisplay->SetEyeOffset(device::Eye::Right, ipd * 0.5f, 0.f, 0.f); - device::CapabilityFlags caps = device::Orientation | device::Present; + device::CapabilityFlags caps = device::Orientation | device::Present | device::StageParameters; if (m.predictedTracking.Status & VRAPI_TRACKING_STATUS_POSITION_TRACKED) { caps |= device::Position; + } else { + caps |= device::PositionEmulated; } m.immersiveDisplay->SetCapabilityFlags(caps); } diff --git a/app/src/wavevr/cpp/DeviceDelegateWaveVR.cpp b/app/src/wavevr/cpp/DeviceDelegateWaveVR.cpp index 615c2d225..472eeac69 100644 --- a/app/src/wavevr/cpp/DeviceDelegateWaveVR.cpp +++ b/app/src/wavevr/cpp/DeviceDelegateWaveVR.cpp @@ -30,6 +30,7 @@ namespace crow { +static const vrb::Vector kAverageHeight(0.0f, 1.7f, 0.0f); static const int32_t kMaxControllerCount = 2; struct Controller { @@ -249,8 +250,17 @@ DeviceDelegateWaveVR::RegisterImmersiveDisplay(ImmersiveDisplayPtr aDisplay) { } m.immersiveDisplay->SetDeviceName("Wave"); - m.immersiveDisplay->SetCapabilityFlags(device::Position | device::Orientation | device::Present); + device::CapabilityFlags flags = device::Orientation | device::Present | device::StageParameters; + + if (WVR_GetDegreeOfFreedom(WVR_DeviceType_HMD) == WVR_NumDoF_6DoF) { + flags |= device::Position; + } else { + flags |= device::PositionEmulated; + } + + m.immersiveDisplay->SetCapabilityFlags(flags); m.immersiveDisplay->SetEyeResolution(m.renderWidth, m.renderHeight); + m.immersiveDisplay->SetSittingToStandingTransform(vrb::Matrix::Translation(kAverageHeight)); m.immersiveDisplay->CompleteEnumeration(); m.InitializeCameras(); } @@ -462,7 +472,6 @@ DeviceDelegateWaveVR::ProcessEvents() { void DeviceDelegateWaveVR::StartFrame() { VRB_GL_CHECK(glClearColor(m.clearColor.Red(), m.clearColor.Green(), m.clearColor.Blue(), m.clearColor.Alpha())); - static const vrb::Vector kAverageHeight(0.0f, 1.7f, 0.0f); if (!m.lastSubmitDiscarded) { m.leftFBOIndex = WVR_GetAvailableTextureIndex(m.leftTextureQueue); m.rightFBOIndex = WVR_GetAvailableTextureIndex(m.rightTextureQueue); diff --git a/versions.gradle b/versions.gradle index c0b20cfd8..e80aa30d0 100644 --- a/versions.gradle +++ b/versions.gradle @@ -24,7 +24,7 @@ ext.deps = [:] def versions = [:] // GeckoView versions can be found here: // https://maven.mozilla.org/?prefix=maven2/org/mozilla/geckoview/ -versions.gecko_view = "67.0.20190311102806" +versions.gecko_view = "68.0.20190322101035" versions.android_components = "0.31.0" versions.mozilla_speech = "1.0.6" versions.google_vr = "1.190.0"