Allow separate friction control

This commit is contained in:
Matthew Territo
2018-11-05 01:28:28 -07:00
parent ff7903fbe7
commit 96245ec60e
2 changed files with 23 additions and 13 deletions

View File

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

View File

@@ -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<std::string> 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);
}