Add lua function to set minimum allowed distance for the OrbitalNavigator

This commit is contained in:
Malin E
2023-01-11 16:40:57 +01:00
parent 8e383b2187
commit a990e1679b
5 changed files with 72 additions and 1 deletions

View File

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

View File

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

View File

@@ -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());

View File

@@ -26,6 +26,7 @@
#include <openspace/engine/openspaceengine.h>
#include <openspace/interaction/mouseinputstate.h>
#include <openspace/interaction/keyboardinputstate.h>
#include <openspace/navigation/navigationhandler.h>
#include <openspace/navigation/orbitalnavigator.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/util/updatestructures.h>
@@ -37,9 +38,10 @@
#include <ghoul/misc/easing.h>
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtx/vector_angle.hpp>
#include <cmath>
#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

View File

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