Skip to content

Commit

Permalink
fix controller hotswapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyabsi committed Jul 26, 2024
1 parent 6565d23 commit d6faf74
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/TrackedController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,15 @@ void TrackedController::UpdatePose(LeapHand hand)
}
else
{
bool isControllerConnected = false;
m_isControllerConnected = false;

for (auto& state : StateManager::Get().getControllerStates())
{
if (state.second == true)
isControllerConnected = true;
m_isControllerConnected = true;
}

if (isControllerConnected && vr::VRSettings()->GetBool("driver_leapify", "automaticControllerSwitching"))
if (m_isControllerConnected && vr::VRSettings()->GetBool("driver_leapify", "automaticControllerSwitching"))
{
m_pose.deviceIsConnected = false;
m_pose.poseIsValid = false;
Expand All @@ -228,7 +229,7 @@ void TrackedController::UpdatePose(LeapHand hand)
}
}

if (hand.role != vr::TrackedControllerRole_Invalid)
if (hand.role != vr::TrackedControllerRole_Invalid && !m_isControllerConnected)
{
memcpy(m_pose.vecWorldFromDriverTranslation, ms_headPosition, sizeof(double) * 3U);
memcpy(&m_pose.qWorldFromDriverRotation, &ms_headRotation, sizeof(vr::HmdQuaternion_t));
Expand Down
1 change: 1 addition & 0 deletions src/TrackedController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class TrackedController: public vr::ITrackedDeviceServerDriver
std::array<glm::quat, 20U> m_boneRotations;
glm::vec3 m_position;
glm::quat m_rotation;
bool m_isControllerConnected { };

static double ms_headPosition[3U];
static vr::HmdQuaternion_t ms_headRotation;
Expand Down

0 comments on commit d6faf74

Please sign in to comment.