Add Lua function to get current distance to focus

This commit is contained in:
Malin E
2023-01-23 10:48:48 +01:00
parent d52c5dd0d9
commit d732b40e1e
2 changed files with 14 additions and 1 deletions

View File

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

View File

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