Showing the changes to interface/src/ControllerScriptingInterface.cpp (1 of 3 files). Show all
Unified · Split
| @@ -23,6 +23,38 @@ const PalmData* ControllerScriptingInterface::getPrimaryPalm() const { · 22 unmodified lines | ||
| 23 | 23 | return NULL; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | +int ControllerScriptingInterface::getNumberOfActivePalms() const { | |
| 27 | + const HandData* handData = Application::getInstance()->getAvatar()->getHandData(); | |
| 28 | + int numberOfPalms = handData->getNumPalms(); | |
| 29 | + int numberOfActivePalms = 0; | |
| 30 | + for (int i = 0; i < numberOfPalms; i++) { | |
| 31 | + if (getPalm(i)->isActive()) { | |
| 32 | + numberOfActivePalms++; | |
| 33 | + } | |
| 34 | + } | |
| 35 | + return numberOfActivePalms; | |
| 36 | +} | |
| 37 | + | |
| 38 | +const PalmData* ControllerScriptingInterface::getPalm(int palmIndex) const { | |
| 39 | + const HandData* handData = Application::getInstance()->getAvatar()->getHandData(); | |
| 40 | + return &handData->getPalms()[palmIndex]; | |
| 41 | +} | |
| 42 | + | |
| 43 | +const PalmData* ControllerScriptingInterface::getActivePalm(int palmIndex) const { | |
| 44 | + const HandData* handData = Application::getInstance()->getAvatar()->getHandData(); | |
| 45 | + int numberOfPalms = handData->getNumPalms(); | |
| 46 | + int numberOfActivePalms = 0; | |
| 47 | + for (int i = 0; i < numberOfPalms; i++) { | |
| 48 | + if (getPalm(i)->isActive()) { | |
| 49 | + if (numberOfActivePalms == palmIndex) { | |
| 50 | + return &handData->getPalms()[i]; | |
| 51 | + } | |
| 52 | + numberOfActivePalms++; | |
| 53 | + } | |
| 54 | + } | |
| 55 | + return NULL; | |
| 56 | +} | |
| 57 | + | |
| 26 | 58 | bool ControllerScriptingInterface::isPrimaryButtonPressed() const { |
| 27 | 59 | const PalmData* primaryPalm = getPrimaryPalm(); |
| 28 | 60 | if (primaryPalm) { |
| @@ -43,3 +75,68 @@ glm::vec2 ControllerScriptingInterface::getPrimaryJoystickPosition() const { · 14 unmodified lines | ||
| 43 | 75 | return glm::vec2(0); |
| 44 | 76 | } |
| 45 | 77 | |
| 78 | +int ControllerScriptingInterface::getNumberOfButtons() const { | |
| 79 | + return getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM; | |
| 80 | +} | |
| 81 | + | |
| 82 | +bool ControllerScriptingInterface::isButtonPressed(int buttonIndex) const { | |
| 83 | + int palmIndex = buttonIndex / NUMBER_OF_BUTTONS_PER_PALM; | |
| 84 | + int buttonOnPalm = buttonIndex % NUMBER_OF_BUTTONS_PER_PALM; | |
| 85 | + const PalmData* palmData = getActivePalm(palmIndex); | |
| 86 | + if (palmData) { | |
| 87 | + switch (buttonOnPalm) { | |
| 88 | + case 0: | |
| 89 | + return palmData->getControllerButtons() & BUTTON_0; | |
| 90 | + case 1: | |
| 91 | + return palmData->getControllerButtons() & BUTTON_1; | |
| 92 | + case 2: | |
| 93 | + return palmData->getControllerButtons() & BUTTON_2; | |
| 94 | + case 3: | |
| 95 | + return palmData->getControllerButtons() & BUTTON_3; | |
| 96 | + case 4: | |
| 97 | + return palmData->getControllerButtons() & BUTTON_4; | |
| 98 | + case 5: | |
| 99 | + return palmData->getControllerButtons() & BUTTON_FWD; | |
| 100 | + } | |
| 101 | + } | |
| 102 | + return false; | |
| 103 | +} | |
| 104 | + | |
| 105 | +int ControllerScriptingInterface::getNumberOfTriggers() const { | |
| 106 | + return getNumberOfActivePalms() * NUMBER_OF_TRIGGERS_PER_PALM; | |
| 107 | +} | |
| 108 | + | |
| 109 | +float ControllerScriptingInterface::getTriggerValue(int triggerIndex) const { | |
| 110 | + // we know there's one trigger per palm, so the triggerIndex is the palm Index | |
| 111 | + int palmIndex = triggerIndex; | |
| 112 | + const PalmData* palmData = getActivePalm(palmIndex); | |
| 113 | + if (palmData) { | |
| 114 | + return palmData->getTrigger(); | |
| 115 | + } | |
| 116 | + return 0.0f; | |
| 117 | +} | |
| 118 | + | |
| 119 | +int ControllerScriptingInterface::getNumberOfJoysticks() const { | |
| 120 | + return getNumberOfActivePalms() * NUMBER_OF_JOYSTICKS_PER_PALM; | |
| 121 | +} | |
| 122 | + | |
| 123 | +glm::vec2 ControllerScriptingInterface::getJoystickPosition(int joystickIndex) const { | |
| 124 | + // we know there's one joystick per palm, so the joystickIndex is the palm Index | |
| 125 | + int palmIndex = joystickIndex; | |
| 126 | + const PalmData* palmData = getActivePalm(palmIndex); | |
| 127 | + if (palmData) { | |
| 128 | + return glm::vec2(palmData->getJoystickX(), palmData->getJoystickY()); | |
| 129 | + } | |
| 130 | + return glm::vec2(0); | |
| 131 | +} | |
| 132 | + | |
| 133 | +int ControllerScriptingInterface::getNumberOfSpatialControls() const { | |
| 134 | + return getNumberOfActivePalms() * NUMBER_OF_SPATIALCONTROLS_PER_PALM; | |
| 135 | +} | |
| 136 | + | |
| 137 | +glm::vec3 ControllerScriptingInterface::getSpatialControlPosition(int controlIndex) const { | |
| 138 | + return glm::vec3(0); // not yet implemented | |
| 139 | +} | |
| 140 | + | |
| 141 | + | |
| 142 | + | |