Skip to content

Commit

Permalink
Add experimental gesture input system
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyabsi committed Aug 27, 2024
1 parent 322711b commit 7772f13
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 12 deletions.
5 changes: 4 additions & 1 deletion dist/leapify/resources/localization/localization_en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"Setting_manual_mounting_orientation_offset": "Adjust Mounting Offset (Orientation)",
"Setting_manual_mounting_offset_x": "Offset (X)",
"Setting_manual_mounting_offset_y": "Offset (Y)",
"Setting_manual_mounting_offset_z": "Offset (Z)"
"Setting_manual_mounting_offset_z": "Offset (Z)",
"Setting_gesture_input": "Gesture Input (Experimental)",
"Setting_pinch_threshold": "Pinch Threshold",
"Setting_movement_threshold": "Movement Threshold"
}
5 changes: 4 additions & 1 deletion dist/leapify/resources/localization/localization_ja_jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"Setting_manual_mounting_orientation_offset": "Adjust Mounting Offset (Orientation)",
"Setting_manual_mounting_offset_x": "オフセット (X)",
"Setting_manual_mounting_offset_y": "オフセット (Y)",
"Setting_manual_mounting_offset_z": "オフセット (Z)"
"Setting_manual_mounting_offset_z": "オフセット (Z)",
"Setting_gesture_input": "Gesture Input (Experimental)",
"Setting_pinch_threshold": "Pinch Threshold",
"Setting_movement_threshold": "Movement Threshold"
}
5 changes: 4 additions & 1 deletion dist/leapify/resources/settings/default.vrsettings
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"manualMountingOrientationOffset": false,
"manualMountingOrientationOffsetX": 0.0,
"manualMountingOrientationOffsetY": 0.0,
"manualMountingOrientationOffsetZ": 0.0
"manualMountingOrientationOffsetZ": 0.0,
"gestureInput": false,
"gestureInputPinchThreshold": 10.0,
"gestureInputMovementThreshold": 25.0
}
}
32 changes: 32 additions & 0 deletions dist/leapify/resources/settings/settingsschema.vrsettings
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,38 @@
"requires": {
"/settings/driver_leapify/manualMountingOrientationOffset": true
}
},
{
"name": "/settings/driver_leapify/gestureInput",
"control": "toggle",
"label": "#{leapify}Setting_gesture_input",
"on_label": "#{leapify}Setting_toggle_on",
"off_label": "#{leapify}Setting_toggle_off",
"requires": {}
},
{
"name": "/settings/driver_leapify/gestureInputPinchThreshold",
"control": "slider",
"label": "#{leapify}Setting_offset_y",
"type": "float",
"min": 0,
"max": 100,
"decimals": 1,
"requires": {
"/settings/driver_leapify/manualMountingOrientationOffset": true
}
},
{
"name": "/settings/driver_leapify/gestureInputMovementThreshold",
"control": "slider",
"label": "#{leapify}Setting_offset_y",
"type": "float",
"min": 0,
"max": 100,
"decimals": 1,
"requires": {
"/settings/driver_leapify/manualMountingOrientationOffset": true
}
}
]
}
Expand Down
8 changes: 2 additions & 6 deletions src/GestureInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,11 @@ void GestureInput::Update(LeapHand hand)
{
auto position = getNormalizedPosition(state.movementOrigin, target);

if (position.z > 0.75f)
if (position.z >= 1.0f)
binding.state.up = true;
else
binding.state.up = false;

if (position.z < -0.75f)
if (position.z <= -1.0f)
binding.state.down = true;
else
binding.state.down = false;

binding.state.click = true;
}
Expand Down
48 changes: 45 additions & 3 deletions src/TrackedController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ vr::EVRInitError TrackedController::Activate(uint32_t unObjectId)
else
vr::VRDriverInput()->CreateSkeletonComponent(props, "/input/skeleton/right", "/skeleton/hand/right", "/pose/raw", vr::VRSkeletalTracking_Full, nullptr, 0, &m_skeletonHandle);

m_gestureInput.setPinchMinimumDistance(10.0f);
m_gestureInput.setMovementDistanceThreshold(25.0f);
m_gestureInput.setPinchMinimumDistance(vr::VRSettings()->GetFloat("driver_leapify", "gestureInputPinchThreshold"));
m_gestureInput.setMovementDistanceThreshold(vr::VRSettings()->GetFloat("driver_leapify", "gestureInputMovementThreshold"));

