From 1770dd6e264094fbf0a16addf8709debe16226f4 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Fri, 7 Apr 2023 20:32:52 +0200 Subject: [PATCH] order panels correctly based on pixel coordinates --- src/app.cpp | 10 ++++++++-- src/panel.cpp | 5 +---- src/panel.h | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/app.cpp b/src/app.cpp index cb56b7e..d44ad82 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -20,12 +20,18 @@ App::App() XRRMonitorInfo *monitor_info = XRRGetMonitors(_xdisplay, _root_window, 1, &monitor_count); 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); + for (int i = 0; i < monitor_count; i++) { XRRMonitorInfo mon = monitor_info[i]; - printf("screen %d: pos(%d, %d) wh(%d, %d)\n", i, mon.x, mon.y, mon.width, mon.height); + printf("screen %d: pos(%d, %d) %dx%d\n", i, mon.x, mon.y, mon.width, mon.height); - _panels.push_back(Panel(this, 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)); } } diff --git a/src/panel.cpp b/src/panel.cpp index 69f1ace..c38e59c 100644 --- a/src/panel.cpp +++ b/src/panel.cpp @@ -5,7 +5,7 @@ #include #include -Panel::Panel(App *app, int index, int x, int y, int width, int height) +Panel::Panel(App *app, vr::HmdMatrix34_t start_pose, int index, int x, int y, int width, int height) : _app(app), _index(index), _x(x), @@ -33,7 +33,6 @@ Panel::Panel(App *app, int index, int x, int y, int width, int height) auto overlay_create_err = _app->vr_overlay->CreateOverlay(_name.c_str(), _name.c_str(), &_id); assert(overlay_create_err == 0); _app->vr_overlay->ShowOverlay(_id); - // _app->vr_overlay->SetOverlayWidthInMeters(_id, 2.5f); uint8_t col[4] = {20, 50, 50, 255}; _app->vr_overlay->SetOverlayRaw(_id, &col, 1, 1, 4); printf("Created overlay instance %d\n", _index); @@ -41,8 +40,6 @@ Panel::Panel(App *app, int index, int x, int y, int width, int height) // (flipping uv on y axis because opengl and xorg are opposite) vr::VRTextureBounds_t bounds{0, 1, 1, 0}; _app->vr_overlay->SetOverlayTextureBounds(_id, &bounds); - vr::HmdMatrix34_t start_pose = DEFAULT_POSE; - start_pose.m[0][3] += index * 1.5f; _app->vr_overlay->SetOverlayTransformAbsolute(_id, _app->_tracking_origin, &start_pose); } } diff --git a/src/panel.h b/src/panel.h index afca6fc..e0abf82 100644 --- a/src/panel.h +++ b/src/panel.h @@ -10,7 +10,7 @@ class App; class Panel { public: - Panel(App *app, int index, int xmin, int xmax, int ymin, int ymax); + Panel(App *app, vr::HmdMatrix34_t start_pose, int index, int xmin, int xmax, int ymin, int ymax); void Update();