mirror of
https://github.com/CrispyPin/sinpin-vr.git
synced 2024-11-22 18:10:26 +01:00
Compare commits
No commits in common. "895bec3bd5b81a7261e0f01e37ee6749bfa94180" and "14b5c8f74572fc6915567a53ca72dd29b3c0351b" have entirely different histories.
895bec3bd5
...
14b5c8f745
9 changed files with 33 additions and 100 deletions
|
@ -1,3 +1,3 @@
|
|||
# ovr-screen
|
||||
A SteamVR overlay for Linux+X11 that displays all your screens in VR.
|
||||
A SteamVR overlay for Linux+X11 that displays the screen in VR.
|
||||
|
||||
|
|
29
src/app.cpp
29
src/app.cpp
|
@ -8,7 +8,6 @@
|
|||
App::App()
|
||||
{
|
||||
_tracking_origin = vr::TrackingUniverseStanding;
|
||||
_frames_since_framebuffer = 999;
|
||||
|
||||
InitOVR();
|
||||
InitX11();
|
||||
|
@ -116,7 +115,7 @@ void App::InitGLFW()
|
|||
void App::InitRootOverlay()
|
||||
{
|
||||
_root_overlay = Overlay(this, "root");
|
||||
_root_overlay.SetAlpha(0.5f);
|
||||
_root_overlay.SetAlpha(0.2f);
|
||||
// clang-format off
|
||||
VRMat root_start_pose = {{
|
||||
{0.25f, 0.0f, 0.0f, 0},
|
||||
|
@ -125,7 +124,6 @@ void App::InitRootOverlay()
|
|||
}};
|
||||
// clang-format on
|
||||
_root_overlay.SetTransformWorld(&root_start_pose);
|
||||
_root_overlay.SetTextureToColor(110, 30, 190);
|
||||
|
||||
_root_overlay._GrabBeginCallback = [this](Controller *controller) {
|
||||
for (auto &panel : _panels)
|
||||
|
@ -153,7 +151,6 @@ void App::Update()
|
|||
panel.Update();
|
||||
}
|
||||
}
|
||||
_frames_since_framebuffer += 1;
|
||||
}
|
||||
|
||||
void App::UpdateInput()
|
||||
|
@ -178,8 +175,6 @@ void App::UpdateInput()
|
|||
{
|
||||
panel.SetHidden(_hidden);
|
||||
}
|
||||
_controllers[0]->SetHidden(_hidden);
|
||||
_controllers[1]->SetHidden(_hidden);
|
||||
}
|
||||
_controllers[0]->Update();
|
||||
_controllers[1]->Update();
|
||||
|
@ -187,11 +182,6 @@ void App::UpdateInput()
|
|||
|
||||
void App::UpdateFramebuffer()
|
||||
{
|
||||
if (_frames_since_framebuffer < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_frames_since_framebuffer = 0;
|
||||
auto frame = XGetImage(
|
||||
_xdisplay,
|
||||
_root_window,
|
||||
|
@ -242,19 +232,22 @@ Ray App::IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len)
|
|||
Ray ray;
|
||||
ray.distance = max_len;
|
||||
ray.overlay = nullptr;
|
||||
|
||||
auto r_root = _root_overlay.IntersectRay(origin, direction, max_len);
|
||||
if (r_root.distance < ray.distance)
|
||||
{
|
||||
ray = r_root;
|
||||
float root_dist = _root_overlay.IntersectRay(origin, direction, max_len);
|
||||
if (root_dist < ray.distance)
|
||||
{
|
||||
ray.distance = root_dist;
|
||||
ray.overlay = &_root_overlay;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &panel : _panels)
|
||||
{
|
||||
auto r_panel = panel.GetOverlay()->IntersectRay(origin, direction, max_len);
|
||||
if (r_panel.distance < ray.distance)
|
||||
float dist = panel.GetOverlay()->IntersectRay(origin, direction, max_len);
|
||||
if (dist < ray.distance)
|
||||
{
|
||||
ray = r_panel;
|
||||
ray.distance = dist;
|
||||
ray.overlay = panel.GetOverlay();
|
||||
}
|
||||
}
|
||||
return ray;
|
||||
|
|
|
@ -50,7 +50,6 @@ class App
|
|||
Window _root_window;
|
||||
GLFWwindow *_gl_window;
|
||||
GLuint _gl_frame;
|
||||
int _frames_since_framebuffer;
|
||||
|
||||
int _root_width;
|
||||
int _root_height;
|
||||
|
|
|
@ -12,7 +12,6 @@ Controller::Controller(App *app, ControllerSide side)
|
|||
_input_handle = 0;
|
||||
_is_connected = false;
|
||||
_side = side;
|
||||
_hidden = false;
|
||||
|
||||
std::string laser_name = "controller_laser_";
|
||||
if (side == ControllerSide::Left)
|
||||
|
@ -46,28 +45,6 @@ bool Controller::IsConnected()
|
|||
return _is_connected;
|
||||
}
|
||||
|
||||
void Controller::SetHidden(bool state)
|
||||
{
|
||||
_hidden = state;
|
||||
}
|
||||
|
||||
void Controller::RegisterGrabbedOverlay(Overlay *overlay)
|
||||
{
|
||||
_grabbed_overlays.push_back(overlay);
|
||||
}
|
||||
|
||||
void Controller::ReleaseOverlay(Overlay *overlay)
|
||||
{
|
||||
for (auto i = _grabbed_overlays.begin(); i != _grabbed_overlays.end(); i++)
|
||||
{
|
||||
if (*i == overlay)
|
||||
{
|
||||
_grabbed_overlays.erase(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::Update()
|
||||
{
|
||||
UpdateStatus();
|
||||
|
@ -95,25 +72,6 @@ void Controller::Update()
|
|||
ray.overlay->ControllerGrab(this);
|
||||
}
|
||||
}
|
||||
|
||||
if (!_grabbed_overlays.empty())
|
||||
{
|
||||
float move = _app->GetInputAnalog(_app->_input_handles.distance, _input_handle).y * 0.1; // TODO use frame time
|
||||
if (move != 0.0f)
|
||||
{
|
||||
// delta is calculated & clamped for first overlay so that child overlays don't move further than the root
|
||||
float main_z = _grabbed_overlays[0]->GetTarget()->transform.m[2][3];
|
||||
float new_main_z = glm::clamp(main_z - move, -5.0f, -0.1f);
|
||||
float real_delta = new_main_z - main_z;
|
||||
|
||||
for (auto overlay : _grabbed_overlays)
|
||||
{
|
||||
auto transform = overlay->GetTarget()->transform;
|
||||
transform.m[2][3] += real_delta;
|
||||
overlay->SetTransformTracker(_device_index, &transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::UpdateStatus()
|
||||
|
@ -133,5 +91,5 @@ void Controller::UpdateStatus()
|
|||
_device_index = _app->vr_sys->GetTrackedDeviceIndexForControllerRole(vr::TrackedControllerRole_RightHand);
|
||||
}
|
||||
_is_connected &= _device_index < MAX_TRACKERS;
|
||||
_laser.SetHidden(!_is_connected || _hidden);
|
||||
_laser.SetHidden(!_is_connected);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
#include "overlay.h"
|
||||
#include "util.h"
|
||||
#include <vector>
|
||||
|
||||
class App;
|
||||
|
||||
|
@ -21,11 +20,6 @@ class Controller
|
|||
|
||||
bool IsConnected();
|
||||
|
||||
void SetHidden(bool state);
|
||||
|
||||
void RegisterGrabbedOverlay(Overlay *overlay);
|
||||
void ReleaseOverlay(Overlay *overlay);
|
||||
|
||||
void Update();
|
||||
void UpdateStatus();
|
||||
|
||||
|
@ -36,6 +30,4 @@ class Controller
|
|||
TrackerID _device_index;
|
||||
vr::VRInputValueHandle_t _input_handle;
|
||||
bool _is_connected;
|
||||
bool _hidden;
|
||||
std::vector<Overlay *> _grabbed_overlays;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "app.h"
|
||||
#include <signal.h>
|
||||
|
||||
#define UPDATE_RATE 60
|
||||
#define FRAMERATE 30
|
||||
|
||||
bool should_exit = false;
|
||||
|
||||
|
@ -19,7 +19,7 @@ int main()
|
|||
while (!should_exit)
|
||||
{
|
||||
app.Update();
|
||||
usleep(1000000 / UPDATE_RATE);
|
||||
usleep(1000000 / FRAMERATE);
|
||||
}
|
||||
printf("\nShutting down\n");
|
||||
return 0;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "app.h"
|
||||
#include "util.h"
|
||||
#include <cstdint>
|
||||
#include <glm/fwd.hpp>
|
||||
|
||||
Overlay::Overlay()
|
||||
{
|
||||
|
@ -16,18 +17,25 @@ Overlay::Overlay(App *app, std::string name)
|
|||
_holding_controller = nullptr;
|
||||
_width_m = 1;
|
||||
_ratio = 1;
|
||||
_hidden = false;
|
||||
|
||||
_target = Target{.type = TargetType::World, .transform = VRMatIdentity};
|
||||
_target.type = TargetType::World;
|
||||
|
||||
auto overlay_create_err = _app->vr_overlay->CreateOverlay(_name.c_str(), _name.c_str(), &_id);
|
||||
assert(overlay_create_err == 0);
|
||||
{
|
||||
vr::ETrackingUniverseOrigin origin;
|
||||
_app->vr_overlay->GetOverlayTransformAbsolute(_id, &origin, &_target.transform);
|
||||
}
|
||||
|
||||
uint8_t col[4] = {20, 50, 50, 255};
|
||||
_app->vr_overlay->SetOverlayRaw(_id, &col, 1, 1, 4);
|
||||
printf("Created overlay instance %s\n", _name.c_str());
|
||||
|
||||
// (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);
|
||||
_hidden = false;
|
||||
_app->vr_overlay->ShowOverlay(_id);
|
||||
printf("Created overlay instance %s\n", _name.c_str());
|
||||
}
|
||||
|
||||
OverlayID Overlay::Id()
|
||||
|
@ -125,10 +133,11 @@ void Overlay::SetTransformWorld(const VRMat *transform)
|
|||
void Overlay::SetTargetWorld()
|
||||
{
|
||||
auto abs_pose = ConvertMat(GetTransformAbsolute());
|
||||
SetTransformWorld(&abs_pose);
|
||||
_app->vr_overlay->SetOverlayTransformAbsolute(_id, vr::TrackingUniverseStanding, &abs_pose);
|
||||
_target.type = TargetType::World;
|
||||
}
|
||||
|
||||
Ray Overlay::IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len)
|
||||
float Overlay::IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len)
|
||||
{
|
||||
float closest_dist = max_len;
|
||||
auto end = origin + direction * max_len;
|
||||
|
@ -153,7 +162,7 @@ Ray Overlay::IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len)
|
|||
closest_dist = dist;
|
||||
}
|
||||
}
|
||||
return Ray{.overlay = this, .distance = closest_dist};
|
||||
return closest_dist;
|
||||
}
|
||||
|
||||
glm::mat4x4 Overlay::GetTransformAbsolute()
|
||||
|
@ -189,11 +198,6 @@ glm::mat4x4 Overlay::GetTransformAbsolute()
|
|||
}
|
||||
}
|
||||
|
||||
Target *Overlay::GetTarget()
|
||||
{
|
||||
return &_target;
|
||||
}
|
||||
|
||||
void Overlay::Update()
|
||||
{
|
||||
if (!_initialized)
|
||||
|
@ -213,20 +217,14 @@ void Overlay::Update()
|
|||
|
||||
void Overlay::ControllerGrab(Controller *controller)
|
||||
{
|
||||
if (_holding_controller != nullptr)
|
||||
{
|
||||
_holding_controller->ReleaseOverlay(this);
|
||||
}
|
||||
|
||||
_app->vr_overlay->SetOverlayColor(_id, 0.6f, 0.8f, 0.8f);
|
||||
|
||||
auto abs_mat = GetTransformAbsolute();
|
||||
auto controller_mat = _app->GetTrackerPose(controller->DeviceIndex());
|
||||
VRMat relative_pose = ConvertMat(glm::inverse(controller_mat) * abs_mat);
|
||||
|
||||
SetTransformTracker(controller->DeviceIndex(), &relative_pose);
|
||||
_app->vr_overlay->SetOverlayTransformTrackedDeviceRelative(_id, controller->DeviceIndex(), &relative_pose);
|
||||
|
||||
controller->RegisterGrabbedOverlay(this);
|
||||
if (_GrabBeginCallback != nullptr)
|
||||
{
|
||||
_GrabBeginCallback(controller);
|
||||
|
@ -237,14 +235,10 @@ void Overlay::ControllerGrab(Controller *controller)
|
|||
|
||||
void Overlay::ControllerRelease()
|
||||
{
|
||||
if (_holding_controller != nullptr)
|
||||
{
|
||||
_holding_controller->ReleaseOverlay(this);
|
||||
}
|
||||
_app->vr_overlay->SetOverlayColor(_id, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
auto new_pose = ConvertMat(GetTransformAbsolute());
|
||||
SetTransformWorld(&new_pose);
|
||||
_app->vr_overlay->SetOverlayTransformAbsolute(_id, _app->_tracking_origin, &new_pose);
|
||||
|
||||
if (_GrabEndCallback != nullptr)
|
||||
{
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include <string>
|
||||
|
||||
class App;
|
||||
struct Ray;
|
||||
class Controller;
|
||||
|
||||
enum class TargetType
|
||||
|
@ -44,7 +43,6 @@ class Overlay
|
|||
void SetTextureToColor(uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
glm::mat4x4 GetTransformAbsolute();
|
||||
Target *GetTarget();
|
||||
|
||||
void SetTransformTracker(TrackerID tracker, const VRMat *transform);
|
||||
void SetTransformWorld(const VRMat *transform);
|
||||
|
@ -52,7 +50,7 @@ class Overlay
|
|||
// void SetTargetTracker(TrackerID tracker);
|
||||
void SetTargetWorld();
|
||||
|
||||
Ray IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len);
|
||||
float IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len);
|
||||
|
||||
std::function<void(Controller *)> _GrabBeginCallback;
|
||||
std::function<void()> _GrabEndCallback;
|
||||
|
|
|
@ -23,7 +23,6 @@ Panel::Panel(App *app, int index, int x, int y, int width, int height)
|
|||
_texture.eType = vr::TextureType_OpenGL;
|
||||
_texture.handle = (void *)(uintptr_t)_gl_texture;
|
||||
_overlay.SetRatio(height / (float)width);
|
||||
_overlay.SetTextureToColor(50, 20, 50);
|
||||
}
|
||||
|
||||
void Panel::Update()
|
||||
|
|
Loading…
Reference in a new issue