diff --git a/src/navigation/navigationhandler.cpp b/src/navigation/navigationhandler.cpp index b6ae48879c..169d47a29f 100644 --- a/src/navigation/navigationhandler.cpp +++ b/src/navigation/navigationhandler.cpp @@ -639,7 +639,8 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() { codegen::lua::TriggerIdleBehavior, codegen::lua::ListAllJoysticks, codegen::lua::TargetNextInterestingAnchor, - codegen::lua::TargetPreviousInterestingAnchor + codegen::lua::TargetPreviousInterestingAnchor, + codegen::lua::DistanceToFocus } }; } diff --git a/src/navigation/navigationhandler_lua.inl b/src/navigation/navigationhandler_lua.inl index d0ecac7b54..7d189044fb 100644 --- a/src/navigation/navigationhandler_lua.inl +++ b/src/navigation/navigationhandler_lua.inl @@ -406,6 +406,18 @@ joystickAxis(std::string joystickName, int axis) return global::navigationHandler->listAllJoysticks(); } +/** + * Returns the distance in meters to the current focus node + */ +[[codegen::luawrap]] double distanceToFocus() { + using namespace openspace; + + const SceneGraphNode * focus = global::navigationHandler->anchorNode(); + Camera * camera = global::navigationHandler->camera(); + + return glm::distance(camera->positionVec3(), focus->worldPosition()); +} + #include "navigationhandler_lua_codegen.cpp" } // namespace