m_gestureInput.addBinding(FINGER_INDEX, GESTURE_DUAL_PINCH, {});
m_gestureInput.addBinding(FINGER_INDEX, GESTURE_SWIPE_VERTICAL, {});
m_gestureInput.addBinding(FINGER_MIDDLE, GESTURE_THUMB_STICK, {});
m_gestureInput.addBinding(FINGER_RING, GESTURE_DUAL_PINCH, {});

result = vr::VRInitError_None;
}
Expand Down Expand Up @@ -156,6 +158,9 @@ void TrackedController::Update(LeapHand hand)
UpdateSkeletalPose(hand);
UpdatePose(hand);

if (vr::VRSettings()->GetBool("driver_leapify", "gestureInput"))
UpdateInput(hand);

if (vr::VRSettings()->GetBool("driver_leapify", "trackerCalibrationMode"))
PoseCalibrationSubroutine(hand);
}
Expand Down Expand Up @@ -350,6 +355,43 @@ void TrackedController::UpdateSkeletalPose(LeapHand hand)
}
}

void TrackedController::UpdateInput(LeapHand hand)
{
if (!vr::VRSettings()->GetBool("driver_leapify", "trackerCalibrationMode"))
{
// mmm yes.
m_gestureInput.setPinchMinimumDistance(vr::VRSettings()->GetFloat("driver_leapify", "gestureInputPinchThreshold"));
m_gestureInput.setMovementDistanceThreshold(vr::VRSettings()->GetFloat("driver_leapify", "gestureInputMovementThreshold"));

m_gestureInput.Update(hand);

auto indexState = m_gestureInput.GetState(FINGER_INDEX);
auto middleState = m_gestureInput.GetState(FINGER_MIDDLE);
auto ringState = m_gestureInput.GetState(FINGER_RING);

auto triggerValue = m_gestureInput.getNormalizedFingerCurl(hand, FINGER_INDEX);
auto gripValue = m_gestureInput.getNormalizedCombinedCurl(hand);


vr::VRDriverInput()->UpdateBooleanComponent(m_bButton, indexState.up, 0.0f);
vr::VRDriverInput()->UpdateBooleanComponent(m_aButton, indexState.down, 0.0f);

vr::VRDriverInput()->UpdateScalarComponent(m_xAxis, middleState.x, 0.0f);
vr::VRDriverInput()->UpdateScalarComponent(m_yAxis, middleState.y, 0.0f);

vr::VRDriverInput()->UpdateBooleanComponent(m_systemMenu, ringState.click, 0.0f);

if (!hand.index.is_extended)
{
vr::VRDriverInput()->UpdateBooleanComponent(m_trigger, triggerValue >= 1.0f, 0.0f);
vr::VRDriverInput()->UpdateScalarComponent(m_triggerValue, triggerValue, 0.0f);
}

vr::VRDriverInput()->UpdateScalarComponent(m_grip, gripValue, 0.0f);
vr::VRDriverInput()->UpdateScalarComponent(m_gripForce, gripValue, 0.0f);
}
}

void TrackedController::PoseCalibrationSubroutine(LeapHand hand)
{
m_gestureInput.Update(hand);
Expand Down
12 changes: 12 additions & 0 deletions src/TrackedController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class TrackedController: public vr::ITrackedDeviceServerDriver
private:
void UpdatePose(LeapHand hand);
void UpdateSkeletalPose(LeapHand hand);
void UpdateInput(LeapHand hand);
void PoseCalibrationSubroutine(LeapHand hand);

void GetFingerBoneLocalRotation(LeapHand hand, size_t p_finger, size_t p_bone, glm::quat& l_result, bool p_ignoreMeta);
Expand All @@ -128,4 +129,15 @@ class TrackedController: public vr::ITrackedDeviceServerDriver
vr::DriverPose_t m_finalPose{};
glm::vec3 m_positionOffset{};
glm::quat m_rotationOffset{};

// Bindings
vr::VRInputComponentHandle_t m_systemMenu{};
vr::VRInputComponentHandle_t m_xAxis{};
vr::VRInputComponentHandle_t m_yAxis{};
vr::VRInputComponentHandle_t m_trigger{};
vr::VRInputComponentHandle_t m_triggerValue{};
vr::VRInputComponentHandle_t m_aButton{};
vr::VRInputComponentHandle_t m_bButton{};
vr::VRInputComponentHandle_t m_grip{};
vr::VRInputComponentHandle_t m_gripForce{};
};

0 comments on commit 7772f13

Please sign in to comment.