Skip to content

Commit

Permalink
Set up WebXR Room Scale sizes (#3065)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed Mar 27, 2020
1 parent 9f5c1d7 commit 28b0362
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/src/main/cpp/DeviceDelegate.h
Expand Up @@ -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;
};
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/cpp/ExternalVR.cpp
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions app/src/main/cpp/ExternalVR.h
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1199,6 +1212,7 @@ DeviceDelegateOculusVR::EnterVR(const crow::BrowserEGLContext& aEGLContext) {
m.UpdateDisplayRefreshRate();
m.UpdateClockLevels();
m.UpdateTrackingMode();
m.UpdateBoundary();
}

// Reset reorientation after Enter VR
Expand Down
21 changes: 20 additions & 1 deletion app/src/wavevr/cpp/DeviceDelegateWaveVR.cpp
Expand Up @@ -28,6 +28,7 @@
#include <wvr/wvr_overlay.h>
#include <wvr/wvr_system.h>
#include <wvr/wvr_events.h>
#include <wvr/wvr_arena.h>

namespace crow {

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 28b0362

Please sign in to comment.