Keep track of aim from navigations state when creating a camera path (#2981)

This commit is contained in:
Emma Broman
2023-12-20 08:28:21 +01:00
committed by GitHub
parent 9c77a12269
commit 8a1b6aceb2
3 changed files with 38 additions and 2 deletions

View File

@@ -47,6 +47,7 @@ public:
glm::dquat rotation() const;
SceneGraphNode* node() const;
std::string nodeIdentifier() const;
std::optional<std::string> 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<std::string> _aimNodeIdentifier;
};
/**

View File

@@ -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;
}

View File

@@ -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<std::string> Waypoint::aimIdentifier() const {
return _aimNodeIdentifier;
}
double Waypoint::validBoundingSphere() const {
return _validBoundingSphere;
}