Showing the changes to interface/src/scripting/ControllerScriptingInterface.cpp (1 of 3 files). Show all
Unified · Split
| @@ -88,10 +88,24 @@ glm::vec2 ControllerScriptingInterface::getPrimaryJoystickPosition() const { · 87 unmodified lines | |||
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | int ControllerScriptingInterface::getNumberOfButtons() const { | 90 | int ControllerScriptingInterface::getNumberOfButtons() const { |
| 91 | return getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM; | 91 | int buttonCount = 0; |
| 92 | foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) { | ||
| 93 | buttonCount += state.buttons.size(); | ||
| 94 | } | ||
| 95 | return buttonCount + getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM; | ||
| 92 | } | 96 | } |
| 93 | 97 | ||
| 94 | bool ControllerScriptingInterface::isButtonPressed(int buttonIndex) const { | 98 | bool ControllerScriptingInterface::isButtonPressed(int buttonIndex) const { |
| 99 | int managedButtonIndex = buttonIndex - getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM; | ||
| 100 | if (managedButtonIndex >= 0) { | ||
| 101 | foreach (const JoystickState& state, Application::getInstance()->getJoystickManager()->getJoystickStates()) { | ||
| 102 | if (managedButtonIndex < state.buttons.size()) { | ||
| 103 | return state.buttons.at(managedButtonIndex); | ||
| 104 | } | ||
| 105 | managedButtonIndex -= state.buttons.size(); | ||
| 106 | } | ||
| 107 | return false; | ||
| 108 | } | ||
| 95 | int palmIndex = buttonIndex / NUMBER_OF_BUTTONS_PER_PALM; | 109 | int palmIndex = buttonIndex / NUMBER_OF_BUTTONS_PER_PALM; |
| 96 | int buttonOnPalm = buttonIndex % NUMBER_OF_BUTTONS_PER_PALM; | 110 | int buttonOnPalm = buttonIndex % NUMBER_OF_BUTTONS_PER_PALM; |
| 97 | const PalmData* palmData = getActivePalm(palmIndex); | 111 | const PalmData* palmData = getActivePalm(palmIndex); |
| @@ -129,11 +143,18 @@ float ControllerScriptingInterface::getTriggerValue(int triggerIndex) const { · 31 unmodified lines | |||
| 129 | } | 143 | } |
| 130 | 144 | ||
| 131 | int ControllerScriptingInterface::getNumberOfJoysticks() const { | 145 | int ControllerScriptingInterface::getNumberOfJoysticks() const { |
| 132 | return getNumberOfActivePalms() * NUMBER_OF_JOYSTICKS_PER_PALM; | 146 | return getNumberOfActivePalms() * NUMBER_OF_JOYSTICKS_PER_PALM + |
| 147 | Application::getInstance()->getJoystickManager()->getJoystickStates().size(); | ||
| 133 | } | 148 | } |
| 134 | 149 | ||
| 135 | glm::vec2 ControllerScriptingInterface::getJoystickPosition(int joystickIndex) const { | 150 | glm::vec2 ControllerScriptingInterface::getJoystickPosition(int joystickIndex) const { |
| 136 | // we know there's one joystick per palm, so the joystickIndex is the palm Index | 151 | // we know there's one joystick per palm, so the joystickIndex is the palm Index |
| 152 | int managedJoystickIndex = joystickIndex - getNumberOfActivePalms(); | ||
| 153 | if (managedJoystickIndex >= 0) { | ||
| 154 | const JoystickState& state = Application::getInstance()->getJoystickManager()->getJoystickStates().at( | ||
| 155 | managedJoystickIndex); | ||
| 156 | return glm::vec2(state.axes.size() > 0 ? state.axes.at(0) : 0.0f, state.axes.size() > 1 ? state.axes.at(1) : 0.0f); | ||
| 157 | } | ||
| 137 | int palmIndex = joystickIndex; | 158 | int palmIndex = joystickIndex; |
| 138 | const PalmData* palmData = getActivePalm(palmIndex); | 159 | const PalmData* palmData = getActivePalm(palmIndex); |
| 139 | if (palmData) { | 160 | if (palmData) { |