diff --git a/include/openspace/interaction/interactionhandler.h b/include/openspace/interaction/interactionhandler.h index 72e73d3566..05b06838bc 100644 --- a/include/openspace/interaction/interactionhandler.h +++ b/include/openspace/interaction/interactionhandler.h @@ -261,6 +261,10 @@ public: ~OrbitalInteractionMode(); virtual void update(double deltaTime); + + void setRotationalFriction(bool friction); + void setZoomFriction(bool friction); + protected: void updateMouseStatesFromInput(double deltaTime); void updateCameraStateFromMouseStates(); @@ -274,6 +278,9 @@ protected: glm::dquat _localCameraRotation; glm::dquat _globalCameraRotation; + + bool _rotationalFriction; + bool _zoomFriction; }; #ifdef OPENSPACE_MODULE_GLOBEBROWSING_ENABLED @@ -360,6 +367,9 @@ private: // Properties properties::StringProperty _origin; properties::StringProperty _coordinateSystem; + + properties::BoolProperty _rotationalFriction; + properties::BoolProperty _zoomFriction; }; #endif // USE_OLD_INTERACTIONHANDLER diff --git a/modules/onscreengui/include/gui.h b/modules/onscreengui/include/gui.h index 6afc285c3a..7f36048b33 100644 --- a/modules/onscreengui/include/gui.h +++ b/modules/onscreengui/include/gui.h @@ -67,9 +67,9 @@ public: GuiHelpComponent _help; GuiOriginComponent _origin; GuiPerformanceComponent _performance; + GuiPropertyComponent _globalProperty; GuiPropertyComponent _property; GuiPropertyComponent _screenSpaceProperty; - GuiPropertyComponent _globalProperty; GuiTimeComponent _time; GuiIswaComponent _iswa; }; diff --git a/modules/onscreengui/src/gui.cpp b/modules/onscreengui/src/gui.cpp index db34aea3a1..ae57b6d9b5 100644 --- a/modules/onscreengui/src/gui.cpp +++ b/modules/onscreengui/src/gui.cpp @@ -164,9 +164,9 @@ namespace gui { GUI::GUI() : GuiComponent() + , _globalProperty("Global") , _property("Properties") , _screenSpaceProperty("ScreenSpace Properties") - , _globalProperty("Global") {} GUI::~GUI() { @@ -369,12 +369,12 @@ void GUI::startFrame(float deltaTime, const glm::vec2& windowSize, void GUI::endFrame() { render(); + if (_globalProperty.isEnabled()) + _globalProperty.render(); if (_property.isEnabled()) _property.render(); if (_screenSpaceProperty.isEnabled()) _screenSpaceProperty.render(); - if (_globalProperty.isEnabled()) - _globalProperty.render(); if (_performance.isEnabled()) _performance.render(); if (_help.isEnabled()) diff --git a/scripts/common.lua b/scripts/common.lua index cef02c1794..7861bbf263 100644 --- a/scripts/common.lua +++ b/scripts/common.lua @@ -16,6 +16,9 @@ helper.setCommonKeys = function() openspace.bindKey("COMMA", "openspace.setRenderer('Framebuffer');") openspace.bindKey("PERIOD", "openspace.setRenderer('ABuffer');") + + openspace.bindKey("f", helper.property.invert('Interaction.rotationalFriction')) + openspace.bindKey("Shift+f", helper.property.invert('Interaction.zoomFriction')) end helper.setDeltaTimeKeys = function(t) diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 8455fda46f..82da0b23c4 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -440,7 +440,10 @@ bool OpenSpaceEngine::initialize() { _gui->initialize(); _gui->_globalProperty.setSource( [&]() { - std::vector res = { _settingsEngine.get() }; + std::vector res = { + _settingsEngine.get(), + _interactionHandler.get() + }; return res; } ); diff --git a/src/interaction/interactionhandler.cpp b/src/interaction/interactionhandler.cpp index 6b238546a0..4a79be111a 100644 --- a/src/interaction/interactionhandler.cpp +++ b/src/interaction/interactionhandler.cpp @@ -756,14 +756,22 @@ OrbitalInteractionMode::OrbitalInteractionMode( , _globalRotationMouseState(velocityScaleFactor) , _localRotationMouseState(velocityScaleFactor) , _truckMovementMouseState(velocityScaleFactor) - , _rollMouseState(velocityScaleFactor) { + , _rollMouseState(velocityScaleFactor) + , _rotationalFriction(true) + , _zoomFriction(true) +{} +OrbitalInteractionMode::~OrbitalInteractionMode() {} + +void OrbitalInteractionMode::setRotationalFriction(bool friction) { + _rotationalFriction = friction; } -OrbitalInteractionMode::~OrbitalInteractionMode() { - +void OrbitalInteractionMode::setZoomFriction(bool friction) { + _zoomFriction = friction; } + void OrbitalInteractionMode::updateMouseStatesFromInput(double deltaTime) { glm::dvec2 mousePosition = _inputState->getMousePosition(); @@ -794,10 +802,12 @@ void OrbitalInteractionMode::updateMouseStatesFromInput(double deltaTime) { } else { // !button1Pressed _localRotationMouseState.previousPosition = mousePosition; - _localRotationMouseState.velocity.set(glm::dvec2(0, 0)); - _globalRotationMouseState.previousPosition = mousePosition; - _globalRotationMouseState.velocity.set(glm::dvec2(0, 0)); + + if (_rotationalFriction) { + _localRotationMouseState.velocity.set(glm::dvec2(0, 0)); + _globalRotationMouseState.velocity.set(glm::dvec2(0, 0)); + } } if (button2Pressed) { glm::dvec2 mousePositionDelta = @@ -806,7 +816,9 @@ void OrbitalInteractionMode::updateMouseStatesFromInput(double deltaTime) { } else { // !button2Pressed _truckMovementMouseState.previousPosition = mousePosition; - _truckMovementMouseState.velocity.set(glm::dvec2(0, 0)); + if (_zoomFriction) { + _truckMovementMouseState.velocity.set(glm::dvec2(0, 0)); + } } if (button3Pressed) { glm::dvec2 mousePositionDelta = @@ -992,7 +1004,10 @@ void GlobeBrowsingInteractionMode::update(double deltaTime) { // InteractionHandler InteractionHandler::InteractionHandler() : _origin("origin", "Origin", "") - , _coordinateSystem("coordinateSystem", "Coordinate System", "") { + , _coordinateSystem("coordinateSystem", "Coordinate System", "") + , _rotationalFriction("rotationalFriction", "Rotational Friction", true) + , _zoomFriction("zoomFriction", "Zoom Friction", true) +{ setName("Interaction"); _origin.onChange([this]() { @@ -1010,6 +1025,7 @@ InteractionHandler::InteractionHandler() }); addProperty(_coordinateSystem); + // Create the interactionModes _inputState = std::shared_ptr(new InputState()); _orbitalInteractionMode = std::shared_ptr( @@ -1022,6 +1038,22 @@ InteractionHandler::InteractionHandler() // Set the interactionMode _currentInteractionMode = _orbitalInteractionMode; + + _rotationalFriction.onChange([&]() { + _orbitalInteractionMode->setRotationalFriction(_rotationalFriction); +#ifdef OPENSPACE_MODULE_GLOBEBROWSING_ENABLED + _globebrowsingInteractionMode->setRotationalFriction(_rotationalFriction); +#endif + }); + addProperty(_rotationalFriction); + + _zoomFriction.onChange([&]() { + _orbitalInteractionMode->setZoomFriction(_zoomFriction); +#ifdef OPENSPACE_MODULE_GLOBEBROWSING_ENABLED + _globebrowsingInteractionMode->setZoomFriction(_zoomFriction); +#endif + }); + addProperty(_zoomFriction); } InteractionHandler::~InteractionHandler() {