From 88f546ca7d0ece306960f9eaadf68ccbd816159d Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 16 Nov 2020 11:36:16 +0100 Subject: [PATCH] Add property to disable joystickinput Set that property to false by default to disable stray joystick input (closes #1370) --- .../openspace/interaction/navigationhandler.h | 3 +- src/interaction/navigationhandler.cpp | 38 +++++++++++++------ src/interaction/orbitalnavigator.cpp | 7 ++++ 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/include/openspace/interaction/navigationhandler.h b/include/openspace/interaction/navigationhandler.h index 24d3ef495b..600456a50d 100644 --- a/include/openspace/interaction/navigationhandler.h +++ b/include/openspace/interaction/navigationhandler.h @@ -166,7 +166,8 @@ private: std::optional _pendingNavigationState; - properties::BoolProperty _disableInputs; + properties::BoolProperty _disableMouseInputs; + properties::BoolProperty _disableJoystickInputs; properties::BoolProperty _useKeyFrameInteraction; }; diff --git a/src/interaction/navigationhandler.cpp b/src/interaction/navigationhandler.cpp index 548a0b9c3b..700dc8d06d 100644 --- a/src/interaction/navigationhandler.cpp +++ b/src/interaction/navigationhandler.cpp @@ -53,13 +53,20 @@ namespace { constexpr const char* KeyReferenceFrame = "ReferenceFrame"; const double Epsilon = 1E-7; - constexpr const openspace::properties::Property::PropertyInfo KeyDisableInputInfo = { - "DisableInputs", + using namespace openspace; + constexpr const properties::Property::PropertyInfo KeyDisableMouseInputInfo = { + "DisableMouseInputs", "Disable all mouse inputs", "Disables all mouse inputs and prevents them from affecting the camera" }; - constexpr const openspace::properties::Property::PropertyInfo KeyFrameInfo = { + constexpr const properties::Property::PropertyInfo KeyDisableJoystickInputInfo = { + "DisableJoystickInputs", + "Disable all joystick inputs", + "Disables all joystick inputs and prevents them from affecting the camera" + }; + + constexpr const properties::Property::PropertyInfo KeyFrameInfo = { "UseKeyFrameInteraction", "Use keyframe interaction", "If this is set to 'true' the entire interaction is based off key frames rather " @@ -148,12 +155,14 @@ NavigationHandler::NavigationState::NavigationState(std::string anchor, std::str NavigationHandler::NavigationHandler() : properties::PropertyOwner({ "NavigationHandler" }) - , _disableInputs(KeyDisableInputInfo, false) + , _disableMouseInputs(KeyDisableMouseInputInfo, false) + , _disableJoystickInputs(KeyDisableJoystickInputInfo, true) , _useKeyFrameInteraction(KeyFrameInfo, false) { addPropertySubOwner(_orbitalNavigator); - addProperty(_disableInputs); + addProperty(_disableMouseInputs); + addProperty(_disableJoystickInputs); addProperty(_useKeyFrameInteraction); } @@ -235,6 +244,13 @@ void NavigationHandler::updateCamera(double deltaTime) { _keyframeNavigator.updateCamera(*_camera, _playbackModeEnabled); } else { + if (_disableJoystickInputs) { + std::fill( + global::joystickInputStates->begin(), + global::joystickInputStates->end(), + JoystickInputState() + ); + } _orbitalNavigator.updateStatesFromInput(_inputState, deltaTime); _orbitalNavigator.updateCameraStateFromStates(deltaTime); } @@ -334,28 +350,28 @@ const InputState& NavigationHandler::inputState() const { } void NavigationHandler::mouseButtonCallback(MouseButton button, MouseAction action) { - if (!_disableInputs) { + if (!_disableMouseInputs) { _inputState.mouseButtonCallback(button, action); } } void NavigationHandler::mousePositionCallback(double x, double y) { - if (!_disableInputs) { + if (!_disableMouseInputs) { _inputState.mousePositionCallback(x, y); } } void NavigationHandler::mouseScrollWheelCallback(double pos) { - if (!_disableInputs) { + if (!_disableMouseInputs) { _inputState.mouseScrollWheelCallback(pos); } } void NavigationHandler::keyboardCallback(Key key, KeyModifier modifier, KeyAction action) { - if (!_disableInputs) { - _inputState.keyboardCallback(key, modifier, action); - } + // There is no need to disable the keyboard callback based on a property as the vast + // majority of input is coming through Lua scripts anyway which are not blocked here + _inputState.keyboardCallback(key, modifier, action); } NavigationHandler::NavigationState NavigationHandler::navigationState() const { diff --git a/src/interaction/orbitalnavigator.cpp b/src/interaction/orbitalnavigator.cpp index 3f923ac7e6..a85f2f1b1d 100644 --- a/src/interaction/orbitalnavigator.cpp +++ b/src/interaction/orbitalnavigator.cpp @@ -103,6 +103,13 @@ namespace { "the sensitivity is the less impact a mouse motion will have." }; + constexpr openspace::properties::Property::PropertyInfo JoystickEnabledInfo = { + "JoystickEnabled", + "Joystick Control Enabled", + "If this is selected, a connected joystick will be used as an optional input " + "device. If this is deselected, any joystick input will be ignored" + }; + constexpr openspace::properties::Property::PropertyInfo JoystickSensitivityInfo = { "JoystickSensitivity", "Joystick Sensitivity",