mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-07 03:59:31 -06:00
Add lua script payload to flight controller. Access websocket sensitivity in orbitalnavigator
This commit is contained in:
@@ -64,6 +64,7 @@ private:
|
||||
void processInputState(const nlohmann::json& json);
|
||||
void setFocusNodes();
|
||||
void changeFocus(const nlohmann::json& json);
|
||||
void processLua(const nlohmann::json& json);
|
||||
|
||||
void setFriction(const bool &on) const;
|
||||
};
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <openspace/rendering/renderengine.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/scripting/scriptengine.h>
|
||||
#include <openspace/util/timemanager.h>
|
||||
#include <ghoul/filesystem/file.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
@@ -50,12 +51,13 @@ namespace {
|
||||
constexpr const char* BasePathToken = "${BASE}";
|
||||
|
||||
enum class Command {
|
||||
Connect = 0,
|
||||
Disconnect,
|
||||
InputState,
|
||||
ChangeFocus,
|
||||
Autopilot,
|
||||
Friction
|
||||
Connect = 0
|
||||
, Disconnect
|
||||
, InputState
|
||||
, ChangeFocus
|
||||
, Autopilot
|
||||
, Friction
|
||||
, Lua
|
||||
};
|
||||
|
||||
using AxisType = openspace::interaction::WebsocketCameraStates::AxisType;
|
||||
@@ -82,13 +84,15 @@ namespace {
|
||||
|
||||
// Friction JSON Keys
|
||||
constexpr const char* FrictionEngagedKey = "engaged";
|
||||
|
||||
constexpr const char* FrictionPropertyUri = "NavigationHandler.OrbitalNavigator.Friction";
|
||||
|
||||
constexpr const char* RotationalFriction = "Friction.RotationalFriction";
|
||||
constexpr const char* ZoomFriction = "Friction.ZoomFriction";
|
||||
constexpr const char* RollFriction = "Friction.RollFriction";
|
||||
|
||||
// Friction Lua Keys
|
||||
constexpr const char* LuaKey = "lua";
|
||||
constexpr const char* LuaScript = "script";
|
||||
|
||||
const std::string OrbitX = "orbitX";
|
||||
const std::string OrbitY = "orbitY";
|
||||
const std::string ZoomIn = "zoomIn";
|
||||
@@ -106,6 +110,7 @@ namespace {
|
||||
const std::string ChangeFocus = "changeFocus";
|
||||
const std::string Autopilot = "autopilot";
|
||||
const std::string Friction = "friction";
|
||||
const std::string Lua = "lua";
|
||||
|
||||
const static std::unordered_map<std::string, AxisType> AxisIndexMap ({
|
||||
{OrbitX, AxisType::OrbitX},
|
||||
@@ -121,12 +126,13 @@ namespace {
|
||||
});
|
||||
|
||||
const static std::unordered_map<std::string, Command> CommandMap ({
|
||||
{Connect, Command::Connect},
|
||||
{Disconnect, Command::Disconnect},
|
||||
{InputState, Command::InputState},
|
||||
{ChangeFocus, Command::ChangeFocus},
|
||||
{Autopilot, Command::Autopilot},
|
||||
{Friction, Command::Friction}
|
||||
{Connect, Command::Connect}
|
||||
, {Disconnect, Command::Disconnect}
|
||||
, {InputState, Command::InputState}
|
||||
, {ChangeFocus, Command::ChangeFocus}
|
||||
, {Autopilot, Command::Autopilot}
|
||||
, {Friction, Command::Friction}
|
||||
, {Lua, Command::Lua}
|
||||
});
|
||||
|
||||
const int Axes = 10;
|
||||
@@ -189,6 +195,9 @@ void FlightControllerTopic::handleJson(const nlohmann::json& json) {
|
||||
case Command::Friction:
|
||||
setFriction(json[Friction][FrictionEngagedKey]);
|
||||
break;
|
||||
case Command::Lua:
|
||||
processLua(json[Lua]);
|
||||
break;
|
||||
default:
|
||||
LWARNING(fmt::format("Unrecognized action: {}", it->first));
|
||||
break;
|
||||
@@ -343,4 +352,10 @@ void FlightControllerTopic::processInputState(const nlohmann::json& json) {
|
||||
_inputState.axes[std::distance(AxisIndexMap.begin(), mapIt)] = float(it.value());
|
||||
}
|
||||
}
|
||||
|
||||
void FlightControllerTopic::processLua(const nlohmann::json &json) {
|
||||
const std::string script = json[LuaScript];
|
||||
global::scriptEngine.queueScript(script, openspace::scripting::ScriptEngine::RemoteScripting::Yes);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -225,6 +225,10 @@ OrbitalNavigator::OrbitalNavigator()
|
||||
_joystickSensitivity.onChange([&]() {
|
||||
_joystickStates.setSensitivity(_joystickSensitivity * pow(10.0, -4));
|
||||
});
|
||||
_websocketSensitivity.onChange([&]() {
|
||||
_websocketStates.setSensitivity(_websocketSensitivity);
|
||||
});
|
||||
|
||||
|
||||
addPropertySubOwner(_friction);
|
||||
|
||||
@@ -239,6 +243,7 @@ OrbitalNavigator::OrbitalNavigator()
|
||||
addProperty(_stereoInterpolationTime);
|
||||
addProperty(_mouseSensitivity);
|
||||
addProperty(_joystickSensitivity);
|
||||
addProperty(_websocketSensitivity);
|
||||
}
|
||||
|
||||
void OrbitalNavigator::updateStatesFromInput(const InputState& inputState,
|
||||
|
||||
Reference in New Issue
Block a user