diff --git a/include/openspace/navigation/orbitalnavigator.h b/include/openspace/navigation/orbitalnavigator.h index 1fa4a95bfb..86f7dfd474 100644 --- a/include/openspace/navigation/orbitalnavigator.h +++ b/include/openspace/navigation/orbitalnavigator.h @@ -50,6 +50,8 @@ namespace openspace { struct SurfacePositionHandle; } // namespace +namespace openspace::scripting { struct LuaLibrary; } + namespace openspace::interaction { class MouseInputState; @@ -110,6 +112,7 @@ public: float retargetInterpolationTime() const; void setRetargetInterpolationTime(float durationInSeconds); void updatePreviousStateVariables(); + void setMinimumAllowedDistance(double distance); JoystickCameraStates& joystickStates(); const JoystickCameraStates& joystickStates() const; @@ -132,6 +135,12 @@ public: glm::dvec3 anchorNodeToCameraVector() const; glm::quat anchorNodeToCameraRotation() const; + /** + * \return The Lua library that contains all Lua functions available to affect the + * orbital navigation + */ + static scripting::LuaLibrary luaLibrary(); + private: struct CameraRotationDecomposition { glm::dquat localRotation = glm::dquat(1.0, 0.0, 0.0, 0.0); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a459b29ed0..abd1d9e607 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -73,6 +73,7 @@ set(OPENSPACE_SOURCE ${OPENSPACE_BASE_DIR}/src/navigation/navigationhandler_lua.inl ${OPENSPACE_BASE_DIR}/src/navigation/navigationstate.cpp ${OPENSPACE_BASE_DIR}/src/navigation/orbitalnavigator.cpp + ${OPENSPACE_BASE_DIR}/src/navigation/orbitalnavigator_lua.inl ${OPENSPACE_BASE_DIR}/src/navigation/path.cpp ${OPENSPACE_BASE_DIR}/src/navigation/pathcurve.cpp ${OPENSPACE_BASE_DIR}/src/navigation/pathnavigator.cpp diff --git a/src/documentation/core_registration.cpp b/src/documentation/core_registration.cpp index eb974bcb36..bf1d77309f 100644 --- a/src/documentation/core_registration.cpp +++ b/src/documentation/core_registration.cpp @@ -91,6 +91,7 @@ void registerCoreClasses(scripting::ScriptEngine& engine) { engine.addLibrary(interaction::ActionManager::luaLibrary()); engine.addLibrary(interaction::KeybindingManager::luaLibrary()); engine.addLibrary(interaction::NavigationHandler::luaLibrary()); + engine.addLibrary(interaction::OrbitalNavigator::luaLibrary()); engine.addLibrary(interaction::PathNavigator::luaLibrary()); engine.addLibrary(interaction::SessionRecording::luaLibrary()); engine.addLibrary(scripting::ScriptScheduler::luaLibrary()); diff --git a/src/navigation/orbitalnavigator.cpp b/src/navigation/orbitalnavigator.cpp index 5d189d5c93..0c2afda88e 100644 --- a/src/navigation/orbitalnavigator.cpp +++ b/src/navigation/orbitalnavigator.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -37,9 +38,10 @@ #include #include #include - #include +#include "orbitalnavigator_lua.inl" + namespace { constexpr std::string_view _loggerCat = "OrbitalNavigator"; @@ -889,6 +891,10 @@ void OrbitalNavigator::updatePreviousStateVariables() { updatePreviousAimState(); } +void OrbitalNavigator::setMinimumAllowedDistance(double distance) { + _minimumAllowedDistance = distance; +} + void OrbitalNavigator::startRetargetAnchor() { if (!_anchorNode) { return; @@ -1719,4 +1725,13 @@ void OrbitalNavigator::orbitAroundAxis(const glm::dvec3 axis, double deltaTime, globalRotation = spinRotation * globalRotation; } +scripting::LuaLibrary OrbitalNavigator::luaLibrary() { + return { + "orbitalnavigation", + { + codegen::lua::SetRelativeMinDistance + } + }; +} + } // namespace openspace::interaction diff --git a/src/navigation/orbitalnavigator_lua.inl b/src/navigation/orbitalnavigator_lua.inl new file mode 100644 index 0000000000..322fd2e849 --- /dev/null +++ b/src/navigation/orbitalnavigator_lua.inl @@ -0,0 +1,45 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2023 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +namespace { + +/** +* Set Minimum allowed distance to a multiplier of the interaction sphere of the focus node +*/ +[[codegen::luawrap]] void setRelativeMinDistance(double multiplier) { + using namespace openspace; + const SceneGraphNode* node = global::navigationHandler->anchorNode(); + if (!node) { + throw ghoul::lua::LuaError("Could not determine current focus node"); + } + + double is = node->interactionSphere(); + global::navigationHandler->orbitalNavigator().setMinimumAllowedDistance( + is * multiplier + ); +} + +#include "orbitalnavigator_lua_codegen.cpp" + +} // namespace