mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-26 06:49:09 -06:00
Store interaction modes in interaction handler in a std::map
This commit is contained in:
@@ -161,8 +161,7 @@ public:
|
||||
|
||||
// Interaction mode setters
|
||||
void setCameraStateFromDictionary(const ghoul::Dictionary& cameraDict);
|
||||
void setInteractionModeToOrbital();
|
||||
void setInteractionModeToGlobeBrowsing();
|
||||
void setInteractionMode(const std::string& interactionModeKey);
|
||||
|
||||
void resetKeyBindings();
|
||||
|
||||
@@ -211,9 +210,10 @@ private:
|
||||
|
||||
std::shared_ptr<InteractionMode> _currentInteractionMode;
|
||||
|
||||
std::map<std::string, std::shared_ptr<InteractionMode>> _interactionModes;
|
||||
std::shared_ptr<OrbitalInteractionMode::MouseStates> _mouseStates;
|
||||
std::shared_ptr<OrbitalInteractionMode> _orbitalInteractionMode;
|
||||
std::shared_ptr<GlobeBrowsingInteractionMode> _globebrowsingInteractionMode;
|
||||
//std::shared_ptr<OrbitalInteractionMode> _orbitalInteractionMode;
|
||||
//std::shared_ptr<GlobeBrowsingInteractionMode> _globebrowsingInteractionMode;
|
||||
|
||||
// Properties
|
||||
properties::StringProperty _origin;
|
||||
|
||||
@@ -649,11 +649,19 @@ InteractionHandler::InteractionHandler()
|
||||
_inputState = std::make_unique<InputState>();
|
||||
// Inject the same mouse states to both orbital and global interaction mode
|
||||
_mouseStates = std::make_unique<OrbitalInteractionMode::MouseStates>(0.002, 1);
|
||||
_orbitalInteractionMode = std::make_shared<OrbitalInteractionMode>(_mouseStates);
|
||||
_globebrowsingInteractionMode = std::make_shared<GlobeBrowsingInteractionMode>(_mouseStates);
|
||||
_interactionModes.insert(
|
||||
std::pair<std::string, std::shared_ptr<InteractionMode>>(
|
||||
"OrbitalInteractionMode",
|
||||
std::make_shared<OrbitalInteractionMode>(_mouseStates)
|
||||
));
|
||||
_interactionModes.insert(
|
||||
std::pair<std::string, std::shared_ptr<InteractionMode>>(
|
||||
"GlobeBrowsingInteractionMode",
|
||||
std::make_shared<GlobeBrowsingInteractionMode>(_mouseStates)
|
||||
));
|
||||
|
||||
// Set the interactionMode
|
||||
_currentInteractionMode = _orbitalInteractionMode;
|
||||
_currentInteractionMode = _interactionModes["OrbitalInteractionMode"];
|
||||
|
||||
// Define lambda functions for changed properties
|
||||
_rotationalFriction.onChange([&]() {
|
||||
@@ -735,14 +743,19 @@ void InteractionHandler::setInteractionMode(std::shared_ptr<InteractionMode> int
|
||||
_currentInteractionMode->setFocusNode(focusNode);
|
||||
}
|
||||
|
||||
void InteractionHandler::setInteractionModeToOrbital() {
|
||||
setInteractionMode(_orbitalInteractionMode);
|
||||
LINFO("Interaction mode set to 'OrbitalInteractionMode'");
|
||||
}
|
||||
|
||||
void InteractionHandler::setInteractionModeToGlobeBrowsing() {
|
||||
setInteractionMode(_globebrowsingInteractionMode);
|
||||
LINFO("Interaction mode set to 'GlobeBrowsingInteractionMode'");
|
||||
void InteractionHandler::setInteractionMode(const std::string& interactionModeKey) {
|
||||
if (_interactionModes.find(interactionModeKey) != _interactionModes.end()) {
|
||||
setInteractionMode(_interactionModes[interactionModeKey]);
|
||||
LINFO("Interaction mode set to '" << interactionModeKey << "'");
|
||||
}
|
||||
else {
|
||||
std::string listInteractionModes("");
|
||||
for (auto pair : _interactionModes) {
|
||||
listInteractionModes += "'" + pair.first + "', ";
|
||||
}
|
||||
LWARNING("'" << interactionModeKey <<
|
||||
"' is not a valid interaction mode. Candidates are " << listInteractionModes);
|
||||
}
|
||||
}
|
||||
|
||||
void InteractionHandler::lockControls() {
|
||||
|
||||
@@ -124,24 +124,12 @@ int setInteractionMode(lua_State* L) {
|
||||
return luaL_error(L, "Expected %i arguments, got %i", 1, nArguments);
|
||||
|
||||
|
||||
std::string interactionModeName = luaL_checkstring(L, -1);
|
||||
std::string interactionModeKey = luaL_checkstring(L, -1);
|
||||
|
||||
if (interactionModeName.empty())
|
||||
if (interactionModeKey.empty())
|
||||
return luaL_error(L, "interactionmode name string is empty");
|
||||
|
||||
if (interactionModeName == "OrbitalInteractionMode") {
|
||||
OsEng.interactionHandler().setInteractionModeToOrbital();
|
||||
}
|
||||
else if (interactionModeName == "GlobeBrowsingInteractionMode") {
|
||||
#ifdef OPENSPACE_MODULE_GLOBEBROWSING_ENABLED
|
||||
OsEng.interactionHandler().setInteractionModeToGlobeBrowsing();
|
||||
#else
|
||||
return luaL_error(L, "OpenSpace compiled without support for GlobeBrowsing");
|
||||
#endif
|
||||
}
|
||||
else { // Default
|
||||
return luaL_error(L, "Unknown interaction mode. default is 'OrbitalInteractionMode'");
|
||||
}
|
||||
OsEng.interactionHandler().setInteractionMode(interactionModeKey);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user