From 4452c2efaafdbd1ac5ac0394ef83f5858db6adae Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Mon, 26 Aug 2019 22:43:50 +0200 Subject: [PATCH] Correctly layout quads on a parent cylinder. Center tray with active window. (#1632) * Correctly layout quads on a parent cylinder. Center tray with active window. * Center settings with active window --- .../vrbrowser/ui/widgets/TrayWidget.java | 14 +++++++++++--- .../ui/widgets/settings/SettingsWidget.java | 8 +++++--- app/src/main/cpp/BrowserWorld.cpp | 4 ++++ app/src/main/cpp/Widget.cpp | 18 +++++++++++++++--- app/src/main/cpp/Widget.h | 1 + 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java index c1626ee01..269e15333 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java @@ -214,12 +214,14 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { aPlacement.width = WidgetPlacement.dpDimension(context, R.dimen.tray_width); aPlacement.height = WidgetPlacement.dpDimension(context, R.dimen.tray_height); aPlacement.worldWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.tray_world_width); - aPlacement.translationY = WidgetPlacement.unitFromMeters(context, R.dimen.tray_world_y); - aPlacement.translationZ = WidgetPlacement.unitFromMeters(context, R.dimen.tray_world_z); + aPlacement.translationY = WidgetPlacement.unitFromMeters(context, R.dimen.tray_world_y) - + WidgetPlacement.unitFromMeters(context, R.dimen.window_world_y); + aPlacement.translationZ = WidgetPlacement.unitFromMeters(context, R.dimen.tray_world_z) - + WidgetPlacement.unitFromMeters(context, R.dimen.window_world_z); aPlacement.anchorX = 0.5f; aPlacement.anchorY = 0.5f; aPlacement.parentAnchorX = 0.5f; - aPlacement.parentAnchorY = 0.5f; + aPlacement.parentAnchorY = 0.0f; aPlacement.rotationAxisX = 1.0f; aPlacement.rotation = (float)Math.toRadians(-45); aPlacement.opaque = false; @@ -267,6 +269,8 @@ public void detachFromWindow() { if (mAttachedWindow != null) { mAttachedWindow.removeBookmarksListener(this); } + mWidgetPlacement.parentHandle = -1; + } @Override @@ -277,6 +281,7 @@ public void attachToWindow(@NonNull WindowWidget aWindow) { detachFromWindow(); mAttachedWindow = aWindow; + mWidgetPlacement.parentHandle = aWindow.getHandle(); mAttachedWindow.addBookmarksListener(this); mSessionStack = aWindow.getSessionStack(); @@ -328,6 +333,9 @@ private void toggleSettingsDialog() { mSettingsDialogHandle = widget.getHandle(); } + if (mAttachedWindow != null) { + widget.getPlacement().parentHandle = mAttachedWindow.getHandle(); + } if (widget.isVisible()) { widget.hide(REMOVE_WIDGET); } else { diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/SettingsWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/SettingsWidget.java index a6c050f92..796fe7f6b 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/SettingsWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/settings/SettingsWidget.java @@ -205,11 +205,13 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { aPlacement.width = WidgetPlacement.dpDimension(getContext(), R.dimen.settings_width); aPlacement.height = WidgetPlacement.dpDimension(getContext(), R.dimen.settings_height); aPlacement.parentAnchorX = 0.5f; - aPlacement.parentAnchorY = 0.5f; + aPlacement.parentAnchorY = 0.0f; aPlacement.anchorX = 0.5f; aPlacement.anchorY = 0.5f; - aPlacement.translationY = WidgetPlacement.unitFromMeters(getContext(), R.dimen.settings_world_y); - aPlacement.translationZ = WidgetPlacement.unitFromMeters(getContext(), R.dimen.settings_world_z); + aPlacement.translationY = WidgetPlacement.unitFromMeters(getContext(), R.dimen.settings_world_y) - + WidgetPlacement.unitFromMeters(getContext(), R.dimen.window_world_y); + aPlacement.translationZ = WidgetPlacement.unitFromMeters(getContext(), R.dimen.settings_world_z) - + WidgetPlacement.unitFromMeters(getContext(), R.dimen.window_world_z); } private void onSettingsPrivacyClick() { diff --git a/app/src/main/cpp/BrowserWorld.cpp b/app/src/main/cpp/BrowserWorld.cpp index 8ea32cd79..58cccc97d 100644 --- a/app/src/main/cpp/BrowserWorld.cpp +++ b/app/src/main/cpp/BrowserWorld.cpp @@ -1062,6 +1062,10 @@ BrowserWorld::LayoutWidget(int32_t aHandle) { translation = transform.GetTranslation(); } widget->SetTransform(parent ? parent->GetTransform().PostMultiply(transform) : transform); + + if (!widget->GetCylinder()) { + widget->LayoutQuadWithCylinderParent(parent && parent->GetCylinder() ? parent->GetCylinder() : nullptr); + } } void diff --git a/app/src/main/cpp/Widget.cpp b/app/src/main/cpp/Widget.cpp index c3b1e43b2..baf0a0d86 100644 --- a/app/src/main/cpp/Widget.cpp +++ b/app/src/main/cpp/Widget.cpp @@ -162,13 +162,16 @@ struct Widget::State { // Translate the z of the cylinder to make the back of the curved surface the z position anchor point. vrb::Matrix translation = vrb::Matrix::Translation(vrb::Vector(0.0f, 0.0f, radius * scale)); cylinder->SetTransform(translation.PostMultiply(scaleMatrix)); + AdjustCylinderRotation(radius * scale); + } + + void AdjustCylinderRotation(const float radius) { const float x = transform->GetTransform().GetTranslation().x(); if (x != 0.0f && placement->cylinderMapRadius > 0) { // Automatically adjust correct yaw angle & position for the cylinders not centered on the X axis - const float r = radius * scale; - const float perimeter = 2.0f * r * (float)M_PI; + const float perimeter = 2.0f * radius * (float)M_PI; float angle = 0.5f * (float)M_PI - x / perimeter * 2.0f * (float)M_PI; - float delta = placement->cylinderMapRadius - radius * scale; + float delta = placement->cylinderMapRadius - radius; vrb::Matrix transform = vrb::Matrix::Rotation(vrb::Vector(-cosf(angle), 0.0f, sinf(angle))); transform.PreMultiplyInPlace(vrb::Matrix::Translation(vrb::Vector(0.0f, 0.0f, -delta))); transform.PostMultiplyInPlace(vrb::Matrix::Translation(vrb::Vector(-x, 0.0f, delta))); @@ -591,6 +594,15 @@ Widget::SetProxifyLayer(const bool aValue) { m.layerProxy->ToggleAll(true); } +Widget::LayoutQuadWithCylinderParent(const CylinderPtr& aCylinder) { + if (aCylinder) { + const float radius = aCylinder->GetTransformNode()->GetTransform().GetScale().x(); + m.AdjustCylinderRotation(radius); + } else { + m.transformContainer->SetTransform(vrb::Matrix::Identity()); + } +} + Widget::Widget(State& aState, vrb::RenderContextPtr& aContext) : m(aState) { m.context = aContext; } diff --git a/app/src/main/cpp/Widget.h b/app/src/main/cpp/Widget.h index bc6d5b8d7..c5724d43a 100644 --- a/app/src/main/cpp/Widget.h +++ b/app/src/main/cpp/Widget.h @@ -76,6 +76,7 @@ class Widget { float GetCylinderDensity() const; void SetBorderColor(const vrb::Color& aColor); void SetProxifyLayer(const bool aValue); + void LayoutQuadWithCylinderParent(const CylinderPtr& aCylinder); protected: struct State; Widget(State& aState, vrb::RenderContextPtr& aContext);