mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 19:50:38 +02:00
Merge pull request #6211 from jherico/killDeviceProxy
Remove DeviceProxy in favor of InputDevice
This commit is contained in:
commit
af20c64c84
32 changed files with 421 additions and 458 deletions
|
@ -636,7 +636,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
|
||||||
});
|
});
|
||||||
|
|
||||||
// A new controllerInput device used to reflect current values from the application state
|
// A new controllerInput device used to reflect current values from the application state
|
||||||
_applicationStateDevice = new controller::StateController("Application");
|
_applicationStateDevice = std::make_shared<controller::StateController>();
|
||||||
auto InHMDLambda = controller::StateController::ReadLambda([]() -> float {
|
auto InHMDLambda = controller::StateController::ReadLambda([]() -> float {
|
||||||
return (float) qApp->getAvatarUpdater()->isHMDMode();
|
return (float) qApp->getAvatarUpdater()->isHMDMode();
|
||||||
});
|
});
|
||||||
|
@ -719,8 +719,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
|
||||||
// Now that menu is initalized we can sync myAvatar with it's state.
|
// Now that menu is initalized we can sync myAvatar with it's state.
|
||||||
getMyAvatar()->updateMotionBehaviorFromMenu();
|
getMyAvatar()->updateMotionBehaviorFromMenu();
|
||||||
|
|
||||||
|
#if 0
|
||||||
// the 3Dconnexion device wants to be initiliazed after a window is displayed.
|
// the 3Dconnexion device wants to be initiliazed after a window is displayed.
|
||||||
ConnexionClient::getInstance().init();
|
ConnexionClient::getInstance().init();
|
||||||
|
#endif
|
||||||
|
|
||||||
auto& packetReceiver = nodeList->getPacketReceiver();
|
auto& packetReceiver = nodeList->getPacketReceiver();
|
||||||
packetReceiver.registerListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket");
|
packetReceiver.registerListener(PacketType::DomainConnectionDenied, this, "handleDomainConnectionDeniedPacket");
|
||||||
|
@ -808,8 +810,7 @@ void Application::cleanupBeforeQuit() {
|
||||||
AnimDebugDraw::getInstance().shutdown();
|
AnimDebugDraw::getInstance().shutdown();
|
||||||
|
|
||||||
// FIXME: once we move to shared pointer for the INputDevice we shoud remove this naked delete:
|
// FIXME: once we move to shared pointer for the INputDevice we shoud remove this naked delete:
|
||||||
delete _applicationStateDevice;
|
_applicationStateDevice.reset();
|
||||||
_applicationStateDevice = nullptr;
|
|
||||||
|
|
||||||
if (_keyboardFocusHighlightID > 0) {
|
if (_keyboardFocusHighlightID > 0) {
|
||||||
getOverlays().deleteOverlay(_keyboardFocusHighlightID);
|
getOverlays().deleteOverlay(_keyboardFocusHighlightID);
|
||||||
|
@ -921,7 +922,10 @@ Application::~Application() {
|
||||||
|
|
||||||
Leapmotion::destroy();
|
Leapmotion::destroy();
|
||||||
RealSense::destroy();
|
RealSense::destroy();
|
||||||
|
|
||||||
|
#if 0
|
||||||
ConnexionClient::getInstance().destroy();
|
ConnexionClient::getInstance().destroy();
|
||||||
|
#endif
|
||||||
|
|
||||||
qInstallMessageHandler(NULL); // NOTE: Do this as late as possible so we continue to get our log messages
|
qInstallMessageHandler(NULL); // NOTE: Do this as late as possible so we continue to get our log messages
|
||||||
}
|
}
|
||||||
|
@ -1024,7 +1028,10 @@ void Application::initializeUi() {
|
||||||
foreach(auto inputPlugin, PluginManager::getInstance()->getInputPlugins()) {
|
foreach(auto inputPlugin, PluginManager::getInstance()->getInputPlugins()) {
|
||||||
QString name = inputPlugin->getName();
|
QString name = inputPlugin->getName();
|
||||||
if (name == KeyboardMouseDevice::NAME) {
|
if (name == KeyboardMouseDevice::NAME) {
|
||||||
_keyboardMouseDevice = static_cast<KeyboardMouseDevice*>(inputPlugin.data()); // TODO: this seems super hacky
|
auto kbm = static_cast<KeyboardMouseDevice*>(inputPlugin.data());
|
||||||
|
// FIXME incredibly evil.... _keyboardMouseDevice is now owned by
|
||||||
|
// both a QSharedPointer and a std::shared_ptr
|
||||||
|
_keyboardMouseDevice = std::shared_ptr<KeyboardMouseDevice>(kbm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateInputModes();
|
updateInputModes();
|
||||||
|
@ -1824,7 +1831,9 @@ void Application::focusOutEvent(QFocusEvent* event) {
|
||||||
inputPlugin->pluginFocusOutEvent();
|
inputPlugin->pluginFocusOutEvent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
ConnexionData::getInstance().focusOutEvent();
|
ConnexionData::getInstance().focusOutEvent();
|
||||||
|
#endif
|
||||||
|
|
||||||
// synthesize events for keys currently pressed, since we may not get their release events
|
// synthesize events for keys currently pressed, since we may not get their release events
|
||||||
foreach (int key, _keysPressed) {
|
foreach (int key, _keysPressed) {
|
||||||
|
|
|
@ -446,8 +446,8 @@ private:
|
||||||
|
|
||||||
OctreeQuery _octreeQuery; // NodeData derived class for querying octee cells from octree servers
|
OctreeQuery _octreeQuery; // NodeData derived class for querying octee cells from octree servers
|
||||||
|
|
||||||
controller::StateController* _applicationStateDevice{ nullptr }; // Default ApplicationDevice reflecting the state of different properties of the session
|
std::shared_ptr<controller::StateController> _applicationStateDevice; // Default ApplicationDevice reflecting the state of different properties of the session
|
||||||
KeyboardMouseDevice* _keyboardMouseDevice{ nullptr }; // Default input device, the good old keyboard mouse and maybe touchpad
|
std::shared_ptr<KeyboardMouseDevice> _keyboardMouseDevice; // Default input device, the good old keyboard mouse and maybe touchpad
|
||||||
AvatarUpdate* _avatarUpdate {nullptr};
|
AvatarUpdate* _avatarUpdate {nullptr};
|
||||||
SimpleMovingAverage _avatarSimsPerSecond {10};
|
SimpleMovingAverage _avatarSimsPerSecond {10};
|
||||||
int _avatarSimsPerSecondReport {0};
|
int _avatarSimsPerSecondReport {0};
|
||||||
|
|
|
@ -464,11 +464,13 @@ Menu::Menu() {
|
||||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::MeshVisible, 0, true,
|
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::MeshVisible, 0, true,
|
||||||
avatar, SLOT(setEnableMeshVisible(bool)));
|
avatar, SLOT(setEnableMeshVisible(bool)));
|
||||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::DisableEyelidAdjustment, 0, false);
|
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::DisableEyelidAdjustment, 0, false);
|
||||||
|
#if 0
|
||||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu,
|
addCheckableActionToQMenuAndActionHash(avatarDebugMenu,
|
||||||
MenuOption::Connexion,
|
MenuOption::Connexion,
|
||||||
0, false,
|
0, false,
|
||||||
&ConnexionClient::getInstance(),
|
&ConnexionClient::getInstance(),
|
||||||
SLOT(toggleConnexion(bool)));
|
SLOT(toggleConnexion(bool)));
|
||||||
|
#endif
|
||||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::ComfortMode, 0, true);
|
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::ComfortMode, 0, true);
|
||||||
|
|
||||||
MenuWrapper* handOptionsMenu = developerMenu->addMenu("Hands");
|
MenuWrapper* handOptionsMenu = developerMenu->addMenu("Hands");
|
||||||
|
|
|
@ -9,8 +9,10 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "3DConnexionClient.h"
|
#include "3DConnexionClient.h"
|
||||||
|
|
||||||
|
#if 0
|
||||||
#include <UserActivityLogger.h>
|
#include <UserActivityLogger.h>
|
||||||
#include <PathUtils.h>
|
#include <PathUtils.h>
|
||||||
|
|
||||||
|
@ -967,3 +969,4 @@ void MessageHandler(unsigned int connection, unsigned int messageType, void *mes
|
||||||
#endif // __APPLE__
|
#endif // __APPLE__
|
||||||
|
|
||||||
#endif // HAVE_3DCONNEXIONCLIENT
|
#endif // HAVE_3DCONNEXIONCLIENT
|
||||||
|
#endif
|
|
@ -11,6 +11,7 @@
|
||||||
#ifndef hifi_3DConnexionClient_h
|
#ifndef hifi_3DConnexionClient_h
|
||||||
#define hifi_3DConnexionClient_h
|
#define hifi_3DConnexionClient_h
|
||||||
|
|
||||||
|
#if 0
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QLibrary>
|
#include <QLibrary>
|
||||||
#include <controllers/UserInputMapper.h>
|
#include <controllers/UserInputMapper.h>
|
||||||
|
@ -217,4 +218,6 @@ public:
|
||||||
void handleAxisEvent();
|
void handleAxisEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // defined(hifi_3DConnexionClient_h)
|
#endif // defined(hifi_3DConnexionClient_h)
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
#include "Actions.h"
|
#include "Actions.h"
|
||||||
|
|
||||||
#include "UserInputMapper.h"
|
#include "impl/endpoints/ActionEndpoint.h"
|
||||||
|
|
||||||
namespace controller {
|
namespace controller {
|
||||||
|
|
||||||
|
@ -29,86 +29,80 @@ namespace controller {
|
||||||
return makePair(ChannelType::POSE, action, name);
|
return makePair(ChannelType::POSE, action, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Device functions
|
EndpointPointer ActionsDevice::createEndpoint(const Input& input) const {
|
||||||
void ActionsDevice::buildDeviceProxy(DeviceProxy::Pointer proxy) {
|
return std::make_shared<ActionEndpoint>(input);
|
||||||
proxy->_name = _name;
|
|
||||||
proxy->getButton = [this](const Input& input, int timestamp) -> bool { return false; };
|
|
||||||
proxy->getAxis = [this](const Input& input, int timestamp) -> float { return 0; };
|
|
||||||
proxy->getAvailabeInputs = [this]() -> QVector<Input::NamedPair> {
|
|
||||||
QVector<Input::NamedPair> availableInputs{
|
|
||||||
makeAxisPair(Action::TRANSLATE_X, "TranslateX"),
|
|
||||||
makeAxisPair(Action::TRANSLATE_Y, "TranslateY"),
|
|
||||||
makeAxisPair(Action::TRANSLATE_Z, "TranslateZ"),
|
|
||||||
makeAxisPair(Action::ROLL, "Roll"),
|
|
||||||
makeAxisPair(Action::PITCH, "Pitch"),
|
|
||||||
makeAxisPair(Action::YAW, "Yaw"),
|
|
||||||
makeAxisPair(Action::STEP_YAW, "StepYaw"),
|
|
||||||
makeAxisPair(Action::STEP_PITCH, "StepPitch"),
|
|
||||||
makeAxisPair(Action::STEP_ROLL, "StepRoll"),
|
|
||||||
makeAxisPair(Action::STEP_TRANSLATE_X, "StepTranslateX"),
|
|
||||||
makeAxisPair(Action::STEP_TRANSLATE_X, "StepTranslateY"),
|
|
||||||
makeAxisPair(Action::STEP_TRANSLATE_X, "StepTranslateZ"),
|
|
||||||
|
|
||||||
makePosePair(Action::LEFT_HAND, "LeftHand"),
|
|
||||||
makePosePair(Action::RIGHT_HAND, "RightHand"),
|
|
||||||
|
|
||||||
makeButtonPair(Action::LEFT_HAND_CLICK, "LeftHandClick"),
|
|
||||||
makeButtonPair(Action::RIGHT_HAND_CLICK, "RightHandClick"),
|
|
||||||
|
|
||||||
makeButtonPair(Action::SHIFT, "Shift"),
|
|
||||||
makeButtonPair(Action::ACTION1, "PrimaryAction"),
|
|
||||||
makeButtonPair(Action::ACTION2, "SecondaryAction"),
|
|
||||||
makeButtonPair(Action::CONTEXT_MENU, "ContextMenu"),
|
|
||||||
makeButtonPair(Action::TOGGLE_MUTE, "ToggleMute"),
|
|
||||||
|
|
||||||
// Aliases and bisected versions
|
|
||||||
makeAxisPair(Action::LONGITUDINAL_BACKWARD, "Backward"),
|
|
||||||
makeAxisPair(Action::LONGITUDINAL_FORWARD, "Forward"),
|
|
||||||
makeAxisPair(Action::LATERAL_LEFT, "StrafeLeft"),
|
|
||||||
makeAxisPair(Action::LATERAL_RIGHT, "StrafeRight"),
|
|
||||||
makeAxisPair(Action::VERTICAL_DOWN, "Down"),
|
|
||||||
makeAxisPair(Action::VERTICAL_UP, "Up"),
|
|
||||||
makeAxisPair(Action::YAW_LEFT, "YawLeft"),
|
|
||||||
makeAxisPair(Action::YAW_RIGHT, "YawRight"),
|
|
||||||
makeAxisPair(Action::PITCH_DOWN, "PitchDown"),
|
|
||||||
makeAxisPair(Action::PITCH_UP, "PitchUp"),
|
|
||||||
makeAxisPair(Action::BOOM_IN, "BoomIn"),
|
|
||||||
makeAxisPair(Action::BOOM_OUT, "BoomOut"),
|
|
||||||
|
|
||||||
// Deprecated aliases
|
|
||||||
// FIXME remove after we port all scripts
|
|
||||||
makeAxisPair(Action::LONGITUDINAL_BACKWARD, "LONGITUDINAL_BACKWARD"),
|
|
||||||
makeAxisPair(Action::LONGITUDINAL_FORWARD, "LONGITUDINAL_FORWARD"),
|
|
||||||
makeAxisPair(Action::LATERAL_LEFT, "LATERAL_LEFT"),
|
|
||||||
makeAxisPair(Action::LATERAL_RIGHT, "LATERAL_RIGHT"),
|
|
||||||
makeAxisPair(Action::VERTICAL_DOWN, "VERTICAL_DOWN"),
|
|
||||||
makeAxisPair(Action::VERTICAL_UP, "VERTICAL_UP"),
|
|
||||||
makeAxisPair(Action::YAW_LEFT, "YAW_LEFT"),
|
|
||||||
makeAxisPair(Action::YAW_RIGHT, "YAW_RIGHT"),
|
|
||||||
makeAxisPair(Action::PITCH_DOWN, "PITCH_DOWN"),
|
|
||||||
makeAxisPair(Action::PITCH_UP, "PITCH_UP"),
|
|
||||||
makeAxisPair(Action::BOOM_IN, "BOOM_IN"),
|
|
||||||
makeAxisPair(Action::BOOM_OUT, "BOOM_OUT"),
|
|
||||||
|
|
||||||
makePosePair(Action::LEFT_HAND, "LEFT_HAND"),
|
|
||||||
makePosePair(Action::RIGHT_HAND, "RIGHT_HAND"),
|
|
||||||
|
|
||||||
makeButtonPair(Action::LEFT_HAND_CLICK, "LEFT_HAND_CLICK"),
|
|
||||||
makeButtonPair(Action::RIGHT_HAND_CLICK, "RIGHT_HAND_CLICK"),
|
|
||||||
|
|
||||||
makeButtonPair(Action::SHIFT, "SHIFT"),
|
|
||||||
makeButtonPair(Action::ACTION1, "ACTION1"),
|
|
||||||
makeButtonPair(Action::ACTION2, "ACTION2"),
|
|
||||||
makeButtonPair(Action::CONTEXT_MENU, "CONTEXT_MENU"),
|
|
||||||
makeButtonPair(Action::TOGGLE_MUTE, "TOGGLE_MUTE"),
|
|
||||||
};
|
|
||||||
return availableInputs;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ActionsDevice::getDefaultMappingConfig() {
|
// Device functions
|
||||||
return QString();
|
Input::NamedVector ActionsDevice::getAvailableInputs() const {
|
||||||
|
static Input::NamedVector availableInputs {
|
||||||
|
makeAxisPair(Action::TRANSLATE_X, "TranslateX"),
|
||||||
|
makeAxisPair(Action::TRANSLATE_Y, "TranslateY"),
|
||||||
|
makeAxisPair(Action::TRANSLATE_Z, "TranslateZ"),
|
||||||
|
makeAxisPair(Action::ROLL, "Roll"),
|
||||||
|
makeAxisPair(Action::PITCH, "Pitch"),
|
||||||
|
makeAxisPair(Action::YAW, "Yaw"),
|
||||||
|
makeAxisPair(Action::STEP_YAW, "StepYaw"),
|
||||||
|
makeAxisPair(Action::STEP_PITCH, "StepPitch"),
|
||||||
|
makeAxisPair(Action::STEP_ROLL, "StepRoll"),
|
||||||
|
makeAxisPair(Action::STEP_TRANSLATE_X, "StepTranslateX"),
|
||||||
|
makeAxisPair(Action::STEP_TRANSLATE_X, "StepTranslateY"),
|
||||||
|
makeAxisPair(Action::STEP_TRANSLATE_X, "StepTranslateZ"),
|
||||||
|
|
||||||
|
makePosePair(Action::LEFT_HAND, "LeftHand"),
|
||||||
|
makePosePair(Action::RIGHT_HAND, "RightHand"),
|
||||||
|
|
||||||
|
makeButtonPair(Action::LEFT_HAND_CLICK, "LeftHandClick"),
|
||||||
|
makeButtonPair(Action::RIGHT_HAND_CLICK, "RightHandClick"),
|
||||||
|
|
||||||
|
makeButtonPair(Action::SHIFT, "Shift"),
|
||||||
|
makeButtonPair(Action::ACTION1, "PrimaryAction"),
|
||||||
|
makeButtonPair(Action::ACTION2, "SecondaryAction"),
|
||||||
|
makeButtonPair(Action::CONTEXT_MENU, "ContextMenu"),
|
||||||
|
makeButtonPair(Action::TOGGLE_MUTE, "ToggleMute"),
|
||||||
|
|
||||||
|
// Aliases and bisected versions
|
||||||
|
makeAxisPair(Action::LONGITUDINAL_BACKWARD, "Backward"),
|
||||||
|
makeAxisPair(Action::LONGITUDINAL_FORWARD, "Forward"),
|
||||||
|
makeAxisPair(Action::LATERAL_LEFT, "StrafeLeft"),
|
||||||
|
makeAxisPair(Action::LATERAL_RIGHT, "StrafeRight"),
|
||||||
|
makeAxisPair(Action::VERTICAL_DOWN, "Down"),
|
||||||
|
makeAxisPair(Action::VERTICAL_UP, "Up"),
|
||||||
|
makeAxisPair(Action::YAW_LEFT, "YawLeft"),
|
||||||
|
makeAxisPair(Action::YAW_RIGHT, "YawRight"),
|
||||||
|
makeAxisPair(Action::PITCH_DOWN, "PitchDown"),
|
||||||
|
makeAxisPair(Action::PITCH_UP, "PitchUp"),
|
||||||
|
makeAxisPair(Action::BOOM_IN, "BoomIn"),
|
||||||
|
makeAxisPair(Action::BOOM_OUT, "BoomOut"),
|
||||||
|
|
||||||
|
// Deprecated aliases
|
||||||
|
// FIXME remove after we port all scripts
|
||||||
|
makeAxisPair(Action::LONGITUDINAL_BACKWARD, "LONGITUDINAL_BACKWARD"),
|
||||||
|
makeAxisPair(Action::LONGITUDINAL_FORWARD, "LONGITUDINAL_FORWARD"),
|
||||||
|
makeAxisPair(Action::LATERAL_LEFT, "LATERAL_LEFT"),
|
||||||
|
makeAxisPair(Action::LATERAL_RIGHT, "LATERAL_RIGHT"),
|
||||||
|
makeAxisPair(Action::VERTICAL_DOWN, "VERTICAL_DOWN"),
|
||||||
|
makeAxisPair(Action::VERTICAL_UP, "VERTICAL_UP"),
|
||||||
|
makeAxisPair(Action::YAW_LEFT, "YAW_LEFT"),
|
||||||
|
makeAxisPair(Action::YAW_RIGHT, "YAW_RIGHT"),
|
||||||
|
makeAxisPair(Action::PITCH_DOWN, "PITCH_DOWN"),
|
||||||
|
makeAxisPair(Action::PITCH_UP, "PITCH_UP"),
|
||||||
|
makeAxisPair(Action::BOOM_IN, "BOOM_IN"),
|
||||||
|
makeAxisPair(Action::BOOM_OUT, "BOOM_OUT"),
|
||||||
|
|
||||||
|
makePosePair(Action::LEFT_HAND, "LEFT_HAND"),
|
||||||
|
makePosePair(Action::RIGHT_HAND, "RIGHT_HAND"),
|
||||||
|
|
||||||
|
makeButtonPair(Action::LEFT_HAND_CLICK, "LEFT_HAND_CLICK"),
|
||||||
|
makeButtonPair(Action::RIGHT_HAND_CLICK, "RIGHT_HAND_CLICK"),
|
||||||
|
|
||||||
|
makeButtonPair(Action::SHIFT, "SHIFT"),
|
||||||
|
makeButtonPair(Action::ACTION1, "ACTION1"),
|
||||||
|
makeButtonPair(Action::ACTION2, "ACTION2"),
|
||||||
|
makeButtonPair(Action::CONTEXT_MENU, "CONTEXT_MENU"),
|
||||||
|
makeButtonPair(Action::TOGGLE_MUTE, "TOGGLE_MUTE"),
|
||||||
|
};
|
||||||
|
return availableInputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionsDevice::update(float deltaTime, bool jointsCaptured) {
|
void ActionsDevice::update(float deltaTime, bool jointsCaptured) {
|
||||||
|
|
|
@ -89,11 +89,8 @@ class ActionsDevice : public QObject, public InputDevice {
|
||||||
Q_PROPERTY(QString name READ getName)
|
Q_PROPERTY(QString name READ getName)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const QString& getName() const { return _name; }
|
virtual EndpointPointer createEndpoint(const Input& input) const override;
|
||||||
|
virtual Input::NamedVector getAvailableInputs() const override;
|
||||||
// Device functions
|
|
||||||
virtual void buildDeviceProxy(DeviceProxy::Pointer proxy) override;
|
|
||||||
virtual QString getDefaultMappingConfig() override;
|
|
||||||
virtual void update(float deltaTime, bool jointsCaptured) override;
|
virtual void update(float deltaTime, bool jointsCaptured) override;
|
||||||
virtual void focusOutEvent() override;
|
virtual void focusOutEvent() override;
|
||||||
|
|
||||||
|
@ -103,10 +100,4 @@ public:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "StandardControls.h"
|
|
||||||
|
|
||||||
|
|
||||||
#endif // hifi_StandardController_h
|
#endif // hifi_StandardController_h
|
||||||
|
|
|
@ -10,21 +10,5 @@
|
||||||
#include "DeviceProxy.h"
|
#include "DeviceProxy.h"
|
||||||
|
|
||||||
namespace controller {
|
namespace controller {
|
||||||
|
|
||||||
float DeviceProxy::getValue(const Input& input, int timestamp) const {
|
|
||||||
switch (input.getType()) {
|
|
||||||
case ChannelType::BUTTON:
|
|
||||||
return getButton(input, timestamp) ? 1.0f : 0.0f;
|
|
||||||
|
|
||||||
case ChannelType::AXIS:
|
|
||||||
return getAxis(input, timestamp);
|
|
||||||
|
|
||||||
case ChannelType::POSE:
|
|
||||||
return getPose(input, timestamp).valid ? 1.0f : 0.0f;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return NAN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
#include "Pose.h"
|
#include "Pose.h"
|
||||||
|
|
||||||
namespace controller {
|
namespace controller {
|
||||||
|
/*
|
||||||
using Modifiers = std::vector<Input>;
|
using Modifiers = std::vector<Input>;
|
||||||
typedef QPair<Input, QString> InputPair;
|
typedef QPair<Input, QString> InputPair;
|
||||||
class Endpoint;
|
class Endpoint;
|
||||||
|
@ -38,17 +38,10 @@ namespace controller {
|
||||||
class DeviceProxy {
|
class DeviceProxy {
|
||||||
public:
|
public:
|
||||||
using Pointer = std::shared_ptr<DeviceProxy>;
|
using Pointer = std::shared_ptr<DeviceProxy>;
|
||||||
const QString& getName() const { return _name; }
|
|
||||||
ButtonGetter getButton = [] (const Input& input, int timestamp) -> bool { return false; };
|
|
||||||
AxisGetter getAxis = [] (const Input& input, int timestamp) -> float { return 0.0f; };
|
|
||||||
PoseGetter getPose = [](const Input& input, int timestamp) -> Pose { return Pose(); };
|
|
||||||
AvailableInputGetter getAvailabeInputs = []() -> Input::NamedVector const { return Input::NamedVector(); };
|
|
||||||
float getValue(const Input& input, int timestamp = 0) const;
|
|
||||||
|
|
||||||
EndpointCreator createEndpoint = [](const Input& input) -> EndpointPtr { return EndpointPtr(); };
|
|
||||||
|
|
||||||
QString _name;
|
QString _name;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "InputDevice.h"
|
#include "InputDevice.h"
|
||||||
|
|
||||||
#include "Input.h"
|
#include "Input.h"
|
||||||
|
#include "impl/endpoints/InputEndpoint.h"
|
||||||
|
|
||||||
namespace controller {
|
namespace controller {
|
||||||
|
|
||||||
|
@ -59,29 +60,55 @@ namespace controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Input InputDevice::makeInput(controller::StandardButtonChannel button) {
|
Input InputDevice::makeInput(controller::StandardButtonChannel button) const {
|
||||||
return Input(_deviceID, button, ChannelType::BUTTON);
|
return Input(_deviceID, button, ChannelType::BUTTON);
|
||||||
}
|
}
|
||||||
|
|
||||||
Input InputDevice::makeInput(controller::StandardAxisChannel axis) {
|
Input InputDevice::makeInput(controller::StandardAxisChannel axis) const {
|
||||||
return Input(_deviceID, axis, ChannelType::AXIS);
|
return Input(_deviceID, axis, ChannelType::AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
Input InputDevice::makeInput(controller::StandardPoseChannel pose) {
|
Input InputDevice::makeInput(controller::StandardPoseChannel pose) const {
|
||||||
return Input(_deviceID, pose, ChannelType::POSE);
|
return Input(_deviceID, pose, ChannelType::POSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
Input::NamedPair InputDevice::makePair(controller::StandardButtonChannel button, const QString& name) {
|
Input::NamedPair InputDevice::makePair(controller::StandardButtonChannel button, const QString& name) const {
|
||||||
return Input::NamedPair(makeInput(button), name);
|
return Input::NamedPair(makeInput(button), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Input::NamedPair InputDevice::makePair(controller::StandardAxisChannel axis, const QString& name) {
|
Input::NamedPair InputDevice::makePair(controller::StandardAxisChannel axis, const QString& name) const {
|
||||||
return Input::NamedPair(makeInput(axis), name);
|
return Input::NamedPair(makeInput(axis), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Input::NamedPair InputDevice::makePair(controller::StandardPoseChannel pose, const QString& name) {
|
Input::NamedPair InputDevice::makePair(controller::StandardPoseChannel pose, const QString& name) const {
|
||||||
return Input::NamedPair(makeInput(pose), name);
|
return Input::NamedPair(makeInput(pose), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float InputDevice::getValue(ChannelType channelType, uint16_t channel) const {
|
||||||
|
switch (channelType) {
|
||||||
|
case ChannelType::AXIS:
|
||||||
|
return getAxis(channel);
|
||||||
|
|
||||||
|
case ChannelType::BUTTON:
|
||||||
|
return getButton(channel);
|
||||||
|
|
||||||
|
case ChannelType::POSE:
|
||||||
|
return getPose(channel).valid ? 1.0f : 0.0f;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float InputDevice::getValue(const Input& input) const {
|
||||||
|
return getValue(input.getType(), input.channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
EndpointPointer InputDevice::createEndpoint(const Input& input) const {
|
||||||
|
return std::make_shared<InputEndpoint>(input);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,12 +21,16 @@
|
||||||
#include "StandardControls.h"
|
#include "StandardControls.h"
|
||||||
#include "DeviceProxy.h"
|
#include "DeviceProxy.h"
|
||||||
|
|
||||||
|
|
||||||
// Event types for each controller
|
// Event types for each controller
|
||||||
const unsigned int CONTROLLER_0_EVENT = 1500U;
|
const unsigned int CONTROLLER_0_EVENT = 1500U;
|
||||||
const unsigned int CONTROLLER_1_EVENT = 1501U;
|
const unsigned int CONTROLLER_1_EVENT = 1501U;
|
||||||
|
|
||||||
namespace controller {
|
namespace controller {
|
||||||
|
|
||||||
|
class Endpoint;
|
||||||
|
using EndpointPointer = std::shared_ptr<Endpoint>;
|
||||||
|
|
||||||
// NOTE: If something inherits from both InputDevice and InputPlugin, InputPlugin must go first.
|
// NOTE: If something inherits from both InputDevice and InputPlugin, InputPlugin must go first.
|
||||||
// e.g. class Example : public InputPlugin, public InputDevice
|
// e.g. class Example : public InputPlugin, public InputDevice
|
||||||
// instead of class Example : public InputDevice, public InputPlugin
|
// instead of class Example : public InputDevice, public InputPlugin
|
||||||
|
@ -45,8 +49,11 @@ public:
|
||||||
float getAxis(int channel) const;
|
float getAxis(int channel) const;
|
||||||
Pose getPose(int channel) const;
|
Pose getPose(int channel) const;
|
||||||
|
|
||||||
virtual void buildDeviceProxy(DeviceProxy::Pointer proxy) = 0;
|
float getValue(const Input& input) const;
|
||||||
virtual QString getDefaultMappingConfig() = 0;
|
float getValue(ChannelType channelType, uint16_t channel) const;
|
||||||
|
Pose getPoseValue(uint16_t channel) const;
|
||||||
|
|
||||||
|
const QString& getName() const { return _name; }
|
||||||
|
|
||||||
// Update call MUST be called once per simulation loop
|
// Update call MUST be called once per simulation loop
|
||||||
// It takes care of updating the action states and deltas
|
// It takes care of updating the action states and deltas
|
||||||
|
@ -63,20 +70,25 @@ public:
|
||||||
|
|
||||||
static bool getLowVelocityFilter() { return _lowVelocityFilter; };
|
static bool getLowVelocityFilter() { return _lowVelocityFilter; };
|
||||||
|
|
||||||
Input makeInput(StandardButtonChannel button);
|
Input makeInput(StandardButtonChannel button) const;
|
||||||
Input makeInput(StandardAxisChannel axis);
|
Input makeInput(StandardAxisChannel axis) const;
|
||||||
Input makeInput(StandardPoseChannel pose);
|
Input makeInput(StandardPoseChannel pose) const;
|
||||||
Input::NamedPair makePair(StandardButtonChannel button, const QString& name);
|
Input::NamedPair makePair(StandardButtonChannel button, const QString& name) const;
|
||||||
Input::NamedPair makePair(StandardAxisChannel button, const QString& name);
|
Input::NamedPair makePair(StandardAxisChannel button, const QString& name) const;
|
||||||
Input::NamedPair makePair(StandardPoseChannel button, const QString& name);
|
Input::NamedPair makePair(StandardPoseChannel button, const QString& name) const;
|
||||||
public slots:
|
public slots:
|
||||||
static void setLowVelocityFilter(bool newLowVelocityFilter) { _lowVelocityFilter = newLowVelocityFilter; };
|
static void setLowVelocityFilter(bool newLowVelocityFilter) { _lowVelocityFilter = newLowVelocityFilter; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class UserInputMapper;
|
friend class UserInputMapper;
|
||||||
uint16_t _deviceID{ Input::INVALID_DEVICE };
|
|
||||||
|
|
||||||
QString _name;
|
virtual Input::NamedVector getAvailableInputs() const = 0;
|
||||||
|
virtual QString getDefaultMappingConfig() const { return QString(); }
|
||||||
|
virtual EndpointPointer createEndpoint(const Input& input) const;
|
||||||
|
|
||||||
|
uint16_t _deviceID { Input::INVALID_DEVICE };
|
||||||
|
|
||||||
|
const QString _name;
|
||||||
|
|
||||||
ButtonPressedMap _buttonPressedMap;
|
ButtonPressedMap _buttonPressedMap;
|
||||||
AxisStateMap _axisStateMap;
|
AxisStateMap _axisStateMap;
|
||||||
|
|
|
@ -27,10 +27,10 @@
|
||||||
|
|
||||||
static QRegularExpression SANITIZE_NAME_EXPRESSION{ "[\\(\\)\\.\\s]" };
|
static QRegularExpression SANITIZE_NAME_EXPRESSION{ "[\\(\\)\\.\\s]" };
|
||||||
|
|
||||||
static QVariantMap createDeviceMap(const controller::DeviceProxy::Pointer device) {
|
static QVariantMap createDeviceMap(const controller::InputDevice::Pointer device) {
|
||||||
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
||||||
QVariantMap deviceMap;
|
QVariantMap deviceMap;
|
||||||
for (const auto& inputMapping : device->getAvailabeInputs()) {
|
for (const auto& inputMapping : userInputMapper->getAvailableInputs(device->getDeviceID())) {
|
||||||
const auto& input = inputMapping.first;
|
const auto& input = inputMapping.first;
|
||||||
const auto inputName = QString(inputMapping.second).remove(SANITIZE_NAME_EXPRESSION);
|
const auto inputName = QString(inputMapping.second).remove(SANITIZE_NAME_EXPRESSION);
|
||||||
qCDebug(controllers) << "\tInput " << input.getChannel() << (int)input.getType()
|
qCDebug(controllers) << "\tInput " << input.getChannel() << (int)input.getType()
|
||||||
|
@ -179,7 +179,7 @@ namespace controller {
|
||||||
return DependencyManager::get<UserInputMapper>()->getDeviceName((unsigned short)device);
|
return DependencyManager::get<UserInputMapper>()->getDeviceName((unsigned short)device);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<InputPair> ScriptingInterface::getAvailableInputs(unsigned int device) {
|
QVector<Input::NamedPair> ScriptingInterface::getAvailableInputs(unsigned int device) {
|
||||||
return DependencyManager::get<UserInputMapper>()->getAvailableInputs((unsigned short)device);
|
return DependencyManager::get<UserInputMapper>()->getAvailableInputs((unsigned short)device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
|
|
||||||
#include <PathUtils.h>
|
#include <PathUtils.h>
|
||||||
|
|
||||||
#include "DeviceProxy.h"
|
|
||||||
#include "UserInputMapper.h"
|
#include "UserInputMapper.h"
|
||||||
|
#include "impl/endpoints/StandardEndpoint.h"
|
||||||
|
|
||||||
namespace controller {
|
namespace controller {
|
||||||
|
|
||||||
|
@ -33,91 +33,87 @@ void StandardController::focusOutEvent() {
|
||||||
_buttonPressedMap.clear();
|
_buttonPressedMap.clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
void StandardController::buildDeviceProxy(DeviceProxy::Pointer proxy) {
|
Input::NamedVector StandardController::getAvailableInputs() const {
|
||||||
proxy->_name = _name;
|
static Input::NamedVector availableInputs {
|
||||||
proxy->getButton = [this] (const Input& input, int timestamp) -> bool { return getButton(input.getChannel()); };
|
|
||||||
proxy->getAxis = [this] (const Input& input, int timestamp) -> float { return getAxis(input.getChannel()); };
|
|
||||||
proxy->getAvailabeInputs = [this] () -> QVector<Input::NamedPair> {
|
|
||||||
QVector<Input::NamedPair> availableInputs;
|
|
||||||
// Buttons
|
// Buttons
|
||||||
availableInputs.append(makePair(A, "A"));
|
makePair(A, "A"),
|
||||||
availableInputs.append(makePair(B, "B"));
|
makePair(B, "B"),
|
||||||
availableInputs.append(makePair(X, "X"));
|
makePair(X, "X"),
|
||||||
availableInputs.append(makePair(Y, "Y"));
|
makePair(Y, "Y"),
|
||||||
|
|
||||||
// DPad
|
// DPad
|
||||||
availableInputs.append(makePair(DU, "DU"));
|
makePair(DU, "DU"),
|
||||||
availableInputs.append(makePair(DD, "DD"));
|
makePair(DD, "DD"),
|
||||||
availableInputs.append(makePair(DL, "DL"));
|
makePair(DL, "DL"),
|
||||||
availableInputs.append(makePair(DR, "DR"));
|
makePair(DR, "DR"),
|
||||||
|
|
||||||
// Bumpers
|
// Bumpers
|
||||||
availableInputs.append(makePair(LB, "LB"));
|
makePair(LB, "LB"),
|
||||||
availableInputs.append(makePair(RB, "RB"));
|
makePair(RB, "RB"),
|
||||||
|
|
||||||
// Stick press
|
// Stick press
|
||||||
availableInputs.append(makePair(LS, "LS"));
|
makePair(LS, "LS"),
|
||||||
availableInputs.append(makePair(RS, "RS"));
|
makePair(RS, "RS"),
|
||||||
|
|
||||||
// Center buttons
|
// Center buttons
|
||||||
availableInputs.append(makePair(START, "Start"));
|
makePair(START, "Start"),
|
||||||
availableInputs.append(makePair(BACK, "Back"));
|
makePair(BACK, "Back"),
|
||||||
|
|
||||||
// Analog sticks
|
// Analog sticks
|
||||||
availableInputs.append(makePair(LY, "LY"));
|
makePair(LY, "LY"),
|
||||||
availableInputs.append(makePair(LX, "LX"));
|
makePair(LX, "LX"),
|
||||||
availableInputs.append(makePair(RY, "RY"));
|
makePair(RY, "RY"),
|
||||||
availableInputs.append(makePair(RX, "RX"));
|
makePair(RX, "RX"),
|
||||||
|
|
||||||
// Triggers
|
// Triggers
|
||||||
availableInputs.append(makePair(LT, "LT"));
|
makePair(LT, "LT"),
|
||||||
availableInputs.append(makePair(RT, "RT"));
|
makePair(RT, "RT"),
|
||||||
|
|
||||||
|
|
||||||
// Finger abstractions
|
// Finger abstractions
|
||||||
availableInputs.append(makePair(LEFT_PRIMARY_THUMB, "LeftPrimaryThumb"));
|
makePair(LEFT_PRIMARY_THUMB, "LeftPrimaryThumb"),
|
||||||
availableInputs.append(makePair(LEFT_SECONDARY_THUMB, "LeftSecondaryThumb"));
|
makePair(LEFT_SECONDARY_THUMB, "LeftSecondaryThumb"),
|
||||||
availableInputs.append(makePair(RIGHT_PRIMARY_THUMB, "RightPrimaryThumb"));
|
makePair(RIGHT_PRIMARY_THUMB, "RightPrimaryThumb"),
|
||||||
availableInputs.append(makePair(RIGHT_SECONDARY_THUMB, "RightSecondaryThumb"));
|
makePair(RIGHT_SECONDARY_THUMB, "RightSecondaryThumb"),
|
||||||
|
|
||||||
availableInputs.append(makePair(LEFT_PRIMARY_INDEX, "LeftPrimaryIndex"));
|
makePair(LEFT_PRIMARY_INDEX, "LeftPrimaryIndex"),
|
||||||
availableInputs.append(makePair(LEFT_SECONDARY_INDEX, "LeftSecondaryIndex"));
|
makePair(LEFT_SECONDARY_INDEX, "LeftSecondaryIndex"),
|
||||||
availableInputs.append(makePair(RIGHT_PRIMARY_INDEX, "RightPrimaryIndex"));
|
makePair(RIGHT_PRIMARY_INDEX, "RightPrimaryIndex"),
|
||||||
availableInputs.append(makePair(RIGHT_SECONDARY_INDEX, "RightSecondaryIndex"));
|
makePair(RIGHT_SECONDARY_INDEX, "RightSecondaryIndex"),
|
||||||
|
|
||||||
availableInputs.append(makePair(LEFT_GRIP, "LeftGrip"));
|
makePair(LEFT_GRIP, "LeftGrip"),
|
||||||
availableInputs.append(makePair(RIGHT_GRIP, "RightGrip"));
|
makePair(RIGHT_GRIP, "RightGrip"),
|
||||||
|
|
||||||
// Poses
|
// Poses
|
||||||
availableInputs.append(makePair(LEFT_HAND, "LeftHand"));
|
makePair(LEFT_HAND, "LeftHand"),
|
||||||
availableInputs.append(makePair(RIGHT_HAND, "RightHand"));
|
makePair(RIGHT_HAND, "RightHand"),
|
||||||
|
|
||||||
|
|
||||||
// Aliases, PlayStation style names
|
// Aliases, PlayStation style names
|
||||||
availableInputs.append(makePair(LB, "L1"));
|
makePair(LB, "L1"),
|
||||||
availableInputs.append(makePair(RB, "R1"));
|
makePair(RB, "R1"),
|
||||||
availableInputs.append(makePair(LT, "L2"));
|
makePair(LT, "L2"),
|
||||||
availableInputs.append(makePair(RT, "R2"));
|
makePair(RT, "R2"),
|
||||||
availableInputs.append(makePair(LS, "L3"));
|
makePair(LS, "L3"),
|
||||||
availableInputs.append(makePair(RS, "R3"));
|
makePair(RS, "R3"),
|
||||||
availableInputs.append(makePair(BACK, "Select"));
|
makePair(BACK, "Select"),
|
||||||
availableInputs.append(makePair(A, "Cross"));
|
makePair(A, "Cross"),
|
||||||
availableInputs.append(makePair(B, "Circle"));
|
makePair(B, "Circle"),
|
||||||
availableInputs.append(makePair(X, "Square"));
|
makePair(X, "Square"),
|
||||||
availableInputs.append(makePair(Y, "Triangle"));
|
makePair(Y, "Triangle"),
|
||||||
availableInputs.append(makePair(DU, "Up"));
|
makePair(DU, "Up"),
|
||||||
availableInputs.append(makePair(DD, "Down"));
|
makePair(DD, "Down"),
|
||||||
availableInputs.append(makePair(DL, "Left"));
|
makePair(DL, "Left"),
|
||||||
availableInputs.append(makePair(DR, "Right"));
|
makePair(DR, "Right"),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return availableInputs;
|
|
||||||
};
|
};
|
||||||
|
return availableInputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EndpointPointer StandardController::createEndpoint(const Input& input) const {
|
||||||
|
return std::make_shared<StandardEndpoint>(input);
|
||||||
|
}
|
||||||
|
|
||||||
QString StandardController::getDefaultMappingConfig() {
|
QString StandardController::getDefaultMappingConfig() const {
|
||||||
static const QString DEFAULT_MAPPING_JSON = PathUtils::resourcesPath() + "/controllers/standard.json";
|
static const QString DEFAULT_MAPPING_JSON = PathUtils::resourcesPath() + "/controllers/standard.json";
|
||||||
return DEFAULT_MAPPING_JSON;
|
return DEFAULT_MAPPING_JSON;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,9 @@ class StandardController : public QObject, public InputDevice {
|
||||||
Q_PROPERTY(QString name READ getName)
|
Q_PROPERTY(QString name READ getName)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const QString& getName() const { return _name; }
|
virtual EndpointPointer createEndpoint(const Input& input) const override;
|
||||||
|
virtual Input::NamedVector getAvailableInputs() const override;
|
||||||
// Device functions
|
virtual QString getDefaultMappingConfig() const override;
|
||||||
virtual void buildDeviceProxy(DeviceProxy::Pointer proxy) override;
|
|
||||||
virtual QString getDefaultMappingConfig() override;
|
|
||||||
virtual void update(float deltaTime, bool jointsCaptured) override;
|
virtual void update(float deltaTime, bool jointsCaptured) override;
|
||||||
virtual void focusOutEvent() override;
|
virtual void focusOutEvent() override;
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,11 @@ namespace controller {
|
||||||
// Left Analog stick
|
// Left Analog stick
|
||||||
LX = 0,
|
LX = 0,
|
||||||
LY,
|
LY,
|
||||||
|
LZ,
|
||||||
// Right Analog stick
|
// Right Analog stick
|
||||||
RX,
|
RX,
|
||||||
RY,
|
RY,
|
||||||
|
RZ,
|
||||||
// Triggers
|
// Triggers
|
||||||
LT,
|
LT,
|
||||||
RT,
|
RT,
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
namespace controller {
|
namespace controller {
|
||||||
|
|
||||||
StateController::StateController(QString name) : InputDevice(name) {
|
StateController::StateController() : InputDevice("Application") {
|
||||||
}
|
}
|
||||||
|
|
||||||
StateController::~StateController() {
|
StateController::~StateController() {
|
||||||
|
@ -32,30 +32,15 @@ void StateController::focusOutEvent() {}
|
||||||
void StateController::addInputVariant(QString name, ReadLambda& lambda) {
|
void StateController::addInputVariant(QString name, ReadLambda& lambda) {
|
||||||
_namedReadLambdas.push_back(NamedReadLambda(name, lambda));
|
_namedReadLambdas.push_back(NamedReadLambda(name, lambda));
|
||||||
}
|
}
|
||||||
void StateController::buildDeviceProxy(DeviceProxy::Pointer proxy) {
|
|
||||||
proxy->_name = _name;
|
|
||||||
proxy->getButton = [this] (const Input& input, int timestamp) -> bool { return getButton(input.getChannel()); };
|
|
||||||
proxy->getAxis = [this] (const Input& input, int timestamp) -> float { return getAxis(input.getChannel()); };
|
|
||||||
proxy->getAvailabeInputs = [this] () -> QVector<Input::NamedPair> {
|
|
||||||
|
|
||||||
|
|
||||||
QVector<Input::NamedPair> availableInputs;
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
for (auto& pair : _namedReadLambdas) {
|
|
||||||
availableInputs.push_back(Input::NamedPair(Input(_deviceID, i, ChannelType::BUTTON), pair.first));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return availableInputs;
|
|
||||||
};
|
|
||||||
proxy->createEndpoint = [this] (const Input& input) -> Endpoint::Pointer {
|
|
||||||
if (input.getChannel() < _namedReadLambdas.size()) {
|
|
||||||
return std::make_shared<LambdaEndpoint>(_namedReadLambdas[input.getChannel()].second);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Endpoint::Pointer();
|
Input::NamedVector StateController::getAvailableInputs() const {
|
||||||
};
|
Input::NamedVector availableInputs;
|
||||||
|
int i = 0;
|
||||||
|
for (auto& pair : _namedReadLambdas) {
|
||||||
|
availableInputs.push_back(Input::NamedPair(Input(_deviceID, i, ChannelType::BUTTON), pair.first));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return availableInputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
|
|
@ -27,12 +27,11 @@ public:
|
||||||
const QString& getName() const { return _name; }
|
const QString& getName() const { return _name; }
|
||||||
|
|
||||||
// Device functions
|
// Device functions
|
||||||
virtual void buildDeviceProxy(DeviceProxy::Pointer proxy) override;
|
virtual Input::NamedVector getAvailableInputs() const override;
|
||||||
virtual QString getDefaultMappingConfig() override { return QString(); }
|
|
||||||
virtual void update(float deltaTime, bool jointsCaptured) override;
|
virtual void update(float deltaTime, bool jointsCaptured) override;
|
||||||
virtual void focusOutEvent() override;
|
virtual void focusOutEvent() override;
|
||||||
|
|
||||||
StateController(QString name);
|
StateController();
|
||||||
virtual ~StateController();
|
virtual ~StateController();
|
||||||
|
|
||||||
using ReadLambda = std::function<float()>;
|
using ReadLambda = std::function<float()>;
|
||||||
|
|
|
@ -49,13 +49,13 @@ namespace controller {
|
||||||
|
|
||||||
// Default contruct allocate the poutput size with the current hardcoded action channels
|
// Default contruct allocate the poutput size with the current hardcoded action channels
|
||||||
controller::UserInputMapper::UserInputMapper() {
|
controller::UserInputMapper::UserInputMapper() {
|
||||||
_standardController = std::make_shared<StandardController>();
|
registerDevice(std::make_shared<ActionsDevice>());
|
||||||
registerDevice(new ActionsDevice());
|
registerDevice(std::make_shared<StandardController>());
|
||||||
registerDevice(_standardController.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace controller {
|
namespace controller {
|
||||||
|
|
||||||
|
|
||||||
UserInputMapper::~UserInputMapper() {
|
UserInputMapper::~UserInputMapper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,31 +67,24 @@ int UserInputMapper::recordDeviceOfType(const QString& deviceName) {
|
||||||
return _deviceCounts[deviceName];
|
return _deviceCounts[deviceName];
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserInputMapper::registerDevice(InputDevice* device) {
|
void UserInputMapper::registerDevice(InputDevice::Pointer device) {
|
||||||
Locker locker(_lock);
|
Locker locker(_lock);
|
||||||
if (device->_deviceID == Input::INVALID_DEVICE) {
|
if (device->_deviceID == Input::INVALID_DEVICE) {
|
||||||
device->_deviceID = getFreeDeviceID();
|
device->_deviceID = getFreeDeviceID();
|
||||||
}
|
}
|
||||||
const auto& deviceID = device->_deviceID;
|
const auto& deviceID = device->_deviceID;
|
||||||
DeviceProxy::Pointer proxy = std::make_shared<DeviceProxy>();
|
|
||||||
proxy->_name = device->_name;
|
|
||||||
device->buildDeviceProxy(proxy);
|
|
||||||
|
|
||||||
int numberOfType = recordDeviceOfType(proxy->_name);
|
int numberOfType = recordDeviceOfType(device->getName());
|
||||||
if (numberOfType > 1) {
|
|
||||||
proxy->_name += QString::number(numberOfType);
|
|
||||||
}
|
|
||||||
|
|
||||||
qCDebug(controllers) << "Registered input device <" << proxy->_name << "> deviceID = " << deviceID;
|
qCDebug(controllers) << "Registered input device <" << device->getName() << "> deviceID = " << deviceID;
|
||||||
|
for (const auto& inputMapping : device->getAvailableInputs()) {
|
||||||
for (const auto& inputMapping : proxy->getAvailabeInputs()) {
|
|
||||||
const auto& input = inputMapping.first;
|
const auto& input = inputMapping.first;
|
||||||
// Ignore aliases
|
// Ignore aliases
|
||||||
if (_endpointsByInput.count(input)) {
|
if (_endpointsByInput.count(input)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Endpoint::Pointer endpoint = proxy->createEndpoint(input);
|
Endpoint::Pointer endpoint = device->createEndpoint(input);
|
||||||
if (!endpoint) {
|
if (!endpoint) {
|
||||||
if (input.device == STANDARD_DEVICE) {
|
if (input.device == STANDARD_DEVICE) {
|
||||||
endpoint = std::make_shared<StandardEndpoint>(input);
|
endpoint = std::make_shared<StandardEndpoint>(input);
|
||||||
|
@ -105,7 +98,7 @@ void UserInputMapper::registerDevice(InputDevice* device) {
|
||||||
_endpointsByInput[input] = endpoint;
|
_endpointsByInput[input] = endpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
_registeredDevices[deviceID] = proxy;
|
_registeredDevices[deviceID] = device;
|
||||||
auto mapping = loadMapping(device->getDefaultMappingConfig());
|
auto mapping = loadMapping(device->getDefaultMappingConfig());
|
||||||
if (mapping) {
|
if (mapping) {
|
||||||
_mappingsByDevice[deviceID] = mapping;
|
_mappingsByDevice[deviceID] = mapping;
|
||||||
|
@ -136,13 +129,13 @@ void UserInputMapper::removeDevice(int deviceID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DeviceProxy::Pointer UserInputMapper::getDeviceProxy(const Input& input) {
|
InputDevice::Pointer UserInputMapper::getDevice(const Input& input) {
|
||||||
Locker locker(_lock);
|
Locker locker(_lock);
|
||||||
auto device = _registeredDevices.find(input.getDevice());
|
auto device = _registeredDevices.find(input.getDevice());
|
||||||
if (device != _registeredDevices.end()) {
|
if (device != _registeredDevices.end()) {
|
||||||
return (device->second);
|
return (device->second);
|
||||||
} else {
|
} else {
|
||||||
return DeviceProxy::Pointer();
|
return InputDevice::Pointer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,8 +183,8 @@ Input UserInputMapper::findDeviceInput(const QString& inputName) const {
|
||||||
|
|
||||||
int deviceID = findDevice(deviceName);
|
int deviceID = findDevice(deviceName);
|
||||||
if (deviceID != Input::INVALID_DEVICE) {
|
if (deviceID != Input::INVALID_DEVICE) {
|
||||||
const auto& deviceProxy = _registeredDevices.at(deviceID);
|
const auto& device = _registeredDevices.at(deviceID);
|
||||||
auto deviceInputs = deviceProxy->getAvailabeInputs();
|
auto deviceInputs = device->getAvailableInputs();
|
||||||
|
|
||||||
for (auto input : deviceInputs) {
|
for (auto input : deviceInputs) {
|
||||||
if (input.second == inputName) {
|
if (input.second == inputName) {
|
||||||
|
@ -273,7 +266,7 @@ void UserInputMapper::update(float deltaTime) {
|
||||||
Input::NamedVector UserInputMapper::getAvailableInputs(uint16 deviceID) const {
|
Input::NamedVector UserInputMapper::getAvailableInputs(uint16 deviceID) const {
|
||||||
Locker locker(_lock);
|
Locker locker(_lock);
|
||||||
auto iterator = _registeredDevices.find(deviceID);
|
auto iterator = _registeredDevices.find(deviceID);
|
||||||
return iterator->second->getAvailabeInputs();
|
return iterator->second->getAvailableInputs();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<Action> UserInputMapper::getAllActions() const {
|
QVector<Action> UserInputMapper::getAllActions() const {
|
||||||
|
@ -336,7 +329,7 @@ void UserInputMapper::assignDefaulActionScales() {
|
||||||
|
|
||||||
static int actionMetaTypeId = qRegisterMetaType<Action>();
|
static int actionMetaTypeId = qRegisterMetaType<Action>();
|
||||||
static int inputMetaTypeId = qRegisterMetaType<Input>();
|
static int inputMetaTypeId = qRegisterMetaType<Input>();
|
||||||
static int inputPairMetaTypeId = qRegisterMetaType<InputPair>();
|
static int inputPairMetaTypeId = qRegisterMetaType<Input::NamedPair>();
|
||||||
static int poseMetaTypeId = qRegisterMetaType<controller::Pose>("Pose");
|
static int poseMetaTypeId = qRegisterMetaType<controller::Pose>("Pose");
|
||||||
|
|
||||||
|
|
||||||
|
@ -344,8 +337,8 @@ QScriptValue inputToScriptValue(QScriptEngine* engine, const Input& input);
|
||||||
void inputFromScriptValue(const QScriptValue& object, Input& input);
|
void inputFromScriptValue(const QScriptValue& object, Input& input);
|
||||||
QScriptValue actionToScriptValue(QScriptEngine* engine, const Action& action);
|
QScriptValue actionToScriptValue(QScriptEngine* engine, const Action& action);
|
||||||
void actionFromScriptValue(const QScriptValue& object, Action& action);
|
void actionFromScriptValue(const QScriptValue& object, Action& action);
|
||||||
QScriptValue inputPairToScriptValue(QScriptEngine* engine, const InputPair& inputPair);
|
QScriptValue inputPairToScriptValue(QScriptEngine* engine, const Input::NamedPair& inputPair);
|
||||||
void inputPairFromScriptValue(const QScriptValue& object, InputPair& inputPair);
|
void inputPairFromScriptValue(const QScriptValue& object, Input::NamedPair& inputPair);
|
||||||
|
|
||||||
QScriptValue inputToScriptValue(QScriptEngine* engine, const Input& input) {
|
QScriptValue inputToScriptValue(QScriptEngine* engine, const Input& input) {
|
||||||
QScriptValue obj = engine->newObject();
|
QScriptValue obj = engine->newObject();
|
||||||
|
@ -372,21 +365,21 @@ void actionFromScriptValue(const QScriptValue& object, Action& action) {
|
||||||
action = Action(object.property("action").toVariant().toInt());
|
action = Action(object.property("action").toVariant().toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue inputPairToScriptValue(QScriptEngine* engine, const InputPair& inputPair) {
|
QScriptValue inputPairToScriptValue(QScriptEngine* engine, const Input::NamedPair& inputPair) {
|
||||||
QScriptValue obj = engine->newObject();
|
QScriptValue obj = engine->newObject();
|
||||||
obj.setProperty("input", inputToScriptValue(engine, inputPair.first));
|
obj.setProperty("input", inputToScriptValue(engine, inputPair.first));
|
||||||
obj.setProperty("inputName", inputPair.second);
|
obj.setProperty("inputName", inputPair.second);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
void inputPairFromScriptValue(const QScriptValue& object, InputPair& inputPair) {
|
void inputPairFromScriptValue(const QScriptValue& object, Input::NamedPair& inputPair) {
|
||||||
inputFromScriptValue(object.property("input"), inputPair.first);
|
inputFromScriptValue(object.property("input"), inputPair.first);
|
||||||
inputPair.second = QString(object.property("inputName").toVariant().toString());
|
inputPair.second = QString(object.property("inputName").toVariant().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserInputMapper::registerControllerTypes(QScriptEngine* engine) {
|
void UserInputMapper::registerControllerTypes(QScriptEngine* engine) {
|
||||||
qScriptRegisterSequenceMetaType<QVector<Action> >(engine);
|
qScriptRegisterSequenceMetaType<QVector<Action> >(engine);
|
||||||
qScriptRegisterSequenceMetaType<QVector<InputPair> >(engine);
|
qScriptRegisterSequenceMetaType<Input::NamedVector>(engine);
|
||||||
qScriptRegisterMetaType(engine, actionToScriptValue, actionFromScriptValue);
|
qScriptRegisterMetaType(engine, actionToScriptValue, actionFromScriptValue);
|
||||||
qScriptRegisterMetaType(engine, inputToScriptValue, inputFromScriptValue);
|
qScriptRegisterMetaType(engine, inputToScriptValue, inputFromScriptValue);
|
||||||
qScriptRegisterMetaType(engine, inputPairToScriptValue, inputPairFromScriptValue);
|
qScriptRegisterMetaType(engine, inputPairToScriptValue, inputPairFromScriptValue);
|
||||||
|
|
|
@ -42,7 +42,6 @@ namespace controller {
|
||||||
Q_ENUMS(Action)
|
Q_ENUMS(Action)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using InputPair = Input::NamedPair;
|
|
||||||
// FIXME move to unordered set / map
|
// FIXME move to unordered set / map
|
||||||
using EndpointToInputMap = std::map<EndpointPointer, Input>;
|
using EndpointToInputMap = std::map<EndpointPointer, Input>;
|
||||||
using MappingNameMap = std::map<QString, MappingPointer>;
|
using MappingNameMap = std::map<QString, MappingPointer>;
|
||||||
|
@ -52,7 +51,7 @@ namespace controller {
|
||||||
using EndpointSet = std::unordered_set<EndpointPointer>;
|
using EndpointSet = std::unordered_set<EndpointPointer>;
|
||||||
using EndpointPair = std::pair<EndpointPointer, EndpointPointer>;
|
using EndpointPair = std::pair<EndpointPointer, EndpointPointer>;
|
||||||
using EndpointPairMap = std::map<EndpointPair, EndpointPointer>;
|
using EndpointPairMap = std::map<EndpointPair, EndpointPointer>;
|
||||||
using DevicesMap = std::map<int, DeviceProxy::Pointer>;
|
using DevicesMap = std::map<int, InputDevice::Pointer>;
|
||||||
using uint16 = uint16_t;
|
using uint16 = uint16_t;
|
||||||
using uint32 = uint32_t;
|
using uint32 = uint32_t;
|
||||||
|
|
||||||
|
@ -65,9 +64,8 @@ namespace controller {
|
||||||
|
|
||||||
static void registerControllerTypes(QScriptEngine* engine);
|
static void registerControllerTypes(QScriptEngine* engine);
|
||||||
|
|
||||||
|
void registerDevice(InputDevice::Pointer device);
|
||||||
void registerDevice(InputDevice* device);
|
InputDevice::Pointer getDevice(const Input& input);
|
||||||
DeviceProxy::Pointer getDeviceProxy(const Input& input);
|
|
||||||
QString getDeviceName(uint16 deviceID);
|
QString getDeviceName(uint16 deviceID);
|
||||||
|
|
||||||
Input::NamedVector getAvailableInputs(uint16 deviceID) const;
|
Input::NamedVector getAvailableInputs(uint16 deviceID) const;
|
||||||
|
@ -104,7 +102,7 @@ namespace controller {
|
||||||
|
|
||||||
DevicesMap getDevices() { return _registeredDevices; }
|
DevicesMap getDevices() { return _registeredDevices; }
|
||||||
uint16 getStandardDeviceID() const { return STANDARD_DEVICE; }
|
uint16 getStandardDeviceID() const { return STANDARD_DEVICE; }
|
||||||
DeviceProxy::Pointer getStandardDevice() { return _registeredDevices[getStandardDeviceID()]; }
|
InputDevice::Pointer getStandardDevice() { return _registeredDevices[getStandardDeviceID()]; }
|
||||||
|
|
||||||
MappingPointer newMapping(const QString& mappingName);
|
MappingPointer newMapping(const QString& mappingName);
|
||||||
MappingPointer parseMapping(const QString& json);
|
MappingPointer parseMapping(const QString& json);
|
||||||
|
@ -122,7 +120,6 @@ namespace controller {
|
||||||
protected:
|
protected:
|
||||||
// GetFreeDeviceID should be called before registering a device to use an ID not used by a different device.
|
// GetFreeDeviceID should be called before registering a device to use an ID not used by a different device.
|
||||||
uint16 getFreeDeviceID() { return _nextFreeDeviceID++; }
|
uint16 getFreeDeviceID() { return _nextFreeDeviceID++; }
|
||||||
InputDevice::Pointer _standardController;
|
|
||||||
DevicesMap _registeredDevices;
|
DevicesMap _registeredDevices;
|
||||||
uint16 _nextFreeDeviceID = STANDARD_DEVICE + 1;
|
uint16 _nextFreeDeviceID = STANDARD_DEVICE + 1;
|
||||||
|
|
||||||
|
@ -184,9 +181,9 @@ namespace controller {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(controller::UserInputMapper::InputPair)
|
Q_DECLARE_METATYPE(controller::Input::NamedPair)
|
||||||
Q_DECLARE_METATYPE(controller::Pose)
|
Q_DECLARE_METATYPE(controller::Pose)
|
||||||
Q_DECLARE_METATYPE(QVector<controller::UserInputMapper::InputPair>)
|
Q_DECLARE_METATYPE(QVector<controller::Input::NamedPair>)
|
||||||
Q_DECLARE_METATYPE(controller::Input)
|
Q_DECLARE_METATYPE(controller::Input)
|
||||||
Q_DECLARE_METATYPE(controller::Action)
|
Q_DECLARE_METATYPE(controller::Action)
|
||||||
Q_DECLARE_METATYPE(QVector<controller::Action>)
|
Q_DECLARE_METATYPE(QVector<controller::Action>)
|
||||||
|
|
|
@ -19,11 +19,11 @@ float InputEndpoint::value(){
|
||||||
return pose().valid ? 1.0f : 0.0f;
|
return pose().valid ? 1.0f : 0.0f;
|
||||||
}
|
}
|
||||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
auto deviceProxy = userInputMapper->getDeviceProxy(_input);
|
auto deviceProxy = userInputMapper->getDevice(_input);
|
||||||
if (!deviceProxy) {
|
if (!deviceProxy) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
return deviceProxy->getValue(_input, 0);
|
return deviceProxy->getValue(_input);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pose InputEndpoint::pose() {
|
Pose InputEndpoint::pose() {
|
||||||
|
@ -32,10 +32,10 @@ Pose InputEndpoint::pose() {
|
||||||
return Pose();
|
return Pose();
|
||||||
}
|
}
|
||||||
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<UserInputMapper>();
|
||||||
auto deviceProxy = userInputMapper->getDeviceProxy(_input);
|
auto deviceProxy = userInputMapper->getDevice(_input);
|
||||||
if (!deviceProxy) {
|
if (!deviceProxy) {
|
||||||
return Pose();
|
return Pose();
|
||||||
}
|
}
|
||||||
return deviceProxy->getPose(_input, 0);
|
return deviceProxy->getPose(_input.channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
set(TARGET_NAME input-plugins)
|
set(TARGET_NAME input-plugins)
|
||||||
setup_hifi_library()
|
setup_hifi_library()
|
||||||
link_hifi_libraries(shared plugins controllers)
|
link_hifi_libraries(shared plugins controllers render-utils)
|
||||||
|
|
||||||
GroupSources("src/input-plugins")
|
GroupSources("src/input-plugins")
|
||||||
|
|
||||||
|
|
|
@ -71,63 +71,58 @@ void Joystick::handleButtonEvent(const SDL_ControllerButtonEvent& event) {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Joystick::buildDeviceProxy(controller::DeviceProxy::Pointer proxy) {
|
controller::Input::NamedVector Joystick::getAvailableInputs() const {
|
||||||
using namespace controller;
|
using namespace controller;
|
||||||
proxy->_name = _name;
|
static const Input::NamedVector availableInputs{
|
||||||
proxy->getButton = [this](const Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); };
|
makePair(A, "A"),
|
||||||
proxy->getAxis = [this](const Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); };
|
makePair(B, "B"),
|
||||||
proxy->getAvailabeInputs = [this]() -> QVector<Input::NamedPair> {
|
makePair(X, "X"),
|
||||||
QVector<Input::NamedPair> availableInputs{
|
makePair(Y, "Y"),
|
||||||
makePair(A, "A"),
|
// DPad
|
||||||
makePair(B, "B"),
|
makePair(DU, "DU"),
|
||||||
makePair(X, "X"),
|
makePair(DD, "DD"),
|
||||||
makePair(Y, "Y"),
|
makePair(DL, "DL"),
|
||||||
// DPad
|
makePair(DR, "DR"),
|
||||||
makePair(DU, "DU"),
|
// Bumpers
|
||||||
makePair(DD, "DD"),
|
makePair(LB, "LB"),
|
||||||
makePair(DL, "DL"),
|
makePair(RB, "RB"),
|
||||||
makePair(DR, "DR"),
|
// Stick press
|
||||||
// Bumpers
|
makePair(LS, "LS"),
|
||||||
makePair(LB, "LB"),
|
makePair(RS, "RS"),
|
||||||
makePair(RB, "RB"),
|
// Center buttons
|
||||||
// Stick press
|
makePair(START, "Start"),
|
||||||
makePair(LS, "LS"),
|
makePair(BACK, "Back"),
|
||||||
makePair(RS, "RS"),
|
// Analog sticks
|
||||||
// Center buttons
|
makePair(LX, "LX"),
|
||||||
makePair(START, "Start"),
|
makePair(LY, "LY"),
|
||||||
makePair(BACK, "Back"),
|
makePair(RX, "RX"),
|
||||||
// Analog sticks
|
makePair(RY, "RY"),
|
||||||
makePair(LX, "LX"),
|
|
||||||
makePair(LY, "LY"),
|
|
||||||
makePair(RX, "RX"),
|
|
||||||
makePair(RY, "RY"),
|
|
||||||
|
|
||||||
// Triggers
|
// Triggers
|
||||||
makePair(LT, "LT"),
|
makePair(LT, "LT"),
|
||||||
makePair(RT, "RT"),
|
makePair(RT, "RT"),
|
||||||
|
|
||||||
// Aliases, PlayStation style names
|
// Aliases, PlayStation style names
|
||||||
makePair(LB, "L1"),
|
makePair(LB, "L1"),
|
||||||
makePair(RB, "R1"),
|
makePair(RB, "R1"),
|
||||||
makePair(LT, "L2"),
|
makePair(LT, "L2"),
|
||||||
makePair(RT, "R2"),
|
makePair(RT, "R2"),
|
||||||
makePair(LS, "L3"),
|
makePair(LS, "L3"),
|
||||||
makePair(RS, "R3"),
|
makePair(RS, "R3"),
|
||||||
makePair(BACK, "Select"),
|
makePair(BACK, "Select"),
|
||||||
makePair(A, "Cross"),
|
makePair(A, "Cross"),
|
||||||
makePair(B, "Circle"),
|
makePair(B, "Circle"),
|
||||||
makePair(X, "Square"),
|
makePair(X, "Square"),
|
||||||
makePair(Y, "Triangle"),
|
makePair(Y, "Triangle"),
|
||||||
makePair(DU, "Up"),
|
makePair(DU, "Up"),
|
||||||
makePair(DD, "Down"),
|
makePair(DD, "Down"),
|
||||||
makePair(DL, "Left"),
|
makePair(DL, "Left"),
|
||||||
makePair(DR, "Right"),
|
makePair(DR, "Right"),
|
||||||
};
|
|
||||||
return availableInputs;
|
|
||||||
};
|
};
|
||||||
|
return availableInputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Joystick::getDefaultMappingConfig() {
|
QString Joystick::getDefaultMappingConfig() const {
|
||||||
static const QString MAPPING_JSON = PathUtils::resourcesPath() + "/controllers/xbox.json";
|
static const QString MAPPING_JSON = PathUtils::resourcesPath() + "/controllers/xbox.json";
|
||||||
return MAPPING_JSON;
|
return MAPPING_JSON;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,12 +32,13 @@ class Joystick : public QObject, public controller::InputDevice {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
using Pointer = std::shared_ptr<Joystick>;
|
||||||
|
|
||||||
const QString& getName() const { return _name; }
|
const QString& getName() const { return _name; }
|
||||||
|
|
||||||
// Device functions
|
// Device functions
|
||||||
virtual void buildDeviceProxy(controller::DeviceProxy::Pointer proxy) override;
|
virtual controller::Input::NamedVector getAvailableInputs() const override;
|
||||||
virtual QString getDefaultMappingConfig() override;
|
virtual QString getDefaultMappingConfig() const override;
|
||||||
virtual void update(float deltaTime, bool jointsCaptured) override;
|
virtual void update(float deltaTime, bool jointsCaptured) override;
|
||||||
virtual void focusOutEvent() override;
|
virtual void focusOutEvent() override;
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ void KeyboardMouseDevice::touchUpdateEvent(const QTouchEvent* event) {
|
||||||
_lastTouch = currentPos;
|
_lastTouch = currentPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
controller::Input KeyboardMouseDevice::makeInput(Qt::Key code) {
|
controller::Input KeyboardMouseDevice::makeInput(Qt::Key code) const {
|
||||||
auto shortCode = (uint16_t)(code & KEYBOARD_MASK);
|
auto shortCode = (uint16_t)(code & KEYBOARD_MASK);
|
||||||
if (shortCode != code) {
|
if (shortCode != code) {
|
||||||
shortCode |= 0x0800; // add this bit instead of the way Qt::Key add a bit on the 3rd byte for some keys
|
shortCode |= 0x0800; // add this bit instead of the way Qt::Key add a bit on the 3rd byte for some keys
|
||||||
|
@ -138,7 +138,7 @@ controller::Input KeyboardMouseDevice::makeInput(Qt::Key code) {
|
||||||
return controller::Input(_deviceID, shortCode, controller::ChannelType::BUTTON);
|
return controller::Input(_deviceID, shortCode, controller::ChannelType::BUTTON);
|
||||||
}
|
}
|
||||||
|
|
||||||
controller::Input KeyboardMouseDevice::makeInput(Qt::MouseButton code) {
|
controller::Input KeyboardMouseDevice::makeInput(Qt::MouseButton code) const {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case Qt::LeftButton:
|
case Qt::LeftButton:
|
||||||
return controller::Input(_deviceID, MOUSE_BUTTON_LEFT, controller::ChannelType::BUTTON);
|
return controller::Input(_deviceID, MOUSE_BUTTON_LEFT, controller::ChannelType::BUTTON);
|
||||||
|
@ -151,31 +151,30 @@ controller::Input KeyboardMouseDevice::makeInput(Qt::MouseButton code) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
controller::Input KeyboardMouseDevice::makeInput(KeyboardMouseDevice::MouseAxisChannel axis) {
|
controller::Input KeyboardMouseDevice::makeInput(KeyboardMouseDevice::MouseAxisChannel axis) const {
|
||||||
return controller::Input(_deviceID, axis, controller::ChannelType::AXIS);
|
return controller::Input(_deviceID, axis, controller::ChannelType::AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
controller::Input KeyboardMouseDevice::makeInput(KeyboardMouseDevice::TouchAxisChannel axis) {
|
controller::Input KeyboardMouseDevice::makeInput(KeyboardMouseDevice::TouchAxisChannel axis) const {
|
||||||
return controller::Input(_deviceID, axis, controller::ChannelType::AXIS);
|
return controller::Input(_deviceID, axis, controller::ChannelType::AXIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
controller::Input KeyboardMouseDevice::makeInput(KeyboardMouseDevice::TouchButtonChannel button) {
|
controller::Input KeyboardMouseDevice::makeInput(KeyboardMouseDevice::TouchButtonChannel button) const {
|
||||||
return controller::Input(_deviceID, button, controller::ChannelType::BUTTON);
|
return controller::Input(_deviceID, button, controller::ChannelType::BUTTON);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardMouseDevice::buildDeviceProxy(controller::DeviceProxy::Pointer proxy) {
|
controller::Input::NamedVector KeyboardMouseDevice::getAvailableInputs() const {
|
||||||
using namespace controller;
|
using namespace controller;
|
||||||
proxy->getButton = [this] (const controller::Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); };
|
static QVector<Input::NamedPair> availableInputs;
|
||||||
proxy->getAxis = [this] (const controller::Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); };
|
static std::once_flag once;
|
||||||
proxy->getAvailabeInputs = [this] () -> QVector<Input::NamedPair> {
|
std::call_once(once, [&] {
|
||||||
QVector<Input::NamedPair> availableInputs;
|
for (int i = (int)Qt::Key_0; i <= (int)Qt::Key_9; i++) {
|
||||||
for (int i = (int) Qt::Key_0; i <= (int) Qt::Key_9; i++) {
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(Qt::Key(i)), QKeySequence(Qt::Key(i)).toString()));
|
availableInputs.append(Input::NamedPair(makeInput(Qt::Key(i)), QKeySequence(Qt::Key(i)).toString()));
|
||||||
}
|
}
|
||||||
for (int i = (int) Qt::Key_A; i <= (int) Qt::Key_Z; i++) {
|
for (int i = (int)Qt::Key_A; i <= (int)Qt::Key_Z; i++) {
|
||||||
availableInputs.append(Input::NamedPair(makeInput(Qt::Key(i)), QKeySequence(Qt::Key(i)).toString()));
|
availableInputs.append(Input::NamedPair(makeInput(Qt::Key(i)), QKeySequence(Qt::Key(i)).toString()));
|
||||||
}
|
}
|
||||||
for (int i = (int) Qt::Key_Left; i <= (int) Qt::Key_Down; i++) {
|
for (int i = (int)Qt::Key_Left; i <= (int)Qt::Key_Down; i++) {
|
||||||
availableInputs.append(Input::NamedPair(makeInput(Qt::Key(i)), QKeySequence(Qt::Key(i)).toString()));
|
availableInputs.append(Input::NamedPair(makeInput(Qt::Key(i)), QKeySequence(Qt::Key(i)).toString()));
|
||||||
}
|
}
|
||||||
availableInputs.append(Input::NamedPair(makeInput(Qt::Key_Space), QKeySequence(Qt::Key_Space).toString()));
|
availableInputs.append(Input::NamedPair(makeInput(Qt::Key_Space), QKeySequence(Qt::Key_Space).toString()));
|
||||||
|
@ -186,27 +185,26 @@ void KeyboardMouseDevice::buildDeviceProxy(controller::DeviceProxy::Pointer prox
|
||||||
availableInputs.append(Input::NamedPair(makeInput(Qt::LeftButton), "LeftMouseClick"));
|
availableInputs.append(Input::NamedPair(makeInput(Qt::LeftButton), "LeftMouseClick"));
|
||||||
availableInputs.append(Input::NamedPair(makeInput(Qt::MiddleButton), "MiddleMouseClick"));
|
availableInputs.append(Input::NamedPair(makeInput(Qt::MiddleButton), "MiddleMouseClick"));
|
||||||
availableInputs.append(Input::NamedPair(makeInput(Qt::RightButton), "RightMouseClick"));
|
availableInputs.append(Input::NamedPair(makeInput(Qt::RightButton), "RightMouseClick"));
|
||||||
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_X_POS), "MouseMoveRight"));
|
availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_X_POS), "MouseMoveRight"));
|
||||||
availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_X_NEG), "MouseMoveLeft"));
|
availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_X_NEG), "MouseMoveLeft"));
|
||||||
availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_Y_POS), "MouseMoveUp"));
|
availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_Y_POS), "MouseMoveUp"));
|
||||||
availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_Y_NEG), "MouseMoveDown"));
|
availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_Y_NEG), "MouseMoveDown"));
|
||||||
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_WHEEL_Y_POS), "MouseWheelRight"));
|
availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_WHEEL_Y_POS), "MouseWheelRight"));
|
||||||
availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_WHEEL_Y_NEG), "MouseWheelLeft"));
|
availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_WHEEL_Y_NEG), "MouseWheelLeft"));
|
||||||
availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_WHEEL_X_POS), "MouseWheelUp"));
|
availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_WHEEL_X_POS), "MouseWheelUp"));
|
||||||
availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_WHEEL_X_NEG), "MouseWheelDown"));
|
availableInputs.append(Input::NamedPair(makeInput(MOUSE_AXIS_WHEEL_X_NEG), "MouseWheelDown"));
|
||||||
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(TOUCH_AXIS_X_POS), "TouchpadRight"));
|
availableInputs.append(Input::NamedPair(makeInput(TOUCH_AXIS_X_POS), "TouchpadRight"));
|
||||||
availableInputs.append(Input::NamedPair(makeInput(TOUCH_AXIS_X_NEG), "TouchpadLeft"));
|
availableInputs.append(Input::NamedPair(makeInput(TOUCH_AXIS_X_NEG), "TouchpadLeft"));
|
||||||
availableInputs.append(Input::NamedPair(makeInput(TOUCH_AXIS_Y_POS), "TouchpadUp"));
|
availableInputs.append(Input::NamedPair(makeInput(TOUCH_AXIS_Y_POS), "TouchpadUp"));
|
||||||
availableInputs.append(Input::NamedPair(makeInput(TOUCH_AXIS_Y_NEG), "TouchpadDown"));
|
availableInputs.append(Input::NamedPair(makeInput(TOUCH_AXIS_Y_NEG), "TouchpadDown"));
|
||||||
|
});
|
||||||
return availableInputs;
|
return availableInputs;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString KeyboardMouseDevice::getDefaultMappingConfig() {
|
QString KeyboardMouseDevice::getDefaultMappingConfig() const {
|
||||||
static const QString MAPPING_JSON = PathUtils::resourcesPath() + "/controllers/keyboardMouse.json";
|
static const QString MAPPING_JSON = PathUtils::resourcesPath() + "/controllers/keyboardMouse.json";
|
||||||
return MAPPING_JSON;
|
return MAPPING_JSON;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,8 +72,8 @@ public:
|
||||||
virtual void pluginUpdate(float deltaTime, bool jointsCaptured) override { update(deltaTime, jointsCaptured); }
|
virtual void pluginUpdate(float deltaTime, bool jointsCaptured) override { update(deltaTime, jointsCaptured); }
|
||||||
|
|
||||||
// Device functions
|
// Device functions
|
||||||
virtual void buildDeviceProxy(controller::DeviceProxy::Pointer proxy) override;
|
virtual controller::Input::NamedVector getAvailableInputs() const override;
|
||||||
virtual QString getDefaultMappingConfig() override;
|
virtual QString getDefaultMappingConfig() const override;
|
||||||
virtual void update(float deltaTime, bool jointsCaptured) override;
|
virtual void update(float deltaTime, bool jointsCaptured) override;
|
||||||
virtual void focusOutEvent() override;
|
virtual void focusOutEvent() override;
|
||||||
|
|
||||||
|
@ -91,11 +91,11 @@ public:
|
||||||
void wheelEvent(QWheelEvent* event);
|
void wheelEvent(QWheelEvent* event);
|
||||||
|
|
||||||
// Let's make it easy for Qt because we assume we love Qt forever
|
// Let's make it easy for Qt because we assume we love Qt forever
|
||||||
controller::Input makeInput(Qt::Key code);
|
controller::Input makeInput(Qt::Key code) const;
|
||||||
controller::Input makeInput(Qt::MouseButton code);
|
controller::Input makeInput(Qt::MouseButton code) const;
|
||||||
controller::Input makeInput(MouseAxisChannel axis);
|
controller::Input makeInput(MouseAxisChannel axis) const;
|
||||||
controller::Input makeInput(TouchAxisChannel axis);
|
controller::Input makeInput(TouchAxisChannel axis) const;
|
||||||
controller::Input makeInput(TouchButtonChannel button);
|
controller::Input makeInput(TouchButtonChannel button) const;
|
||||||
|
|
||||||
static const QString NAME;
|
static const QString NAME;
|
||||||
|
|
||||||
|
|
|
@ -49,11 +49,11 @@ void SDL2Manager::init() {
|
||||||
SDL_JoystickID id = getInstanceId(controller);
|
SDL_JoystickID id = getInstanceId(controller);
|
||||||
if (!_openJoysticks.contains(id)) {
|
if (!_openJoysticks.contains(id)) {
|
||||||
//Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller);
|
//Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller);
|
||||||
Joystick* joystick = new Joystick(id, controller);
|
Joystick::Pointer joystick = std::make_shared<Joystick>(id, controller);
|
||||||
_openJoysticks[id] = joystick;
|
_openJoysticks[id] = joystick;
|
||||||
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
||||||
userInputMapper->registerDevice(joystick);
|
userInputMapper->registerDevice(joystick);
|
||||||
emit joystickAdded(joystick);
|
emit joystickAdded(joystick.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ void SDL2Manager::init() {
|
||||||
|
|
||||||
void SDL2Manager::deinit() {
|
void SDL2Manager::deinit() {
|
||||||
#ifdef HAVE_SDL2
|
#ifdef HAVE_SDL2
|
||||||
qDeleteAll(_openJoysticks);
|
_openJoysticks.clear();
|
||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
#endif
|
#endif
|
||||||
|
@ -103,12 +103,12 @@ void SDL2Manager::pluginUpdate(float deltaTime, bool jointsCaptured) {
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event)) {
|
while (SDL_PollEvent(&event)) {
|
||||||
if (event.type == SDL_CONTROLLERAXISMOTION) {
|
if (event.type == SDL_CONTROLLERAXISMOTION) {
|
||||||
Joystick* joystick = _openJoysticks[event.caxis.which];
|
Joystick::Pointer joystick = _openJoysticks[event.caxis.which];
|
||||||
if (joystick) {
|
if (joystick) {
|
||||||
joystick->handleAxisEvent(event.caxis);
|
joystick->handleAxisEvent(event.caxis);
|
||||||
}
|
}
|
||||||
} else if (event.type == SDL_CONTROLLERBUTTONDOWN || event.type == SDL_CONTROLLERBUTTONUP) {
|
} else if (event.type == SDL_CONTROLLERBUTTONDOWN || event.type == SDL_CONTROLLERBUTTONUP) {
|
||||||
Joystick* joystick = _openJoysticks[event.cbutton.which];
|
Joystick::Pointer joystick = _openJoysticks[event.cbutton.which];
|
||||||
if (joystick) {
|
if (joystick) {
|
||||||
joystick->handleButtonEvent(event.cbutton);
|
joystick->handleButtonEvent(event.cbutton);
|
||||||
}
|
}
|
||||||
|
@ -128,16 +128,18 @@ void SDL2Manager::pluginUpdate(float deltaTime, bool jointsCaptured) {
|
||||||
SDL_JoystickID id = getInstanceId(controller);
|
SDL_JoystickID id = getInstanceId(controller);
|
||||||
if (!_openJoysticks.contains(id)) {
|
if (!_openJoysticks.contains(id)) {
|
||||||
// Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller);
|
// Joystick* joystick = new Joystick(id, SDL_GameControllerName(controller), controller);
|
||||||
Joystick* joystick = new Joystick(id, controller);
|
Joystick::Pointer joystick = std::make_shared<Joystick>(id, controller);
|
||||||
_openJoysticks[id] = joystick;
|
_openJoysticks[id] = joystick;
|
||||||
userInputMapper->registerDevice(joystick);
|
userInputMapper->registerDevice(joystick);
|
||||||
emit joystickAdded(joystick);
|
emit joystickAdded(joystick.get());
|
||||||
}
|
}
|
||||||
} else if (event.type == SDL_CONTROLLERDEVICEREMOVED) {
|
} else if (event.type == SDL_CONTROLLERDEVICEREMOVED) {
|
||||||
Joystick* joystick = _openJoysticks[event.cdevice.which];
|
if (_openJoysticks.contains(event.cdevice.which)) {
|
||||||
_openJoysticks.remove(event.cdevice.which);
|
Joystick::Pointer joystick = _openJoysticks[event.cdevice.which];
|
||||||
userInputMapper->removeDevice(joystick->getDeviceID());
|
_openJoysticks.remove(event.cdevice.which);
|
||||||
emit joystickRemoved(joystick);
|
userInputMapper->removeDevice(joystick->getDeviceID());
|
||||||
|
emit joystickRemoved(joystick.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ private:
|
||||||
int buttonPressed() const { return SDL_PRESSED; }
|
int buttonPressed() const { return SDL_PRESSED; }
|
||||||
int buttonRelease() const { return SDL_RELEASED; }
|
int buttonRelease() const { return SDL_RELEASED; }
|
||||||
|
|
||||||
QMap<SDL_JoystickID, Joystick*> _openJoysticks;
|
QMap<SDL_JoystickID, Joystick::Pointer> _openJoysticks;
|
||||||
#endif
|
#endif
|
||||||
bool _isInitialized;
|
bool _isInitialized;
|
||||||
static const QString NAME;
|
static const QString NAME;
|
||||||
|
|
|
@ -64,11 +64,12 @@ const QString MENU_PATH = MENU_PARENT + ">" + MENU_NAME;
|
||||||
const QString TOGGLE_SMOOTH = "Smooth Sixense Movement";
|
const QString TOGGLE_SMOOTH = "Smooth Sixense Movement";
|
||||||
const float DEFAULT_REACH_LENGTH = 1.5f;
|
const float DEFAULT_REACH_LENGTH = 1.5f;
|
||||||
|
|
||||||
|
static std::shared_ptr<SixenseManager> instance;
|
||||||
SixenseManager::SixenseManager() :
|
SixenseManager::SixenseManager() :
|
||||||
InputDevice("Hydra"),
|
InputDevice("Hydra"),
|
||||||
_reachLength(DEFAULT_REACH_LENGTH)
|
_reachLength(DEFAULT_REACH_LENGTH)
|
||||||
{
|
{
|
||||||
|
instance = std::shared_ptr<SixenseManager>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SixenseManager::isSupported() const {
|
bool SixenseManager::isSupported() const {
|
||||||
|
@ -91,7 +92,7 @@ void SixenseManager::activate() {
|
||||||
true, true);
|
true, true);
|
||||||
|
|
||||||
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
||||||
userInputMapper->registerDevice(this);
|
userInputMapper->registerDevice(instance);
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
|
||||||
|
@ -512,42 +513,37 @@ static const auto R4 = controller::Y;
|
||||||
|
|
||||||
using namespace controller;
|
using namespace controller;
|
||||||
|
|
||||||
void SixenseManager::buildDeviceProxy(controller::DeviceProxy::Pointer proxy) {
|
controller::Input::NamedVector SixenseManager::getAvailableInputs() const {
|
||||||
proxy->getButton = [this](const Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); };
|
using namespace controller;
|
||||||
proxy->getAxis = [this](const Input& input, int timestamp) -> float {
|
static const Input::NamedVector availableInputs {
|
||||||
return this->getAxis(input.getChannel());
|
makePair(L0, "L0"),
|
||||||
|
makePair(L1, "L1"),
|
||||||
|
makePair(L2, "L2"),
|
||||||
|
makePair(L3, "L3"),
|
||||||
|
makePair(L4, "L4"),
|
||||||
|
makePair(LB, "LB"),
|
||||||
|
makePair(LS, "LS"),
|
||||||
|
makePair(LX, "LX"),
|
||||||
|
makePair(LY, "LY"),
|
||||||
|
makePair(LT, "LT"),
|
||||||
|
makePair(R0, "R0"),
|
||||||
|
makePair(R1, "R1"),
|
||||||
|
makePair(R2, "R2"),
|
||||||
|
makePair(R3, "R3"),
|
||||||
|
makePair(R4, "R4"),
|
||||||
|
makePair(RB, "RB"),
|
||||||
|
makePair(RS, "RS"),
|
||||||
|
makePair(RX, "RX"),
|
||||||
|
makePair(RY, "RY"),
|
||||||
|
makePair(RT, "RT"),
|
||||||
|
makePair(LEFT_HAND, "LeftHand"),
|
||||||
|
makePair(RIGHT_HAND, "RightHand"),
|
||||||
};
|
};
|
||||||
proxy->getPose = [this](const Input& input, int timestamp) -> Pose { return this->getPose(input.getChannel()); };
|
return availableInputs;
|
||||||
proxy->getAvailabeInputs = [this]() -> QVector<Input::NamedPair> {
|
};
|
||||||
QVector<Input::NamedPair> availableInputs;
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(L0), "L0"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(L1), "L1"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(L2), "L2"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(L3), "L3"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(L4), "L4"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(LB), "LB"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(LS), "LS"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(LX), "LX"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(LY), "LY"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(LT), "LT"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(R0), "R0"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(R1), "R1"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(R2), "R2"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(R3), "R3"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(R4), "R4"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(RB), "RB"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(RS), "RS"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(RX), "RX"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(RY), "RY"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(RT), "RT"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(LEFT_HAND), "LeftHand"));
|
|
||||||
availableInputs.append(Input::NamedPair(makeInput(RIGHT_HAND), "RightHand"));
|
|
||||||
return availableInputs;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString SixenseManager::getDefaultMappingConfig() {
|
QString SixenseManager::getDefaultMappingConfig() const {
|
||||||
static const QString MAPPING_JSON = PathUtils::resourcesPath() + "/controllers/hydra.json";
|
static const QString MAPPING_JSON = PathUtils::resourcesPath() + "/controllers/hydra.json";
|
||||||
return MAPPING_JSON;
|
return MAPPING_JSON;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,8 +62,8 @@ public:
|
||||||
virtual void pluginUpdate(float deltaTime, bool jointsCaptured) override { update(deltaTime, jointsCaptured); }
|
virtual void pluginUpdate(float deltaTime, bool jointsCaptured) override { update(deltaTime, jointsCaptured); }
|
||||||
|
|
||||||
// Device functions
|
// Device functions
|
||||||
virtual void buildDeviceProxy(controller::DeviceProxy::Pointer proxy) override;
|
virtual controller::Input::NamedVector getAvailableInputs() const override;
|
||||||
virtual QString getDefaultMappingConfig() override;
|
virtual QString getDefaultMappingConfig() const override;
|
||||||
|
|
||||||
virtual void update(float deltaTime, bool jointsCaptured) override;
|
virtual void update(float deltaTime, bool jointsCaptured) override;
|
||||||
virtual void focusOutEvent() override;
|
virtual void focusOutEvent() override;
|
||||||
|
|
|
@ -44,6 +44,8 @@ const QString MENU_NAME = "Vive Controllers";
|
||||||
const QString MENU_PATH = MENU_PARENT + ">" + MENU_NAME;
|
const QString MENU_PATH = MENU_PARENT + ">" + MENU_NAME;
|
||||||
const QString RENDER_CONTROLLERS = "Render Hand Controllers";
|
const QString RENDER_CONTROLLERS = "Render Hand Controllers";
|
||||||
|
|
||||||
|
static std::shared_ptr<ViveControllerManager> instance;
|
||||||
|
|
||||||
ViveControllerManager::ViveControllerManager() :
|
ViveControllerManager::ViveControllerManager() :
|
||||||
InputDevice("Vive"),
|
InputDevice("Vive"),
|
||||||
_trackedControllers(0),
|
_trackedControllers(0),
|
||||||
|
@ -52,7 +54,7 @@ ViveControllerManager::ViveControllerManager() :
|
||||||
_rightHandRenderID(0),
|
_rightHandRenderID(0),
|
||||||
_renderControllers(false)
|
_renderControllers(false)
|
||||||
{
|
{
|
||||||
|
instance = std::shared_ptr<ViveControllerManager>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ViveControllerManager::isSupported() const {
|
bool ViveControllerManager::isSupported() const {
|
||||||
|
@ -278,7 +280,7 @@ void ViveControllerManager::update(float deltaTime, bool jointsCaptured) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_trackedControllers == 0 && numTrackedControllers > 0) {
|
if (_trackedControllers == 0 && numTrackedControllers > 0) {
|
||||||
userInputMapper->registerDevice(this);
|
userInputMapper->registerDevice(instance);
|
||||||
UserActivityLogger::getInstance().connectedDevice("spatial_controller", "steamVR");
|
UserActivityLogger::getInstance().connectedDevice("spatial_controller", "steamVR");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,62 +394,43 @@ void ViveControllerManager::handlePoseEvent(const mat4& mat, bool left) {
|
||||||
_poseStateMap[left ? controller::LEFT_HAND : controller::RIGHT_HAND] = controller::Pose(position, rotation);
|
_poseStateMap[left ? controller::LEFT_HAND : controller::RIGHT_HAND] = controller::Pose(position, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViveControllerManager::buildDeviceProxy(controller::DeviceProxy::Pointer proxy) {
|
controller::Input::NamedVector ViveControllerManager::getAvailableInputs() const {
|
||||||
using namespace controller;
|
using namespace controller;
|
||||||
proxy->_name = _name;
|
QVector<Input::NamedPair> availableInputs{
|
||||||
proxy->getButton = [this](const Input& input, int timestamp) -> bool { return this->getButton(input.getChannel()); };
|
// Trackpad analogs
|
||||||
proxy->getAxis = [this](const Input& input, int timestamp) -> float { return this->getAxis(input.getChannel()); };
|
makePair(LX, "LX"),
|
||||||
proxy->getPose = [this](const Input& input, int timestamp) -> Pose { return this->getPose(input.getChannel()); };
|
makePair(LY, "LY"),
|
||||||
proxy->getAvailabeInputs = [this]() -> QVector<Input::NamedPair> {
|
makePair(RX, "RX"),
|
||||||
QVector<Input::NamedPair> availableInputs{
|
makePair(RY, "RY"),
|
||||||
// Trackpad analogs
|
// trigger analogs
|
||||||
makePair(LX, "LX"),
|
makePair(LT, "LT"),
|
||||||
makePair(LY, "LY"),
|
makePair(RT, "RT"),
|
||||||
makePair(RX, "RX"),
|
|
||||||
makePair(RY, "RY"),
|
|
||||||
// trigger analogs
|
|
||||||
makePair(LT, "LT"),
|
|
||||||
makePair(RT, "RT"),
|
|
||||||
|
|
||||||
makePair(LB, "LB"),
|
makePair(LB, "LB"),
|
||||||
makePair(RB, "RB"),
|
makePair(RB, "RB"),
|
||||||
|
|
||||||
makePair(LS, "LS"),
|
makePair(LS, "LS"),
|
||||||
makePair(RS, "RS"),
|
makePair(RS, "RS"),
|
||||||
makePair(LEFT_HAND, "LeftHand"),
|
makePair(LEFT_HAND, "LeftHand"),
|
||||||
makePair(RIGHT_HAND, "RightHand"),
|
makePair(RIGHT_HAND, "RightHand"),
|
||||||
};
|
|
||||||
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(BUTTON_A, 0), "Left Button A"));
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(GRIP_BUTTON, 0), "Left Grip Button"));
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(TRACKPAD_BUTTON, 0), "Left Trackpad Button"));
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(TRIGGER_BUTTON, 0), "Left Trigger Button"));
|
|
||||||
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(AXIS_Y_POS, 0), "Left Trackpad Up"));
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(AXIS_Y_NEG, 0), "Left Trackpad Down"));
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(AXIS_X_POS, 0), "Left Trackpad Right"));
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(AXIS_X_NEG, 0), "Left Trackpad Left"));
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(BACK_TRIGGER, 0), "Left Back Trigger"));
|
|
||||||
|
|
||||||
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(RIGHT_HAND), "Right Hand"));
|
|
||||||
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(BUTTON_A, 1), "Right Button A"));
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(GRIP_BUTTON, 1), "Right Grip Button"));
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(TRACKPAD_BUTTON, 1), "Right Trackpad Button"));
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(TRIGGER_BUTTON, 1), "Right Trigger Button"));
|
|
||||||
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(AXIS_Y_POS, 1), "Right Trackpad Up"));
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(AXIS_Y_NEG, 1), "Right Trackpad Down"));
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(AXIS_X_POS, 1), "Right Trackpad Right"));
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(AXIS_X_NEG, 1), "Right Trackpad Left"));
|
|
||||||
//availableInputs.append(Input::NamedPair(makeInput(BACK_TRIGGER, 1), "Right Back Trigger"));
|
|
||||||
|
|
||||||
return availableInputs;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//availableInputs.append(Input::NamedPair(makeInput(BUTTON_A, 0), "Left Button A"));
|
||||||
|
//availableInputs.append(Input::NamedPair(makeInput(GRIP_BUTTON, 0), "Left Grip Button"));
|
||||||
|
//availableInputs.append(Input::NamedPair(makeInput(TRACKPAD_BUTTON, 0), "Left Trackpad Button"));
|
||||||
|
//availableInputs.append(Input::NamedPair(makeInput(TRIGGER_BUTTON, 0), "Left Trigger Button"));
|
||||||
|
//availableInputs.append(Input::NamedPair(makeInput(BACK_TRIGGER, 0), "Left Back Trigger"));
|
||||||
|
//availableInputs.append(Input::NamedPair(makeInput(RIGHT_HAND), "Right Hand"));
|
||||||
|
//availableInputs.append(Input::NamedPair(makeInput(BUTTON_A, 1), "Right Button A"));
|
||||||
|
//availableInputs.append(Input::NamedPair(makeInput(GRIP_BUTTON, 1), "Right Grip Button"));
|
||||||
|
//availableInputs.append(Input::NamedPair(makeInput(TRACKPAD_BUTTON, 1), "Right Trackpad Button"));
|
||||||
|
//availableInputs.append(Input::NamedPair(makeInput(TRIGGER_BUTTON, 1), "Right Trigger Button"));
|
||||||
|
//availableInputs.append(Input::NamedPair(makeInput(BACK_TRIGGER, 1), "Right Back Trigger"));
|
||||||
|
|
||||||
|
return availableInputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ViveControllerManager::getDefaultMappingConfig() {
|
QString ViveControllerManager::getDefaultMappingConfig() const {
|
||||||
static const QString MAPPING_JSON = PathUtils::resourcesPath() + "/controllers/vive.json";
|
static const QString MAPPING_JSON = PathUtils::resourcesPath() + "/controllers/vive.json";
|
||||||
return MAPPING_JSON;
|
return MAPPING_JSON;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,8 @@ public:
|
||||||
virtual void pluginUpdate(float deltaTime, bool jointsCaptured) override { update(deltaTime, jointsCaptured); }
|
virtual void pluginUpdate(float deltaTime, bool jointsCaptured) override { update(deltaTime, jointsCaptured); }
|
||||||
|
|
||||||
// Device functions
|
// Device functions
|
||||||
virtual void buildDeviceProxy(controller::DeviceProxy::Pointer proxy) override;
|
virtual controller::Input::NamedVector getAvailableInputs() const override;
|
||||||
virtual QString getDefaultMappingConfig() override;
|
virtual QString getDefaultMappingConfig() const override;
|
||||||
virtual void update(float deltaTime, bool jointsCaptured) override;
|
virtual void update(float deltaTime, bool jointsCaptured) override;
|
||||||
virtual void focusOutEvent() override;
|
virtual void focusOutEvent() override;
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ int main(int argc, char** argv) {
|
||||||
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
auto userInputMapper = DependencyManager::get<controller::UserInputMapper>();
|
||||||
if (name == KeyboardMouseDevice::NAME) {
|
if (name == KeyboardMouseDevice::NAME) {
|
||||||
auto keyboardMouseDevice = static_cast<KeyboardMouseDevice*>(inputPlugin.data()); // TODO: this seems super hacky
|
auto keyboardMouseDevice = static_cast<KeyboardMouseDevice*>(inputPlugin.data()); // TODO: this seems super hacky
|
||||||
userInputMapper->registerDevice(keyboardMouseDevice);
|
userInputMapper->registerDevice(std::shared_ptr<InputDevice>(keyboardMouseDevice));
|
||||||
}
|
}
|
||||||
inputPlugin->pluginUpdate(0, false);
|
inputPlugin->pluginUpdate(0, false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue