From 96245ec60eb57c86a187d64633dbf9a01e8c2000 Mon Sep 17 00:00:00 2001 From: Matthew Territo Date: Mon, 5 Nov 2018 01:28:28 -0700 Subject: [PATCH] Allow separate friction control --- .../include/topics/flightcontrollertopic.h | 5 +-- .../src/topics/flightcontrollertopic.cpp | 31 ++++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/modules/server/include/topics/flightcontrollertopic.h b/modules/server/include/topics/flightcontrollertopic.h index 21fc928902..0652a61628 100644 --- a/modules/server/include/topics/flightcontrollertopic.h +++ b/modules/server/include/topics/flightcontrollertopic.h @@ -67,8 +67,9 @@ private: void setInterestingTimes(); void changeFocus(const nlohmann::json& json); void processLua(const nlohmann::json& json); - - void setFriction(const bool &on) const; + void setFriction(const nlohmann::json& json) const; + void setFriction(const bool& roll, const bool& rotation, const bool& zoom) const; + void setFriction(const bool& all) const; }; } // namespace openspace diff --git a/modules/server/src/topics/flightcontrollertopic.cpp b/modules/server/src/topics/flightcontrollertopic.cpp index dd5d62ecdb..011116db44 100644 --- a/modules/server/src/topics/flightcontrollertopic.cpp +++ b/modules/server/src/topics/flightcontrollertopic.cpp @@ -86,6 +86,9 @@ namespace { // Friction JSON Keys constexpr const char* FrictionEngagedKey = "engaged"; constexpr const char* FrictionPropertyUri = "NavigationHandler.OrbitalNavigator.Friction"; + constexpr const char* FrictionRotationKey = "rotation"; + constexpr const char* FrictionZoomKey = "zoom"; + constexpr const char* FrictionRollKey = "roll"; constexpr const char* RotationalFriction = "Friction.RotationalFriction"; constexpr const char* ZoomFriction = "Friction.ZoomFriction"; constexpr const char* RollFriction = "Friction.RollFriction"; @@ -194,7 +197,7 @@ void FlightControllerTopic::handleJson(const nlohmann::json& json) { handleAutopilot(json[Autopilot]); break; case Command::Friction: - setFriction(json[Friction][FrictionEngagedKey]); + setFriction(json[Friction]); break; case Command::Lua: processLua(json[Lua]); @@ -289,24 +292,30 @@ void FlightControllerTopic::disconnect() { _isDone = true; } -void FlightControllerTopic::setFriction(const bool &on) const { - std::vector frictions; - frictions.push_back(RotationalFriction); - frictions.push_back(ZoomFriction); - frictions.push_back(RollFriction); +void FlightControllerTopic::setFriction(const bool& all) const { + setFriction(all, all, all); +} - for (auto &f: frictions) { - auto property = global::navigationHandler.orbitalNavigator().property(f); - property->set(on); - } +void FlightControllerTopic::setFriction(const bool& roll, const bool& rotation, const bool& zoom) const { + const auto navigator = global::navigationHandler.orbitalNavigator(); + + navigator.property(RollFriction)->set(roll); + navigator.property(RotationalFriction)->set(rotation); + navigator.property(ZoomFriction)->set(zoom); // Update FlightController nlohmann::json j; j[TypeKey] = Friction; - j[Friction][FrictionEngagedKey] = on; + j[Friction][FrictionRollKey] = roll; + j[Friction][FrictionRotationKey] = rotation; + j[Friction][FrictionZoomKey] = zoom; _connection->sendJson(wrappedPayload(j)); } +void FlightControllerTopic::setFriction(const nlohmann::json& json) const { + setFriction(json[FrictionRollKey], json[FrictionRotationKey], json[FrictionZoomKey]); +} + void FlightControllerTopic::disengageAutopilot() const { setFriction(true); }