From f0034844e7b5ba938b7234239f2f2683f99fd917 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 16 Oct 2015 12:24:12 -0700 Subject: [PATCH] Actions working from the Controller layer --- examples/controllers/controllerMappings.js | 39 ++++++++----------- interface/src/Application.cpp | 2 +- .../src/controllers/ScriptingInterface.cpp | 6 +-- .../src/controllers/UserInputMapper.cpp | 23 ++++++----- .../src/controllers/UserInputMapper.h | 6 ++- 5 files changed, 39 insertions(+), 37 deletions(-) diff --git a/examples/controllers/controllerMappings.js b/examples/controllers/controllerMappings.js index 959dc1b0ca..1007e7bf22 100644 --- a/examples/controllers/controllerMappings.js +++ b/examples/controllers/controllerMappings.js @@ -15,32 +15,26 @@ myFirstMapping = function() { return { "name": "example", - "channels": [ { - "from": "Keyboard.A", - "filters": [ { - "type": "clamp", - "params": [0, 1], - } - ], - "to": "Actions.LONGITUDINAL_FORWARD", - }, { - "from": "Keyboard.Left", - "filters": [ { - "type": "clamp", - "params": [0, 1], - }, { - "type": "invert" - } - ], - "to": "Actions.LONGITUDINAL_BACKWARD", - }, { - "from": "Keyboard.C", + "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.Yaw", + "to": "Actions.LATERAL_LEFT", }, { "from": "Keyboard.B", "to": "Actions.Yaw" @@ -57,7 +51,7 @@ print('myFirstMappingJSON' + JSON.stringify(myFirstMappingJSON)); var mapping = Controller.parseMapping(JSON.stringify(myFirstMappingJSON)); Controller.enableMapping("example"); - +/* Object.keys(Controller.Standard).forEach(function (input) { print("Controller.Standard." + input + ":" + Controller.Standard[input]); }); @@ -71,3 +65,4 @@ Object.keys(Controller.Hardware).forEach(function (deviceName) { Object.keys(Controller.Actions).forEach(function (actionName) { print("Controller.Actions." + actionName + ":" + Controller.Actions[actionName]); }); +*/ \ No newline at end of file diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1e0c296e61..c01e89c6d9 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2692,7 +2692,7 @@ void Application::update(float deltaTime) { auto myAvatar = getMyAvatar(); auto userInputMapper = DependencyManager::get(); userInputMapper->setSensorToWorldMat(myAvatar->getSensorToWorldMatrix()); - userInputMapper->update(deltaTime); + // userInputMapper->update(deltaTime); // This needs to go after userInputMapper->update() because of the keyboard bool jointsCaptured = false; diff --git a/libraries/controllers/src/controllers/ScriptingInterface.cpp b/libraries/controllers/src/controllers/ScriptingInterface.cpp index e91e627f16..a72f24e651 100644 --- a/libraries/controllers/src/controllers/ScriptingInterface.cpp +++ b/libraries/controllers/src/controllers/ScriptingInterface.cpp @@ -103,10 +103,10 @@ namespace controller { virtual float value() override { return _currentValue; } virtual void apply(float newValue, float oldValue, const Pointer& source) override { - _currentValue = newValue; + _currentValue += newValue; if (!(_id == UserInputMapper::Input::INVALID_INPUT)) { auto userInputMapper = DependencyManager::get(); - userInputMapper->setActionState(UserInputMapper::Action(_id.getChannel()), newValue); + userInputMapper->deltaActionState(UserInputMapper::Action(_id.getChannel()), newValue); } } @@ -159,7 +159,7 @@ namespace controller { // Create the endpoints // FIXME action endpoints need to accumulate values, and have them cleared at each frame // _endpoints[actionInput] = std::make_shared(); - _endpoints[actionInput] = std::make_shared(); + _endpoints[actionInput] = std::make_shared(actionInput); } updateMaps(); diff --git a/libraries/controllers/src/controllers/UserInputMapper.cpp b/libraries/controllers/src/controllers/UserInputMapper.cpp index b62e2e0e8f..daa7c78640 100755 --- a/libraries/controllers/src/controllers/UserInputMapper.cpp +++ b/libraries/controllers/src/controllers/UserInputMapper.cpp @@ -295,7 +295,12 @@ void UserInputMapper::update(float deltaTime) { // Scale all the channel step with the scale static const float EPSILON = 0.01f; for (auto i = 0; i < NUM_ACTIONS; i++) { + if (_externalActionStates[i] != 0) { + _actionStates[i] += _externalActionStates[i]; + _externalActionStates[i] = 0.0f; + } _actionStates[i] *= _actionScales[i]; + // Emit only on change, and emit when moving back to 0 if (fabsf(_actionStates[i] - _lastActionStates[i]) > EPSILON) { _lastActionStates[i] = _actionStates[i]; @@ -359,15 +364,15 @@ void UserInputMapper::assignDefaulActionScales() { _actionScales[RIGHT_HAND] = 1.0f; // default _actionScales[LEFT_HAND_CLICK] = 1.0f; // on _actionScales[RIGHT_HAND_CLICK] = 1.0f; // on - _actionStates[SHIFT] = 1.0f; // on - _actionStates[ACTION1] = 1.0f; // default - _actionStates[ACTION2] = 1.0f; // default - _actionStates[TRANSLATE_X] = 1.0f; // default - _actionStates[TRANSLATE_Y] = 1.0f; // default - _actionStates[TRANSLATE_Z] = 1.0f; // default - _actionStates[ROLL] = 1.0f; // default - _actionStates[PITCH] = 1.0f; // default - _actionStates[YAW] = 1.0f; // default + _actionScales[SHIFT] = 1.0f; // on + _actionScales[ACTION1] = 1.0f; // default + _actionScales[ACTION2] = 1.0f; // default + _actionScales[TRANSLATE_X] = 1.0f; // default + _actionScales[TRANSLATE_Y] = 1.0f; // default + _actionScales[TRANSLATE_Z] = 1.0f; // default + _actionScales[ROLL] = 1.0f; // default + _actionScales[PITCH] = 1.0f; // default + _actionScales[YAW] = 1.0f; // default } // This is only necessary as long as the actions are hardcoded diff --git a/libraries/controllers/src/controllers/UserInputMapper.h b/libraries/controllers/src/controllers/UserInputMapper.h index 117fd163bf..7e0832b55a 100644 --- a/libraries/controllers/src/controllers/UserInputMapper.h +++ b/libraries/controllers/src/controllers/UserInputMapper.h @@ -138,7 +138,7 @@ public: uint16 getFreeDeviceID() { return _nextFreeDeviceID++; } bool registerDevice(uint16 deviceID, const DeviceProxy::Pointer& device); - bool registerStandardDevice(const DeviceProxy::Pointer& device) { _standardDevice = device; return true; } + bool registerStandardDevice(const DeviceProxy::Pointer& device) { _standardDevice = device; _registeredDevices[getStandardDeviceID()] = device; return true; } DeviceProxy::Pointer getDeviceProxy(const Input& input); QString getDeviceName(uint16 deviceID); QVector getAvailableInputs(uint16 deviceID) { return _registeredDevices[deviceID]->getAvailabeInputs(); } @@ -214,7 +214,8 @@ public: QVector getActionNames() const; void assignDefaulActionScales(); - void setActionState(Action action, float value) { _actionStates[action] = value; } + void setActionState(Action action, float value) { _externalActionStates[action] = value; } + void deltaActionState(Action action, float delta) { _externalActionStates[action] += delta; } // 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 @@ -297,6 +298,7 @@ protected: ActionToInputsMap _actionToInputsMap; 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);