Compare commits

..

No commits in common. "main" and "v0.2.1" have entirely different histories.
main ... v0.2.1

12 changed files with 33 additions and 98 deletions

1
.gitignore vendored
View file

@ -1,4 +1,3 @@
sinpin_vr sinpin_vr
.vscode/ .vscode/
*.zip *.zip
*.tar.xz

View file

@ -1,23 +1,18 @@
VERSION=v0.2.3 VERSION=v0.2.1
# CC := g++
CXX := g++ CC := clang++
# CXX := clang++
CPPFLAGS := -g -Wall -std=c++17
LFLAGS := -lX11 -lXrandr -lXtst -lglfw -lGL LFLAGS := -lX11 -lXrandr -lXtst -lglfw -lGL
OVR := -Llib -lopenvr_api LIBS := openvr/libopenvr_api.so
TARGET := ./sinpin_vr SRC := src/*.cpp
OUT := ./sinpin_vr
CPPFLAGS := -Wall -std=c++17 $(LFLAGS) $(LIBS) $(SRC) -o $(OUT)
build: build:
$(CXX) src/*.cpp $(CPPFLAGS) $(LFLAGS) -Wl,-rpath,'$$ORIGIN/lib' $(OVR) -o $(TARGET) $(CC) -g $(CPPFLAGS)
release: build release: build
mkdir -p sinpin-vr/lib zip -r sinpin_vr-$(VERSION).zip sinpin_vr bindings openvr/libopenvr_api.so
cp lib/libopenvr_api.so sinpin-vr/lib
cp -r bindings sinpin-vr
cp sinpin_vr sinpin-vr
tar -caf sinpin-vr-$(VERSION).tar.xz sinpin-vr
rm -rf sinpin-vr
run: build run: build
$(TARGET) $(OUT)

View file

@ -55,16 +55,6 @@
"name": "/actions/cursor/in/scroll", "name": "/actions/cursor/in/scroll",
"requirement": "suggested", "requirement": "suggested",
"type": "vector2" "type": "vector2"
},
{
"name": "/actions/cursor/in/toggle_transparent",
"requirement": "suggested",
"type": "boolean"
},
{
"name": "/actions/cursor/out/scroll_haptic",
"requirement": "suggested",
"type": "vibration"
} }
], ],
"action_sets": [ "action_sets": [
@ -93,9 +83,7 @@
"/actions/cursor/in/mouse_left": "left mouse button", "/actions/cursor/in/mouse_left": "left mouse button",
"/actions/cursor/in/mouse_right": "right mouse button", "/actions/cursor/in/mouse_right": "right mouse button",
"/actions/cursor/in/mouse_middle": "middle mouse button", "/actions/cursor/in/mouse_middle": "middle mouse button",
"/actions/cursor/in/scroll": "scroll", "/actions/cursor/in/scroll": "scroll"
"/actions/cursor/in/toggle_transparent": "toggle transparency",
"/actions/cursor/out/scroll_haptic": "scrolling haptic feedback"
} }
] ]
} }

View file

@ -141,16 +141,6 @@
"app_key" : "system.generated.sinpin_vr", "app_key" : "system.generated.sinpin_vr",
"bindings" : { "bindings" : {
"/actions/cursor" : { "/actions/cursor" : {
"haptics" : [
{
"output" : "/actions/cursor/out/scroll_haptic",
"path" : "/user/hand/left/output/haptic"
},
{
"output" : "/actions/cursor/out/scroll_haptic",
"path" : "/user/hand/right/output/haptic"
}
],
"sources" : [ "sources" : [
{ {
"inputs" : { "inputs" : {

View file

@ -10,7 +10,6 @@
const VRMat root_start_pose = {{{1, 0, 0, 0}, {0, 1, 0, 0.8f}, {0, 0, 1, 0}}}; // 0.8m above origin const VRMat root_start_pose = {{{1, 0, 0, 0}, {0, 1, 0, 0.8f}, {0, 0, 1, 0}}}; // 0.8m above origin
const int FRAME_INTERVAL = 4; // number of update loops until the frame buffer is updated const int FRAME_INTERVAL = 4; // number of update loops until the frame buffer is updated
const float TRANSPARENCY = 0.6f;
App::App() App::App()
{ {
@ -76,10 +75,6 @@ App::App()
assert(action_err == 0); assert(action_err == 0);
action_err = vr_input->GetActionHandle("/actions/cursor/in/scroll", &_input_handles.cursor.scroll); action_err = vr_input->GetActionHandle("/actions/cursor/in/scroll", &_input_handles.cursor.scroll);
assert(action_err == 0); assert(action_err == 0);
action_err = vr_input->GetActionHandle("/actions/cursor/in/toggle_transparent", &_input_handles.cursor.toggle_transparent);
assert(action_err == 0);
action_err = vr_input->GetActionHandle("/actions/cursor/out/scroll_haptic", &_input_handles.cursor.scroll_haptic);
assert(action_err == 0);
action_err = vr_input->GetActionSetHandle("/actions/main", &_input_handles.main_set); action_err = vr_input->GetActionSetHandle("/actions/main", &_input_handles.main_set);
assert(action_err == 0); assert(action_err == 0);
action_err = vr_input->GetActionSetHandle("/actions/edit", &_input_handles.edit_set); action_err = vr_input->GetActionSetHandle("/actions/edit", &_input_handles.edit_set);
@ -147,7 +142,6 @@ void App::InitRootOverlay()
_root_overlay.SetWidth(0.25f); _root_overlay.SetWidth(0.25f);
_root_overlay.SetTransformWorld(&root_start_pose); _root_overlay.SetTransformWorld(&root_start_pose);
_root_overlay.SetTextureToColor(110, 30, 190); _root_overlay.SetTextureToColor(110, 30, 190);
_root_overlay.SetHidden(true);
} }
void App::Update(float dtime) void App::Update(float dtime)
@ -196,20 +190,6 @@ void App::UpdateInput(float dtime)
} }
UpdateUIVisibility(); UpdateUIVisibility();
} }
if (IsInputJustPressed(_input_handles.cursor.toggle_transparent))
{
_transparent = !_transparent;
if (_transparent)
{
for (auto &panel : _panels)
panel.GetOverlay()->SetAlpha(TRANSPARENCY);
}
else
{
for (auto &panel : _panels)
panel.GetOverlay()->SetAlpha(1);
}
}
if (!_hidden) if (!_hidden)
{ {
if (IsInputJustPressed(_input_handles.main.reset)) if (IsInputJustPressed(_input_handles.main.reset))

View file

@ -32,8 +32,6 @@ struct InputHandles
vr::VRActionHandle_t mouse_right; vr::VRActionHandle_t mouse_right;
vr::VRActionHandle_t mouse_middle; vr::VRActionHandle_t mouse_middle;
vr::VRActionHandle_t scroll; vr::VRActionHandle_t scroll;
vr::VRActionHandle_t scroll_haptic;
vr::VRActionHandle_t toggle_transparent;
} cursor; } cursor;
vr::VRActionSetHandle_t cursor_set; vr::VRActionSetHandle_t cursor_set;
struct struct
@ -88,7 +86,6 @@ class App
Overlay _root_overlay; Overlay _root_overlay;
std::vector<Panel> _panels; std::vector<Panel> _panels;
bool _hidden = false; bool _hidden = false;
bool _transparent = false;
bool _edit_mode = false; bool _edit_mode = false;
std::optional<Controller *> _active_cursor; std::optional<Controller *> _active_cursor;

View file

@ -7,10 +7,7 @@
const float LASER_WIDTH = 0.004f; const float LASER_WIDTH = 0.004f;
const Color EDIT_COLOR{1, 0.6f, 1}; const Color EDIT_COLOR{1, 0.6f, 1};
const Color CURSOR_COLOR{0.3f, 1, 1}; const Color CURSOR_COLOR{0.3f, 1, 1};
const float SCROLL_SPEED = 48; const float SCROLL_SPEED = 48.0f;
const float SCROLL_HAPTIC_STRENGTH = 0.15f;
const float SCROLL_HAPTIC_TIME = 0.1f;
const float MOUSE_DRAG_THRESHOLD = 48;
Controller::Controller(App *app, ControllerSide side) Controller::Controller(App *app, ControllerSide side)
{ {
@ -19,6 +16,8 @@ Controller::Controller(App *app, ControllerSide side)
_input_handle = 0; _input_handle = 0;
_is_connected = false; _is_connected = false;
_side = side; _side = side;
_cursor_active = false;
_last_sent_scroll = 0;
std::string laser_name = "controller_laser_"; std::string laser_name = "controller_laser_";
if (side == ControllerSide::Left) if (side == ControllerSide::Left)
@ -127,6 +126,7 @@ void Controller::Update(float dtime)
} }
if (_cursor_active) if (_cursor_active)
{ {
// printf("update cursor on hand %d\n", _side);
if (_last_ray.overlay != nullptr && _last_ray.hit_panel != nullptr) if (_last_ray.overlay != nullptr && _last_ray.hit_panel != nullptr)
{ {
auto pos = glm::vec2(_last_ray.local_pos.x, _last_ray.local_pos.y); auto pos = glm::vec2(_last_ray.local_pos.x, _last_ray.local_pos.y);
@ -139,15 +139,7 @@ void Controller::Update(float dtime)
pos.y += 0.5f * _last_ray.overlay->Ratio(); pos.y += 0.5f * _last_ray.overlay->Ratio();
pos *= _last_ray.hit_panel->Width(); pos *= _last_ray.hit_panel->Width();
if (glm::length(pos - _last_set_mouse_pos) > MOUSE_DRAG_THRESHOLD)
{
_mouse_drag_lock = false;
}
if (!_mouse_drag_lock)
{
_last_ray.hit_panel->SetCursor(pos.x, pos.y); _last_ray.hit_panel->SetCursor(pos.x, pos.y);
_last_set_mouse_pos = pos;
}
} }
UpdateMouseButton(_app->_input_handles.cursor.mouse_left, 1); UpdateMouseButton(_app->_input_handles.cursor.mouse_left, 1);
UpdateMouseButton(_app->_input_handles.cursor.mouse_middle, 2); UpdateMouseButton(_app->_input_handles.cursor.mouse_middle, 2);
@ -163,13 +155,11 @@ void Controller::Update(float dtime)
{ {
_app->SendMouseInput(4, true); _app->SendMouseInput(4, true);
_app->SendMouseInput(4, false); _app->SendMouseInput(4, false);
_app->vr_input->TriggerHapticVibrationAction(_app->_input_handles.cursor.scroll_haptic, 0, SCROLL_HAPTIC_TIME, 1 / SCROLL_HAPTIC_TIME, SCROLL_HAPTIC_STRENGTH, _input_handle);
} }
else if (scroll_state.y < 0) else if (scroll_state.y < 0)
{ {
_app->SendMouseInput(5, true); _app->SendMouseInput(5, true);
_app->SendMouseInput(5, false); _app->SendMouseInput(5, false);
_app->vr_input->TriggerHapticVibrationAction(_app->_input_handles.cursor.scroll_haptic, 0, SCROLL_HAPTIC_TIME, 1 / SCROLL_HAPTIC_TIME, SCROLL_HAPTIC_STRENGTH, _input_handle);
} }
} }
} }
@ -183,7 +173,6 @@ void Controller::UpdateMouseButton(vr::VRActionHandle_t binding, unsigned int bu
if (state.bChanged) if (state.bChanged)
{ {
_app->SendMouseInput(button, state.bState); _app->SendMouseInput(button, state.bState);
_mouse_drag_lock = state.bState;
} }
} }

View file

@ -28,7 +28,7 @@ class Controller
void Update(float dtime); void Update(float dtime);
bool _cursor_active = false; bool _cursor_active;
private: private:
void UpdateStatus(); void UpdateStatus();
@ -50,7 +50,5 @@ class Controller
glm::vec3 _last_rotation; glm::vec3 _last_rotation;
glm::vec3 _last_pos; glm::vec3 _last_pos;
float _last_sent_scroll = 0; float _last_sent_scroll;
bool _mouse_drag_lock = false;
glm::vec2 _last_set_mouse_pos;
}; };

View file

@ -159,29 +159,28 @@ void Overlay::SetTargetWorld()
SetTransformWorld(&abs_pose); SetTransformWorld(&abs_pose);
} }
Ray Overlay::IntersectRay(glm::vec3 ray_start_g, glm::vec3 direction, float max_len) Ray Overlay::IntersectRay(glm::vec3 origin, glm::vec3 direction, float max_len)
{ {
float dist = max_len; float dist = max_len;
auto ray_end_g = ray_start_g + direction * max_len; auto end = origin + direction * max_len;
auto panel_transform = GetTransformAbsolute(); auto panel_transform = GetTransformAbsolute();
auto panel_pos = GetPos(panel_transform); auto panel_pos = GetPos(panel_transform);
auto ray_start = glm::inverse(panel_transform) * glm::vec4(ray_start_g - panel_pos, 0); auto a = glm::inverse(panel_transform) * glm::vec4(origin - panel_pos, 0);
auto ray_end = glm::inverse(panel_transform) * glm::vec4(ray_end_g - panel_pos, 0); auto b = glm::inverse(panel_transform) * glm::vec4(end - panel_pos, 0);
float length_frac = ray_start.z / (ray_start.z - ray_end.z); float r = a.z / (a.z - b.z);
auto hit_pos = ray_start + (ray_end - ray_start) * length_frac; auto p = a + (b - a) * r;
// printf("panel pos: (%.2f,%.2f,%.2f)\n", panel_pos.x, panel_pos.y, panel_pos.z);
// printf("a: (%.2f,%.2f,%.2f)\n", a.x, a.y, a.z);
// printf("b: (%.2f,%.2f,%.2f)\n", b.x, b.y, b.z);
// printf("r: %.2f\n", r);
// printf("p: (%.2f,%.2f,%.2f)\n", p.x, p.y, p.z);
// clang-format off 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))
if (ray_end.z < ray_start.z
&& ray_end.z < 0
&& glm::abs(hit_pos.x) < (_width_m * 0.5f)
&& glm::abs(hit_pos.y) < (_width_m * 0.5f * _ratio)
&& length_frac > 0)
{ {
// clang-format on dist = glm::min(r * max_len, max_len);
dist = glm::min(length_frac * max_len, max_len);
} }
return Ray{.overlay = this, .distance = dist, .local_pos = hit_pos, .hit_panel = nullptr}; return Ray{.overlay = this, .distance = dist, .local_pos = p, .hit_panel = nullptr};
} }
glm::mat4x4 Overlay::GetTransformAbsolute() glm::mat4x4 Overlay::GetTransformAbsolute()

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../lib/openvr.h" #include "../openvr/openvr.h"
#include <glm/glm.hpp> #include <glm/glm.hpp>
typedef vr::TrackedDeviceIndex_t TrackerID; typedef vr::TrackedDeviceIndex_t TrackerID;