mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 16:25:38 +00:00
Bug 1621369 - Part 1: Refactor OpenVR controller and adjust its button/axis order for WebXR. r=kip
Differential Revision: https://phabricator.services.mozilla.com/D66677 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
b2e798ad9e
commit
5469f66b91
@ -47,8 +47,8 @@ namespace gfx {
|
||||
// and mapped files if we have both release and nightlies
|
||||
// running at the same time? Or...what if we have multiple
|
||||
// release builds running on same machine? (Bug 1563232)
|
||||
#define SHMEM_VERSION "0.0.7"
|
||||
static const int32_t kVRExternalVersion = 14;
|
||||
#define SHMEM_VERSION "0.0.8"
|
||||
static const int32_t kVRExternalVersion = 15;
|
||||
|
||||
// We assign VR presentations to groups with a bitmask.
|
||||
// Currently, we will only display either content or chrome.
|
||||
@ -131,6 +131,16 @@ enum class ControllerCapabilityFlags : uint16_t {
|
||||
|
||||
#endif // ifndef MOZILLA_INTERNAL_API
|
||||
|
||||
enum class VRControllerType : uint8_t {
|
||||
_empty,
|
||||
Vive,
|
||||
WMR,
|
||||
Knuckles,
|
||||
Cosmos,
|
||||
OculusTouch,
|
||||
_end
|
||||
};
|
||||
|
||||
enum class TargetRayMode : uint8_t { Gaze, TrackedPointer, Screen };
|
||||
|
||||
enum class GamepadMappingType : uint8_t { _empty, Standard, XRStandard };
|
||||
@ -341,6 +351,9 @@ struct VRControllerState {
|
||||
#else
|
||||
ControllerHand hand;
|
||||
#endif
|
||||
// For WebXR->WebVR mapping conversion, once we remove WebVR,
|
||||
// we can remove this item.
|
||||
VRControllerType type;
|
||||
// https://immersive-web.github.io/webxr/#enumdef-xrtargetraymode
|
||||
TargetRayMode targetRayMode;
|
||||
|
||||
|
@ -41,14 +41,6 @@ class VRManagerPromise;
|
||||
// conservative value.
|
||||
static const int kVRMaxLatencyFrames = 100;
|
||||
|
||||
enum class OpenVRControllerType : uint16_t {
|
||||
Vive,
|
||||
WMR,
|
||||
Knuckles,
|
||||
Cosmos,
|
||||
NumOpenVRControllerTypes
|
||||
};
|
||||
|
||||
struct VRDisplayInfo {
|
||||
uint32_t mDisplayID;
|
||||
uint32_t mPresentingGroups;
|
||||
|
89
gfx/vr/service/OpenVRControllerMapper.cpp
Normal file
89
gfx/vr/service/OpenVRControllerMapper.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
/* -*- 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 "OpenVRControllerMapper.h"
|
||||
#include "mozilla/StaticPrefs_dom.h"
|
||||
|
||||
#include "VRSession.h"
|
||||
|
||||
namespace mozilla::gfx {
|
||||
|
||||
OpenVRControllerMapper::OpenVRControllerMapper()
|
||||
: mNumButtons(0), mNumAxes(0) {}
|
||||
|
||||
void OpenVRControllerMapper::GetButtonValueFromAction(
|
||||
VRControllerState& aControllerState, const ControllerAction& aPressAction,
|
||||
const ControllerAction& aTouchAction) {
|
||||
vr::InputDigitalActionData_t actionData = {};
|
||||
bool bPressed = false;
|
||||
bool bTouched = false;
|
||||
uint64_t mask = 0;
|
||||
|
||||
if (aPressAction.handle &&
|
||||
vr::VRInput()->GetDigitalActionData(
|
||||
aPressAction.handle, &actionData, sizeof(actionData),
|
||||
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
||||
actionData.bActive) {
|
||||
bPressed = actionData.bState;
|
||||
mask = (1ULL << mNumButtons);
|
||||
aControllerState.triggerValue[mNumButtons] = bPressed ? 1.0 : 0.0f;
|
||||
if (bPressed) {
|
||||
aControllerState.buttonPressed |= mask;
|
||||
} else {
|
||||
aControllerState.buttonPressed &= ~mask;
|
||||
}
|
||||
if (aTouchAction.handle &&
|
||||
vr::VRInput()->GetDigitalActionData(
|
||||
aTouchAction.handle, &actionData, sizeof(actionData),
|
||||
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None) {
|
||||
bTouched = actionData.bActive && actionData.bState;
|
||||
mask = (1ULL << mNumButtons);
|
||||
if (bTouched) {
|
||||
aControllerState.buttonTouched |= mask;
|
||||
} else {
|
||||
aControllerState.buttonTouched &= ~mask;
|
||||
}
|
||||
}
|
||||
++mNumButtons;
|
||||
}
|
||||
}
|
||||
|
||||
void OpenVRControllerMapper::GetTriggerValueFromAction(
|
||||
VRControllerState& aControllerState, const ControllerAction& aAction) {
|
||||
vr::InputAnalogActionData_t analogData = {};
|
||||
const float triggerThreshold =
|
||||
StaticPrefs::dom_vr_controller_trigger_threshold();
|
||||
|
||||
if (aAction.handle &&
|
||||
vr::VRInput()->GetAnalogActionData(
|
||||
aAction.handle, &analogData, sizeof(analogData),
|
||||
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
||||
analogData.bActive) {
|
||||
VRSession::UpdateTrigger(aControllerState, mNumButtons, analogData.x,
|
||||
triggerThreshold);
|
||||
++mNumButtons;
|
||||
}
|
||||
}
|
||||
|
||||
void OpenVRControllerMapper::GetAxisValueFromAction(
|
||||
VRControllerState& aControllerState, const ControllerAction& aAction,
|
||||
bool aInvertAxis) {
|
||||
vr::InputAnalogActionData_t analogData = {};
|
||||
const float yAxisInvert = (aInvertAxis) ? -1.0f : 1.0f;
|
||||
|
||||
if (aAction.handle &&
|
||||
vr::VRInput()->GetAnalogActionData(
|
||||
aAction.handle, &analogData, sizeof(analogData),
|
||||
vr::k_ulInvalidInputValueHandle) == vr::VRInputError_None &&
|
||||
analogData.bActive) {
|
||||
aControllerState.axisValue[mNumAxes] = analogData.x;
|
||||
++mNumAxes;
|
||||
aControllerState.axisValue[mNumAxes] = analogData.y * yAxisInvert;
|
||||
++mNumAxes;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mozilla::gfx
|
96
gfx/vr/service/OpenVRControllerMapper.h
Normal file
96
gfx/vr/service/OpenVRControllerMapper.h
Normal file
@ -0,0 +1,96 @@
|
||||
/* -*- 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_OPENVRCONTROLLERMAPPER_H
|
||||
#define GFX_VR_SERVICE_OPENVRCONTROLLERMAPPER_H
|
||||
|
||||
#include "openvr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "moz_external_vr.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
struct ControllerAction {
|
||||
nsCString name;
|
||||
nsCString type;
|
||||
vr::VRActionHandle_t handle = vr::k_ulInvalidActionHandle;
|
||||
|
||||
ControllerAction() = default;
|
||||
|
||||
ControllerAction(const char* aName, const char* aType)
|
||||
: name(aName), type(aType) {}
|
||||
};
|
||||
|
||||
struct ControllerInfo {
|
||||
vr::VRInputValueHandle_t mSource = vr::k_ulInvalidInputValueHandle;
|
||||
|
||||
ControllerAction mActionPose;
|
||||
ControllerAction mActionHaptic;
|
||||
|
||||
ControllerAction mActionTrackpad_Analog;
|
||||
ControllerAction mActionTrackpad_Pressed;
|
||||
ControllerAction mActionTrackpad_Touched;
|
||||
|
||||
ControllerAction mActionTrigger_Value;
|
||||
|
||||
ControllerAction mActionGrip_Pressed;
|
||||
ControllerAction mActionGrip_Touched;
|
||||
ControllerAction mActionMenu_Pressed;
|
||||
ControllerAction mActionMenu_Touched;
|
||||
// It seems like there's no way to get response from a sys. btn.
|
||||
ControllerAction mActionSystem_Pressed;
|
||||
ControllerAction mActionSystem_Touched;
|
||||
|
||||
// --- Knuckles & Cosmos
|
||||
ControllerAction mActionA_Pressed;
|
||||
ControllerAction mActionA_Touched;
|
||||
ControllerAction mActionB_Pressed;
|
||||
ControllerAction mActionB_Touched;
|
||||
|
||||
// --- Knuckles, Cosmos, and WMR
|
||||
ControllerAction mActionThumbstick_Analog;
|
||||
ControllerAction mActionThumbstick_Pressed;
|
||||
ControllerAction mActionThumbstick_Touched;
|
||||
|
||||
// --- Knuckles
|
||||
ControllerAction mActionFingerIndex_Value;
|
||||
ControllerAction mActionFingerMiddle_Value;
|
||||
ControllerAction mActionFingerRing_Value;
|
||||
ControllerAction mActionFingerPinky_Value;
|
||||
|
||||
// --- Cosmos
|
||||
ControllerAction mActionBumper_Pressed;
|
||||
};
|
||||
|
||||
class OpenVRControllerMapper {
|
||||
public:
|
||||
OpenVRControllerMapper();
|
||||
virtual ~OpenVRControllerMapper() = default;
|
||||
|
||||
virtual void UpdateButtons(VRControllerState& aControllerState,
|
||||
ControllerInfo& aControllerInfo) = 0;
|
||||
uint32_t GetButtonCount() { return mNumButtons; }
|
||||
uint32_t GetAxisCount() { return mNumAxes; }
|
||||
|
||||
protected:
|
||||
void GetButtonValueFromAction(VRControllerState& aControllerState,
|
||||
const ControllerAction& aPressAction,
|
||||
const ControllerAction& aTouchAction);
|
||||
void GetTriggerValueFromAction(VRControllerState& aControllerState,
|
||||
const ControllerAction& aAction);
|
||||
void GetAxisValueFromAction(VRControllerState& aControllerState,
|
||||
const ControllerAction& aAction,
|
||||
bool aInvertAxis = false);
|
||||
uint32_t mNumButtons;
|
||||
uint32_t mNumAxes;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // GFX_VR_SERVICE_OPENVRCONTROLLERMAPPER_H
|
51
gfx/vr/service/OpenVRCosmosMapper.cpp
Normal file
51
gfx/vr/service/OpenVRCosmosMapper.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
/* -*- 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 "OpenVRCosmosMapper.h"
|
||||
|
||||
#include "moz_external_vr.h"
|
||||
#include "VRSession.h"
|
||||
|
||||
namespace mozilla::gfx {
|
||||
|
||||
void OpenVRCosmosMapper::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: a placeholder button for trackpad.
|
||||
++mNumButtons;
|
||||
// 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: Bumper
|
||||
GetButtonValueFromAction(aControllerState,
|
||||
aControllerInfo.mActionBumper_Pressed,
|
||||
aControllerInfo.mActionBumper_Pressed);
|
||||
|
||||
// Axis 0, 1: placeholder axes for touchpad.
|
||||
mNumAxes += 2;
|
||||
// Axis 2, 3: Thumbstick
|
||||
GetAxisValueFromAction(aControllerState,
|
||||
aControllerInfo.mActionThumbstick_Analog);
|
||||
|
||||
aControllerState.numButtons = mNumButtons;
|
||||
aControllerState.numAxes = mNumAxes;
|
||||
}
|
||||
|
||||
} // namespace mozilla::gfx
|
26
gfx/vr/service/OpenVRCosmosMapper.h
Normal file
26
gfx/vr/service/OpenVRCosmosMapper.h
Normal file
@ -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_OPENVRCOSMOSMAPPER_H
|
||||
#define GFX_VR_SERVICE_OPENVRCOSMOSMAPPER_H
|
||||
|
||||
#include "OpenVRControllerMapper.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
class OpenVRCosmosMapper : public OpenVRControllerMapper {
|
||||
public:
|
||||
OpenVRCosmosMapper() = default;
|
||||
virtual ~OpenVRCosmosMapper() = default;
|
||||
virtual void UpdateButtons(VRControllerState& aControllerState,
|
||||
ControllerInfo& aControllerInfo);
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // GFX_VR_SERVICE_OPENVRCOSMOSMAPPER_H
|
70
gfx/vr/service/OpenVRDefaultMapper.cpp
Normal file
70
gfx/vr/service/OpenVRDefaultMapper.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
/* -*- 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 "OpenVRDefaultMapper.h"
|
||||
|
||||
#include "moz_external_vr.h"
|
||||
#include "VRSession.h"
|
||||
|
||||
namespace mozilla::gfx {
|
||||
|
||||
void OpenVRDefaultMapper::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: Menu
|
||||
GetButtonValueFromAction(aControllerState,
|
||||
aControllerInfo.mActionMenu_Pressed,
|
||||
aControllerInfo.mActionMenu_Touched);
|
||||
// Button 5: A
|
||||
GetButtonValueFromAction(aControllerState, aControllerInfo.mActionA_Pressed,
|
||||
aControllerInfo.mActionA_Touched);
|
||||
// Button 6: B
|
||||
GetButtonValueFromAction(aControllerState, aControllerInfo.mActionB_Pressed,
|
||||
aControllerInfo.mActionB_Touched);
|
||||
// Button 7: Bumper
|
||||
GetButtonValueFromAction(aControllerState,
|
||||
aControllerInfo.mActionBumper_Pressed,
|
||||
aControllerInfo.mActionBumper_Pressed);
|
||||
// Button 8: Finger index
|
||||
GetTriggerValueFromAction(aControllerState,
|
||||
aControllerInfo.mActionFingerIndex_Value);
|
||||
// Button 9: Finger middle
|
||||
GetTriggerValueFromAction(aControllerState,
|
||||
aControllerInfo.mActionFingerMiddle_Value);
|
||||
// Button 10: Finger ring
|
||||
GetTriggerValueFromAction(aControllerState,
|
||||
aControllerInfo.mActionFingerRing_Value);
|
||||
// Button 11: 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
|
26
gfx/vr/service/OpenVRDefaultMapper.h
Normal file
26
gfx/vr/service/OpenVRDefaultMapper.h
Normal file
@ -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_OPENVRDEFAULTMAPPER_H
|
||||
#define GFX_VR_SERVICE_OPENVRDEFAULTMAPPER_H
|
||||
|
||||
#include "OpenVRControllerMapper.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
class OpenVRDefaultMapper : public OpenVRControllerMapper {
|
||||
public:
|
||||
OpenVRDefaultMapper() = default;
|
||||
virtual ~OpenVRDefaultMapper() = default;
|
||||
virtual void UpdateButtons(VRControllerState& aControllerState,
|
||||
ControllerInfo& aControllerInfo);
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // GFX_VR_SERVICE_OPENVRDEFAULTMAPPER_H
|
File diff suppressed because it is too large
Load Diff
@ -12,6 +12,7 @@
|
||||
#include "openvr.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "moz_external_vr.h"
|
||||
#include "OpenVRControllerMapper.h"
|
||||
|
||||
#if defined(XP_WIN)
|
||||
# include <d3d11_1.h>
|
||||
@ -21,6 +22,7 @@ class nsITimer;
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
class VRThread;
|
||||
class OpenVRControllerMapper;
|
||||
|
||||
static const int kNumOpenVRHaptics = 1;
|
||||
|
||||
@ -32,57 +34,6 @@ enum OpenVRHand : int8_t {
|
||||
None = -1
|
||||
};
|
||||
|
||||
struct ControllerAction {
|
||||
nsCString name;
|
||||
nsCString type;
|
||||
vr::VRActionHandle_t handle = vr::k_ulInvalidActionHandle;
|
||||
|
||||
ControllerAction() = default;
|
||||
|
||||
ControllerAction(const char* aName, const char* aType)
|
||||
: name(aName), type(aType) {}
|
||||
};
|
||||
|
||||
struct ControllerInfo {
|
||||
vr::VRInputValueHandle_t mSource = vr::k_ulInvalidInputValueHandle;
|
||||
|
||||
ControllerAction mActionPose;
|
||||
ControllerAction mActionHaptic;
|
||||
|
||||
ControllerAction mActionTrackpad_Analog;
|
||||
ControllerAction mActionTrackpad_Pressed;
|
||||
ControllerAction mActionTrackpad_Touched;
|
||||
|
||||
ControllerAction mActionTrigger_Value;
|
||||
|
||||
ControllerAction mActionGrip_Pressed;
|
||||
ControllerAction mActionGrip_Touched;
|
||||
ControllerAction mActionMenu_Pressed;
|
||||
ControllerAction mActionMenu_Touched;
|
||||
ControllerAction mActionSystem_Pressed;
|
||||
ControllerAction mActionSystem_Touched;
|
||||
|
||||
// --- Knuckles & Cosmos
|
||||
ControllerAction mActionA_Pressed;
|
||||
ControllerAction mActionA_Touched;
|
||||
ControllerAction mActionB_Pressed;
|
||||
ControllerAction mActionB_Touched;
|
||||
|
||||
// --- Knuckles, Cosmos, and WMR
|
||||
ControllerAction mActionThumbstick_Analog;
|
||||
ControllerAction mActionThumbstick_Pressed;
|
||||
ControllerAction mActionThumbstick_Touched;
|
||||
|
||||
// --- Knuckles
|
||||
ControllerAction mActionFingerIndex_Value;
|
||||
ControllerAction mActionFingerMiddle_Value;
|
||||
ControllerAction mActionFingerRing_Value;
|
||||
ControllerAction mActionFingerPinky_Value;
|
||||
|
||||
// --- Cosmos
|
||||
ControllerAction mActionBumper_Pressed;
|
||||
};
|
||||
|
||||
class OpenVRSession : public VRSession {
|
||||
public:
|
||||
OpenVRSession();
|
||||
@ -141,7 +92,8 @@ class OpenVRSession : public VRSession {
|
||||
#endif
|
||||
void GetControllerDeviceId(::vr::ETrackedDeviceClass aDeviceType,
|
||||
::vr::TrackedDeviceIndex_t aDeviceIndex,
|
||||
nsCString& aId);
|
||||
nsCString& aId,
|
||||
mozilla::gfx::VRControllerType& aControllerType);
|
||||
void UpdateHaptics();
|
||||
void StartHapticThread();
|
||||
void StopHapticThread();
|
||||
@ -151,6 +103,7 @@ class OpenVRSession : public VRSession {
|
||||
RefPtr<nsITimer> mHapticTimer;
|
||||
RefPtr<VRThread> mHapticThread;
|
||||
mozilla::Mutex mControllerHapticStateMutex;
|
||||
UniquePtr<OpenVRControllerMapper> mControllerMapper;
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
43
gfx/vr/service/OpenVRViveMapper.cpp
Normal file
43
gfx/vr/service/OpenVRViveMapper.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/* -*- 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 "OpenVRViveMapper.h"
|
||||
|
||||
#include "moz_external_vr.h"
|
||||
#include "VRSession.h"
|
||||
|
||||
namespace mozilla::gfx {
|
||||
|
||||
void OpenVRViveMapper::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: Trackpad
|
||||
GetButtonValueFromAction(aControllerState,
|
||||
aControllerInfo.mActionTrackpad_Pressed,
|
||||
aControllerInfo.mActionTrackpad_Touched);
|
||||
// Button 3: a placeholder button for thumbstick.
|
||||
++mNumButtons;
|
||||
// Button 4: Menu
|
||||
GetButtonValueFromAction(aControllerState,
|
||||
aControllerInfo.mActionMenu_Pressed,
|
||||
aControllerInfo.mActionMenu_Touched);
|
||||
|
||||
// Axis 0, 1: Trackpad
|
||||
GetAxisValueFromAction(aControllerState,
|
||||
aControllerInfo.mActionTrackpad_Analog);
|
||||
|
||||
aControllerState.numButtons = mNumButtons;
|
||||
aControllerState.numAxes = mNumAxes;
|
||||
}
|
||||
|
||||
} // namespace mozilla::gfx
|
26
gfx/vr/service/OpenVRViveMapper.h
Normal file
26
gfx/vr/service/OpenVRViveMapper.h
Normal file
@ -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_OPENVRVIVEMAPPER_H
|
||||
#define GFX_VR_SERVICE_OPENVRVIVEMAPPER_H
|
||||
|
||||
#include "OpenVRControllerMapper.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
class OpenVRViveMapper : public OpenVRControllerMapper {
|
||||
public:
|
||||
OpenVRViveMapper() = default;
|
||||
virtual ~OpenVRViveMapper() = default;
|
||||
virtual void UpdateButtons(VRControllerState& aControllerState,
|
||||
ControllerInfo& aControllerInfo);
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // GFX_VR_SERVICE_OPENVRVIVEMAPPER_H
|
51
gfx/vr/service/OpenVRWMRMapper.cpp
Normal file
51
gfx/vr/service/OpenVRWMRMapper.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
/* -*- 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 "OpenVRWMRMapper.h"
|
||||
|
||||
#include "moz_external_vr.h"
|
||||
#include "VRSession.h"
|
||||
|
||||
namespace mozilla::gfx {
|
||||
|
||||
void OpenVRWMRMapper::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: Menu
|
||||
GetButtonValueFromAction(aControllerState,
|
||||
aControllerInfo.mActionMenu_Pressed,
|
||||
aControllerInfo.mActionMenu_Touched);
|
||||
|
||||
// Compared to Edge, we have a wrong implementation for the vertical axis
|
||||
// value. In order to not affect the current VR content, we add a workaround
|
||||
// for yAxis.
|
||||
// Axis 0, 1: Trackpad
|
||||
GetAxisValueFromAction(aControllerState,
|
||||
aControllerInfo.mActionTrackpad_Analog, true);
|
||||
// Axis 2, 3: Thumbstick
|
||||
GetAxisValueFromAction(aControllerState,
|
||||
aControllerInfo.mActionThumbstick_Analog, true);
|
||||
|
||||
aControllerState.numButtons = mNumButtons;
|
||||
aControllerState.numAxes = mNumAxes;
|
||||
}
|
||||
|
||||
} // namespace mozilla::gfx
|
26
gfx/vr/service/OpenVRWMRMapper.h
Normal file
26
gfx/vr/service/OpenVRWMRMapper.h
Normal file
@ -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_OPENVRWMRMAPPER_H
|
||||
#define GFX_VR_SERVICE_OPENVRWMRMAPPER_H
|
||||
|
||||
#include "OpenVRControllerMapper.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
class OpenVRWMRMapper : public OpenVRControllerMapper {
|
||||
public:
|
||||
OpenVRWMRMapper() = default;
|
||||
virtual ~OpenVRWMRMapper() = default;
|
||||
virtual void UpdateButtons(VRControllerState& aControllerState,
|
||||
ControllerInfo& aControllerInfo);
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // GFX_VR_SERVICE_OPENVRWMRMAPPER_H
|
@ -34,6 +34,8 @@ class VRSession {
|
||||
virtual ~VRSession() = default;
|
||||
#endif
|
||||
|
||||
static void UpdateTrigger(VRControllerState& aState, uint32_t aButtonIndex,
|
||||
float aValue, float aThreshold);
|
||||
/**
|
||||
* In order to support WebXR's navigator.xr.IsSessionSupported call without
|
||||
* displaying any permission dialogue, it is necessary to have a safe way to
|
||||
@ -82,8 +84,6 @@ class VRSession {
|
||||
virtual bool SubmitFrame(const mozilla::gfx::VRLayer_Stereo_Immersive& aLayer,
|
||||
const VRLayerTextureHandle& aTexture) = 0;
|
||||
#endif
|
||||
void UpdateTrigger(VRControllerState& aState, uint32_t aButtonIndex,
|
||||
float aValue, float aThreshold);
|
||||
};
|
||||
|
||||
} // namespace gfx
|
||||
|
@ -8,6 +8,7 @@
|
||||
if CONFIG['OS_TARGET'] == 'WINNT':
|
||||
SOURCES += [
|
||||
'OculusSession.cpp',
|
||||
'OpenVRWMRMapper.cpp',
|
||||
]
|
||||
|
||||
# Build OSVR on all platforms except Android
|
||||
@ -39,7 +40,11 @@ if CONFIG['OS_TARGET'] in ('WINNT', 'Linux', 'Darwin'):
|
||||
# which define Size and Points types in the root namespace that
|
||||
# often conflict with our own types.
|
||||
SOURCES += [
|
||||
'OpenVRControllerMapper.cpp',
|
||||
'OpenVRCosmosMapper.cpp',
|
||||
'OpenVRDefaultMapper.cpp',
|
||||
'OpenVRSession.cpp',
|
||||
'OpenVRViveMapper.cpp',
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
Loading…
Reference in New Issue
Block a user