diff --git a/include/openspace/interaction/orbitalnavigator.h b/include/openspace/interaction/orbitalnavigator.h index eaf3c6277c..24a86b1a44 100644 --- a/include/openspace/interaction/orbitalnavigator.h +++ b/include/openspace/interaction/orbitalnavigator.h @@ -64,10 +64,16 @@ private: glm::dquat globalRotation; }; - // Properties - properties::BoolProperty _rollFriction; - properties::BoolProperty _rotationalFriction; - properties::BoolProperty _zoomFriction; + struct Friction : public properties::PropertyOwner { + Friction(); + + properties::BoolProperty roll; + properties::BoolProperty rotational; + properties::BoolProperty zoom; + }; + + Friction _friction; + properties::FloatProperty _followFocusNodeRotationDistance; properties::FloatProperty _minimumAllowedDistance; properties::FloatProperty _sensitivity; diff --git a/modules/base/rendering/renderablesphericalgrid.h b/modules/base/rendering/renderablesphericalgrid.h index 7774c8d7d7..ee5d829885 100644 --- a/modules/base/rendering/renderablesphericalgrid.h +++ b/modules/base/rendering/renderablesphericalgrid.h @@ -39,7 +39,7 @@ namespace ghoul::opengl { class ProgramObject; } // namespace ghoul::opengl -namespace openspace::documentation { class Documentation; } +namespace openspace::documentation { struct Documentation; } namespace openspace { diff --git a/scripts/common.lua b/scripts/common.lua index b80c4fdc1a..2a69962d24 100644 --- a/scripts/common.lua +++ b/scripts/common.lua @@ -52,18 +52,18 @@ helper.setCommonKeys = function() openspace.bindKey( "f", - helper.property.invert('NavigationHandler.OrbitalNavigator.RotationalFriction'), + helper.property.invert('NavigationHandler.OrbitalNavigator.Friction.RotationalFriction'), "Toggles the rotational friction of the camera. If it is disabled, the camera rotates around the focus object indefinitely." ) openspace.bindKey( "Shift+f", - helper.property.invert('NavigationHandler.OrbitalNavigator.ZoomFriction'), + helper.property.invert('NavigationHandler.OrbitalNavigator.Friction.ZoomFriction'), "Toggles the zoom friction of the camera. If it is disabled, the camera rises up from or closes in towards the focus object indefinitely." ) openspace.bindKey( "Ctrl+f", - helper.property.invert('NavigationHandler.OrbitalNavigator.RollFriction'), + helper.property.invert('NavigationHandler.OrbitalNavigator.Friction.RollFriction'), "Toggles the roll friction of the camera. If it is disabled, the camera rolls around its own axis indefinitely." ) diff --git a/src/interaction/orbitalnavigator.cpp b/src/interaction/orbitalnavigator.cpp index 52b0c2fe13..3c5a139a13 100644 --- a/src/interaction/orbitalnavigator.cpp +++ b/src/interaction/orbitalnavigator.cpp @@ -90,16 +90,24 @@ namespace { namespace openspace::interaction { +OrbitalNavigator::Friction::Friction() + : properties::PropertyOwner("Friction") + , roll(RollFrictionInfo, true) + , rotational(RotationalFrictionInfo, true) + , zoom(ZoomFrictionInfo, true) +{ + addProperty(roll); + addProperty(rotational); + addProperty(zoom); +} + OrbitalNavigator::OrbitalNavigator() : properties::PropertyOwner("OrbitalNavigator") - , _rollFriction(RollFrictionInfo, true) - , _rotationalFriction(RotationalFrictionInfo, true) - , _zoomFriction(ZoomFrictionInfo, true) , _followFocusNodeRotationDistance(FollowFocusNodeInfo, 2.0f, 0.0f, 10.f) , _minimumAllowedDistance(MinimumDistanceInfo, 10.0f, 0.0f, 10000.f) , _sensitivity(SensitivityInfo, 20.0f, 1.0f, 50.f) , _motionLag(FrictionInfo, 0.5f, 0.f, 1.f) - , _mouseStates(_sensitivity * pow(10.0,-4), 1 / (_motionLag + 0.0000001)) + , _mouseStates(_sensitivity * pow(10.0, -4), 1 / (_motionLag + 0.0000001)) { auto smoothStep = [](double t) { @@ -123,21 +131,20 @@ OrbitalNavigator::OrbitalNavigator() // As an example f_orig(t) = 1 - t yields f(t) = 1 / (1 - t) which results in a linear // interpolation from 1 to 0. - auto smoothStepDerivedTranferFunction = - [](double t) { - return (6 * (t + t*t) / (1 - 3 * t*t + 2 * t*t*t)); - }; + auto smoothStepDerivedTranferFunction = [](double t) { + return (6 * (t + t*t) / (1 - 3 * t*t + 2 * t*t*t)); + }; _rotateToFocusNodeInterpolator.setTransferFunction(smoothStepDerivedTranferFunction); // Define callback functions for changed properties - _rollFriction.onChange([&]() { - _mouseStates.setRotationalFriction(_rollFriction); + _friction.roll.onChange([&]() { + _mouseStates.setRotationalFriction(_friction.roll); }); - _rotationalFriction.onChange([&]() { - _mouseStates.setHorizontalFriction(_rotationalFriction); + _friction.rotational.onChange([&]() { + _mouseStates.setHorizontalFriction(_friction.rotational); }); - _zoomFriction.onChange([&]() { - _mouseStates.setVerticalFriction(_zoomFriction); + _friction.zoom.onChange([&]() { + _mouseStates.setVerticalFriction(_friction.zoom); }); _sensitivity.onChange([&]() { _mouseStates.setSensitivity(_sensitivity * pow(10.0,-4)); @@ -146,18 +153,15 @@ OrbitalNavigator::OrbitalNavigator() _mouseStates.setVelocityScaleFactor(1 / (_motionLag + 0.0000001)); }); - // Add the properties - addProperty(_rollFriction); - addProperty(_rotationalFriction); - addProperty(_zoomFriction); + addPropertySubOwner(_friction); + addProperty(_followFocusNodeRotationDistance); addProperty(_minimumAllowedDistance); addProperty(_sensitivity); addProperty(_motionLag); } -OrbitalNavigator::~OrbitalNavigator() -{ } +OrbitalNavigator::~OrbitalNavigator() {} void OrbitalNavigator::updateMouseStatesFromInput(const InputState& inputState, double deltaTime) @@ -165,9 +169,7 @@ void OrbitalNavigator::updateMouseStatesFromInput(const InputState& inputState, _mouseStates.updateMouseStatesFromInput(inputState, deltaTime); } -void OrbitalNavigator::updateCameraStateFromMouseStates(Camera& camera, - double deltaTime) -{ +void OrbitalNavigator::updateCameraStateFromMouseStates(Camera& camera, double deltaTime){ if (_focusNode) { // Read the current state of the camera glm::dvec3 camPos = camera.positionVec3(); @@ -332,7 +334,7 @@ OrbitalNavigator::CameraRotationDecomposition } glm::dquat OrbitalNavigator::roll(double deltaTime, - const glm::dquat& localCameraRotation) const + const glm::dquat& localCameraRotation) const { glm::dquat rollQuat = glm::angleAxis( _mouseStates.localRollMouseVelocity().x * deltaTime, @@ -353,9 +355,8 @@ glm::dquat OrbitalNavigator::rotateLocally(double deltaTime, return localCameraRotation * rotationDiff; } -glm::dquat OrbitalNavigator::interpolateLocalRotation( - double deltaTime, - const glm::dquat& localCameraRotation) +glm::dquat OrbitalNavigator::interpolateLocalRotation(double deltaTime, + const glm::dquat& localCameraRotation) { if (_rotateToFocusNodeInterpolator.isInterpolating()) { double t = _rotateToFocusNodeInterpolator.value(); @@ -375,13 +376,12 @@ glm::dquat OrbitalNavigator::interpolateLocalRotation( } } -glm::dvec3 OrbitalNavigator::translateHorizontally( - double deltaTime, - const glm::dvec3& cameraPosition, - const glm::dvec3& objectPosition, - const glm::dquat& /*focusNodeRotationDiff*/, - const glm::dquat& globalCameraRotation, - const SurfacePositionHandle& positionHandle) const +glm::dvec3 OrbitalNavigator::translateHorizontally(double deltaTime, + const glm::dvec3& cameraPosition, + const glm::dvec3& objectPosition, + const glm::dquat& /*focusNodeRotationDiff*/, + const glm::dquat& globalCameraRotation, + const SurfacePositionHandle& positionHandle) const { glm::dmat4 modelTransform = _focusNode->modelTransform();