From b00dab62dbc1fddd7d6d203583fc38be7ff05a50 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Thu, 13 Apr 2023 23:01:26 +0200 Subject: [PATCH] properly align & scale monitors --- src/app.cpp | 25 +++++++++++++++---------- src/panel.cpp | 4 ++-- src/panel.h | 4 ++-- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index 064fa75..73aece3 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -21,18 +21,23 @@ App::App() printf("found %d monitors:\n", monitor_count); float pixels_per_meter = 1920; - float x_min = -(monitor_info[0].x + monitor_info[0].width / 2.0f); - // float x_min = _root_width / -2.0f; + float total_width_meters = _root_width / pixels_per_meter; + float total_height_meters = _root_height / pixels_per_meter; for (int i = 0; i < monitor_count; i++) { XRRMonitorInfo mon = monitor_info[i]; printf("screen %d: pos(%d, %d) %dx%d\n", i, mon.x, mon.y, mon.width, mon.height); - float pos_x = (x_min + mon.x) / pixels_per_meter; - float pos_y = 1.2f; - vr::HmdMatrix34_t start_pose = {{{1, 0, 0, pos_x}, {0, 1, 0, pos_y}, {0, 0, 1, 0}}}; - _panels.push_back(Panel(this, start_pose, i, mon.x, mon.y, mon.width, mon.height)); + _panels.push_back(Panel(this, i, mon.x, mon.y, mon.width, mon.height)); + + float width = mon.width / pixels_per_meter; + float pos_x = mon.x / pixels_per_meter + width / 2.0f - total_width_meters / 2.0f; + float height = mon.height / pixels_per_meter; + float pos_y = 1.2f + mon.y / pixels_per_meter - height / 2.0f + total_height_meters / 2.0f; + VRMat start_pose = {{{1, 0, 0, pos_x}, {0, 1, 0, pos_y}, {0, 0, 1, 0}}}; + _panels[i].GetOverlay()->SetTransformWorld(&start_pose); + _panels[i].GetOverlay()->SetWidth(width); } { // initialize SteamVR input @@ -107,10 +112,10 @@ void App::InitRootOverlay() _root_overlay = Overlay(this, "root"); _root_overlay.SetAlpha(0.2f); // clang-format off - vr::HmdMatrix34_t root_start_pose = {{ - {0.1f, 0.0f, 0.0, 0}, - {0.0f, 0.0f, 1.0f, 0.8f}, - {0.0f, -0.5f, 0.0f, 0.25f} + VRMat root_start_pose = {{ + {0.25f, 0.0f, 0.0f, 0}, + {0.0f, 0.25f, 0.0f, 0.8f}, + {0.0f, 0.0f, 1.0f, 0} }}; // clang-format on _root_overlay.SetTransformWorld(&root_start_pose); diff --git a/src/panel.cpp b/src/panel.cpp index 7f9103b..36573f5 100644 --- a/src/panel.cpp +++ b/src/panel.cpp @@ -2,7 +2,7 @@ #include "app.h" #include "overlay.h" -Panel::Panel(App *app, vr::HmdMatrix34_t start_pose, int index, int x, int y, int width, int height) +Panel::Panel(App *app, int index, int x, int y, int width, int height) : _app(app), _index(index), _x(x), @@ -23,7 +23,7 @@ Panel::Panel(App *app, vr::HmdMatrix34_t start_pose, int index, int x, int y, in _texture.eType = vr::TextureType_OpenGL; _texture.handle = (void *)(uintptr_t)_gl_texture; - _overlay.SetTransformWorld(&start_pose); + // _overlay; } void Panel::Update() diff --git a/src/panel.h b/src/panel.h index 3cbb5b7..eb635db 100644 --- a/src/panel.h +++ b/src/panel.h @@ -5,7 +5,7 @@ #include "util.h" #include -const vr::HmdMatrix34_t DEFAULT_POSE = {{{1, 0, 0, 0}, {0, 1, 0, 1}, {0, 0, 1, 0}}}; +const VRMat DEFAULT_POSE = {{{1, 0, 0, 0}, {0, 1, 0, 1}, {0, 0, 1, 0}}}; class App; class Overlay; @@ -13,7 +13,7 @@ class Overlay; class Panel { public: - Panel(App *app, vr::HmdMatrix34_t start_pose, int index, int xmin, int xmax, int ymin, int ymax); + Panel(App *app, int index, int xmin, int xmax, int ymin, int ymax); void Update(); void SetHidden(bool state);