Skip to content

Commit

Permalink
add haptic feedback on scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
CrispyPin committed May 3, 2023
1 parent 47ebf9d commit 6f44ea6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion bindings/action_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
"name": "/actions/cursor/in/scroll",
"requirement": "suggested",
"type": "vector2"
},
{
"name": "/actions/cursor/out/scroll_haptic",
"requirement": "suggested",
"type": "vibration"
}
],
"action_sets": [
Expand Down Expand Up @@ -83,7 +88,8 @@
"/actions/cursor/in/mouse_left": "left mouse button",
"/actions/cursor/in/mouse_right": "right mouse button",
"/actions/cursor/in/mouse_middle": "middle mouse button",
"/actions/cursor/in/scroll": "scroll"
"/actions/cursor/in/scroll": "scroll",
"/actions/cursor/out/scroll_haptic": "scrolling haptic feedback"
}
]
}
10 changes: 10 additions & 0 deletions bindings/index_controller.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@
"app_key" : "system.generated.sinpin_vr",
"bindings" : {
"/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" : [
{
"inputs" : {
Expand Down
2 changes: 2 additions & 0 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ App::App()
assert(action_err == 0);
action_err = vr_input->GetActionHandle("/actions/cursor/in/scroll", &_input_handles.cursor.scroll);
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);
assert(action_err == 0);
action_err = vr_input->GetActionSetHandle("/actions/edit", &_input_handles.edit_set);
Expand Down
1 change: 1 addition & 0 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct InputHandles
vr::VRActionHandle_t mouse_right;
vr::VRActionHandle_t mouse_middle;
vr::VRActionHandle_t scroll;
vr::VRActionHandle_t scroll_haptic;
} cursor;
vr::VRActionSetHandle_t cursor_set;
struct
Expand Down
4 changes: 4 additions & 0 deletions src/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const float LASER_WIDTH = 0.004f;
const Color EDIT_COLOR{1, 0.6f, 1};
const Color CURSOR_COLOR{0.3f, 1, 1};
const float SCROLL_SPEED = 48;
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)
Expand Down Expand Up @@ -161,11 +163,13 @@ void Controller::Update(float dtime)
{
_app->SendMouseInput(4, true);
_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)
{
_app->SendMouseInput(5, true);
_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);
}
}
}
Expand Down

0 comments on commit 6f44ea6

Please sign in to comment.