Skip to content

Commit 80912a4

Browse files
committed
Fix the logic for handling handedness
1 parent c8c3182 commit 80912a4

File tree

1 file changed

+48
-14
lines changed

1 file changed

+48
-14
lines changed

Diff for: Assets/ThirdParty/Logitech/Scripts/VrStylusHandler.cs

+48-14
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public override bool CanDraw()
6767
private float _hapticClickAmplitude = 0.9f;
6868
private float _hapticClickMinThreshold = 0.2f;
6969

70+
private OVRPlugin.Hand prevHandSetting = OVRPlugin.Hand.None;
71+
7072
private void UpdatePose()
7173
{
7274
_positionIsTracked = false;
@@ -80,22 +82,54 @@ private void UpdatePose()
8082
// The MX Ink interaction profile is: /interaction_profiles/logitech/mx_ink_stylus_logitech
8183

8284
// Find whether the Logitech MX Ink is on the left or the right hand
83-
bool stylusIsOnLeftHand = leftDevice.Contains("logitech");
84-
bool stylusIsOnRightHand = rightDevice.Contains("logitech");
85-
// Debug.Log($"Device: Left hand: {leftDevice}, Right hand: {rightDevice}");
85+
bool stylusIsAssignedLeft = leftDevice.Contains("logitech");
86+
bool stylusIsAssignedRight = rightDevice.Contains("logitech");
87+
8688
// Flag the stylus as active/inactive, on right/left hand
87-
_stylus.isActive = stylusIsOnLeftHand || stylusIsOnRightHand;
88-
_stylus.isOnRightHand = stylusIsOnRightHand;
89-
// Hide the 3D model if not active
90-
_mxInk_model.SetActive(_stylus.isActive);
91-
// Hacky
92-
InputManager.m_Instance.ShowController(!_stylus.isActive, stylusIsOnLeftHand ? 0 : 1);
93-
InputManager.m_Instance.ShowController(true, stylusIsOnLeftHand ? 1 : 0);
89+
_stylus.isActive = stylusIsAssignedLeft || stylusIsAssignedRight;
90+
_stylus.isOnRightHand = stylusIsAssignedRight;
91+
92+
if (!_stylus.isActive)
93+
{
94+
_mxInk_model.SetActive(false);
95+
InputManager.m_Instance.ShowController(true, 0);
96+
InputManager.m_Instance.ShowController(true, 1);
97+
return;
98+
}
99+
100+
_mxInk_model.SetActive(true);
101+
102+
// Initial pass. Set our handedness based on the OS settings
103+
if (prevHandSetting == OVRPlugin.Hand.None)
104+
{
105+
prevHandSetting = stylusIsAssignedRight ? OVRPlugin.Hand.HandRight : OVRPlugin.Hand.HandLeft;
106+
// If both stylus and wand are assigned to the same hand, swap the controls
107+
if (stylusIsAssignedRight == InputManager.m_Instance.WandOnRight)
108+
{
109+
SketchControlsScript.DoSwapControls();
110+
}
111+
}
112+
else
113+
{
114+
// Subsequent passes. Check if the handedness has changed
115+
var newHandSetting = stylusIsAssignedRight ? OVRPlugin.Hand.HandRight : OVRPlugin.Hand.HandLeft;
116+
if (newHandSetting != prevHandSetting)
117+
{
118+
// If both stylus and wand are assigned to the same hand, swap the controls
119+
if (stylusIsAssignedRight == InputManager.m_Instance.WandOnRight)
120+
{
121+
SketchControlsScript.DoSwapControls();
122+
}
123+
prevHandSetting = newHandSetting;
124+
}
125+
}
94126

95-
// Select the right/left hand stylus pose to be used
96-
string MX_Ink_Pose = _stylus.isOnRightHand ? MX_Ink_Pose_Right : MX_Ink_Pose_Left;
127+
// Not sure why but this works whether stylusIsAssignedRight or stylusIsAssignedLeft
128+
InputManager.Brush.ShowController(false);
129+
InputManager.Wand.ShowController(true);
97130

98-
if (OVRPlugin.GetActionStatePose(MX_Ink_Pose, out OVRPlugin.Posef handPose))
131+
string mxInkPose = stylusIsAssignedRight ? MX_Ink_Pose_Right : MX_Ink_Pose_Left;
132+
if (OVRPlugin.GetActionStatePose(mxInkPose, out OVRPlugin.Posef handPose))
99133
{
100134
transform.localPosition = handPose.Position.FromFlippedZVector3f();
101135
transform.rotation = handPose.Orientation.FromFlippedZQuatf();
@@ -106,7 +140,7 @@ private void UpdatePose()
106140
}
107141
else
108142
{
109-
Debug.LogError($"MX_Ink: Error getting Pose action name {MX_Ink_Pose}, check logcat for specifics.");
143+
Debug.LogError($"MX_Ink: Error getting Pose action name {mxInkPose}, check logcat for specifics.");
110144
}
111145
}
112146

0 commit comments

Comments
 (0)