diff --git a/include/openspace/navigation/waypoint.h b/include/openspace/navigation/waypoint.h index 57dca42b10..3a12dd39d2 100644 --- a/include/openspace/navigation/waypoint.h +++ b/include/openspace/navigation/waypoint.h @@ -47,6 +47,7 @@ public: glm::dquat rotation() const; SceneGraphNode* node() const; std::string nodeIdentifier() const; + std::optional aimIdentifier() const; double validBoundingSphere() const; private: @@ -54,6 +55,11 @@ private: std::string _nodeIdentifier; // To be able to handle nodes with faulty bounding spheres double _validBoundingSphere = 0.0; + + // Keep track of if there was an aim node, specified in for example the + // navigation state used to create this waypoint. It may be required in + // certain situations + std::optional _aimNodeIdentifier; }; /** diff --git a/src/navigation/pathnavigator.cpp b/src/navigation/pathnavigator.cpp index 21bed27223..f7d4eae85f 100644 --- a/src/navigation/pathnavigator.cpp +++ b/src/navigation/pathnavigator.cpp @@ -236,11 +236,19 @@ void PathNavigator::updateCamera(double deltaTime) { if (_setCameraToEndNextFrame) { LDEBUG("Skipped to end of camera path"); _currentPath->quitPath(); - camera()->setPose(_currentPath->endPoint().pose()); + + const interaction::Waypoint endPoint = _currentPath->endPoint(); + camera()->setPose(endPoint.pose()); global::navigationHandler->orbitalNavigator().setFocusNode( - _currentPath->endPoint().nodeIdentifier(), + endPoint.nodeIdentifier(), false ); + if (endPoint.aimIdentifier().has_value()) { + global::navigationHandler->orbitalNavigator().setAimNode( + *endPoint.aimIdentifier() + ); + } + handlePathEnd(); _setCameraToEndNextFrame = false; return; @@ -272,6 +280,14 @@ void PathNavigator::updateCamera(double deltaTime) { if (_currentPath->hasReachedEnd()) { LINFO("Reached target"); + + // Also set the aim once the path is finished, if one should be set + if (_currentPath->endPoint().aimIdentifier().has_value()) { + global::navigationHandler->orbitalNavigator().setAimNode( + *_currentPath->endPoint().aimIdentifier() + ); + } + handlePathEnd(); return; } diff --git a/src/navigation/waypoint.cpp b/src/navigation/waypoint.cpp index c7f1b86286..1b0f929a62 100644 --- a/src/navigation/waypoint.cpp +++ b/src/navigation/waypoint.cpp @@ -67,6 +67,16 @@ Waypoint::Waypoint(const NavigationState& ns) { } _nodeIdentifier = ns.anchor; + + if (!ns.aim.empty()) { + const SceneGraphNode* aimNode = sceneGraphNode(ns.aim); + if (!aimNode) { + LERROR(fmt::format("Could not find node '{}' to use as aim", ns.aim)); + return; + } + _aimNodeIdentifier = ns.aim; + } + const PathNavigator& navigator = global::navigationHandler->pathNavigator(); _validBoundingSphere = navigator.findValidBoundingSphere(anchorNode); _pose = ns.cameraPose(); @@ -92,6 +102,10 @@ std::string Waypoint::nodeIdentifier() const { return _nodeIdentifier; } +std::optional Waypoint::aimIdentifier() const { + return _aimNodeIdentifier; +} + double Waypoint::validBoundingSphere() const { return _validBoundingSphere; }