History

First cut at adding external joysticks to the mix.

Andrzej Kapolka committed 12 years ago

Commit a5444891 parent 946e2b53 files · +24 −3Browse files

Showing the changes to interface/src/scripting/ControllerScriptingInterface.cpp (1 of 3 files). Show all

Unified · Split

interface/src/scripting/ControllerScriptingInterface.cpp+23−2
@@ -88,10 +88,24 @@ glm::vec2 ControllerScriptingInterface::getPrimaryJoystickPosition() const { · 87 unmodified lines
8888 }
8989
9090 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;
9296 }
9397
9498 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+ }
95109 int palmIndex = buttonIndex / NUMBER_OF_BUTTONS_PER_PALM;
96110 int buttonOnPalm = buttonIndex % NUMBER_OF_BUTTONS_PER_PALM;
97111 const PalmData* palmData = getActivePalm(palmIndex);
@@ -129,11 +143,18 @@ float ControllerScriptingInterface::getTriggerValue(int triggerIndex) const { · 31 unmodified lines
129143 }
130144
131145 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();
133148 }
134149
135150 glm::vec2 ControllerScriptingInterface::getJoystickPosition(int joystickIndex) const {
136151 // 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+ }
137158 int palmIndex = joystickIndex;
138159 const PalmData* palmData = getActivePalm(palmIndex);
139160 if (palmData) {