diff --git a/gfx/vr/VRDisplayClient.cpp b/gfx/vr/VRDisplayClient.cpp index fc60fffca7e6..8eca405cab7a 100644 --- a/gfx/vr/VRDisplayClient.cpp +++ b/gfx/vr/VRDisplayClient.cpp @@ -238,6 +238,26 @@ void VRDisplayClient::GamepadMappingForWebVR( aControllerState.numButtons = 6; aControllerState.numAxes = 2; break; + case VRControllerType::ValveIndex: + aControllerState.buttonPressed = + ShiftButtonBitForNewSlot(1, 0) | ShiftButtonBitForNewSlot(2, 1) | + ShiftButtonBitForNewSlot(0, 2) | ShiftButtonBitForNewSlot(5, 3) | + ShiftButtonBitForNewSlot(3, 4) | ShiftButtonBitForNewSlot(4, 5) | + ShiftButtonBitForNewSlot(6, 6) | ShiftButtonBitForNewSlot(7, 7) | + ShiftButtonBitForNewSlot(8, 8) | ShiftButtonBitForNewSlot(9, 9); + aControllerState.buttonTouched = ShiftButtonBitForNewSlot(1, 0, true) | + ShiftButtonBitForNewSlot(2, 1, true) | + ShiftButtonBitForNewSlot(0, 2, true) | + ShiftButtonBitForNewSlot(5, 3, true) | + ShiftButtonBitForNewSlot(3, 4, true) | + ShiftButtonBitForNewSlot(4, 5, true) | + ShiftButtonBitForNewSlot(6, 6, true) | + ShiftButtonBitForNewSlot(7, 7, true) | + ShiftButtonBitForNewSlot(8, 8, true) | + ShiftButtonBitForNewSlot(9, 9, true); + aControllerState.numButtons = 10; + aControllerState.numAxes = 4; + break; case VRControllerType::PicoGaze: aControllerState.buttonPressed = ShiftButtonBitForNewSlot(0, 0); aControllerState.buttonTouched = ShiftButtonBitForNewSlot(0, 0, true); diff --git a/gfx/vr/service/OpenVRKnucklesMapper.cpp b/gfx/vr/service/OpenVRKnucklesMapper.cpp new file mode 100644 index 000000000000..a4600d83c66c --- /dev/null +++ b/gfx/vr/service/OpenVRKnucklesMapper.cpp @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "OpenVRKnucklesMapper.h" + +#include "moz_external_vr.h" +#include "VRSession.h" + +namespace mozilla::gfx { + +void OpenVRKnucklesMapper::UpdateButtons(VRControllerState& aControllerState, + ControllerInfo& aControllerInfo) { + mNumButtons = mNumAxes = 0; + // Button 0: Trigger + GetTriggerValueFromAction(aControllerState, + aControllerInfo.mActionTrigger_Value); + // Button 1: Grip + GetButtonValueFromAction(aControllerState, + aControllerInfo.mActionGrip_Pressed, + aControllerInfo.mActionGrip_Touched); + // Button 2: Touchpad. + GetButtonValueFromAction(aControllerState, + aControllerInfo.mActionTrackpad_Pressed, + aControllerInfo.mActionTrackpad_Touched); + // Button 3: Thumbstick + GetButtonValueFromAction(aControllerState, + aControllerInfo.mActionThumbstick_Pressed, + aControllerInfo.mActionThumbstick_Touched); + // Button 4: A + GetButtonValueFromAction(aControllerState, aControllerInfo.mActionA_Pressed, + aControllerInfo.mActionA_Touched); + // Button 5: B + GetButtonValueFromAction(aControllerState, aControllerInfo.mActionB_Pressed, + aControllerInfo.mActionB_Touched); + // Button 6: Finger index + GetTriggerValueFromAction(aControllerState, + aControllerInfo.mActionFingerIndex_Value); + // Button 7: Finger middle + GetTriggerValueFromAction(aControllerState, + aControllerInfo.mActionFingerMiddle_Value); + // Button 8: Finger ring + GetTriggerValueFromAction(aControllerState, + aControllerInfo.mActionFingerRing_Value); + // Button 9: Finger pinky + GetTriggerValueFromAction(aControllerState, + aControllerInfo.mActionFingerPinky_Value); + + // Axis 0, 1: Touchpad + GetAxisValueFromAction(aControllerState, + aControllerInfo.mActionTrackpad_Analog); + // Axis 2, 3: Thumbstick + GetAxisValueFromAction(aControllerState, + aControllerInfo.mActionThumbstick_Analog); + + aControllerState.numButtons = mNumButtons; + aControllerState.numAxes = mNumAxes; +} + +} // namespace mozilla::gfx \ No newline at end of file diff --git a/gfx/vr/service/OpenVRKnucklesMapper.h b/gfx/vr/service/OpenVRKnucklesMapper.h new file mode 100644 index 000000000000..84e40d0c9eef --- /dev/null +++ b/gfx/vr/service/OpenVRKnucklesMapper.h @@ -0,0 +1,26 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef GFX_VR_SERVICE_OPENVRKNUCKLESMAPPER_H +#define GFX_VR_SERVICE_OPENVRKNUCKLESMAPPER_H + +#include "OpenVRControllerMapper.h" + +namespace mozilla { +namespace gfx { + +class OpenVRKnucklesMapper : public OpenVRControllerMapper { + public: + OpenVRKnucklesMapper() = default; + virtual ~OpenVRKnucklesMapper() = default; + virtual void UpdateButtons(VRControllerState& aControllerState, + ControllerInfo& aControllerInfo); +}; + +} // namespace gfx +} // namespace mozilla + +#endif // GFX_VR_SERVICE_OPENVRKNUCKLESMAPPER_H \ No newline at end of file diff --git a/gfx/vr/service/OpenVRSession.cpp b/gfx/vr/service/OpenVRSession.cpp index b26a49cf4491..cb72bf6dc711 100644 --- a/gfx/vr/service/OpenVRSession.cpp +++ b/gfx/vr/service/OpenVRSession.cpp @@ -30,6 +30,7 @@ #include "binding/OpenVRViveBinding.h" #include "OpenVRCosmosMapper.h" #include "OpenVRDefaultMapper.h" +#include "OpenVRKnucklesMapper.h" #include "OpenVRViveMapper.h" #if defined(XP_WIN) // Windows Mixed Reality is only available in Windows. # include "OpenVRWMRMapper.h" @@ -1023,8 +1024,7 @@ void OpenVRSession::EnumerateControllers(VRSystemState& aState) { break; #endif case VRControllerType::ValveIndex: - // TODO: Replace Knuckles with Valve Index. - mControllerMapper = MakeUnique(); + mControllerMapper = MakeUnique(); break; default: mControllerMapper = MakeUnique(); diff --git a/gfx/vr/service/moz.build b/gfx/vr/service/moz.build index 4f3841eddf7d..8b77e80fafd1 100644 --- a/gfx/vr/service/moz.build +++ b/gfx/vr/service/moz.build @@ -43,6 +43,7 @@ if CONFIG['OS_TARGET'] in ('WINNT', 'Linux', 'Darwin'): 'OpenVRControllerMapper.cpp', 'OpenVRCosmosMapper.cpp', 'OpenVRDefaultMapper.cpp', + 'OpenVRKnucklesMapper.cpp', 'OpenVRSession.cpp', 'OpenVRViveMapper.cpp', ]