Tiny navigation code cleanup/fix

This commit is contained in:
Emma Broman
2021-12-01 11:31:53 +01:00
parent 01a04a6faa
commit 76ea508dab
3 changed files with 13 additions and 8 deletions

View File

@@ -131,8 +131,7 @@ void NavigationHandler::setCamera(Camera* camera) {
_orbitalNavigator.setCamera(camera);
}
void NavigationHandler::setNavigationStateNextFrame(NavigationState state)
{
void NavigationHandler::setNavigationStateNextFrame(NavigationState state) {
_pendingNavigationState = std::move(state);
}

View File

@@ -95,16 +95,17 @@ NavigationState::NavigationState(std::string anchor_, std::string aim_,
CameraPose NavigationState::cameraPose() const {
const SceneGraphNode* referenceFrameNode = sceneGraphNode(referenceFrame);
const SceneGraphNode* anchorNode = sceneGraphNode(anchor);
const SceneGraphNode* aimNode = sceneGraphNode(aim);
if (!anchorNode) {
LERROR(fmt::format(
"Could not find scene graph node '{}' used as anchor.", referenceFrame
"Could not find scene graph node '{}' used as anchor.", anchor
));
return CameraPose();
}
if (!aim.empty() && !sceneGraphNode(aim)) {
if (!aim.empty() && !aimNode) {
LERROR(fmt::format(
"Could not find scene graph node '{}' used as aim.", referenceFrame
"Could not find scene graph node '{}' used as aim.", aim
));
return CameraPose();
}
@@ -116,6 +117,9 @@ CameraPose NavigationState::cameraPose() const {
return CameraPose();
}
// @TODO (2021-12-01, emmbr) The aim is not used at all below, so this code does
// not work if the navigation state has a defined aim node. This should be fixed
CameraPose resultingPose;
const glm::dvec3 anchorWorldPosition = anchorNode->worldPosition();

View File

@@ -37,6 +37,8 @@
#include <ghoul/logging/logmanager.h>
#include <glm/gtx/vector_angle.hpp>
using namespace std::string_literals;
namespace {
constexpr const double Epsilon = 1e-5;
} // namespace
@@ -87,7 +89,7 @@ int goTo(lua_State* L) {
}
ghoul::Dictionary insDict;
insDict.setValue("TargetType", std::string("Node"));
insDict.setValue("TargetType", "Node"s);
insDict.setValue("Target", nodeIdentifier);
if (useUpFromTargetOrDuration.has_value()) {
if (std::holds_alternative<bool>(*useUpFromTargetOrDuration)) {
@@ -134,7 +136,7 @@ int goToHeight(lua_State* L) {
}
ghoul::Dictionary insDict;
insDict.setValue("TargetType", std::string("Node"));
insDict.setValue("TargetType", "Node"s);
insDict.setValue("Target", nodeIdentifier);
insDict.setValue("Height", height);
if (useUpFromTargetOrDuration.has_value()) {
@@ -189,7 +191,7 @@ int goToNavigationState(lua_State* L) {
}
ghoul::Dictionary instruction;
instruction.setValue("TargetType", std::string("NavigationState"));
instruction.setValue("TargetType", "NavigationState"s);
instruction.setValue("NavigationState", navigationState);
if (duration.has_value()) {