From 8701d73ee957f39c6d8e27e98b9a6b47198ac545 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 19 Oct 2015 19:05:37 -0700 Subject: [PATCH 1/3] DOing the groundwork to pass along the pose still not working --- examples/controllers/controllerMappings.js | 178 +++++++++--------- .../controllers/src/controllers/Endpoint.h | 7 +- .../src/controllers/ScriptingInterface.cpp | 121 ++++++++++-- .../src/controllers/ScriptingInterface.h | 3 + .../src/controllers/StandardController.cpp | 4 +- .../src/controllers/StandardControls.h | 4 +- .../src/controllers/UserInputMapper.cpp | 36 +++- .../src/controllers/UserInputMapper.h | 7 +- .../src/input-plugins/SixenseManager.cpp | 8 +- 9 files changed, 254 insertions(+), 114 deletions(-) diff --git a/examples/controllers/controllerMappings.js b/examples/controllers/controllerMappings.js index 4de173f16c..66efa63676 100644 --- a/examples/controllers/controllerMappings.js +++ b/examples/controllers/controllerMappings.js @@ -1,90 +1,90 @@ - -// -// controllerScriptingExamples.js -// examples -// -// Created by Sam Gondelman on 6/2/15 -// Copyright 2015 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// Assumes you only have the default keyboard connected - -/*myFirstMapping = function() { -return { - "name": "example", - "channels": [ - { "from": "Keyboard.W", "to": "Actions.LONGITUDINAL_FORWARD" }, - { "from": "Keyboard.S", "to": "Actions.LONGITUDINAL_BACKWARD" }, - - { "from": "Keyboard.Left", "to": "Actions.LATERAL_LEFT" }, - { "from": "Keyboard.Right", "to": "Actions.LATERAL_RIGHT" }, - - { "from": "Keyboard.A", "to": "Actions.YAW_LEFT" }, - { "from": "Keyboard.D", "to": "Actions.YAW_RIGHT" }, - - { "from": "Keyboard.C", "to": "Actions.VERTICAL_DOWN" }, - { "from": "Keyboard.E", "to": "Actions.VERTICAL_UP" }, - { - "from": "Standard.LX", - "filters": [ { - "type": "scale", - "params": [2.0], - } - ], - "to": "Actions.LATERAL_LEFT", - }, { - "from": "Keyboard.B", - "to": "Actions.Yaw" - } - ] -} -} -*/ -mySecondMapping = function() { -return { - "name": "example2", - "channels": [ - { "from": "Standard.LY", "to": "Actions.TranslateZ" }, - { "from": "Standard.LX", "to": "Actions.Yaw" }, - ] -} -} - -//Script.include('mapping-test0.json'); -/*var myFirstMappingJSON = myFirstMapping(); -print('myFirstMappingJSON' + JSON.stringify(myFirstMappingJSON)); - -var mapping = Controller.parseMapping(JSON.stringify(myFirstMappingJSON)); - - -Controller.enableMapping("example3"); - -var mySecondMappingJSON = mySecondMapping(); -print('mySecondMappingJSON' + JSON.stringify(mySecondMappingJSON)); - -var mapping2 = Controller.parseMapping(JSON.stringify(mySecondMappingJSON)); -mapping2.enable(); - -Controller.enableMapping("example2"); -*/ -var mapping3 = Controller.loadMapping(Script.resolvePath("example3.json")); -Controller.enableMapping("example3"); - -/* -Object.keys(Controller.Standard).forEach(function (input) { - print("Controller.Standard." + input + ":" + Controller.Standard[input]); -}); - -Object.keys(Controller.Hardware).forEach(function (deviceName) { - Object.keys(Controller.Hardware[deviceName]).forEach(function (input) { - print("Controller.Hardware." + deviceName + "." + input + ":" + Controller.Hardware[deviceName][input]); - }); -}); - -Object.keys(Controller.Actions).forEach(function (actionName) { - print("Controller.Actions." + actionName + ":" + Controller.Actions[actionName]); -}); + +// +// controllerScriptingExamples.js +// examples +// +// Created by Sam Gondelman on 6/2/15 +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// Assumes you only have the default keyboard connected + +/*myFirstMapping = function() { +return { + "name": "example", + "channels": [ + { "from": "Keyboard.W", "to": "Actions.LONGITUDINAL_FORWARD" }, + { "from": "Keyboard.S", "to": "Actions.LONGITUDINAL_BACKWARD" }, + + { "from": "Keyboard.Left", "to": "Actions.LATERAL_LEFT" }, + { "from": "Keyboard.Right", "to": "Actions.LATERAL_RIGHT" }, + + { "from": "Keyboard.A", "to": "Actions.YAW_LEFT" }, + { "from": "Keyboard.D", "to": "Actions.YAW_RIGHT" }, + + { "from": "Keyboard.C", "to": "Actions.VERTICAL_DOWN" }, + { "from": "Keyboard.E", "to": "Actions.VERTICAL_UP" }, + { + "from": "Standard.LX", + "filters": [ { + "type": "scale", + "params": [2.0], + } + ], + "to": "Actions.LATERAL_LEFT", + }, { + "from": "Keyboard.B", + "to": "Actions.Yaw" + } + ] +} +} +*/ +mySecondMapping = function() { +return { + "name": "example2", + "channels": [ + { "from": "Standard.LY", "to": "Actions.TranslateZ" }, + { "from": "Standard.LX", "to": "Actions.Yaw" }, + ] +} +} + +//Script.include('mapping-test0.json'); +/*var myFirstMappingJSON = myFirstMapping(); +print('myFirstMappingJSON' + JSON.stringify(myFirstMappingJSON)); + +var mapping = Controller.parseMapping(JSON.stringify(myFirstMappingJSON)); + + +Controller.enableMapping("example3"); + +var mySecondMappingJSON = mySecondMapping(); +print('mySecondMappingJSON' + JSON.stringify(mySecondMappingJSON)); + +var mapping2 = Controller.parseMapping(JSON.stringify(mySecondMappingJSON)); +mapping2.enable(); + +Controller.enableMapping("example2"); +*/ +var mapping3 = Controller.loadMapping(Script.resolvePath("example3.json")); +Controller.enableMapping("example3"); + +/* +Object.keys(Controller.Standard).forEach(function (input) { + print("Controller.Standard." + input + ":" + Controller.Standard[input]); +}); + +Object.keys(Controller.Hardware).forEach(function (deviceName) { + Object.keys(Controller.Hardware[deviceName]).forEach(function (input) { + print("Controller.Hardware." + deviceName + "." + input + ":" + Controller.Hardware[deviceName][input]); + }); +}); + +Object.keys(Controller.Actions).forEach(function (actionName) { + print("Controller.Actions." + actionName + ":" + Controller.Actions[actionName]); +}); */ \ No newline at end of file diff --git a/libraries/controllers/src/controllers/Endpoint.h b/libraries/controllers/src/controllers/Endpoint.h index 923412ac6c..ee549b3af8 100644 --- a/libraries/controllers/src/controllers/Endpoint.h +++ b/libraries/controllers/src/controllers/Endpoint.h @@ -35,7 +35,12 @@ namespace controller { Endpoint(const UserInputMapper::Input& input) : _input(input) {} virtual float value() = 0; virtual void apply(float newValue, float oldValue, const Pointer& source) = 0; - const UserInputMapper::Input& getInput() { return _input; } + virtual Pose pose() { return Pose(); } + virtual void apply(const Pose& newValue, const Pose& oldValue, const Pointer& source) {} + + virtual const bool isPose() { return _input.isPose(); } + + const UserInputMapper::Input& getInput() { return _input; } protected: UserInputMapper::Input _input; }; diff --git a/libraries/controllers/src/controllers/ScriptingInterface.cpp b/libraries/controllers/src/controllers/ScriptingInterface.cpp index 3e470fd365..1c753cf750 100644 --- a/libraries/controllers/src/controllers/ScriptingInterface.cpp +++ b/libraries/controllers/src/controllers/ScriptingInterface.cpp @@ -35,10 +35,16 @@ namespace controller { } virtual float value() override { return _currentValue; } - virtual void apply(float newValue, float oldValue, const Pointer& source) override { _currentValue = newValue; } - + virtual void apply(float newValue, float oldValue, const Pointer& source) override { + _currentValue = newValue; + } + virtual Pose pose() override { return _currentPose; } + virtual void apply(const Pose& newValue, const Pose& oldValue, const Pointer& source) override { + _currentPose = newValue; + } private: float _currentValue{ 0.0f }; + Pose _currentPose{}; }; @@ -109,6 +115,49 @@ namespace controller { Endpoint::Pointer _second; }; + class InputEndpoint : public Endpoint { + public: + InputEndpoint(const UserInputMapper::Input& id = UserInputMapper::Input::INVALID_INPUT) + : Endpoint(id) { + } + + virtual float value() override { + _currentValue = 0.0f; + if (isPose()) { + return _currentValue; + } + auto userInputMapper = DependencyManager::get(); + auto deviceProxy = userInputMapper->getDeviceProxy(_input); + if (!deviceProxy) { + return _currentValue; + } + _currentValue = deviceProxy->getValue(_input, 0); + return _currentValue; + } + virtual void apply(float newValue, float oldValue, const Pointer& source) override {} + + virtual Pose pose() override { + _currentPose = Pose(); + if (!isPose()) { + return _currentPose; + } + auto userInputMapper = DependencyManager::get(); + auto deviceProxy = userInputMapper->getDeviceProxy(_input); + if (!deviceProxy) { + return _currentPose; + } + _currentPose = deviceProxy->getPose(_input, 0); + return _currentPose; + } + + virtual void apply(const Pose& newValue, const Pose& oldValue, const Pointer& source) override { + } + + private: + float _currentValue{ 0.0f }; + Pose _currentPose{}; + }; + class ActionEndpoint : public Endpoint { public: ActionEndpoint(const UserInputMapper::Input& id = UserInputMapper::Input::INVALID_INPUT) @@ -125,8 +174,18 @@ namespace controller { } } + virtual Pose pose() override { return _currentPose; } + virtual void apply(const Pose& newValue, const Pose& oldValue, const Pointer& source) override { + _currentPose = newValue; + if (!(_input == UserInputMapper::Input::INVALID_INPUT)) { + auto userInputMapper = DependencyManager::get(); + userInputMapper->setActionState(UserInputMapper::Action(_input.getChannel()), _currentPose); + } + } + private: float _currentValue{ 0.0f }; + Pose _currentPose{}; }; QRegularExpression ScriptingInterface::SANITIZE_NAME_EXPRESSION{ "[\\(\\)\\.\\s]" }; @@ -263,8 +322,34 @@ namespace controller { return getValue(UserInputMapper::Input(device, source, UserInputMapper::ChannelType::AXIS).getID()); } + + Pose ScriptingInterface::getPoseValue(const int& source) const { + if (!Input(source).isPose()) { + return Pose(); + } + + UserInputMapper::Input input(source); + auto iterator = _endpoints.find(input); + if (_endpoints.end() == iterator) { + return Pose(); + } + + const auto& endpoint = iterator->second; + return getPoseValue(endpoint); + } + + Pose ScriptingInterface::getPoseValue(const Endpoint::Pointer& endpoint) const { + + /*auto valuesIterator = _overrideValues.find(endpoint); + if (_overrideValues.end() != valuesIterator) { + return valuesIterator->second; + }*/ + + return endpoint->pose(); + } + Pose ScriptingInterface::getPoseValue(StandardPoseChannel source, uint16_t device) const { - return Pose(); + return getPoseValue(UserInputMapper::Input(device, source, UserInputMapper::ChannelType::POSE).getID()); } void ScriptingInterface::update() { @@ -321,18 +406,25 @@ namespace controller { } // Fetch the value, may have been overriden by previous loopback routes - float value = getValue(source); + if (source->isPose()) { + Pose value = getPoseValue(source); - // Apply each of the filters. - const auto& filters = route->_filters; - for (const auto& filter : route->_filters) { - value = filter->apply(value); - } - if (loopback) { - _overrideValues[source] = value; + destination->apply(value, Pose(), source); } else { - destination->apply(value, 0, source); + float value = getValue(source); + + // Apply each of the filters. + const auto& filters = route->_filters; + for (const auto& filter : route->_filters) { + value = filter->apply(value); + } + + if (loopback) { + _overrideValues[source] = value; + } else { + destination->apply(value, 0, source); + } } } } @@ -483,13 +575,14 @@ namespace controller { if (_endpoints.count(input)) { continue; } - _endpoints[input] = std::make_shared([=] { + /* _endpoints[input] = std::make_shared([=] { auto deviceProxy = userInputMapper->getDeviceProxy(input); if (!deviceProxy) { return 0.0f; } return deviceProxy->getValue(input, 0); - }); + });*/ + _endpoints[input] = std::make_shared(input); } } } diff --git a/libraries/controllers/src/controllers/ScriptingInterface.h b/libraries/controllers/src/controllers/ScriptingInterface.h index f473562b9e..ac3cd6b6c8 100644 --- a/libraries/controllers/src/controllers/ScriptingInterface.h +++ b/libraries/controllers/src/controllers/ScriptingInterface.h @@ -79,7 +79,9 @@ namespace controller { Q_INVOKABLE float getValue(const int& source) const; Q_INVOKABLE float getButtonValue(StandardButtonChannel source, uint16_t device = 0) const; Q_INVOKABLE float getAxisValue(StandardAxisChannel source, uint16_t device = 0) const; + Q_INVOKABLE Pose getPoseValue(const int& source) const; Q_INVOKABLE Pose getPoseValue(StandardPoseChannel source, uint16_t device = 0) const; + Q_INVOKABLE QObject* newMapping(const QString& mappingName = QUuid::createUuid().toString()); Q_INVOKABLE void enableMapping(const QString& mappingName, bool enable = true); Q_INVOKABLE void disableMapping(const QString& mappingName) { enableMapping(mappingName, false); } @@ -148,6 +150,7 @@ namespace controller { void update(Mapping::Pointer& mapping, EndpointSet& consumed); float getValue(const Endpoint::Pointer& endpoint) const; + Pose getPoseValue(const Endpoint::Pointer& endpoint) const; Endpoint::Pointer endpointFor(const QJSValue& endpoint); Endpoint::Pointer endpointFor(const QScriptValue& endpoint); Endpoint::Pointer endpointFor(const UserInputMapper::Input& endpoint); diff --git a/libraries/controllers/src/controllers/StandardController.cpp b/libraries/controllers/src/controllers/StandardController.cpp index 6b1ada25ed..c3261bc789 100644 --- a/libraries/controllers/src/controllers/StandardController.cpp +++ b/libraries/controllers/src/controllers/StandardController.cpp @@ -72,8 +72,8 @@ void StandardController::registerToUserInputMapper(UserInputMapper& mapper) { availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RT), "RT")); // Poses - availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LEFT), "LeftPose")); - availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RIGHT), "RightPose")); + availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LEFT_HAND), "LeftHand")); + availableInputs.append(UserInputMapper::InputPair(makeInput(controller::RIGHT_HAND), "RightHand")); // Aliases, PlayStation style names availableInputs.append(UserInputMapper::InputPair(makeInput(controller::LB), "L1")); diff --git a/libraries/controllers/src/controllers/StandardControls.h b/libraries/controllers/src/controllers/StandardControls.h index 0990e34224..dc39a8bbeb 100644 --- a/libraries/controllers/src/controllers/StandardControls.h +++ b/libraries/controllers/src/controllers/StandardControls.h @@ -50,8 +50,8 @@ namespace controller { // No correlation to SDL enum StandardPoseChannel { - LEFT = 0, - RIGHT, + LEFT_HAND = 0, + RIGHT_HAND, HEAD, NUM_STANDARD_POSES }; diff --git a/libraries/controllers/src/controllers/UserInputMapper.cpp b/libraries/controllers/src/controllers/UserInputMapper.cpp index 26e03b7719..520d19f83f 100755 --- a/libraries/controllers/src/controllers/UserInputMapper.cpp +++ b/libraries/controllers/src/controllers/UserInputMapper.cpp @@ -308,12 +308,17 @@ void UserInputMapper::update(float deltaTime) { } } - // Scale all the channel step with the scale + //manage the external action states changes coming from the Controllers Graph for (auto i = 0; i < NUM_ACTIONS; i++) { if (_externalActionStates[i] != 0) { _actionStates[i] += _externalActionStates[i]; _externalActionStates[i] = 0.0f; } + + if (_externalPoseStates[i].isValid()) { + _poseStates[i] = _externalPoseStates[i]; + _externalPoseStates[i] = PoseValue(); + } } // merge the bisected and non-bisected axes for now @@ -432,6 +437,35 @@ void UserInputMapper::createActionNames() { _actionNames[ROLL] = "Roll"; _actionNames[PITCH] = "Pitch"; _actionNames[YAW] = "Yaw"; + + _actionInputs[LONGITUDINAL_BACKWARD] = Input(ACTIONS_DEVICE, LONGITUDINAL_BACKWARD, ChannelType::AXIS); + _actionInputs[LONGITUDINAL_FORWARD] = Input(ACTIONS_DEVICE, LONGITUDINAL_BACKWARD, ChannelType::AXIS); + _actionInputs[LATERAL_LEFT] = Input(ACTIONS_DEVICE, LATERAL_LEFT, ChannelType::AXIS); + _actionInputs[LATERAL_RIGHT] = Input(ACTIONS_DEVICE, LATERAL_RIGHT, ChannelType::AXIS); + _actionInputs[VERTICAL_DOWN] = Input(ACTIONS_DEVICE, VERTICAL_DOWN, ChannelType::AXIS); + _actionInputs[VERTICAL_UP] = Input(ACTIONS_DEVICE, VERTICAL_UP, ChannelType::AXIS); + _actionInputs[YAW_LEFT] = Input(ACTIONS_DEVICE, YAW_LEFT, ChannelType::AXIS); + _actionInputs[YAW_RIGHT] = Input(ACTIONS_DEVICE, YAW_RIGHT, ChannelType::AXIS); + _actionInputs[PITCH_DOWN] = Input(ACTIONS_DEVICE, PITCH_DOWN, ChannelType::AXIS); + _actionInputs[PITCH_UP] = Input(ACTIONS_DEVICE, PITCH_UP, ChannelType::AXIS); + _actionInputs[BOOM_IN] = Input(ACTIONS_DEVICE, BOOM_IN, ChannelType::AXIS); + _actionInputs[BOOM_OUT] = Input(ACTIONS_DEVICE, BOOM_OUT, ChannelType::AXIS); + _actionInputs[LEFT_HAND] = Input(ACTIONS_DEVICE, LEFT_HAND, ChannelType::POSE); + _actionInputs[RIGHT_HAND] = Input(ACTIONS_DEVICE, RIGHT_HAND, ChannelType::POSE); + _actionInputs[LEFT_HAND_CLICK] = Input(ACTIONS_DEVICE, LEFT_HAND_CLICK, ChannelType::AXIS); + _actionInputs[RIGHT_HAND_CLICK] = Input(ACTIONS_DEVICE, RIGHT_HAND_CLICK, ChannelType::AXIS); + _actionInputs[SHIFT] = Input(ACTIONS_DEVICE, SHIFT, ChannelType::BUTTON); + _actionInputs[ACTION1] = Input(ACTIONS_DEVICE, ACTION1, ChannelType::BUTTON); + _actionInputs[ACTION2] = Input(ACTIONS_DEVICE, ACTION2, ChannelType::BUTTON); + _actionInputs[CONTEXT_MENU] = Input(ACTIONS_DEVICE, CONTEXT_MENU, ChannelType::BUTTON); + _actionInputs[TOGGLE_MUTE] = Input(ACTIONS_DEVICE, TOGGLE_MUTE, ChannelType::AXIS); + _actionInputs[TRANSLATE_X] = Input(ACTIONS_DEVICE, TRANSLATE_X, ChannelType::AXIS); + _actionInputs[TRANSLATE_Y] = Input(ACTIONS_DEVICE, TRANSLATE_Y, ChannelType::AXIS); + _actionInputs[TRANSLATE_Z] = Input(ACTIONS_DEVICE, TRANSLATE_Z, ChannelType::AXIS); + _actionInputs[ROLL] = Input(ACTIONS_DEVICE, ROLL, ChannelType::AXIS); + _actionInputs[PITCH] = Input(ACTIONS_DEVICE, PITCH, ChannelType::AXIS); + _actionInputs[YAW] = Input(ACTIONS_DEVICE, YAW, ChannelType::AXIS); + } void UserInputMapper::registerStandardDevice() { diff --git a/libraries/controllers/src/controllers/UserInputMapper.h b/libraries/controllers/src/controllers/UserInputMapper.h index d463ed0482..c9a6af3bd8 100644 --- a/libraries/controllers/src/controllers/UserInputMapper.h +++ b/libraries/controllers/src/controllers/UserInputMapper.h @@ -134,13 +134,15 @@ public: QVector getAllActions() const; QString getActionName(Action action) const { return UserInputMapper::_actionNames[(int) action]; } float getActionState(Action action) const { return _actionStates[action]; } - PoseValue getPoseState(Action action) const { return _poseStates[action]; } + const PoseValue& getPoseState(Action action) const { return _poseStates[action]; } int findAction(const QString& actionName) const; QVector getActionNames() const; + Input getActionInput(Action action) const { return _actionInputs[action]; } void assignDefaulActionScales(); void setActionState(Action action, float value) { _externalActionStates[action] = value; } void deltaActionState(Action action, float delta) { _externalActionStates[action] += delta; } + void setActionState(Action action, const PoseValue& value) { _externalPoseStates[action] = value; } // Add input channel to the mapper and check that all the used channels are registered. // Return true if theinput channel is created correctly, false either @@ -224,11 +226,14 @@ protected: typedef std::multimap ActionToInputsMap; ActionToInputsMap _actionToInputsMap; + std::vector _actionInputs = std::vector(NUM_ACTIONS, Input()); + std::vector _actionStates = std::vector(NUM_ACTIONS, 0.0f); std::vector _externalActionStates = std::vector(NUM_ACTIONS, 0.0f); std::vector _actionScales = std::vector(NUM_ACTIONS, 1.0f); std::vector _lastActionStates = std::vector(NUM_ACTIONS, 0.0f); std::vector _poseStates = std::vector(NUM_ACTIONS); + std::vector _externalPoseStates = std::vector(NUM_ACTIONS); glm::mat4 _sensorToWorldMat; diff --git a/libraries/input-plugins/src/input-plugins/SixenseManager.cpp b/libraries/input-plugins/src/input-plugins/SixenseManager.cpp index e8cebd8e54..845c51019e 100644 --- a/libraries/input-plugins/src/input-plugins/SixenseManager.cpp +++ b/libraries/input-plugins/src/input-plugins/SixenseManager.cpp @@ -236,7 +236,7 @@ void SixenseManager::update(float deltaTime, bool jointsCaptured) { _poseStateMap.clear(); } } else { - _poseStateMap[left ? controller::StandardPoseChannel::LEFT : controller::StandardPoseChannel::RIGHT] = UserInputMapper::PoseValue(); + _poseStateMap[left ? controller::StandardPoseChannel::LEFT_HAND : controller::StandardPoseChannel::RIGHT_HAND] = UserInputMapper::PoseValue(); } } @@ -444,7 +444,7 @@ void SixenseManager::handlePoseEvent(glm::vec3 position, glm::quat rotation, boo // TODO: find a shortcut with fewer rotations. rotation = _avatarRotation * postOffset * glm::inverse(sixenseToHand) * rotation * preOffset * sixenseToHand; - _poseStateMap[left ? controller::StandardPoseChannel::LEFT : controller::StandardPoseChannel::RIGHT] = + _poseStateMap[left ? controller::StandardPoseChannel::LEFT_HAND : controller::StandardPoseChannel::RIGHT_HAND] = UserInputMapper::PoseValue(position, rotation); #endif // HAVE_SIXENSE } @@ -490,8 +490,8 @@ void SixenseManager::registerToUserInputMapper(UserInputMapper& mapper) { availableInputs.append(UserInputMapper::InputPair(makeInput(RX), "RX")); availableInputs.append(UserInputMapper::InputPair(makeInput(RY), "RY")); availableInputs.append(UserInputMapper::InputPair(makeInput(RT), "RT")); - availableInputs.append(UserInputMapper::InputPair(makeInput(LEFT), "LeftPose")); - availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT), "RightPose")); + availableInputs.append(UserInputMapper::InputPair(makeInput(LEFT_HAND), "LeftHand")); + availableInputs.append(UserInputMapper::InputPair(makeInput(RIGHT_HAND), "RightHand")); return availableInputs; }; mapper.registerDevice(_deviceID, proxy); From 6f7719e9e9cb021545f807129ad5e8c8a4eb2b8a Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 20 Oct 2015 17:44:24 -0700 Subject: [PATCH 2/3] Finally getting the merge to work --- libraries/controllers/src/controllers/Actions.h | 3 ++- .../src/controllers/ScriptingInterface.cpp | 14 ++++++++++++++ .../src/controllers/UserInputMapper.cpp | 1 - .../controllers/src/controllers/UserInputMapper.h | 9 ++++++--- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/libraries/controllers/src/controllers/Actions.h b/libraries/controllers/src/controllers/Actions.h index 2b581eb706..77a772de9e 100644 --- a/libraries/controllers/src/controllers/Actions.h +++ b/libraries/controllers/src/controllers/Actions.h @@ -71,7 +71,8 @@ enum class Action { NUM_ACTIONS, }; -int toInt(Action action) { return static_cast(action); } +template +int toInt(T enumValue) { return static_cast(enumValue); } class ActionsDevice : public QObject, public InputDevice { Q_OBJECT diff --git a/libraries/controllers/src/controllers/ScriptingInterface.cpp b/libraries/controllers/src/controllers/ScriptingInterface.cpp index 37c3035535..40c65549a8 100644 --- a/libraries/controllers/src/controllers/ScriptingInterface.cpp +++ b/libraries/controllers/src/controllers/ScriptingInterface.cpp @@ -71,6 +71,16 @@ controller::ScriptingInterface::ScriptingInterface() { namespace controller { + QObject* ScriptingInterface::newMapping(const QString& mappingName) { + auto userInputMapper = DependencyManager::get(); + return new MappingBuilderProxy(*userInputMapper, userInputMapper->newMapping(mappingName)); + } + + void ScriptingInterface::enableMapping(const QString& mappingName, bool enable) { + auto userInputMapper = DependencyManager::get(); + userInputMapper->enableMapping(mappingName, enable); + } + float ScriptingInterface::getValue(const int& source) const { auto userInputMapper = DependencyManager::get(); return userInputMapper->getValue(Input((uint32_t)source)); @@ -88,6 +98,10 @@ namespace controller { auto userInputMapper = DependencyManager::get(); return userInputMapper->getPose(Input((uint32_t)source)); } + + Pose ScriptingInterface::getPoseValue(StandardPoseChannel source, uint16_t device) const { + return getPoseValue(Input(device, source, ChannelType::POSE).getID()); + } //bool ScriptingInterface::isPrimaryButtonPressed() const { // return isButtonPressed(StandardButtonChannel::A); diff --git a/libraries/controllers/src/controllers/UserInputMapper.cpp b/libraries/controllers/src/controllers/UserInputMapper.cpp index 8dfdd33eba..6c530020a9 100755 --- a/libraries/controllers/src/controllers/UserInputMapper.cpp +++ b/libraries/controllers/src/controllers/UserInputMapper.cpp @@ -31,7 +31,6 @@ controller::UserInputMapper::UserInputMapper() { _standardController = std::make_shared(); registerDevice(new ActionsDevice()); registerDevice(_standardController.get()); - assignDefaulActionScales(); } namespace controller { diff --git a/libraries/controllers/src/controllers/UserInputMapper.h b/libraries/controllers/src/controllers/UserInputMapper.h index d5b2e4e282..e9b6c59596 100644 --- a/libraries/controllers/src/controllers/UserInputMapper.h +++ b/libraries/controllers/src/controllers/UserInputMapper.h @@ -32,6 +32,10 @@ #include "Actions.h" namespace controller { + + class RouteBuilderProxy; + class MappingBuilderProxy; + class UserInputMapper : public QObject, public Dependency { Q_OBJECT SINGLETON_DEPENDENCY @@ -81,7 +85,6 @@ namespace controller { Pose getPoseState(Action action) const { return _poseStates[toInt(action)]; } int findAction(const QString& actionName) const; QVector getActionNames() const; - void assignDefaulActionScales(); void setActionState(Action action, float value) { _externalActionStates[toInt(action)] = value; } void deltaActionState(Action action, float delta) { _externalActionStates[toInt(action)] += delta; } @@ -139,8 +142,8 @@ namespace controller { float getValue(const Endpoint::Pointer& endpoint) const; Pose getPose(const Endpoint::Pointer& endpoint) const; - friend class ::controller::RouteBuilderProxy; - friend class ::controller::MappingBuilderProxy; + friend class RouteBuilderProxy; + friend class MappingBuilderProxy; Endpoint::Pointer endpointFor(const QJSValue& endpoint); Endpoint::Pointer endpointFor(const QScriptValue& endpoint); Endpoint::Pointer endpointFor(const Input& endpoint) const; From da26d0dee159b241932ee2eaadc5921386ce095a Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 20 Oct 2015 18:19:44 -0700 Subject: [PATCH 3/3] Adding the hand poses channels in the controller mapping files --- interface/resources/controllers/hydra.json | 7 +++++-- interface/resources/controllers/standard.json | 4 +++- libraries/controllers/src/controllers/UserInputMapper.h | 1 - 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/interface/resources/controllers/hydra.json b/interface/resources/controllers/hydra.json index 25c8db61cb..c20d54b7c1 100644 --- a/interface/resources/controllers/hydra.json +++ b/interface/resources/controllers/hydra.json @@ -23,6 +23,9 @@ { "from": "Hydra.R1", "to": "Standard.X" }, { "from": "Hydra.R2", "to": "Standard.A" }, { "from": "Hydra.R3", "to": "Standard.B" }, - { "from": "Hydra.R4", "to": "Standard.Y" } - ] + { "from": "Hydra.R4", "to": "Standard.Y" }, + + { "from": "Hydra.LeftHand", "to": "Standard.LeftHand" }, + { "from": "Hydra.RightHand", "to": "Standard.RightHand" } + ] } diff --git a/interface/resources/controllers/standard.json b/interface/resources/controllers/standard.json index 364d24ae16..b662e5394d 100644 --- a/interface/resources/controllers/standard.json +++ b/interface/resources/controllers/standard.json @@ -36,6 +36,8 @@ "from": "Standard.LT", "to": "Actions.BOOM_OUT", "filters": [ { "type": "scale", "scale": 0.1 } ] - } + }, + { "from": "Standard.LeftHand", "to": "Actions.LEFT_HAND" }, + { "from": "Standard.RightHand", "to": "Actions.RIGHT_HAND" } ] } diff --git a/libraries/controllers/src/controllers/UserInputMapper.h b/libraries/controllers/src/controllers/UserInputMapper.h index e9b6c59596..7561ba84af 100644 --- a/libraries/controllers/src/controllers/UserInputMapper.h +++ b/libraries/controllers/src/controllers/UserInputMapper.h @@ -174,6 +174,5 @@ Q_DECLARE_METATYPE(QVector) // Cheating. using UserInputMapper = controller::UserInputMapper; -//>>>>>>> 9c031b6bef988f123cb955c81299395386ec488c #endif // hifi_UserInputMapper_h