From 102ceafd6f8ac4bd9b3ad9fa0a5bc1f47f327334 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 13 Apr 2022 15:32:03 +0200 Subject: [PATCH 01/14] Add Lua function to list all connected joysticks --- include/openspace/navigation/navigationhandler.h | 1 + src/navigation/navigationhandler.cpp | 15 ++++++++++++++- src/navigation/navigationhandler_lua.inl | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/openspace/navigation/navigationhandler.h b/include/openspace/navigation/navigationhandler.h index ddd33f1156..5a2bfd6be3 100644 --- a/include/openspace/navigation/navigationhandler.h +++ b/include/openspace/navigation/navigationhandler.h @@ -94,6 +94,7 @@ public: void mousePositionCallback(double x, double y); void mouseScrollWheelCallback(double pos); + std::vector listAllJoysticks() const; void setJoystickAxisMapping(std::string joystickName, int axis, JoystickCameraStates::AxisType mapping, JoystickCameraStates::AxisInvert shouldInvert = diff --git a/src/navigation/navigationhandler.cpp b/src/navigation/navigationhandler.cpp index 40de9812aa..bffcb64484 100644 --- a/src/navigation/navigationhandler.cpp +++ b/src/navigation/navigationhandler.cpp @@ -477,6 +477,18 @@ void NavigationHandler::loadNavigationState(const std::string& filepath) { } } +std::vector NavigationHandler::listAllJoysticks() const { + std::vector result; + result.reserve(global::joystickInputStates->size()); + + for (const JoystickInputState& joystickInputState : *global::joystickInputStates) { + if (!joystickInputState.name.empty()) { + result.push_back(joystickInputState.name); + } + } + return result; +} + void NavigationHandler::setJoystickAxisMapping(std::string joystickName, int axis, JoystickCameraStates::AxisType mapping, JoystickCameraStates::AxisInvert shouldInvert, @@ -604,7 +616,8 @@ scripting::LuaLibrary NavigationHandler::luaLibrary() { codegen::lua::AddTruckMovement, codegen::lua::AddLocalRoll, codegen::lua::AddGlobalRoll, - codegen::lua::TriggerIdleBehavior + codegen::lua::TriggerIdleBehavior, + codegen::lua::ListAllJoysticks } }; } diff --git a/src/navigation/navigationhandler_lua.inl b/src/navigation/navigationhandler_lua.inl index 6b284837cf..6b0ff2c8bf 100644 --- a/src/navigation/navigationhandler_lua.inl +++ b/src/navigation/navigationhandler_lua.inl @@ -354,6 +354,14 @@ joystickAxis(std::string joystickName, int axis) } } +/** + * Return the complete list of connected joysticks + */ +[[codegen::luawrap]] std::vector listAllJoysticks() { + using namespace openspace; + return global::navigationHandler->listAllJoysticks(); +} + #include "navigationhandler_lua_codegen.cpp" } // namespace From d70af0221bcaef060efb1787e6f04da0b72c66a9 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 13 Apr 2022 17:05:10 +0200 Subject: [PATCH 02/14] Add helper function to find joystick with many possible names * And check connected joystick statuses at start up as well as run time --- apps/OpenSpace/main.cpp | 84 ++++++++++++++++++- .../util/joysticks/joystick_helper.asset | 19 +++++ 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index a4e914a7ed..d382d5e28d 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -319,6 +319,88 @@ void mainInitFunc(GLFWwindow*) { #endif // OPENSPACE_HAS_SPOUT } + // Query joystick status, those connected before start up + using namespace interaction; + + for (int i = GLFW_JOYSTICK_1; i <= GLFW_JOYSTICK_LAST; ++i) { + ZoneScopedN("Joystick state"); + + JoystickInputState& state = global::joystickInputStates->at(i); + + int present = glfwJoystickPresent(i); + if (present == GLFW_FALSE) { + state.isConnected = false; + continue; + } + + if (!state.isConnected) { + // Joystick was added + state.isConnected = true; + state.name = glfwGetJoystickName(i); + + std::fill(state.axes.begin(), state.axes.end(), 0.f); + std::fill(state.buttons.begin(), state.buttons.end(), JoystickAction::Idle); + + // Check axes and buttons + glfwGetJoystickAxes(i, &state.nAxes); + if (state.nAxes > JoystickInputState::MaxAxes) { + LWARNING(fmt::format( + "Joystick/Gamepad {} has {} axes, but only {} axes are supported. " + "All excess axes are ignored", + state.name, state.nAxes, JoystickInputState::MaxAxes + )); + } + glfwGetJoystickButtons(i, &state.nButtons); + if (state.nButtons > JoystickInputState::MaxButtons) { + LWARNING(fmt::format( + "Joystick/Gamepad {} has {} buttons, but only {} buttons are " + "supported. All excess buttons are ignored", + state.name, state.nButtons, JoystickInputState::MaxButtons + )); + } + } + + const float* axes = glfwGetJoystickAxes(i, &state.nAxes); + if (state.nAxes > JoystickInputState::MaxAxes) { + state.nAxes = JoystickInputState::MaxAxes; + } + std::memcpy(state.axes.data(), axes, state.nAxes * sizeof(float)); + + const unsigned char* buttons = glfwGetJoystickButtons(i, &state.nButtons); + if (state.nButtons > JoystickInputState::MaxButtons) { + state.nButtons = JoystickInputState::MaxButtons; + } + + for (int j = 0; j < state.nButtons; ++j) { + const bool currentlyPressed = buttons[j] == GLFW_PRESS; + + if (currentlyPressed) { + switch (state.buttons[j]) { + case JoystickAction::Idle: + case JoystickAction::Release: + state.buttons[j] = JoystickAction::Press; + break; + case JoystickAction::Press: + case JoystickAction::Repeat: + state.buttons[j] = JoystickAction::Repeat; + break; + } + } + else { + switch (state.buttons[j]) { + case JoystickAction::Idle: + case JoystickAction::Release: + state.buttons[j] = JoystickAction::Idle; + break; + case JoystickAction::Press: + case JoystickAction::Repeat: + state.buttons[j] = JoystickAction::Release; + break; + } + } + } + } + LTRACE("main::mainInitFunc(end)"); } @@ -336,7 +418,7 @@ void mainPreSyncFunc() { Engine::instance().terminate(); } - // Query joystick status + // Query joystick status, those connected at run time using namespace interaction; for (int i = GLFW_JOYSTICK_1; i <= GLFW_JOYSTICK_LAST; ++i) { diff --git a/data/assets/util/joysticks/joystick_helper.asset b/data/assets/util/joysticks/joystick_helper.asset index 66e376d1f9..f803711282 100644 --- a/data/assets/util/joysticks/joystick_helper.asset +++ b/data/assets/util/joysticks/joystick_helper.asset @@ -63,8 +63,27 @@ local unbindRoll = function(name, axis) ]] end + +-- Function that will find the first connected joystick with a name that matches one of +-- the given possible names +local findJoystick = function(possibleNames) + -- Will only catch the joysticks that are connected before start up + local joysticks = openspace.navigation.listAllJoysticks() + + for _, joyStickName in ipairs(joysticks) do + for _, name in ipairs(possibleNames) do + if joyStickName == name then + return name + end + end + end + + return nil +end + asset.export("bindLocalRoll", bindLocalRoll) asset.export("bindGlobalRoll", bindGlobalRoll) asset.export("permaBindLocalRoll", permaBindLocalRoll) asset.export("permaBindGlobalRoll", permaBindGlobalRoll) asset.export("unbindRoll", unbindRoll) +asset.export("findJoystick", findJoystick) From 9d61fbf980e81b6f7e3eba818fb3028bd3dc4836 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 13 Apr 2022 17:24:01 +0200 Subject: [PATCH 03/14] Add asset file for xbox wireless joystick input --- .../assets/util/joysticks/xbox-wireless.asset | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 data/assets/util/joysticks/xbox-wireless.asset diff --git a/data/assets/util/joysticks/xbox-wireless.asset b/data/assets/util/joysticks/xbox-wireless.asset new file mode 100644 index 0000000000..75955c4294 --- /dev/null +++ b/data/assets/util/joysticks/xbox-wireless.asset @@ -0,0 +1,133 @@ +local propertyHelper = asset.require("../property_helper") +local joystickHelper = asset.require("./joystick_helper") + +-- Allowed values for the third parameter of bindJoystickAxis: +-- "None" +-- "Orbit X" +-- "Orbit Y" +-- "Zoom" -- both in and out +-- "Zoom In" +-- "Zoom Out" +-- "LocalRoll X" +-- "LocalRoll Y" +-- "GlobalRoll X" +-- "GlobalRoll Y" +-- "Pan X" +-- "Pan Y" +-- Fourth parameter determines whether the axis should be inverted +-- Fifth parameter determines whether the axis behaves like a joystick or a Trigger. +-- Allowed values are "JoystickLike" and "TriggerLike", the first one is the default +-- Sixth parameters determins if the axis should be "Sticky" or not. +-- The axis values can either go back to 0 when the joystick is released or it can +-- stay at the value it was before the joystick was released. +-- The latter is called a sticky axis, when the values don't go back to 0. +-- Seventh parameter is the sensitivity for the axis + +local XBoxController = { + LeftThumbStick = { 0 , 1 }, + RightThumbStick = { 2, 3 }, + LeftTrigger = 4, + RightTrigger = 5, + A = 0, + B = 1, + X = 2, + Y = 3, + LB = 4, + RB = 5, + Select = 6, + Start = 7, + LeftStickButton = 8, + RightStickButton = 9, + DPad = { + Up = 10, + Right = 11, + Down = 12, + Left = 13 + } +} + +asset.onInitialize(function() + local controller = XBoxController; + local name = "Wireless Xbox Controller"; + + openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[1], 0.15) + openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[2], 0.15) + openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[1], 0.15) + openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[2], 0.15) + openspace.navigation.setAxisDeadZone(name, controller.LeftTrigger, 0.05) + openspace.navigation.setAxisDeadZone(name, controller.RightTrigger, 0.05) + + openspace.navigation.bindJoystickAxis(name, controller.LeftThumbStick[1], "Orbit X"); + openspace.navigation.bindJoystickAxis(name, controller.LeftThumbStick[2], "Orbit Y", true); + openspace.navigation.bindJoystickAxis(name, controller.RightThumbStick[1], "Pan X", true); + openspace.navigation.bindJoystickAxis(name, controller.RightThumbStick[2], "Pan Y", true); + openspace.navigation.bindJoystickAxis(name, controller.LeftTrigger, "Zoom Out", false, "TriggerLike"); + openspace.navigation.bindJoystickAxis(name, controller.RightTrigger, "Zoom In", false, "TriggerLike"); + + openspace.navigation.bindJoystickButton( + name, + controller.LB, + joystickHelper.bindLocalRoll(name, controller.RightThumbStick[1]), + "Switch to local roll mode" + ) + openspace.navigation.bindJoystickButton( + name, + controller.LB, + joystickHelper.unbindRoll(name, controller.RightThumbStick[1]), + "Switch back to normal mode", + "Release" + ) + openspace.navigation.bindJoystickButton( + name, + controller.RB, + joystickHelper.bindGlobalRoll(name, controller.RightThumbStick[1]), + "Switch to global roll mode" + ) + openspace.navigation.bindJoystickButton( + name, + controller.RB, + joystickHelper.unbindRoll(name, controller.RightThumbStick[1]), + "Switch back to normal mode", + "Release" + ) + + openspace.navigation.bindJoystickButton( + name, + controller.A, + propertyHelper.invert("NavigationHandler.OrbitalNavigator.Friction.ZoomFriction"), + "Toggle zoom friction" + ) + openspace.navigation.bindJoystickButton( + name, + controller.B, + propertyHelper.invert("NavigationHandler.OrbitalNavigator.Friction.RotationalFriction"), + "Toggle rotational friction" + ) + openspace.navigation.bindJoystickButton( + name, + controller.DPad.Left, + propertyHelper.invert("NavigationHandler.OrbitalNavigator.Friction.RollFriction"), + "Toggle roll friction" + ) + + openspace.navigation.bindJoystickButton( + name, + controller.X, + [[ + "openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Aim", ""); + "openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Anchor", "Earth"); + "openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.RetargetAnchor", nil); + ]], + "Switch target to Earth" + ) + openspace.navigation.bindJoystickButton( + name, + controller.Y, + [[ + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Aim", ""); + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Anchor", "Mars"); + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.RetargetAnchor", nil); + ]], + "Switch target to Mars" + ) +end) From 8e2fd76e7edcbf408f418ca956e3572bea8da046 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 14 Apr 2022 09:38:48 +0200 Subject: [PATCH 04/14] Add different versions of spacemouse joystick asset --- .../space-mouse-compact-wireless.asset | 60 +++++++++++++++++++ ...-mouse.asset => space-mouse-compact.asset} | 1 + .../space-mouse-enterprise-wireless.asset | 60 +++++++++++++++++++ ...cky.asset => space-mouse-enterprise.asset} | 3 +- 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 data/assets/util/joysticks/space-mouse-compact-wireless.asset rename data/assets/util/joysticks/{space-mouse.asset => space-mouse-compact.asset} (99%) create mode 100644 data/assets/util/joysticks/space-mouse-enterprise-wireless.asset rename data/assets/util/joysticks/{space-mouse-not-sticky.asset => space-mouse-enterprise.asset} (98%) diff --git a/data/assets/util/joysticks/space-mouse-compact-wireless.asset b/data/assets/util/joysticks/space-mouse-compact-wireless.asset new file mode 100644 index 0000000000..2874aa23f2 --- /dev/null +++ b/data/assets/util/joysticks/space-mouse-compact-wireless.asset @@ -0,0 +1,60 @@ +local propertyHelper = asset.require("../property_helper") +local joystickHelper = asset.require("./joystick_helper") + +-- Allowed values for the third parameter of bindJoystickAxis: +-- "None" +-- "Orbit X" +-- "Orbit Y" +-- "Zoom" -- both in and out +-- "Zoom In" +-- "Zoom Out" +-- "LocalRoll X" +-- "LocalRoll Y" +-- "GlobalRoll X" +-- "GlobalRoll Y" +-- "Pan X" +-- "Pan Y" +-- Fourth parameter determines whether the axis should be inverted +-- Fifth parameter determines whether the axis behaves like a joystick or a Trigger. +-- Allowed values are "JoystickLike" and "TriggerLike", the first one is the default +-- Sixth parameters determins if the axis should be "Sticky" or not. +-- The axis values can either go back to 0 when the joystick is released or it can +-- stay at the value it was before the joystick was released. +-- The latter is called a sticky axis, when the values don't go back to 0. +-- This version of the SpaceMouse IS Sticky. +-- Seventh parameter is the sensitivity for the axis + +local SpaceMouse = { + Push = {0, 1, 2}, -- left/right, back/forth, up/down + Twist = {5}, -- left/right + Tilt = {4, 3}, -- left/right, back/forth + + LeftButton = 0, + RightButton = 1 +} + +asset.onInitialize(function() + local controller = SpaceMouse; + local name = "3Dconnexion Universal Receiver"; + + openspace.navigation.bindJoystickAxis(name, controller.Push[1], "Orbit X", false, "JoystickLike", true, 40.0); + openspace.navigation.bindJoystickAxis(name, controller.Push[2], "Orbit Y", false, "JoystickLike", true, 40.0); + openspace.navigation.bindJoystickAxis(name, controller.Twist[1], "Pan X", true, "JoystickLike", true, 40.0); + openspace.navigation.bindJoystickAxis(name, controller.Tilt[2], "Pan Y", false, "JoystickLike", true, 35.0); + openspace.navigation.bindJoystickAxis(name, controller.Push[3], "Zoom", false, "JoystickLike", true, 40.0); + openspace.navigation.bindJoystickAxis(name, controller.Tilt[1], "LocalRoll X", false, "JoystickLike", true, 35.0); + + openspace.navigation.bindJoystickButton( + name, + controller.LeftButton, + joystickHelper.permaBindLocalRoll(name, controller.Tilt[1]), + "Switch to local roll mode" + ) + + openspace.navigation.bindJoystickButton( + name, + controller.RightButton, + joystickHelper.permaBindGlobalRoll(name, controller.Tilt[1]), + "Switch to global roll mode" + ) +end) diff --git a/data/assets/util/joysticks/space-mouse.asset b/data/assets/util/joysticks/space-mouse-compact.asset similarity index 99% rename from data/assets/util/joysticks/space-mouse.asset rename to data/assets/util/joysticks/space-mouse-compact.asset index 3d36804891..d9a2d13fed 100644 --- a/data/assets/util/joysticks/space-mouse.asset +++ b/data/assets/util/joysticks/space-mouse-compact.asset @@ -28,6 +28,7 @@ local SpaceMouse = { Push = {0, 1, 2}, -- left/right, back/forth, up/down Twist = {5}, -- left/right Tilt = {4, 3}, -- left/right, back/forth + LeftButton = 0, RightButton = 1 } diff --git a/data/assets/util/joysticks/space-mouse-enterprise-wireless.asset b/data/assets/util/joysticks/space-mouse-enterprise-wireless.asset new file mode 100644 index 0000000000..76087df224 --- /dev/null +++ b/data/assets/util/joysticks/space-mouse-enterprise-wireless.asset @@ -0,0 +1,60 @@ +local propertyHelper = asset.require("../property_helper") +local joystickHelper = asset.require("./joystick_helper") + +-- Allowed values for the third parameter of bindJoystickAxis: +-- "None" +-- "Orbit X" +-- "Orbit Y" +-- "Zoom" -- both in and out +-- "Zoom In" +-- "Zoom Out" +-- "LocalRoll X" +-- "LocalRoll Y" +-- "GlobalRoll X" +-- "GlobalRoll Y" +-- "Pan X" +-- "Pan Y" +-- Fourth parameter determines whether the axis should be inverted +-- Fifth parameter determines whether the axis behaves like a joystick or a Trigger. +-- Allowed values are "JoystickLike" and "TriggerLike", the first one is the default +-- Sixth parameters determins if the axis should be "Sticky" or not. +-- The axis values can either go back to 0 when the joystick is released or it can +-- stay at the value it was before the joystick was released. +-- The latter is called a sticky axis, when the values don't go back to 0. +-- This version of the SpaceMouse is NOT Sticky. +-- Seventh parameter is the sensitivity for the axis + +local SpaceMouse = { + Push = {0, 1, 2}, -- left/right, back/forth, up/down + Twist = {5}, -- left/right + Tilt = {4, 3}, -- left/right, back/forth + + LeftButton = 0, + RightButton = 1 +} + +asset.onInitialize(function() + local controller = SpaceMouse; + local name = "3Dconnexion Universal Receiver"; + + openspace.navigation.bindJoystickAxis(name, controller.Push[1], "Orbit X"); + openspace.navigation.bindJoystickAxis(name, controller.Push[2], "Orbit Y"); + openspace.navigation.bindJoystickAxis(name, controller.Twist[1], "Pan X", true); + openspace.navigation.bindJoystickAxis(name, controller.Tilt[2], "Pan Y"); + openspace.navigation.bindJoystickAxis(name, controller.Push[3], "Zoom"); + openspace.navigation.bindJoystickAxis(name, controller.Tilt[1], "LocalRoll X"); + + openspace.navigation.bindJoystickButton( + name, + controller.LeftButton, + joystickHelper.permaBindLocalRoll(name, controller.Tilt[1]), + "Switch to local roll mode" + ) + + openspace.navigation.bindJoystickButton( + name, + controller.RightButton, + joystickHelper.permaBindGlobalRoll(name, controller.Tilt[1]), + "Switch to global roll mode" + ) +end) diff --git a/data/assets/util/joysticks/space-mouse-not-sticky.asset b/data/assets/util/joysticks/space-mouse-enterprise.asset similarity index 98% rename from data/assets/util/joysticks/space-mouse-not-sticky.asset rename to data/assets/util/joysticks/space-mouse-enterprise.asset index cea4fb0681..98d8697908 100644 --- a/data/assets/util/joysticks/space-mouse-not-sticky.asset +++ b/data/assets/util/joysticks/space-mouse-enterprise.asset @@ -28,13 +28,14 @@ local SpaceMouse = { Push = {0, 1, 2}, -- left/right, back/forth, up/down Twist = {5}, -- left/right Tilt = {4, 3}, -- left/right, back/forth + LeftButton = 0, RightButton = 1 } asset.onInitialize(function() local controller = SpaceMouse; - local name = "SpaceNavigator"; + local name = "SpaceMouse Enterprise"; openspace.navigation.bindJoystickAxis(name, controller.Push[1], "Orbit X"); openspace.navigation.bindJoystickAxis(name, controller.Push[2], "Orbit Y"); From 7165eeb8e14702cc059662ab039a547b13273205 Mon Sep 17 00:00:00 2001 From: Malin E Date: Thu, 14 Apr 2022 13:58:34 +0200 Subject: [PATCH 05/14] Remove cap on number of axes and buttons for joysticks --- apps/OpenSpace/main.cpp | 227 ++++++------------ .../interaction/joystickcamerastates.h | 12 +- .../interaction/joystickinputstate.h | 36 ++- modules/imgui/src/guijoystickcomponent.cpp | 4 +- src/interaction/joystickcamerastates.cpp | 37 ++- src/interaction/joystickinputstate.cpp | 38 +++ 6 files changed, 167 insertions(+), 187 deletions(-) diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index d382d5e28d..8c70fd08b6 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -207,6 +207,71 @@ LONG WINAPI generateMiniDump(EXCEPTION_POINTERS* exceptionPointers) { } #endif // WIN32 +void checkJoystickStatus() { + using namespace interaction; + + for (int i = GLFW_JOYSTICK_1; i <= GLFW_JOYSTICK_LAST; ++i) { + ZoneScopedN("Joystick state"); + + JoystickInputState& state = global::joystickInputStates->at(i); + + int present = glfwJoystickPresent(i); + if (present == GLFW_FALSE) { + state.isConnected = false; + continue; + } + + if (!state.isConnected) { + // Joystick was added + state.isConnected = true; + state.name = glfwGetJoystickName(i); + + std::fill(state.axes.begin(), state.axes.end(), 0.f); + std::fill(state.buttons.begin(), state.buttons.end(), JoystickAction::Idle); + + // Check axes and buttons + glfwGetJoystickAxes(i, &state.nAxes); + glfwGetJoystickButtons(i, &state.nButtons); + } + + const float* axes = glfwGetJoystickAxes(i, &state.nAxes); + state.axes.resize(state.nAxes); + std::memcpy(state.axes.data(), axes, state.nAxes * sizeof(float)); + + const unsigned char* buttons = glfwGetJoystickButtons(i, &state.nButtons); + state.buttons.resize(state.nButtons); + + for (int j = 0; j < state.nButtons; ++j) { + const bool currentlyPressed = buttons[j] == GLFW_PRESS; + + if (currentlyPressed) { + switch (state.buttons[j]) { + case JoystickAction::Idle: + case JoystickAction::Release: + state.buttons[j] = JoystickAction::Press; + break; + case JoystickAction::Press: + case JoystickAction::Repeat: + state.buttons[j] = JoystickAction::Repeat; + break; + } + } + else { + switch (state.buttons[j]) { + case JoystickAction::Idle: + case JoystickAction::Release: + state.buttons[j] = JoystickAction::Idle; + break; + case JoystickAction::Press: + case JoystickAction::Repeat: + state.buttons[j] = JoystickAction::Release; + break; + } + } + } + } +} + // // Init function // @@ -320,86 +385,7 @@ void mainInitFunc(GLFWwindow*) { } // Query joystick status, those connected before start up - using namespace interaction; - - for (int i = GLFW_JOYSTICK_1; i <= GLFW_JOYSTICK_LAST; ++i) { - ZoneScopedN("Joystick state"); - - JoystickInputState& state = global::joystickInputStates->at(i); - - int present = glfwJoystickPresent(i); - if (present == GLFW_FALSE) { - state.isConnected = false; - continue; - } - - if (!state.isConnected) { - // Joystick was added - state.isConnected = true; - state.name = glfwGetJoystickName(i); - - std::fill(state.axes.begin(), state.axes.end(), 0.f); - std::fill(state.buttons.begin(), state.buttons.end(), JoystickAction::Idle); - - // Check axes and buttons - glfwGetJoystickAxes(i, &state.nAxes); - if (state.nAxes > JoystickInputState::MaxAxes) { - LWARNING(fmt::format( - "Joystick/Gamepad {} has {} axes, but only {} axes are supported. " - "All excess axes are ignored", - state.name, state.nAxes, JoystickInputState::MaxAxes - )); - } - glfwGetJoystickButtons(i, &state.nButtons); - if (state.nButtons > JoystickInputState::MaxButtons) { - LWARNING(fmt::format( - "Joystick/Gamepad {} has {} buttons, but only {} buttons are " - "supported. All excess buttons are ignored", - state.name, state.nButtons, JoystickInputState::MaxButtons - )); - } - } - - const float* axes = glfwGetJoystickAxes(i, &state.nAxes); - if (state.nAxes > JoystickInputState::MaxAxes) { - state.nAxes = JoystickInputState::MaxAxes; - } - std::memcpy(state.axes.data(), axes, state.nAxes * sizeof(float)); - - const unsigned char* buttons = glfwGetJoystickButtons(i, &state.nButtons); - if (state.nButtons > JoystickInputState::MaxButtons) { - state.nButtons = JoystickInputState::MaxButtons; - } - - for (int j = 0; j < state.nButtons; ++j) { - const bool currentlyPressed = buttons[j] == GLFW_PRESS; - - if (currentlyPressed) { - switch (state.buttons[j]) { - case JoystickAction::Idle: - case JoystickAction::Release: - state.buttons[j] = JoystickAction::Press; - break; - case JoystickAction::Press: - case JoystickAction::Repeat: - state.buttons[j] = JoystickAction::Repeat; - break; - } - } - else { - switch (state.buttons[j]) { - case JoystickAction::Idle: - case JoystickAction::Release: - state.buttons[j] = JoystickAction::Idle; - break; - case JoystickAction::Press: - case JoystickAction::Repeat: - state.buttons[j] = JoystickAction::Release; - break; - } - } - } - } + checkJoystickStatus(); LTRACE("main::mainInitFunc(end)"); } @@ -419,86 +405,7 @@ void mainPreSyncFunc() { } // Query joystick status, those connected at run time - using namespace interaction; - - for (int i = GLFW_JOYSTICK_1; i <= GLFW_JOYSTICK_LAST; ++i) { - ZoneScopedN("Joystick state"); - - JoystickInputState& state = global::joystickInputStates->at(i); - - int present = glfwJoystickPresent(i); - if (present == GLFW_FALSE) { - state.isConnected = false; - continue; - } - - if (!state.isConnected) { - // Joystick was added - state.isConnected = true; - state.name = glfwGetJoystickName(i); - - std::fill(state.axes.begin(), state.axes.end(), 0.f); - std::fill(state.buttons.begin(), state.buttons.end(), JoystickAction::Idle); - - // Check axes and buttons - glfwGetJoystickAxes(i, &state.nAxes); - if (state.nAxes > JoystickInputState::MaxAxes) { - LWARNING(fmt::format( - "Joystick/Gamepad {} has {} axes, but only {} axes are supported. " - "All excess axes are ignored", - state.name, state.nAxes, JoystickInputState::MaxAxes - )); - } - glfwGetJoystickButtons(i, &state.nButtons); - if (state.nButtons > JoystickInputState::MaxButtons) { - LWARNING(fmt::format( - "Joystick/Gamepad {} has {} buttons, but only {} buttons are " - "supported. All excess buttons are ignored", - state.name, state.nButtons, JoystickInputState::MaxButtons - )); - } - } - - const float* axes = glfwGetJoystickAxes(i, &state.nAxes); - if (state.nAxes > JoystickInputState::MaxAxes) { - state.nAxes = JoystickInputState::MaxAxes; - } - std::memcpy(state.axes.data(), axes, state.nAxes * sizeof(float)); - - const unsigned char* buttons = glfwGetJoystickButtons(i, &state.nButtons); - if (state.nButtons > JoystickInputState::MaxButtons) { - state.nButtons = JoystickInputState::MaxButtons; - } - - for (int j = 0; j < state.nButtons; ++j) { - const bool currentlyPressed = buttons[j] == GLFW_PRESS; - - if (currentlyPressed) { - switch (state.buttons[j]) { - case JoystickAction::Idle: - case JoystickAction::Release: - state.buttons[j] = JoystickAction::Press; - break; - case JoystickAction::Press: - case JoystickAction::Repeat: - state.buttons[j] = JoystickAction::Repeat; - break; - } - } - else { - switch (state.buttons[j]) { - case JoystickAction::Idle: - case JoystickAction::Release: - state.buttons[j] = JoystickAction::Idle; - break; - case JoystickAction::Press: - case JoystickAction::Repeat: - state.buttons[j] = JoystickAction::Release; - break; - } - } - } - } + checkJoystickStatus(); LTRACE("main::mainPreSyncFunc(end)"); } diff --git a/include/openspace/interaction/joystickcamerastates.h b/include/openspace/interaction/joystickcamerastates.h index 6aa19a5b94..2e61f4a666 100644 --- a/include/openspace/interaction/joystickcamerastates.h +++ b/include/openspace/interaction/joystickcamerastates.h @@ -115,15 +115,13 @@ private: struct JoystickCameraState { std::string joystickName; - // We use an array for the axes and a map for the buttons since the axis are going - // to be accessed much more often and thus have to be more efficient. And storing - // a few extra AxisInformation that are not used will not matter that much; - // finding an axis location in a potential map each frame, however, would - std::array axisMapping; + // We use a vector for the axes and a map for the buttons since the axis are going + // to be accessed much more often and thus have to be more efficient + std::vector axisMapping; - // This array is used to store the old axis values from the previous frame, it is + // This vector is used to store the old axis values from the previous frame, it is // used to calculate the difference in the values in the case of a sticky axis - std::array prevAxisValues; + std::vector prevAxisValues; struct ButtonInformation { // The script that is run when the button is activated diff --git a/include/openspace/interaction/joystickinputstate.h b/include/openspace/interaction/joystickinputstate.h index 06c3b3642c..e2bc42fdf0 100644 --- a/include/openspace/interaction/joystickinputstate.h +++ b/include/openspace/interaction/joystickinputstate.h @@ -54,12 +54,6 @@ enum class JoystickAction : uint8_t { * The input state of a single joystick. */ struct JoystickInputState { - /// These two are just randomly selected numbers that can be increased if needed - /// The maximum number of supported axes - static constexpr const int MaxAxes = 8; - /// The maximum number of supported buttons - static constexpr const int MaxButtons = 48; - /// Marks whether this joystick is connected. If this value is \c false, all other /// members of this struct are undefined bool isConnected = false; @@ -69,15 +63,13 @@ struct JoystickInputState { /// The number of axes that this joystick supports int nAxes = 0; - /// The values for each axis. Each value is in the range [-1, 1]. Only the first - /// \c nAxes values are defined values, the rest are undefined - std::array axes; + /// The values for each axis. Each value is in the range [-1, 1] + std::vector axes; /// The number of buttons that this joystick possesses int nButtons = 0; - /// The status of each button. Only the first \c nButtons values are defined, the rest - /// are undefined - std::array buttons; + /// The status of each button + std::vector buttons; }; /// The maximum number of joysticks that are supported by this system. This number is @@ -88,12 +80,31 @@ struct JoystickInputStates : public std::array /// derived from the available GLFW constants static constexpr const int MaxNumJoysticks = 16; + /** + * This function return the number of axes the joystick with the given name has + * + * \param joystickName The name of the joystick to check how many axes it has, + * if empty the max number of axes for all joysticks are returned + * \return The number of axes for the joystick with the given name + */ + int numAxes(const std::string& joystickName) const; + + /** + * This function return the number of buttons the joystick with the given name has + * + * \param joystickName The name of the joystick to check how many buttons it has, + * if empty the max number of buttons for all joysticks are returned + * \return The number of buttons for the joystick with the given name + */ + int numButtons(const std::string& joystickName) const; + /** * This function adds the contributions of all connected joysticks for the provided * \p axis. After adding each joysticks contribution, the result is clamped to [-1,1]. * If a joystick does not possess a particular axis, it's does not contribute to the * sum. * + * \param joystickName The name of the joystick, if empty all joysticks are combined * \param axis The numerical axis for which the values are added * \return The summed axis values of all connected joysticks * @@ -106,6 +117,7 @@ struct JoystickInputStates : public std::array * passed \p action. Any joystick that does not posses the \p button, it will be * ignored. * + * \param joystickName The name of the joystick, if empty all joysticks are combined * \param button The button that is to be checked * \param action The action which is checked for each button * \return \c true if there is at least one joystick whose \param button is in the diff --git a/modules/imgui/src/guijoystickcomponent.cpp b/modules/imgui/src/guijoystickcomponent.cpp index 187290a844..1f5aa98ab7 100644 --- a/modules/imgui/src/guijoystickcomponent.cpp +++ b/modules/imgui/src/guijoystickcomponent.cpp @@ -84,7 +84,7 @@ void GuiJoystickComponent::render() { ImGui::Text("%s", "Summed contributions"); ImGui::Text("%s", "Axes"); - for (int i = 0; i < JoystickInputState::MaxAxes; ++i) { + for (int i = 0; i < global::joystickInputStates->numAxes(""); ++i) { float f = global::joystickInputStates->axis("", i); ImGui::SliderFloat( std::to_string(i).c_str(), @@ -94,7 +94,7 @@ void GuiJoystickComponent::render() { ); } ImGui::Text("%s", "Buttons"); - for (int i = 0; i < JoystickInputState::MaxButtons; ++i) { + for (int i = 0; i < global::joystickInputStates->numButtons(""); ++i) { ImGui::RadioButton( std::to_string(i).c_str(), global::joystickInputStates->button("", i, JoystickAction::Press) || diff --git a/src/interaction/joystickcamerastates.cpp b/src/interaction/joystickcamerastates.cpp index 0e8ab1b985..a626112311 100644 --- a/src/interaction/joystickcamerastates.cpp +++ b/src/interaction/joystickcamerastates.cpp @@ -62,7 +62,8 @@ void JoystickCameraStates::updateStateFromInput( continue; } - for (int i = 0; i < JoystickInputState::MaxAxes; ++i) { + int nAxes = joystickInputStates.numAxes(joystickInputState.name); + for (int i = 0; i < nAxes; ++i) { AxisInformation t = joystick->axisMapping[i]; if (t.type == AxisType::None) { continue; @@ -166,7 +167,8 @@ void JoystickCameraStates::updateStateFromInput( } } - for (int i = 0; i < JoystickInputState::MaxButtons; ++i) { + int nButtons = joystickInputStates.numAxes(joystickInputState.name); + for (int i = 0; i < nButtons; ++i) { auto itRange = joystick->buttonMapping.equal_range(i); for (auto it = itRange.first; it != itRange.second; ++it) { bool active = global::joystickInputStates->button( @@ -230,13 +232,17 @@ void JoystickCameraStates::setAxisMapping(std::string joystickName, bool isSticky, double sensitivity) { - ghoul_assert(axis < JoystickInputState::MaxAxes, "axis must be < MaxAxes"); - JoystickCameraState* joystickCameraState = findOrAddJoystickCameraState(joystickName); if (!joystickCameraState) { return; } + // If the axis index is too big for the vector then resize it to have room + if (axis >= joystickCameraState->axisMapping.size()) { + joystickCameraState->axisMapping.resize(axis + 1); + joystickCameraState->prevAxisValues.resize(axis + 1); + } + joystickCameraState->axisMapping[axis].type = mapping; joystickCameraState->axisMapping[axis].invert = shouldInvert; joystickCameraState->axisMapping[axis].joystickType = joystickType; @@ -254,13 +260,17 @@ void JoystickCameraStates::setAxisMappingProperty(std::string joystickName, AxisInvert shouldInvert, bool isRemote) { - ghoul_assert(axis < JoystickInputState::MaxAxes, "axis must be < MaxAxes"); - JoystickCameraState* joystickCameraState = findOrAddJoystickCameraState(joystickName); if (!joystickCameraState) { return; } + // If the axis index is too big for the vector then resize it to have room + if (axis >= joystickCameraState->axisMapping.size()) { + joystickCameraState->axisMapping.resize(axis + 1); + joystickCameraState->prevAxisValues.resize(axis + 1); + } + joystickCameraState->axisMapping[axis].type = AxisType::Property; joystickCameraState->axisMapping[axis].invert = shouldInvert; joystickCameraState->axisMapping[axis].propertyUri = propertyUri; @@ -282,6 +292,11 @@ JoystickCameraStates::AxisInformation JoystickCameraStates::axisMapping( return dummy; } + if (axis >= joystick->axisMapping.size()) { + JoystickCameraStates::AxisInformation dummy; + return dummy; + } + return joystick->axisMapping[axis]; } @@ -293,6 +308,12 @@ void JoystickCameraStates::setDeadzone(const std::string& joystickName, int axis return; } + // If the axis index is too big for the vector then resize it to have room + if (axis >= joystickCameraState->axisMapping.size()) { + joystickCameraState->axisMapping.resize(axis + 1); + joystickCameraState->prevAxisValues.resize(axis + 1); + } + joystickCameraState->axisMapping[axis].deadzone = deadzone; } @@ -302,6 +323,10 @@ float JoystickCameraStates::deadzone(const std::string& joystickName, int axis) return 0.f; } + if (axis >= joystick->axisMapping.size()) { + return 0.f; + } + return joystick->axisMapping[axis].deadzone; } diff --git a/src/interaction/joystickinputstate.cpp b/src/interaction/joystickinputstate.cpp index c372a8f4d1..7e3ad29088 100644 --- a/src/interaction/joystickinputstate.cpp +++ b/src/interaction/joystickinputstate.cpp @@ -33,6 +33,44 @@ namespace openspace::interaction { +int JoystickInputStates::numAxes(const std::string& joystickName) const { + if (joystickName.empty()) { + int maxNumAxes = -1; + for (auto it = begin(); it < end(); ++it) { + if (it->nAxes > maxNumAxes) { + maxNumAxes = it->nAxes; + } + } + return maxNumAxes; + } + + for (auto it = begin(); it < end(); ++it) { + if (it->name == joystickName) { + return it->nAxes; + } + } + return -1; +} + +int JoystickInputStates::numButtons(const std::string& joystickName) const { + if (joystickName.empty()) { + int maxNumButtons = -1; + for (auto it = begin(); it < end(); ++it) { + if (it->nButtons > maxNumButtons) { + maxNumButtons = it->nButtons; + } + } + return maxNumButtons; + } + + for (auto it = begin(); it < end(); ++it) { + if (it->name == joystickName) { + return it->nButtons; + } + } + return -1; +} + float JoystickInputStates::axis(const std::string& joystickName, int axis) const { ghoul_precondition(axis >= 0, "axis must be 0 or positive"); From aff89c4d47dfd05460e8e8683089c56ddfce4d95 Mon Sep 17 00:00:00 2001 From: Malin E Date: Tue, 19 Apr 2022 12:13:47 +0200 Subject: [PATCH 06/14] Add asset for auto detection of supported joysticks --- data/assets/util/joysticks/any-joystick.asset | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 data/assets/util/joysticks/any-joystick.asset diff --git a/data/assets/util/joysticks/any-joystick.asset b/data/assets/util/joysticks/any-joystick.asset new file mode 100644 index 0000000000..2de692bba6 --- /dev/null +++ b/data/assets/util/joysticks/any-joystick.asset @@ -0,0 +1,70 @@ +local propertyHelper = asset.require("../property_helper") +local joystickHelper = asset.require("./joystick_helper") + +local function numItems(iTable) + local counter = 0 + for k, v in ipairs(iTable) do + counter = counter + 1 + end + return counter +end + +asset.onInitialize(function() + local joysticks = openspace.navigation.listAllJoysticks() + local numJoysticks = numItems(joysticks) + local joystick = "" + + -- Is any connected? + if numJoysticks == 0 then + openspace.printWarning("Could not find any connected joysticks") + return + end + + -- when only one joystick is connected + if numJoysticks == 1 then + local joyStickName = joysticks[1] + if joyStickName ~= "3Dconnexion KMJ Emulator" then -- Skip the SpaceMouse emulator + joystick = joyStickName + end + -- When two joystics are connected, make sure the second one is not the SpaceMouse emulator + -- If so then it is essentially only one connected + elseif numJoysticks == 2 then + local onlyOne = false + for _, joyStickName in ipairs(joysticks) do + if joyStickName == "3Dconnexion KMJ Emulator" then -- Skip the SpaceMouse emulator + onlyOne = true + else + joystick = joyStickName + end + end + + if onlyOne == false then + openspace.printWarning("Cannot auto detect and add several joysticks") + return + end + else + openspace.printWarning("Cannot auto detect and add several joysticks") + return + end + + if joystick == "" then + openspace.printWarning("Could not find any connected joysticks") + return + end + + if joystick == "Wireless Controller" then + openspace.asset.add("./util/joysticks/ps4") + elseif joystick == "Xbox Controller" then + openspace.asset.add("./util/joysticks/xbox") + elseif joystick == "Wireless Xbox Controller" then + openspace.asset.add("./util/joysticks/xbox-wireless") + elseif joystick == "SpaceNavigator" then + openspace.asset.add("./util/joysticks/space-mouse-compact") + elseif joystick == "SpaceMouse Enterprise" then + openspace.asset.add("./util/joysticks/space-mouse-enterprise") + elseif joystick == "3Dconnexion Universal Receiver" then + openspace.printWarning("SpaceMouse in wireless mode cannot be automatically detected and added. Please add the matching asset file manually.") + else + openspace.printWarning("Could not find a matching asset for joystick: " .. joystick) + end +end) From 425b771d8d747ff9fbea0f49b21c329aa22b1588 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 20 Apr 2022 13:30:17 +0200 Subject: [PATCH 07/14] Fix issue with imgui joystick sliders being coupled * The identifiers for the gui components were not unique, now they are --- modules/imgui/src/guijoystickcomponent.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/imgui/src/guijoystickcomponent.cpp b/modules/imgui/src/guijoystickcomponent.cpp index 1f5aa98ab7..a4c980c9bf 100644 --- a/modules/imgui/src/guijoystickcomponent.cpp +++ b/modules/imgui/src/guijoystickcomponent.cpp @@ -60,8 +60,9 @@ void GuiJoystickComponent::render() { ImGui::Text("%s", "Axes"); for (int j = 0; j < state.nAxes; ++j) { float f = state.axes[j]; + std::string id = std::to_string(j) + "##" + state.name + "Axis"; ImGui::SliderFloat( - std::to_string(j).c_str(), + id.c_str(), &f, -1.f, 1.f @@ -69,8 +70,9 @@ void GuiJoystickComponent::render() { } ImGui::Text("%s", "Buttons"); for (int j = 0; j < state.nButtons; ++j) { + std::string id = std::to_string(j) + "##" + state.name + "Button"; ImGui::RadioButton( - std::to_string(j).c_str(), + id.c_str(), state.buttons[j] == JoystickAction::Press || state.buttons[j] == JoystickAction::Repeat ); @@ -86,8 +88,9 @@ void GuiJoystickComponent::render() { ImGui::Text("%s", "Axes"); for (int i = 0; i < global::joystickInputStates->numAxes(""); ++i) { float f = global::joystickInputStates->axis("", i); + std::string id = std::to_string(i) + "##" + "TotalAxis"; ImGui::SliderFloat( - std::to_string(i).c_str(), + id.c_str(), &f, -1.f, 1.f @@ -95,8 +98,9 @@ void GuiJoystickComponent::render() { } ImGui::Text("%s", "Buttons"); for (int i = 0; i < global::joystickInputStates->numButtons(""); ++i) { + std::string id = std::to_string(i) + "##" + "TotalButton"; ImGui::RadioButton( - std::to_string(i).c_str(), + id.c_str(), global::joystickInputStates->button("", i, JoystickAction::Press) || global::joystickInputStates->button("", i, JoystickAction::Repeat) ); From 1d2011e7a26d23229cf7074404cc13edbd019ab0 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 20 Apr 2022 14:27:43 +0200 Subject: [PATCH 08/14] Small clean up of auto detect asset --- data/assets/util/joysticks/any-joystick.asset | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/data/assets/util/joysticks/any-joystick.asset b/data/assets/util/joysticks/any-joystick.asset index 2de692bba6..4c35f91399 100644 --- a/data/assets/util/joysticks/any-joystick.asset +++ b/data/assets/util/joysticks/any-joystick.asset @@ -10,11 +10,21 @@ local function numItems(iTable) end asset.onInitialize(function() - local joysticks = openspace.navigation.listAllJoysticks() - local numJoysticks = numItems(joysticks) + local rawJoysticks = openspace.navigation.listAllJoysticks() + local numJoysticks = numItems(rawJoysticks) local joystick = "" - -- Is any connected? + -- Remove the SpaceMouse emulator if it exists + local joysticks = {} + for _, joyStickName in ipairs(rawJoysticks) do + if joyStickName == "3Dconnexion KMJ Emulator" then + numJoysticks = numJoysticks - 1 + else + table.insert(joysticks, joyStickName) + end + end + + -- Is any joysticks connected? if numJoysticks == 0 then openspace.printWarning("Could not find any connected joysticks") return @@ -23,25 +33,9 @@ asset.onInitialize(function() -- when only one joystick is connected if numJoysticks == 1 then local joyStickName = joysticks[1] - if joyStickName ~= "3Dconnexion KMJ Emulator" then -- Skip the SpaceMouse emulator + if joyStickName ~= nil then joystick = joyStickName end - -- When two joystics are connected, make sure the second one is not the SpaceMouse emulator - -- If so then it is essentially only one connected - elseif numJoysticks == 2 then - local onlyOne = false - for _, joyStickName in ipairs(joysticks) do - if joyStickName == "3Dconnexion KMJ Emulator" then -- Skip the SpaceMouse emulator - onlyOne = true - else - joystick = joyStickName - end - end - - if onlyOne == false then - openspace.printWarning("Cannot auto detect and add several joysticks") - return - end else openspace.printWarning("Cannot auto detect and add several joysticks") return From 6085c6affce534e4d27fce8d0f1082c9dd4051c6 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 20 Apr 2022 14:57:41 +0200 Subject: [PATCH 09/14] Add variable to add all detected joysticks or not * And remove the added joystick assets in the deinitialize --- data/assets/util/joysticks/any-joystick.asset | 78 +++++++++++-------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/data/assets/util/joysticks/any-joystick.asset b/data/assets/util/joysticks/any-joystick.asset index 4c35f91399..3af079b45c 100644 --- a/data/assets/util/joysticks/any-joystick.asset +++ b/data/assets/util/joysticks/any-joystick.asset @@ -1,5 +1,6 @@ local propertyHelper = asset.require("../property_helper") local joystickHelper = asset.require("./joystick_helper") +local initializeAll = false local function numItems(iTable) local counter = 0 @@ -9,6 +10,25 @@ local function numItems(iTable) return counter end +-- Add the asset cooresponding to the joystick name +local function addJoystickAsset(joystick) + if joystick == "Wireless Controller" then + openspace.asset.add("./util/joysticks/ps4") + elseif joystick == "Xbox Controller" then + openspace.asset.add("./util/joysticks/xbox") + elseif joystick == "Wireless Xbox Controller" then + openspace.asset.add("./util/joysticks/xbox-wireless") + elseif joystick == "SpaceNavigator" then + openspace.asset.add("./util/joysticks/space-mouse-compact") + elseif joystick == "SpaceMouse Enterprise" then + openspace.asset.add("./util/joysticks/space-mouse-enterprise") + elseif joystick == "3Dconnexion Universal Receiver" then + openspace.printWarning("SpaceMouse in wireless mode cannot be automatically detected and added. Please add the matching asset file manually.") + else + openspace.printWarning("Could not find a matching asset for joystick: " .. joystick) + end +end + asset.onInitialize(function() local rawJoysticks = openspace.navigation.listAllJoysticks() local numJoysticks = numItems(rawJoysticks) @@ -24,41 +44,37 @@ asset.onInitialize(function() end end - -- Is any joysticks connected? if numJoysticks == 0 then openspace.printWarning("Could not find any connected joysticks") - return - end - - -- when only one joystick is connected - if numJoysticks == 1 then - local joyStickName = joysticks[1] - if joyStickName ~= nil then - joystick = joyStickName + elseif numJoysticks == 1 then + addJoystickAsset(joysticks[1]) + elseif numJoysticks > 1 and initializeAll then + for _, joyStickName in ipairs(joysticks) do + addJoystickAsset(joyStickName) end else openspace.printWarning("Cannot auto detect and add several joysticks") - return - end - - if joystick == "" then - openspace.printWarning("Could not find any connected joysticks") - return - end - - if joystick == "Wireless Controller" then - openspace.asset.add("./util/joysticks/ps4") - elseif joystick == "Xbox Controller" then - openspace.asset.add("./util/joysticks/xbox") - elseif joystick == "Wireless Xbox Controller" then - openspace.asset.add("./util/joysticks/xbox-wireless") - elseif joystick == "SpaceNavigator" then - openspace.asset.add("./util/joysticks/space-mouse-compact") - elseif joystick == "SpaceMouse Enterprise" then - openspace.asset.add("./util/joysticks/space-mouse-enterprise") - elseif joystick == "3Dconnexion Universal Receiver" then - openspace.printWarning("SpaceMouse in wireless mode cannot be automatically detected and added. Please add the matching asset file manually.") - else - openspace.printWarning("Could not find a matching asset for joystick: " .. joystick) + end +end) + +asset.onDeinitialize(function() + if openspace.asset.isLoaded("./util/joysticks/ps4") then + openspace.asset.remove("./util/joysticks/ps4") + end + + if openspace.asset.isLoaded("./util/joysticks/xbox") then + openspace.asset.remove("./util/joysticks/xbox") + end + + if openspace.asset.isLoaded("./util/joysticks/xbox-wireless") then + openspace.asset.remove("./util/joysticks/xbox-wireless") + end + + if openspace.asset.isLoaded("./util/joysticks/space-mouse-compact") then + openspace.asset.remove("./util/joysticks/space-mouse-compact") + end + + if openspace.asset.isLoaded("./util/joysticks/space-mouse-enterprise") then + openspace.asset.remove("./util/joysticks/space-mouse-enterprise") end end) From 71cae1363d9471f4ebbcddb9f0e3346abc49d6d6 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 20 Apr 2022 17:35:29 +0200 Subject: [PATCH 10/14] Add axis deadzones to enterprise version of SpaceMouse --- .../util/joysticks/space-mouse-enterprise-wireless.asset | 7 +++++++ data/assets/util/joysticks/space-mouse-enterprise.asset | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/data/assets/util/joysticks/space-mouse-enterprise-wireless.asset b/data/assets/util/joysticks/space-mouse-enterprise-wireless.asset index 76087df224..d561244ca8 100644 --- a/data/assets/util/joysticks/space-mouse-enterprise-wireless.asset +++ b/data/assets/util/joysticks/space-mouse-enterprise-wireless.asset @@ -37,6 +37,13 @@ asset.onInitialize(function() local controller = SpaceMouse; local name = "3Dconnexion Universal Receiver"; + openspace.navigation.setAxisDeadZone(name, controller.Push[1], 0.1) + openspace.navigation.setAxisDeadZone(name, controller.Push[2], 0.1) + openspace.navigation.setAxisDeadZone(name, controller.Twist[1], 0.1) + openspace.navigation.setAxisDeadZone(name, controller.Tilt[2], 0.1) + openspace.navigation.setAxisDeadZone(name, controller.Push[3], 0.1) + openspace.navigation.setAxisDeadZone(name, controller.Tilt[1], 0.1) + openspace.navigation.bindJoystickAxis(name, controller.Push[1], "Orbit X"); openspace.navigation.bindJoystickAxis(name, controller.Push[2], "Orbit Y"); openspace.navigation.bindJoystickAxis(name, controller.Twist[1], "Pan X", true); diff --git a/data/assets/util/joysticks/space-mouse-enterprise.asset b/data/assets/util/joysticks/space-mouse-enterprise.asset index 98d8697908..158555df5a 100644 --- a/data/assets/util/joysticks/space-mouse-enterprise.asset +++ b/data/assets/util/joysticks/space-mouse-enterprise.asset @@ -37,6 +37,13 @@ asset.onInitialize(function() local controller = SpaceMouse; local name = "SpaceMouse Enterprise"; + openspace.navigation.setAxisDeadZone(name, controller.Push[1], 0.1) + openspace.navigation.setAxisDeadZone(name, controller.Push[2], 0.1) + openspace.navigation.setAxisDeadZone(name, controller.Twist[1], 0.1) + openspace.navigation.setAxisDeadZone(name, controller.Tilt[2], 0.1) + openspace.navigation.setAxisDeadZone(name, controller.Push[3], 0.1) + openspace.navigation.setAxisDeadZone(name, controller.Tilt[1], 0.1) + openspace.navigation.bindJoystickAxis(name, controller.Push[1], "Orbit X"); openspace.navigation.bindJoystickAxis(name, controller.Push[2], "Orbit Y"); openspace.navigation.bindJoystickAxis(name, controller.Twist[1], "Pan X", true); From 516be81ecd1bdd0f3403222dbcff2357feae0117 Mon Sep 17 00:00:00 2001 From: Malin E Date: Mon, 25 Apr 2022 10:45:54 +0200 Subject: [PATCH 11/14] Simplify setting of deadzone size in assets --- data/assets/examples/joystickProperty.asset | 4 ++-- data/assets/util/joysticks/ps4.asset | 14 ++++++++------ .../space-mouse-enterprise-wireless.asset | 13 +++++++------ .../util/joysticks/space-mouse-enterprise.asset | 13 +++++++------ data/assets/util/joysticks/xbox-wireless.asset | 14 ++++++++------ data/assets/util/joysticks/xbox.asset | 14 ++++++++------ 6 files changed, 40 insertions(+), 32 deletions(-) diff --git a/data/assets/examples/joystickProperty.asset b/data/assets/examples/joystickProperty.asset index 04088a783a..bcd71b14e9 100644 --- a/data/assets/examples/joystickProperty.asset +++ b/data/assets/examples/joystickProperty.asset @@ -25,8 +25,8 @@ -- First - Name of the joystick that should be bound -- Second - Which axis should be bound of this joystick -- Third - The property uri --- Fourth - (optional) The smallest value that you wnat to allow this property on the joystick --- Fifth - (optional) The largest value that you wnat to allow this property on the joystick +-- Fourth - (optional) The smallest value that you want to allow this property on the joystick +-- Fifth - (optional) The largest value that you want to allow this property on the joystick -- Sixth - (optional) Determines whether the axis should be inverted -- Seventh - (optional) Should this property change be sent to other connected remote sessions diff --git a/data/assets/util/joysticks/ps4.asset b/data/assets/util/joysticks/ps4.asset index 829661f96a..8da5b61a39 100644 --- a/data/assets/util/joysticks/ps4.asset +++ b/data/assets/util/joysticks/ps4.asset @@ -52,12 +52,14 @@ asset.onInitialize(function() local controller = PS4Controller; local name = "Wireless Controller"; - openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[1], 0.15) - openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[2], 0.15) - openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[1], 0.15) - openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[2], 0.15) - openspace.navigation.setAxisDeadZone(name, controller.L2, 0.05) - openspace.navigation.setAxisDeadZone(name, controller.R2, 0.05) + local deadzoneJoysticks = 0.15 + local deadzoneTriggers = 0.05 + openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[1], deadzoneJoysticks) + openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[2], deadzoneJoysticks) + openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[1], deadzoneJoysticks) + openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[2], deadzoneJoysticks) + openspace.navigation.setAxisDeadZone(name, controller.L2, deadzoneTriggers) + openspace.navigation.setAxisDeadZone(name, controller.R2, deadzoneTriggers) openspace.navigation.bindJoystickAxis(name, controller.LeftThumbStick[1], "Orbit X"); openspace.navigation.bindJoystickAxis(name, controller.LeftThumbStick[2], "Orbit Y", true); diff --git a/data/assets/util/joysticks/space-mouse-enterprise-wireless.asset b/data/assets/util/joysticks/space-mouse-enterprise-wireless.asset index d561244ca8..e1b5d0ee9c 100644 --- a/data/assets/util/joysticks/space-mouse-enterprise-wireless.asset +++ b/data/assets/util/joysticks/space-mouse-enterprise-wireless.asset @@ -37,12 +37,13 @@ asset.onInitialize(function() local controller = SpaceMouse; local name = "3Dconnexion Universal Receiver"; - openspace.navigation.setAxisDeadZone(name, controller.Push[1], 0.1) - openspace.navigation.setAxisDeadZone(name, controller.Push[2], 0.1) - openspace.navigation.setAxisDeadZone(name, controller.Twist[1], 0.1) - openspace.navigation.setAxisDeadZone(name, controller.Tilt[2], 0.1) - openspace.navigation.setAxisDeadZone(name, controller.Push[3], 0.1) - openspace.navigation.setAxisDeadZone(name, controller.Tilt[1], 0.1) + local deadzone = 0.15 + openspace.navigation.setAxisDeadZone(name, controller.Push[1], deadzone) + openspace.navigation.setAxisDeadZone(name, controller.Push[2], deadzone) + openspace.navigation.setAxisDeadZone(name, controller.Twist[1], deadzone) + openspace.navigation.setAxisDeadZone(name, controller.Tilt[2], deadzone) + openspace.navigation.setAxisDeadZone(name, controller.Push[3], deadzone) + openspace.navigation.setAxisDeadZone(name, controller.Tilt[1], deadzone) openspace.navigation.bindJoystickAxis(name, controller.Push[1], "Orbit X"); openspace.navigation.bindJoystickAxis(name, controller.Push[2], "Orbit Y"); diff --git a/data/assets/util/joysticks/space-mouse-enterprise.asset b/data/assets/util/joysticks/space-mouse-enterprise.asset index 158555df5a..517d55217e 100644 --- a/data/assets/util/joysticks/space-mouse-enterprise.asset +++ b/data/assets/util/joysticks/space-mouse-enterprise.asset @@ -37,12 +37,13 @@ asset.onInitialize(function() local controller = SpaceMouse; local name = "SpaceMouse Enterprise"; - openspace.navigation.setAxisDeadZone(name, controller.Push[1], 0.1) - openspace.navigation.setAxisDeadZone(name, controller.Push[2], 0.1) - openspace.navigation.setAxisDeadZone(name, controller.Twist[1], 0.1) - openspace.navigation.setAxisDeadZone(name, controller.Tilt[2], 0.1) - openspace.navigation.setAxisDeadZone(name, controller.Push[3], 0.1) - openspace.navigation.setAxisDeadZone(name, controller.Tilt[1], 0.1) + local deadzone = 0.15 + openspace.navigation.setAxisDeadZone(name, controller.Push[1], deadzone) + openspace.navigation.setAxisDeadZone(name, controller.Push[2], deadzone) + openspace.navigation.setAxisDeadZone(name, controller.Twist[1], deadzone) + openspace.navigation.setAxisDeadZone(name, controller.Tilt[2], deadzone) + openspace.navigation.setAxisDeadZone(name, controller.Push[3], deadzone) + openspace.navigation.setAxisDeadZone(name, controller.Tilt[1], deadzone) openspace.navigation.bindJoystickAxis(name, controller.Push[1], "Orbit X"); openspace.navigation.bindJoystickAxis(name, controller.Push[2], "Orbit Y"); diff --git a/data/assets/util/joysticks/xbox-wireless.asset b/data/assets/util/joysticks/xbox-wireless.asset index 75955c4294..239edbeb88 100644 --- a/data/assets/util/joysticks/xbox-wireless.asset +++ b/data/assets/util/joysticks/xbox-wireless.asset @@ -50,12 +50,14 @@ asset.onInitialize(function() local controller = XBoxController; local name = "Wireless Xbox Controller"; - openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[1], 0.15) - openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[2], 0.15) - openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[1], 0.15) - openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[2], 0.15) - openspace.navigation.setAxisDeadZone(name, controller.LeftTrigger, 0.05) - openspace.navigation.setAxisDeadZone(name, controller.RightTrigger, 0.05) + local deadzoneJoysticks = 0.15 + local deadzoneTriggers = 0.05 + openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[1], deadzoneJoysticks) + openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[2], deadzoneJoysticks) + openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[1], deadzoneJoysticks) + openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[2], deadzoneJoysticks) + openspace.navigation.setAxisDeadZone(name, controller.LeftTrigger, deadzoneTriggers) + openspace.navigation.setAxisDeadZone(name, controller.RightTrigger, deadzoneTriggers) openspace.navigation.bindJoystickAxis(name, controller.LeftThumbStick[1], "Orbit X"); openspace.navigation.bindJoystickAxis(name, controller.LeftThumbStick[2], "Orbit Y", true); diff --git a/data/assets/util/joysticks/xbox.asset b/data/assets/util/joysticks/xbox.asset index c94449ba68..1bc5314d4d 100644 --- a/data/assets/util/joysticks/xbox.asset +++ b/data/assets/util/joysticks/xbox.asset @@ -50,12 +50,14 @@ asset.onInitialize(function() local controller = XBoxController; local name = "Xbox Controller"; - openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[1], 0.15) - openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[2], 0.15) - openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[1], 0.15) - openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[2], 0.15) - openspace.navigation.setAxisDeadZone(name, controller.LeftTrigger, 0.05) - openspace.navigation.setAxisDeadZone(name, controller.RightTrigger, 0.05) + local deadzoneJoysticks = 0.15 + local deadzoneTriggers = 0.05 + openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[1], deadzoneJoysticks) + openspace.navigation.setAxisDeadZone(name, controller.LeftThumbStick[2], deadzoneJoysticks) + openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[1], deadzoneJoysticks) + openspace.navigation.setAxisDeadZone(name, controller.RightThumbStick[2], deadzoneJoysticks) + openspace.navigation.setAxisDeadZone(name, controller.LeftTrigger, deadzoneTriggers) + openspace.navigation.setAxisDeadZone(name, controller.RightTrigger, deadzoneTriggers) openspace.navigation.bindJoystickAxis(name, controller.LeftThumbStick[1], "Orbit X"); openspace.navigation.bindJoystickAxis(name, controller.LeftThumbStick[2], "Orbit Y", true); From 860d4c30d25456b21bb8adb4125520505b0110d4 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 27 Apr 2022 10:49:17 +0200 Subject: [PATCH 12/14] Address PR comments + fix issue with refocus button on joysticks --- apps/OpenSpace/main.cpp | 32 +++++++++---------- data/assets/util/joysticks/any-joystick.asset | 10 +----- data/assets/util/joysticks/ps4.asset | 6 ++-- .../assets/util/joysticks/xbox-wireless.asset | 6 ++-- data/assets/util/joysticks/xbox.asset | 6 ++-- .../interaction/joystickinputstate.h | 4 +-- modules/imgui/src/guijoystickcomponent.cpp | 4 +-- 7 files changed, 30 insertions(+), 38 deletions(-) diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index 8c70fd08b6..90bd7dda8c 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -246,26 +246,26 @@ void checkJoystickStatus() { if (currentlyPressed) { switch (state.buttons[j]) { - case JoystickAction::Idle: - case JoystickAction::Release: - state.buttons[j] = JoystickAction::Press; - break; - case JoystickAction::Press: - case JoystickAction::Repeat: - state.buttons[j] = JoystickAction::Repeat; - break; + case JoystickAction::Idle: + case JoystickAction::Release: + state.buttons[j] = JoystickAction::Press; + break; + case JoystickAction::Press: + case JoystickAction::Repeat: + state.buttons[j] = JoystickAction::Repeat; + break; } } else { switch (state.buttons[j]) { - case JoystickAction::Idle: - case JoystickAction::Release: - state.buttons[j] = JoystickAction::Idle; - break; - case JoystickAction::Press: - case JoystickAction::Repeat: - state.buttons[j] = JoystickAction::Release; - break; + case JoystickAction::Idle: + case JoystickAction::Release: + state.buttons[j] = JoystickAction::Idle; + break; + case JoystickAction::Press: + case JoystickAction::Repeat: + state.buttons[j] = JoystickAction::Release; + break; } } } diff --git a/data/assets/util/joysticks/any-joystick.asset b/data/assets/util/joysticks/any-joystick.asset index 3af079b45c..d53777aff0 100644 --- a/data/assets/util/joysticks/any-joystick.asset +++ b/data/assets/util/joysticks/any-joystick.asset @@ -2,14 +2,6 @@ local propertyHelper = asset.require("../property_helper") local joystickHelper = asset.require("./joystick_helper") local initializeAll = false -local function numItems(iTable) - local counter = 0 - for k, v in ipairs(iTable) do - counter = counter + 1 - end - return counter -end - -- Add the asset cooresponding to the joystick name local function addJoystickAsset(joystick) if joystick == "Wireless Controller" then @@ -31,7 +23,7 @@ end asset.onInitialize(function() local rawJoysticks = openspace.navigation.listAllJoysticks() - local numJoysticks = numItems(rawJoysticks) + local numJoysticks = #rawJoysticks local joystick = "" -- Remove the SpaceMouse emulator if it exists diff --git a/data/assets/util/joysticks/ps4.asset b/data/assets/util/joysticks/ps4.asset index 8da5b61a39..40db2d4533 100644 --- a/data/assets/util/joysticks/ps4.asset +++ b/data/assets/util/joysticks/ps4.asset @@ -118,9 +118,9 @@ asset.onInitialize(function() name, controller.Square, [[ - "openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Aim", ""); - "openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Anchor", "Earth"); - "openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.RetargetAnchor", nil); + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Aim", ""); + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Anchor", "Earth"); + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.RetargetAnchor", nil); ]], "Switch target to Earth" ) diff --git a/data/assets/util/joysticks/xbox-wireless.asset b/data/assets/util/joysticks/xbox-wireless.asset index 239edbeb88..aaef2fc79d 100644 --- a/data/assets/util/joysticks/xbox-wireless.asset +++ b/data/assets/util/joysticks/xbox-wireless.asset @@ -116,9 +116,9 @@ asset.onInitialize(function() name, controller.X, [[ - "openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Aim", ""); - "openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Anchor", "Earth"); - "openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.RetargetAnchor", nil); + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Aim", ""); + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Anchor", "Earth"); + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.RetargetAnchor", nil); ]], "Switch target to Earth" ) diff --git a/data/assets/util/joysticks/xbox.asset b/data/assets/util/joysticks/xbox.asset index 1bc5314d4d..f4389e83f1 100644 --- a/data/assets/util/joysticks/xbox.asset +++ b/data/assets/util/joysticks/xbox.asset @@ -116,9 +116,9 @@ asset.onInitialize(function() name, controller.X, [[ - "openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Aim", ""); - "openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Anchor", "Earth"); - "openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.RetargetAnchor", nil); + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Aim", ""); + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Anchor", "Earth"); + openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.RetargetAnchor", nil); ]], "Switch target to Earth" ) diff --git a/include/openspace/interaction/joystickinputstate.h b/include/openspace/interaction/joystickinputstate.h index e2bc42fdf0..a37196fbb5 100644 --- a/include/openspace/interaction/joystickinputstate.h +++ b/include/openspace/interaction/joystickinputstate.h @@ -87,7 +87,7 @@ struct JoystickInputStates : public std::array * if empty the max number of axes for all joysticks are returned * \return The number of axes for the joystick with the given name */ - int numAxes(const std::string& joystickName) const; + int numAxes(const std::string& joystickName = "") const; /** * This function return the number of buttons the joystick with the given name has @@ -96,7 +96,7 @@ struct JoystickInputStates : public std::array * if empty the max number of buttons for all joysticks are returned * \return The number of buttons for the joystick with the given name */ - int numButtons(const std::string& joystickName) const; + int numButtons(const std::string& joystickName = "") const; /** * This function adds the contributions of all connected joysticks for the provided diff --git a/modules/imgui/src/guijoystickcomponent.cpp b/modules/imgui/src/guijoystickcomponent.cpp index a4c980c9bf..8e06c3a7a6 100644 --- a/modules/imgui/src/guijoystickcomponent.cpp +++ b/modules/imgui/src/guijoystickcomponent.cpp @@ -86,7 +86,7 @@ void GuiJoystickComponent::render() { ImGui::Text("%s", "Summed contributions"); ImGui::Text("%s", "Axes"); - for (int i = 0; i < global::joystickInputStates->numAxes(""); ++i) { + for (int i = 0; i < global::joystickInputStates->numAxes(); ++i) { float f = global::joystickInputStates->axis("", i); std::string id = std::to_string(i) + "##" + "TotalAxis"; ImGui::SliderFloat( @@ -97,7 +97,7 @@ void GuiJoystickComponent::render() { ); } ImGui::Text("%s", "Buttons"); - for (int i = 0; i < global::joystickInputStates->numButtons(""); ++i) { + for (int i = 0; i < global::joystickInputStates->numButtons(); ++i) { std::string id = std::to_string(i) + "##" + "TotalButton"; ImGui::RadioButton( id.c_str(), From 7912141099f8c767d4e60138cb1ddc5328f68e28 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 27 Apr 2022 10:57:09 +0200 Subject: [PATCH 13/14] Small copy paste error fix --- src/interaction/joystickcamerastates.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interaction/joystickcamerastates.cpp b/src/interaction/joystickcamerastates.cpp index a626112311..ef8259dff7 100644 --- a/src/interaction/joystickcamerastates.cpp +++ b/src/interaction/joystickcamerastates.cpp @@ -167,7 +167,7 @@ void JoystickCameraStates::updateStateFromInput( } } - int nButtons = joystickInputStates.numAxes(joystickInputState.name); + int nButtons = joystickInputStates.numButtons(joystickInputState.name); for (int i = 0; i < nButtons; ++i) { auto itRange = joystick->buttonMapping.equal_range(i); for (auto it = itRange.first; it != itRange.second; ++it) { From 55278574e9fee6179d4f8cff57a86bf6477232f8 Mon Sep 17 00:00:00 2001 From: Malin E Date: Wed, 27 Apr 2022 11:21:56 +0200 Subject: [PATCH 14/14] Remove unsupported buttons on the SpaceMouse enterprise joystick * GLFW cannot detect the buttons for the enterprise version of the SpaceMouse --- .../space-mouse-enterprise-wireless.asset | 18 ++---------------- .../joysticks/space-mouse-enterprise.asset | 18 ++---------------- 2 files changed, 4 insertions(+), 32 deletions(-) diff --git a/data/assets/util/joysticks/space-mouse-enterprise-wireless.asset b/data/assets/util/joysticks/space-mouse-enterprise-wireless.asset index e1b5d0ee9c..2a8f124196 100644 --- a/data/assets/util/joysticks/space-mouse-enterprise-wireless.asset +++ b/data/assets/util/joysticks/space-mouse-enterprise-wireless.asset @@ -29,8 +29,8 @@ local SpaceMouse = { Twist = {5}, -- left/right Tilt = {4, 3}, -- left/right, back/forth - LeftButton = 0, - RightButton = 1 + -- Buttons on the Enterprise version of the SpaceMouse is not detectable, use regular + -- keybindings instead, for more information see our wiki page. } asset.onInitialize(function() @@ -51,18 +51,4 @@ asset.onInitialize(function() openspace.navigation.bindJoystickAxis(name, controller.Tilt[2], "Pan Y"); openspace.navigation.bindJoystickAxis(name, controller.Push[3], "Zoom"); openspace.navigation.bindJoystickAxis(name, controller.Tilt[1], "LocalRoll X"); - - openspace.navigation.bindJoystickButton( - name, - controller.LeftButton, - joystickHelper.permaBindLocalRoll(name, controller.Tilt[1]), - "Switch to local roll mode" - ) - - openspace.navigation.bindJoystickButton( - name, - controller.RightButton, - joystickHelper.permaBindGlobalRoll(name, controller.Tilt[1]), - "Switch to global roll mode" - ) end) diff --git a/data/assets/util/joysticks/space-mouse-enterprise.asset b/data/assets/util/joysticks/space-mouse-enterprise.asset index 517d55217e..cb9510a641 100644 --- a/data/assets/util/joysticks/space-mouse-enterprise.asset +++ b/data/assets/util/joysticks/space-mouse-enterprise.asset @@ -29,8 +29,8 @@ local SpaceMouse = { Twist = {5}, -- left/right Tilt = {4, 3}, -- left/right, back/forth - LeftButton = 0, - RightButton = 1 + -- Buttons on the Enterprise version of the SpaceMouse is not detectable, use regular + -- keybindings instead, for more information see our wiki page. } asset.onInitialize(function() @@ -51,18 +51,4 @@ asset.onInitialize(function() openspace.navigation.bindJoystickAxis(name, controller.Tilt[2], "Pan Y"); openspace.navigation.bindJoystickAxis(name, controller.Push[3], "Zoom"); openspace.navigation.bindJoystickAxis(name, controller.Tilt[1], "LocalRoll X"); - - openspace.navigation.bindJoystickButton( - name, - controller.LeftButton, - joystickHelper.permaBindLocalRoll(name, controller.Tilt[1]), - "Switch to local roll mode" - ) - - openspace.navigation.bindJoystickButton( - name, - controller.RightButton, - joystickHelper.permaBindGlobalRoll(name, controller.Tilt[1]), - "Switch to global roll mode" - ) end)