Compare commits

..

No commits in common. "5f773e2d4d893d37a3cf471d5144a0e9e5b03ed5" and "286c1d08a7fc012c262b047d63b53a58968dbfcb" have entirely different histories.

12 changed files with 99 additions and 843 deletions

3
.gitignore vendored
View file

@ -1,3 +1,2 @@
sinpin_vr
overlay
.vscode/
*.zip

View file

@ -1,18 +1,18 @@
VERSION=v0.1.0
# CC := g++
CC := clang++
LFLAGS := -lX11 -lXrandr -lglfw -lGL
LIBS := openvr/libopenvr_api.so
SRC := src/*.cpp
OUT := ./sinpin_vr
OUT := ./overlay
CPPFLAGS := -Wall -std=c++17 $(LFLAGS) $(LIBS) $(SRC) -o $(OUT)
build:
$(CC) -g $(CPPFLAGS)
release: build
zip -r sinpin_vr-$(VERSION).zip sinpin_vr bindings openvr/libopenvr_api.so
release:
$(CC) $(CPPFLAGS)
run: build
$(OUT)
./overlay

View file

@ -1,19 +1,5 @@
# sinpin-vr
# ovr-screen
A SteamVR overlay for Linux+X11 that displays all your screens in VR.
https://user-images.githubusercontent.com/54243225/233798783-27d1a6ae-b71d-448f-bb67-76015e539452.mp4
## features
- one overlay per screen
- shows cursor position
- global visibility toggle (default: long press left B)
- edit mode (default: long press right B)
- move screens around (default: trigger)
- resize screens (move with two controllers)
- push/pull screens (default: joystick up/down)
- move all screens at once with the same controls by grabbing the purple square
## performance
From my limited testing, this uses about half the CPU performance of Steam's built-in desktop overlay, if running at 60 FPS. Currently the default is 30 FPS which brings that factor to 3-4x. On my machine, the Steam desktop view increases cpu usage by about 100% of a CPU thread (looking only at the `steam` process), while this overlay uses around 25% at 30 FPS and 45% at 60 FPS.
From my limited testing, this uses about half the CPU performance of Steam's built-in desktop overlay, if running at 60 FPS. Currently the default is 30 FPS which brings the factor to 3-4x. On my machine, the Steam desktop view increases cpu usage by about 100% of a CPU thread (looking only at the `steam` process), while this overlay uses around 25% at 30 FPS and 45% at 60 FPS.

View file

@ -7,22 +7,17 @@
],
"actions": [
{
"name": "/actions/main/in/toggle_visibility",
"name": "/actions/main/in/ToggleAll",
"requirement": "mandatory",
"type": "boolean"
},
{
"name": "/actions/main/in/edit_mode",
"name": "/actions/main/in/Grab",
"requirement": "mandatory",
"type": "boolean"
},
{
"name": "/actions/main/in/grab",
"requirement": "mandatory",
"type": "boolean"
},
{
"name": "/actions/main/in/distance",
"name": "/actions/main/in/Distance",
"requirement": "suggested",
"type": "vector2"
}
@ -37,10 +32,9 @@
{
"language_tag": "en_us",
"/actions/main": "Overlay actions",
"/actions/main/in/toggle_visibility": "Toggle visibility",
"/actions/main/in/edit_mode": "Toggle edit mode",
"/actions/main/in/grab": "grab panel",
"/actions/main/in/distance": "Move away"
"/actions/main/in/ToggleAll": "Toggle all",
"/actions/main/in/Grab": "Grab panel",
"/actions/main/in/Distance": "Move away"
}
]
}

View file

@ -1,658 +1,33 @@
{
"action_manifest_version" : 0,
"alias_info" : {
"/actions/legacy/in/head_proximity" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/left_axis2_press" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/left_axis2_touch" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/left_axis3_press" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/left_axis3_touch" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/left_axis3_value_e0" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/left_axis3_value_e1" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/left_axis4_press" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/left_axis4_touch" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/left_axis4_value_e0" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/left_axis4_value_e1" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/left_system_press" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/left_system_touch" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/right_axis3_press" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/right_axis3_touch" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/right_axis3_value_e0" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/right_axis3_value_e1" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/right_axis4_press" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/right_axis4_touch" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/right_axis4_value_e0" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/right_axis4_value_e1" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/right_system_press" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy/in/right_system_touch" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy_mirrored/in/axis2_press" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy_mirrored/in/axis2_touch" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy_mirrored/in/axis3_press" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy_mirrored/in/axis3_touch" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy_mirrored/in/axis3_value_e0" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy_mirrored/in/axis3_value_e1" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy_mirrored/in/axis4_press" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy_mirrored/in/axis4_touch" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy_mirrored/in/axis4_value_e0" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy_mirrored/in/axis4_value_e1" : {
"alias_name" : "",
"hidden" : true
},
"/actions/legacy_mirrored/in/system_press" : {
"alias_name" : "",
"hidden" : true
}
},
"app_key" : "system.generated.overlay",
"bindings" : {
"/actions/legacy" : {
"haptics" : [
{
"output" : "/actions/legacy/out/left_haptic",
"path" : "/user/hand/left/output/haptic"
},
{
"output" : "/actions/legacy/out/right_haptic",
"path" : "/user/hand/right/output/haptic"
}
],
"poses" : [
{
"output" : "/actions/legacy/in/Left_Pose",
"path" : "/user/hand/left/pose/raw"
},
{
"output" : "/actions/legacy/in/Right_Pose",
"path" : "/user/hand/right/pose/raw"
}
],
"sources" : [
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/left_system_press"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/system"
},
{
"inputs" : {
"pull" : {
"output" : "/actions/legacy/in/left_axis1_value"
},
"touch" : {
"output" : "/actions/legacy/in/left_axis1_touch"
}
},
"mode" : "trigger",
"path" : "/user/hand/left/input/trigger"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/right_system_press"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/system"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/right_grip_press"
},
"touch" : {
"output" : "/actions/legacy/in/right_grip_touch"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/a"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/left_grip_press"
},
"touch" : {
"output" : "/actions/legacy/in/left_grip_touch"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/a"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/left_applicationmenu_press"
},
"touch" : {
"output" : "/actions/legacy/in/left_applicationmenu_touch"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/b"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/right_applicationmenu_press"
},
"touch" : {
"output" : "/actions/legacy/in/right_applicationmenu_touch"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/b"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/left_axis0_press"
},
"position" : {
"output" : "/actions/legacy/in/left_axis0_value"
},
"touch" : {
"output" : "/actions/legacy/in/left_axis0_touch"
}
},
"mode" : "trackpad",
"path" : "/user/hand/left/input/trackpad"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/right_axis0_press"
},
"position" : {
"output" : "/actions/legacy/in/right_axis0_value"
},
"touch" : {
"output" : "/actions/legacy/in/right_axis0_touch"
}
},
"mode" : "trackpad",
"path" : "/user/hand/right/input/trackpad"
},
{
"inputs" : {
"pull" : {
"output" : "/actions/legacy/in/right_axis1_value"
},
"touch" : {
"output" : "/actions/legacy/in/right_axis1_touch"
}
},
"mode" : "trigger",
"path" : "/user/hand/right/input/trigger"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/left_axis1_press"
},
"touch" : {
"output" : "/actions/legacy/in/left_axis1_touch"
}
},
"mode" : "button",
"parameters" : {
"click_activate_threshold" : "0.55",
"click_deactivate_threshold" : "0.5",
"haptic_amplitude" : "0",
"touch_activate_threshold" : "0.1",
"touch_deactivate_threshold" : "0.05"
},
"path" : "/user/hand/left/input/trigger"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/right_axis1_press"
},
"touch" : {
"output" : "/actions/legacy/in/right_axis1_touch"
}
},
"mode" : "button",
"parameters" : {
"click_activate_threshold" : "0.55",
"click_deactivate_threshold" : "0.5",
"haptic_amplitude" : "0",
"touch_activate_threshold" : "0.1",
"touch_deactivate_threshold" : "0.05"
},
"path" : "/user/hand/right/input/trigger"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/left_axis0_press"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/trackpad"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/right_axis0_press"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/trackpad"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/left_axis0_press"
},
"position" : {
"output" : "/actions/legacy/in/left_axis0_value"
},
"touch" : {
"output" : "/actions/legacy/in/left_axis0_touch"
}
},
"mode" : "joystick",
"path" : "/user/hand/left/input/thumbstick"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/right_axis0_press"
},
"position" : {
"output" : "/actions/legacy/in/right_axis0_value"
},
"touch" : {
"output" : "/actions/legacy/in/right_axis0_touch"
}
},
"mode" : "joystick",
"path" : "/user/hand/right/input/thumbstick"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/left_axis0_press"
}
},
"mode" : "button",
"parameters" : {
"click_activate_threshold" : 0.80000000000000004,
"click_deactivate_threshold" : 0.69999999999999996,
"force_input" : "position",
"haptic_amplitude" : 0
},
"path" : "/user/hand/left/input/thumbstick"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/right_axis0_press"
}
},
"mode" : "button",
"parameters" : {
"click_activate_threshold" : 0.80000000000000004,
"click_deactivate_threshold" : 0.69999999999999996,
"force_input" : "position",
"haptic_amplitude" : 0
},
"path" : "/user/hand/right/input/thumbstick"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/left_grip_press"
},
"touch" : {
"output" : "/actions/legacy/in/left_grip_touch"
}
},
"mode" : "button",
"parameters" : {
"click_activate_threshold" : "0.8",
"force_input" : "force"
},
"path" : "/user/hand/left/input/grip"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy/in/right_grip_press"
},
"touch" : {
"output" : "/actions/legacy/in/right_grip_touch"
}
},
"mode" : "button",
"parameters" : {
"click_activate_threshold" : "0.8",
"force_input" : "force"
},
"path" : "/user/hand/right/input/grip"
}
]
},
"/actions/legacy_mirrored" : {
"haptics" : [
{
"output" : "/actions/legacy_mirrored/out/haptic",
"path" : "/user/hand/left/output/haptic"
},
{
"output" : "/actions/legacy_mirrored/out/haptic",
"path" : "/user/hand/right/output/haptic"
}
],
"poses" : [
{
"output" : "/actions/legacy_mirrored/in/pose",
"path" : "/user/hand/left/pose/raw"
},
{
"output" : "/actions/legacy_mirrored/in/pose",
"path" : "/user/hand/right/pose/raw"
}
],
"sources" : [
{
"inputs" : {
"click" : {
"output" : "/actions/legacy_mirrored/in/axis1_press"
},
"pull" : {
"output" : "/actions/legacy_mirrored/in/axis1_value"
},
"touch" : {
"output" : "/actions/legacy_mirrored/in/axis1_touch"
}
},
"mode" : "trigger",
"path" : "/user/hand/left/input/trigger"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy_mirrored/in/axis1_press"
},
"pull" : {
"output" : "/actions/legacy_mirrored/in/axis1_value"
},
"touch" : {
"output" : "/actions/legacy_mirrored/in/axis1_touch"
}
},
"mode" : "trigger",
"path" : "/user/hand/right/input/trigger"
},
{
"inputs" : {
"position" : {
"output" : "/actions/legacy_mirrored/in/axis0_value"
},
"touch" : {
"output" : "/actions/legacy_mirrored/in/axis0_touch"
}
},
"mode" : "trackpad",
"path" : "/user/hand/left/input/trackpad"
},
{
"inputs" : {
"position" : {
"output" : "/actions/legacy_mirrored/in/axis0_value"
},
"touch" : {
"output" : "/actions/legacy_mirrored/in/axis0_touch"
}
},
"mode" : "trackpad",
"path" : "/user/hand/right/input/trackpad"
},
{
"inputs" : {},
"mode" : "joystick",
"path" : "/user/hand/left/input/thumbstick"
},
{
"inputs" : {},
"mode" : "joystick",
"path" : "/user/hand/right/input/thumbstick"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy_mirrored/in/grip_press"
},
"touch" : {
"output" : "/actions/legacy_mirrored/in/grip_touch"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/a"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy_mirrored/in/grip_press"
},
"touch" : {
"output" : "/actions/legacy_mirrored/in/grip_touch"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/a"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy_mirrored/in/applicationmenu_press"
},
"touch" : {
"output" : "/actions/legacy_mirrored/in/applicationmenu_touch"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/b"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy_mirrored/in/applicationmenu_press"
},
"touch" : {
"output" : "/actions/legacy_mirrored/in/applicationmenu_touch"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/b"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy_mirrored/in/axis0_press"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/trackpad"
},
{
"inputs" : {
"click" : {
"output" : "/actions/legacy_mirrored/in/axis0_press"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/trackpad"
}
]
},
"/actions/main" : {
"sources" : [
{
"inputs" : {
"long" : {
"output" : "/actions/main/in/edit_mode"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/b"
},
{
"inputs" : {
"position" : {
"output" : "/actions/main/in/distance"
}
},
"mode" : "joystick",
"path" : "/user/hand/right/input/thumbstick"
},
{
"inputs" : {
"click" : {
"output" : "/actions/main/in/grab"
}
},
"mode" : "button",
"path" : "/user/hand/right/input/trigger"
},
{
"inputs" : {
"click" : {
"output" : "/actions/main/in/grab"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/trigger"
},
{
"inputs" : {
"long" : {
"output" : "/actions/main/in/toggle_visibility"
}
},
"mode" : "button",
"path" : "/user/hand/left/input/b"
},
{
"inputs" : {
"position" : {
"output" : "/actions/main/in/distance"
}
},
"mode" : "joystick",
"path" : "/user/hand/left/input/thumbstick"
}
]
}
},
"category" : "steamvr_input",
"controller_type" : "knuckles",
"description" : "Default binding values for legacy apps using the Index Controller",
"interaction_profile" : "",
"name" : "Saved overlay configuration for Index Controller",
"options" : {
"mirror_actions" : true,
"simulated_controller_type" : "none"
},
"simulated_actions" : []
"/actions/main": {
"sources": [
{
"path": "/user/hand/right/input/b",
"mode": "button",
"inputs": {
"long": {
"output": "/actions/main/in/toggleall"
}
}
},
{
"path": "/user/hand/right/input/thumbstick",
"mode": "joystick",
"inputs": {
"position": {
"output": "/actions/main/in/distance"
}
}
},
{
"path": "/user/hand/right/input/trigger",
"mode": "button",
"inputs": {
"click": {
"output": "/actions/main/in/grab"
}
}
}
]
}
}

View file

@ -57,13 +57,11 @@ App::App()
printf("actions path: %s\n", _actions_path.c_str());
vr_input->SetActionManifestPath(_actions_path.c_str());
auto action_err = vr_input->GetActionHandle("/actions/main/in/grab", &_input_handles.grab);
auto action_err = vr_input->GetActionHandle("/actions/main/in/Grab", &_input_handles.grab);
assert(action_err == 0);
action_err = vr_input->GetActionHandle("/actions/main/in/toggle_visibility", &_input_handles.toggle_hidden);
action_err = vr_input->GetActionHandle("/actions/main/in/ToggleAll", &_input_handles.toggle);
assert(action_err == 0);
action_err = vr_input->GetActionHandle("/actions/main/in/edit_mode", &_input_handles.edit_mode);
assert(action_err == 0);
action_err = vr_input->GetActionHandle("/actions/main/in/distance", &_input_handles.distance);
action_err = vr_input->GetActionHandle("/actions/main/in/Distance", &_input_handles.distance);
assert(action_err == 0);
action_err = vr_input->GetActionSetHandle("/actions/main", &_input_handles.set);
assert(action_err == 0);
@ -164,29 +162,19 @@ void App::UpdateInput()
vr_sys->GetDeviceToAbsoluteTrackingPose(_tracking_origin, 0, _tracker_poses, MAX_TRACKERS);
if (IsInputJustPressed(_input_handles.toggle_hidden))
if (IsInputJustPressed(_input_handles.toggle))
{
_hidden = !_hidden;
_root_overlay.SetHidden(_hidden);
for (auto &panel : _panels)
{
panel.SetHidden(_hidden);
}
_root_overlay.SetHidden(_hidden || !_edit_mode);
_controllers[0]->SetHidden(_hidden || !_edit_mode);
_controllers[1]->SetHidden(_hidden || !_edit_mode);
}
if (!_hidden && IsInputJustPressed(_input_handles.edit_mode))
{
_edit_mode = !_edit_mode;
_root_overlay.SetHidden(_hidden || !_edit_mode);
_controllers[0]->SetHidden(_hidden || !_edit_mode);
_controllers[1]->SetHidden(_hidden || !_edit_mode);
}
if (_edit_mode)
{
_controllers[0]->Update();
_controllers[1]->Update();
_controllers[0]->SetHidden(_hidden);
_controllers[1]->SetHidden(_hidden);
}
_controllers[0]->Update();
_controllers[1]->Update();
}
void App::UpdateFramebuffer()

View file

@ -19,10 +19,15 @@ struct CursorPos
struct InputHandles
{
vr::VRActionSetHandle_t set;
vr::VRActionHandle_t toggle_hidden;
vr::VRActionHandle_t toggle;
vr::VRActionHandle_t distance;
vr::VRActionHandle_t grab;
vr::VRActionHandle_t edit_mode;
};
struct Ray
{
Overlay *overlay;
float distance;
};
class App
@ -64,7 +69,6 @@ class App
Overlay _root_overlay;
std::vector<Panel> _panels;
bool _hidden = false;
bool _edit_mode = false;
private:
void InitX11();

View file

@ -25,7 +25,6 @@ Controller::Controller(App *app, ControllerSide side)
UpdateStatus();
_laser.SetTextureToColor(255, 200, 255);
_laser.SetAlpha(0.2f);
_laser.SetHidden(true);
}
TrackerID Controller::DeviceIndex()
@ -51,7 +50,6 @@ bool Controller::IsConnected()
void Controller::SetHidden(bool state)
{
_hidden = state;
_laser.SetHidden(_hidden);
}
void Controller::ReleaseOverlay()
@ -59,21 +57,6 @@ void Controller::ReleaseOverlay()
_grabbed_overlay = nullptr;
}
Ray Controller::GetLastRay()
{
return _last_ray;
}
glm::vec3 Controller::GetLastPos()
{
return _last_pos;
}
glm::vec3 Controller::GetLastRot()
{
return _last_rotation;
}
void Controller::Update()
{
UpdateStatus();
@ -96,13 +79,9 @@ void Controller::UpdateLaser()
auto controller_pose = _app->GetTrackerPose(_device_index);
auto controller_pos = GetPos(controller_pose);
auto forward = -glm::vec3(controller_pose[2]);
auto ray = _app->IntersectRay(controller_pos, forward, 8.0f);
auto ray = _app->IntersectRay(controller_pos, forward, 5.0f);
float len = ray.distance;
_last_pos = controller_pos;
_last_rotation = forward;
_last_ray = ray;
auto hmd_global_pos = GetPos(_app->GetTrackerPose(0));
auto hmd_local_pos = glm::inverse(controller_pose) * glm::vec4(hmd_global_pos - controller_pos, 0);
hmd_local_pos.z = 0;
@ -117,7 +96,7 @@ void Controller::UpdateLaser()
{
if (ray.overlay->IsHeld())
{
ray.overlay->ControllerResize(this);
// TODO resize mode
}
else
{
@ -145,8 +124,5 @@ void Controller::UpdateStatus()
_device_index = _app->vr_sys->GetTrackedDeviceIndexForControllerRole(vr::TrackedControllerRole_RightHand);
}
_is_connected &= _device_index < MAX_TRACKERS;
if (!_is_connected)
{
_laser.SetHidden(true);
}
_laser.SetHidden(!_is_connected || _hidden);
}

View file

@ -20,9 +20,6 @@ class Controller
ControllerSide Side();
bool IsConnected();
Ray GetLastRay();
glm::vec3 GetLastPos();
glm::vec3 GetLastRot();
void SetHidden(bool state);
@ -42,7 +39,4 @@ class Controller
bool _is_connected;
bool _hidden;
Overlay *_grabbed_overlay;
Ray _last_ray;
glm::vec3 _last_rotation;
glm::vec3 _last_pos;
};

View file

@ -14,7 +14,6 @@ Overlay::Overlay(App *app, std::string name)
_name = name;
_app = app;
_holding_controller = nullptr;
_resize_controller = nullptr;
_width_m = 1;
_ratio = 1;
_hidden = false;
@ -150,7 +149,7 @@ void Overlay::SetTargetWorld()
Ray Overlay::IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len)
{
float dist = max_len;
float closest_dist = max_len;
auto end = origin + direction * max_len;
auto panel_transform = GetTransformAbsolute();
@ -167,30 +166,46 @@ Ray Overlay::IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len)
if (b.z < a.z && b.z < 0 && glm::abs(p.x) < (_width_m * 0.5f) && glm::abs(p.y) < (_width_m * 0.5f * _ratio))
{
dist = glm::min(r * max_len, max_len);
float dist = r * max_len;
if (dist < closest_dist)
{
closest_dist = dist;
}
}
return Ray{.overlay = this, .distance = dist};
return Ray{.overlay = this, .distance = closest_dist};
}
glm::mat4x4 Overlay::GetTransformAbsolute()
{
if (_target.type == TargetType::World)
if (_holding_controller != nullptr)
{
VRMat pose;
vr::ETrackingUniverseOrigin tracking_universe;
_app->vr_overlay->GetOverlayTransformAbsolute(_id, &tracking_universe, &pose);
return ConvertMat(pose);
}
if (_target.type == TargetType::Tracker)
{
VRMat pose;
_app->vr_overlay->GetOverlayTransformTrackedDeviceRelative(_id, &_target.id, &pose);
TrackerID tracker;
auto err = _app->vr_overlay->GetOverlayTransformTrackedDeviceRelative(_id, &tracker, &pose);
assert(err == 0);
auto offset = ConvertMat(pose);
auto tracker_pose = _app->GetTrackerPose(_target.id);
return tracker_pose * offset;
auto controller = _app->GetTrackerPose(_holding_controller->DeviceIndex());
return controller * offset;
}
else
{
switch (_target.type)
{
case TargetType::World: {
VRMat pose;
vr::ETrackingUniverseOrigin tracking_universe;
_app->vr_overlay->GetOverlayTransformAbsolute(_id, &tracking_universe, &pose);
return ConvertMat(pose);
}
case TargetType::Tracker: {
VRMat pose;
_app->vr_overlay->GetOverlayTransformTrackedDeviceRelative(_id, &_target.id, &pose);
auto offset = ConvertMat(pose);
auto tracker_pose = _app->GetTrackerPose(_target.id);
return tracker_pose * offset;
}
}
}
printf("Error: overlay '%s' not set to a valid target", _name.c_str());
return ConvertMat(VRMatIdentity);
}
Target *Overlay::GetTarget()
@ -208,41 +223,7 @@ void Overlay::Update()
if (_holding_controller != nullptr)
{
bool hold_controller_holding = _app->GetInputDigital(_app->_input_handles.grab, _holding_controller->InputHandle()).bState;
if (_resize_controller != nullptr)
{
bool resize_controller_holding = _app->GetInputDigital(_app->_input_handles.grab, _resize_controller->InputHandle()).bState;
if (!resize_controller_holding)
{
_resize_controller = nullptr;
}
else if (!hold_controller_holding)
{
_resize_controller = nullptr;
ControllerRelease();
}
else
{
auto pos_a = _holding_controller->GetLastPos() + _holding_controller->GetLastRot() * _resize_length_a;
auto pos_b = _resize_controller->GetLastPos() + _resize_controller->GetLastRot() * _resize_length_b;
float distance = glm::length(pos_a - pos_b);
float factor = (distance / _resize_base_distance);
float min_factor = 0.1f / _resize_original_size;
float max_factor = 5.0f / _resize_original_size;
factor = glm::clamp(factor, min_factor, max_factor);
float new_size = _resize_original_size * factor;
SetWidth(new_size);
auto transform = _target.transform;
auto pos = _resize_held_offset * factor;
transform.m[0][3] = pos.x;
transform.m[1][3] = pos.y;
SetTransformTracker(_holding_controller->DeviceIndex(), &transform);
}
}
else if (!hold_controller_holding)
if (!_app->GetInputDigital(_app->_input_handles.grab, _holding_controller->InputHandle()).bState)
{
ControllerRelease();
}
@ -283,33 +264,6 @@ void Overlay::ControllerRelease()
_holding_controller = nullptr;
}
void Overlay::ControllerResize(Controller *controller)
{
if (_resize_controller || controller == _holding_controller)
{
return;
}
for (auto child : _children)
{
if (!child->IsHeld())
{
child->SetTargetWorld();
}
}
_resize_controller = controller;
_resize_original_size = _width_m;
_resize_length_a = _holding_controller->GetLastRay().distance;
_resize_length_b = _resize_controller->GetLastRay().distance;
auto pos_a = _holding_controller->GetLastPos() + _holding_controller->GetLastRot() * _resize_length_a;
auto pos_b = _resize_controller->GetLastPos() + _resize_controller->GetLastRot() * _resize_length_b;
// distance between laser points
_resize_base_distance = glm::length(pos_a - pos_b);
_resize_held_offset = GetPos(_target.transform);
}
void Overlay::AddChildOverlay(Overlay *overlay)
{
_children.push_back(overlay);

View file

@ -55,9 +55,8 @@ class Overlay
Ray IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len);
void ControllerGrab(Controller *controller);
void ControllerRelease();
void ControllerResize(Controller *controller);
void ControllerGrab(Controller *controller);
void AddChildOverlay(Overlay *child);
void RemoveChildOverlay(Overlay *child);
@ -74,12 +73,6 @@ class Overlay
float _alpha;
float _ratio;
Controller *_holding_controller;
Controller *_resize_controller;
float _resize_original_size;
float _resize_base_distance;
float _resize_length_a;
float _resize_length_b;
glm::vec3 _resize_held_offset;
std::vector<Overlay *> _children;

View file

@ -10,13 +10,6 @@ typedef vr::HmdMatrix34_t VRMat;
const VRMat VRMatIdentity{{{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}}};
const int MAX_TRACKERS = vr::k_unMaxTrackedDeviceCount;
class Overlay;
struct Ray
{
Overlay *overlay;
float distance;
};
inline void PrintVec(glm::vec3 v)
{
printf("(%.2f, %.2f, %.2f)\n", v.x, v.y, v.z);