mirror of
https://github.com/CrispyPin/sinpin-vr.git
synced 2024-11-12 21:20:27 +01:00
push&pull overlays while moving them
This commit is contained in:
parent
14b5c8f745
commit
00566021a0
7 changed files with 76 additions and 17 deletions
|
@ -1,3 +1,3 @@
|
||||||
# ovr-screen
|
# ovr-screen
|
||||||
A SteamVR overlay for Linux+X11 that displays the screen in VR.
|
A SteamVR overlay for Linux+X11 that displays all your screens in VR.
|
||||||
|
|
||||||
|
|
22
src/app.cpp
22
src/app.cpp
|
@ -115,7 +115,7 @@ void App::InitGLFW()
|
||||||
void App::InitRootOverlay()
|
void App::InitRootOverlay()
|
||||||
{
|
{
|
||||||
_root_overlay = Overlay(this, "root");
|
_root_overlay = Overlay(this, "root");
|
||||||
_root_overlay.SetAlpha(0.2f);
|
_root_overlay.SetAlpha(0.5f);
|
||||||
// clang-format off
|
// clang-format off
|
||||||
VRMat root_start_pose = {{
|
VRMat root_start_pose = {{
|
||||||
{0.25f, 0.0f, 0.0f, 0},
|
{0.25f, 0.0f, 0.0f, 0},
|
||||||
|
@ -124,6 +124,7 @@ void App::InitRootOverlay()
|
||||||
}};
|
}};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
_root_overlay.SetTransformWorld(&root_start_pose);
|
_root_overlay.SetTransformWorld(&root_start_pose);
|
||||||
|
_root_overlay.SetTextureToColor(110, 30, 190);
|
||||||
|
|
||||||
_root_overlay._GrabBeginCallback = [this](Controller *controller) {
|
_root_overlay._GrabBeginCallback = [this](Controller *controller) {
|
||||||
for (auto &panel : _panels)
|
for (auto &panel : _panels)
|
||||||
|
@ -175,6 +176,8 @@ void App::UpdateInput()
|
||||||
{
|
{
|
||||||
panel.SetHidden(_hidden);
|
panel.SetHidden(_hidden);
|
||||||
}
|
}
|
||||||
|
_controllers[0]->SetHidden(_hidden);
|
||||||
|
_controllers[1]->SetHidden(_hidden);
|
||||||
}
|
}
|
||||||
_controllers[0]->Update();
|
_controllers[0]->Update();
|
||||||
_controllers[1]->Update();
|
_controllers[1]->Update();
|
||||||
|
@ -232,22 +235,19 @@ Ray App::IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len)
|
||||||
Ray ray;
|
Ray ray;
|
||||||
ray.distance = max_len;
|
ray.distance = max_len;
|
||||||
ray.overlay = nullptr;
|
ray.overlay = nullptr;
|
||||||
|
|
||||||
|
auto r_root = _root_overlay.IntersectRay(origin, direction, max_len);
|
||||||
|
if (r_root.distance < ray.distance)
|
||||||
{
|
{
|
||||||
float root_dist = _root_overlay.IntersectRay(origin, direction, max_len);
|
ray = r_root;
|
||||||
if (root_dist < ray.distance)
|
|
||||||
{
|
|
||||||
ray.distance = root_dist;
|
|
||||||
ray.overlay = &_root_overlay;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &panel : _panels)
|
for (auto &panel : _panels)
|
||||||
{
|
{
|
||||||
float dist = panel.GetOverlay()->IntersectRay(origin, direction, max_len);
|
auto r_panel = panel.GetOverlay()->IntersectRay(origin, direction, max_len);
|
||||||
if (dist < ray.distance)
|
if (r_panel.distance < ray.distance)
|
||||||
{
|
{
|
||||||
ray.distance = dist;
|
ray = r_panel;
|
||||||
ray.overlay = panel.GetOverlay();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ray;
|
return ray;
|
||||||
|
|
|
@ -28,6 +28,7 @@ struct Ray
|
||||||
{
|
{
|
||||||
Overlay *overlay;
|
Overlay *overlay;
|
||||||
float distance;
|
float distance;
|
||||||
|
// glm::vec3 pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
class App
|
class App
|
||||||
|
|
|
@ -12,6 +12,7 @@ Controller::Controller(App *app, ControllerSide side)
|
||||||
_input_handle = 0;
|
_input_handle = 0;
|
||||||
_is_connected = false;
|
_is_connected = false;
|
||||||
_side = side;
|
_side = side;
|
||||||
|
_hidden = false;
|
||||||
|
|
||||||
std::string laser_name = "controller_laser_";
|
std::string laser_name = "controller_laser_";
|
||||||
if (side == ControllerSide::Left)
|
if (side == ControllerSide::Left)
|
||||||
|
@ -45,6 +46,28 @@ bool Controller::IsConnected()
|
||||||
return _is_connected;
|
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()
|
void Controller::Update()
|
||||||
{
|
{
|
||||||
UpdateStatus();
|
UpdateStatus();
|
||||||
|
@ -72,6 +95,24 @@ void Controller::Update()
|
||||||
ray.overlay->ControllerGrab(this);
|
ray.overlay->ControllerGrab(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_grabbed_overlays.empty())
|
||||||
|
{
|
||||||
|
float move = _app->GetInputAnalog(_app->_input_handles.distance).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)
|
||||||
|
{
|
||||||
|
overlay->GetTarget()->transform.m[2][3] += real_delta;
|
||||||
|
_app->vr_overlay->SetOverlayTransformTrackedDeviceRelative(overlay->Id(), _device_index, &overlay->GetTarget()->transform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::UpdateStatus()
|
void Controller::UpdateStatus()
|
||||||
|
@ -91,5 +132,5 @@ void Controller::UpdateStatus()
|
||||||
_device_index = _app->vr_sys->GetTrackedDeviceIndexForControllerRole(vr::TrackedControllerRole_RightHand);
|
_device_index = _app->vr_sys->GetTrackedDeviceIndexForControllerRole(vr::TrackedControllerRole_RightHand);
|
||||||
}
|
}
|
||||||
_is_connected &= _device_index < MAX_TRACKERS;
|
_is_connected &= _device_index < MAX_TRACKERS;
|
||||||
_laser.SetHidden(!_is_connected);
|
_laser.SetHidden(!_is_connected || _hidden);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "overlay.h"
|
#include "overlay.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class App;
|
class App;
|
||||||
|
|
||||||
|
@ -20,6 +21,11 @@ class Controller
|
||||||
|
|
||||||
bool IsConnected();
|
bool IsConnected();
|
||||||
|
|
||||||
|
void SetHidden(bool state);
|
||||||
|
|
||||||
|
void RegisterGrabbedOverlay(Overlay *overlay);
|
||||||
|
void ReleaseOverlay(Overlay *overlay);
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
void UpdateStatus();
|
void UpdateStatus();
|
||||||
|
|
||||||
|
@ -30,4 +36,6 @@ class Controller
|
||||||
TrackerID _device_index;
|
TrackerID _device_index;
|
||||||
vr::VRInputValueHandle_t _input_handle;
|
vr::VRInputValueHandle_t _input_handle;
|
||||||
bool _is_connected;
|
bool _is_connected;
|
||||||
|
bool _hidden;
|
||||||
|
std::vector<Overlay *> _grabbed_overlays;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <glm/fwd.hpp>
|
|
||||||
|
|
||||||
Overlay::Overlay()
|
Overlay::Overlay()
|
||||||
{
|
{
|
||||||
|
@ -137,7 +136,7 @@ void Overlay::SetTargetWorld()
|
||||||
_target.type = TargetType::World;
|
_target.type = TargetType::World;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Overlay::IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len)
|
Ray Overlay::IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len)
|
||||||
{
|
{
|
||||||
float closest_dist = max_len;
|
float closest_dist = max_len;
|
||||||
auto end = origin + direction * max_len;
|
auto end = origin + direction * max_len;
|
||||||
|
@ -162,7 +161,7 @@ float Overlay::IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len
|
||||||
closest_dist = dist;
|
closest_dist = dist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return closest_dist;
|
return Ray{.overlay = this, .distance = closest_dist /* , .pos = p */};
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4x4 Overlay::GetTransformAbsolute()
|
glm::mat4x4 Overlay::GetTransformAbsolute()
|
||||||
|
@ -198,6 +197,11 @@ glm::mat4x4 Overlay::GetTransformAbsolute()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Target *Overlay::GetTarget()
|
||||||
|
{
|
||||||
|
return &_target;
|
||||||
|
}
|
||||||
|
|
||||||
void Overlay::Update()
|
void Overlay::Update()
|
||||||
{
|
{
|
||||||
if (!_initialized)
|
if (!_initialized)
|
||||||
|
@ -224,7 +228,9 @@ void Overlay::ControllerGrab(Controller *controller)
|
||||||
VRMat relative_pose = ConvertMat(glm::inverse(controller_mat) * abs_mat);
|
VRMat relative_pose = ConvertMat(glm::inverse(controller_mat) * abs_mat);
|
||||||
|
|
||||||
_app->vr_overlay->SetOverlayTransformTrackedDeviceRelative(_id, controller->DeviceIndex(), &relative_pose);
|
_app->vr_overlay->SetOverlayTransformTrackedDeviceRelative(_id, controller->DeviceIndex(), &relative_pose);
|
||||||
|
_target.transform = relative_pose;
|
||||||
|
|
||||||
|
controller->RegisterGrabbedOverlay(this);
|
||||||
if (_GrabBeginCallback != nullptr)
|
if (_GrabBeginCallback != nullptr)
|
||||||
{
|
{
|
||||||
_GrabBeginCallback(controller);
|
_GrabBeginCallback(controller);
|
||||||
|
@ -235,6 +241,7 @@ void Overlay::ControllerGrab(Controller *controller)
|
||||||
|
|
||||||
void Overlay::ControllerRelease()
|
void Overlay::ControllerRelease()
|
||||||
{
|
{
|
||||||
|
_holding_controller->ReleaseOverlay(this);
|
||||||
_app->vr_overlay->SetOverlayColor(_id, 1.0f, 1.0f, 1.0f);
|
_app->vr_overlay->SetOverlayColor(_id, 1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
auto new_pose = ConvertMat(GetTransformAbsolute());
|
auto new_pose = ConvertMat(GetTransformAbsolute());
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class App;
|
class App;
|
||||||
|
struct Ray;
|
||||||
class Controller;
|
class Controller;
|
||||||
|
|
||||||
enum class TargetType
|
enum class TargetType
|
||||||
|
@ -43,6 +44,7 @@ class Overlay
|
||||||
void SetTextureToColor(uint8_t r, uint8_t g, uint8_t b);
|
void SetTextureToColor(uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
|
||||||
glm::mat4x4 GetTransformAbsolute();
|
glm::mat4x4 GetTransformAbsolute();
|
||||||
|
Target *GetTarget();
|
||||||
|
|
||||||
void SetTransformTracker(TrackerID tracker, const VRMat *transform);
|
void SetTransformTracker(TrackerID tracker, const VRMat *transform);
|
||||||
void SetTransformWorld(const VRMat *transform);
|
void SetTransformWorld(const VRMat *transform);
|
||||||
|
@ -50,7 +52,7 @@ class Overlay
|
||||||
// void SetTargetTracker(TrackerID tracker);
|
// void SetTargetTracker(TrackerID tracker);
|
||||||
void SetTargetWorld();
|
void SetTargetWorld();
|
||||||
|
|
||||||
float IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len);
|
Ray IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len);
|
||||||
|
|
||||||
std::function<void(Controller *)> _GrabBeginCallback;
|
std::function<void(Controller *)> _GrabBeginCallback;
|
||||||
std::function<void()> _GrabEndCallback;
|
std::function<void()> _GrabEndCallback;
|
||||||
|
|
Loading…
Reference in a new issue