From edb7d9ba1df248592d5831a60c6c380dfc938a8a Mon Sep 17 00:00:00 2001 From: Micah Date: Thu, 13 Aug 2020 20:16:46 -0400 Subject: [PATCH 1/4] adding option to not reset velocity on anchor change --- .../openspace/interaction/orbitalnavigator.h | 6 +- .../src/topics/flightcontrollertopic.cpp | 60 +++++++++++++++---- src/interaction/orbitalnavigator.cpp | 10 ++-- 3 files changed, 57 insertions(+), 19 deletions(-) diff --git a/include/openspace/interaction/orbitalnavigator.h b/include/openspace/interaction/orbitalnavigator.h index c453691809..3fdbfa76a8 100644 --- a/include/openspace/interaction/orbitalnavigator.h +++ b/include/openspace/interaction/orbitalnavigator.h @@ -66,8 +66,8 @@ public: void clearPreviousState(); SceneGraphNode* focusNode() const; - void setFocusNode(const SceneGraphNode* focusNode); - void setFocusNode(const std::string& focusNode); + void setFocusNode(const SceneGraphNode* focusNode, bool resetVelocitiesOnChange = true); + void setFocusNode(const std::string& focusNode, bool resetVelocitiesOnChange = true); void setAnchorNode(const std::string& anchorNode); void setAimNode(const std::string& aimNode); @@ -121,7 +121,7 @@ private: properties::FloatProperty friction; }; - void setAnchorNode(const SceneGraphNode* anchorNode); + void setAnchorNode(const SceneGraphNode* anchorNode, bool resetVelocitiesOnChange = true); void setAimNode(const SceneGraphNode* aimNode); Camera* _camera; diff --git a/modules/server/src/topics/flightcontrollertopic.cpp b/modules/server/src/topics/flightcontrollertopic.cpp index 6d8dc96573..fc6c5a29fe 100644 --- a/modules/server/src/topics/flightcontrollertopic.cpp +++ b/modules/server/src/topics/flightcontrollertopic.cpp @@ -75,6 +75,11 @@ namespace { // Change focus JSON keys constexpr const char* FocusKey = "focus"; + constexpr const char* AnchorKey = "anchor"; + constexpr const char* AimKey = "aim"; + constexpr const char* ResetVelocitiesKey = "resetVelocities"; + constexpr const char* RetargetAnchorKey = "retargetAnchor"; + constexpr const char* RetargetAimKey = "retargetAim"; constexpr const char* SceneNodeName = "identifier"; constexpr const char* SceneNodeEnabled = "enabled"; @@ -282,31 +287,64 @@ void FlightControllerTopic::setInterestingTimes() { } void FlightControllerTopic::updateView(const nlohmann::json& json) const { - if (json.find(FocusKey) != json.end()) { - changeFocus(json); - } + if (json.find(RenderableKey) != json.end()) { setRenderableEnabled(json); } + else { + changeFocus(json); + } } void FlightControllerTopic::changeFocus(const nlohmann::json& json) const { - if (json[FocusKey].find(SceneNodeName) == json[FocusKey].end()) { + if (json.find(FocusKey) == json.end()) { const std::string j = json; LWARNING( fmt::format("Could not find {} key in JSON. JSON was:\n{}", FocusKey, j) ); - return; + if (json.find(AimKey) == json.end()) { + const std::string j = json; + LWARNING( + fmt::format("Could not find {} key in JSON. JSON was:\n{}", AimKey, j) + ); + if (json.find(AnchorKey) == json.end()) { + const std::string j = json; + LWARNING( + fmt::format("Could not find {} key in JSON. JSON was:\n{}", AnchorKey, j) + ); + return; + } + } } - const std::string focus = json[FocusKey][SceneNodeName]; - const SceneGraphNode* node = global::renderEngine.scene()->sceneGraphNode(focus); - if (node) { - global::navigationHandler.orbitalNavigator().setFocusNode(node->identifier()); - global::navigationHandler.orbitalNavigator().startRetargetAnchor(); + const std::string focus = json.find(FocusKey) != json.end() ? json[FocusKey] : ""; + const std::string aim = json.find(AimKey) != json.end() ? json[AimKey] : ""; + const std::string anchor = json.find(AnchorKey) != json.end() ? json[AnchorKey] : ""; + + const bool resetVelocities = json[ResetVelocitiesKey]; + const bool retargetAnchor = json[RetargetAnchorKey]; + const bool retargetAim = json[RetargetAimKey]; + + const SceneGraphNode* focusNode = global::renderEngine.scene()->sceneGraphNode(focus); + const SceneGraphNode* aimNode = global::renderEngine.scene()->sceneGraphNode(aim); + const SceneGraphNode* anchorNode = global::renderEngine.scene()->sceneGraphNode(anchor); + if (focusNode) { + global::navigationHandler.orbitalNavigator().setFocusNode(focusNode, resetVelocities); } else { - LWARNING(fmt::format("Could not find node named {}", focus)); + if (aimNode) { + global::navigationHandler.orbitalNavigator().setAimNode(aim); + } + if (anchorNode) { + global::navigationHandler.orbitalNavigator().setAnchorNode(anchor); + } + } + + if (retargetAnchor) { + global::navigationHandler.orbitalNavigator().startRetargetAnchor(); + } + if (retargetAim) { + global::navigationHandler.orbitalNavigator().startRetargetAim(); } } diff --git a/src/interaction/orbitalnavigator.cpp b/src/interaction/orbitalnavigator.cpp index b383eef56e..b767d7c662 100644 --- a/src/interaction/orbitalnavigator.cpp +++ b/src/interaction/orbitalnavigator.cpp @@ -659,17 +659,17 @@ glm::dvec3 OrbitalNavigator::cameraToSurfaceVector(const glm::dvec3& cameraPos, return centerToActualSurface - posDiff; } -void OrbitalNavigator::setFocusNode(const SceneGraphNode* focusNode) { - setAnchorNode(focusNode); +void OrbitalNavigator::setFocusNode(const SceneGraphNode* focusNode, bool resetVelocitiesOnChange) { + setAnchorNode(focusNode, resetVelocitiesOnChange); setAimNode(nullptr); } -void OrbitalNavigator::setFocusNode(const std::string& focusNode) { +void OrbitalNavigator::setFocusNode(const std::string& focusNode, bool resetVelocitiesOnChange) { _anchor.set(focusNode); _aim.set(std::string("")); } -void OrbitalNavigator::setAnchorNode(const SceneGraphNode* anchorNode) { +void OrbitalNavigator::setAnchorNode(const SceneGraphNode* anchorNode, bool resetVelocitiesOnChange) { if (!_anchorNode) { _directlySetStereoDistance = true; } @@ -679,7 +679,7 @@ void OrbitalNavigator::setAnchorNode(const SceneGraphNode* anchorNode) { // Need to reset velocities after the actual switch in anchor node, // since the reset behavior depends on the anchor node. - if (changedAnchor) { + if (changedAnchor && resetVelocitiesOnChange) { resetVelocities(); } From 0f71f7b654c892a0f481061fafc2cf56f376f21d Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 17 Aug 2020 21:35:22 +0200 Subject: [PATCH 2/4] Update submodules --- apps/OpenSpace/ext/sgct | 2 +- ext/ghoul | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/OpenSpace/ext/sgct b/apps/OpenSpace/ext/sgct index f51dcffcc1..b712e64848 160000 --- a/apps/OpenSpace/ext/sgct +++ b/apps/OpenSpace/ext/sgct @@ -1 +1 @@ -Subproject commit f51dcffcc18f0edbfa0ae87ffaa05af8eb52b91d +Subproject commit b712e6484894d70a60277bdcf719613b217954a7 diff --git a/ext/ghoul b/ext/ghoul index 44531db21c..9491e84282 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 44531db21c0c9c5c0e90e672baa6f5d3f851be83 +Subproject commit 9491e84282f5cc0cda74523c82568ef16df2ca23 From f5eec4e97f5bb912d456d5a018d0998f5875efb5 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 17 Aug 2020 22:28:17 +0200 Subject: [PATCH 3/4] Update Ghoul repository (closes #1278) --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index 9491e84282..bd812defd7 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 9491e84282f5cc0cda74523c82568ef16df2ca23 +Subproject commit bd812defd787ad34119cfe7ecef2be71a7a1553e From a6d8d0e7353a92871a952326954ec329320bb1c1 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 17 Aug 2020 22:50:27 +0200 Subject: [PATCH 4/4] Small coding style fixes --- .../openspace/interaction/orbitalnavigator.h | 7 ++++--- .../src/topics/flightcontrollertopic.cpp | 18 +++++++++++------- src/interaction/orbitalnavigator.cpp | 10 +++++++--- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/include/openspace/interaction/orbitalnavigator.h b/include/openspace/interaction/orbitalnavigator.h index 3fdbfa76a8..e541ab23fd 100644 --- a/include/openspace/interaction/orbitalnavigator.h +++ b/include/openspace/interaction/orbitalnavigator.h @@ -65,8 +65,8 @@ public: void setCamera(Camera* camera); void clearPreviousState(); - SceneGraphNode* focusNode() const; - void setFocusNode(const SceneGraphNode* focusNode, bool resetVelocitiesOnChange = true); + void setFocusNode(const SceneGraphNode* focusNode, + bool resetVelocitiesOnChange = true); void setFocusNode(const std::string& focusNode, bool resetVelocitiesOnChange = true); void setAnchorNode(const std::string& anchorNode); void setAimNode(const std::string& aimNode); @@ -121,7 +121,8 @@ private: properties::FloatProperty friction; }; - void setAnchorNode(const SceneGraphNode* anchorNode, bool resetVelocitiesOnChange = true); + void setAnchorNode(const SceneGraphNode* anchorNode, + bool resetVelocitiesOnChange = true); void setAimNode(const SceneGraphNode* aimNode); Camera* _camera; diff --git a/modules/server/src/topics/flightcontrollertopic.cpp b/modules/server/src/topics/flightcontrollertopic.cpp index fc6c5a29fe..3e2289c5a5 100644 --- a/modules/server/src/topics/flightcontrollertopic.cpp +++ b/modules/server/src/topics/flightcontrollertopic.cpp @@ -309,9 +309,9 @@ void FlightControllerTopic::changeFocus(const nlohmann::json& json) const { ); if (json.find(AnchorKey) == json.end()) { const std::string j = json; - LWARNING( - fmt::format("Could not find {} key in JSON. JSON was:\n{}", AnchorKey, j) - ); + LWARNING(fmt::format( + "Could not find {} key in JSON. JSON was:\n{}", AnchorKey, j + )); return; } } @@ -325,11 +325,15 @@ void FlightControllerTopic::changeFocus(const nlohmann::json& json) const { const bool retargetAnchor = json[RetargetAnchorKey]; const bool retargetAim = json[RetargetAimKey]; - const SceneGraphNode* focusNode = global::renderEngine.scene()->sceneGraphNode(focus); - const SceneGraphNode* aimNode = global::renderEngine.scene()->sceneGraphNode(aim); - const SceneGraphNode* anchorNode = global::renderEngine.scene()->sceneGraphNode(anchor); + Scene* scene = global::renderEngine.scene(); + const SceneGraphNode* focusNode = scene->sceneGraphNode(focus); + const SceneGraphNode* aimNode = scene->sceneGraphNode(aim); + const SceneGraphNode* anchorNode = scene->sceneGraphNode(anchor); if (focusNode) { - global::navigationHandler.orbitalNavigator().setFocusNode(focusNode, resetVelocities); + global::navigationHandler.orbitalNavigator().setFocusNode( + focusNode, + resetVelocities + ); } else { if (aimNode) { diff --git a/src/interaction/orbitalnavigator.cpp b/src/interaction/orbitalnavigator.cpp index b767d7c662..4268b5c180 100644 --- a/src/interaction/orbitalnavigator.cpp +++ b/src/interaction/orbitalnavigator.cpp @@ -659,17 +659,21 @@ glm::dvec3 OrbitalNavigator::cameraToSurfaceVector(const glm::dvec3& cameraPos, return centerToActualSurface - posDiff; } -void OrbitalNavigator::setFocusNode(const SceneGraphNode* focusNode, bool resetVelocitiesOnChange) { +void OrbitalNavigator::setFocusNode(const SceneGraphNode* focusNode, + bool resetVelocitiesOnChange) +{ setAnchorNode(focusNode, resetVelocitiesOnChange); setAimNode(nullptr); } -void OrbitalNavigator::setFocusNode(const std::string& focusNode, bool resetVelocitiesOnChange) { +void OrbitalNavigator::setFocusNode(const std::string& focusNode, bool) { _anchor.set(focusNode); _aim.set(std::string("")); } -void OrbitalNavigator::setAnchorNode(const SceneGraphNode* anchorNode, bool resetVelocitiesOnChange) { +void OrbitalNavigator::setAnchorNode(const SceneGraphNode* anchorNode, + bool resetVelocitiesOnChange) +{ if (!_anchorNode) { _directlySetStereoDistance = true; }