properly align & scale monitors

This commit is contained in:
Crispy 2023-04-13 23:01:26 +02:00
parent 7ff9475174
commit b00dab62db
3 changed files with 19 additions and 14 deletions

View file

@ -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);

View file

@ -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()

View file

@ -5,7 +5,7 @@
#include "util.h"
#include <GLFW/glfw3.h>
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);