Showing the changes to interface/src/scripting/ControllerScriptingInterface.cpp (1 of 21 files). Show all
Unified · Split
| @@ -23,109 +23,6 @@ · 22 unmodified lines | |||
| 23 | // TODO: this needs to be removed, as well as any related controller-specific information | 23 | // TODO: this needs to be removed, as well as any related controller-specific information |
| 24 | #include <input-plugins/SixenseManager.h> | 24 | #include <input-plugins/SixenseManager.h> |
| 25 | 25 | ||
| 26 | ControllerScriptingInterface::ControllerScriptingInterface() : | ||
| 27 | _mouseCaptured(false), | ||
| 28 | _touchCaptured(false), | ||
| 29 | _wheelCaptured(false), | ||
| 30 | _actionsCaptured(false) | ||
| 31 | { | ||
| 32 | |||
| 33 | } | ||
| 34 | |||
| 35 | ControllerScriptingInterface::~ControllerScriptingInterface() { | ||
| 36 | } | ||
| 37 | |||
| 38 | |||
| 39 | static int actionMetaTypeId = qRegisterMetaType<UserInputMapper::Action>(); | ||
| 40 | static int inputChannelMetaTypeId = qRegisterMetaType<UserInputMapper::InputChannel>(); | ||
| 41 | static int inputMetaTypeId = qRegisterMetaType<UserInputMapper::Input>(); | ||
| 42 | static int inputPairMetaTypeId = qRegisterMetaType<UserInputMapper::InputPair>(); | ||
| 43 | |||
| 44 | QScriptValue inputToScriptValue(QScriptEngine* engine, const UserInputMapper::Input& input); | ||
| 45 | void inputFromScriptValue(const QScriptValue& object, UserInputMapper::Input& input); | ||
| 46 | QScriptValue inputChannelToScriptValue(QScriptEngine* engine, const UserInputMapper::InputChannel& inputChannel); | ||
| 47 | void inputChannelFromScriptValue(const QScriptValue& object, UserInputMapper::InputChannel& inputChannel); | ||
| 48 | QScriptValue actionToScriptValue(QScriptEngine* engine, const UserInputMapper::Action& action); | ||
| 49 | void actionFromScriptValue(const QScriptValue& object, UserInputMapper::Action& action); | ||
| 50 | QScriptValue inputPairToScriptValue(QScriptEngine* engine, const UserInputMapper::InputPair& inputPair); | ||
| 51 | void inputPairFromScriptValue(const QScriptValue& object, UserInputMapper::InputPair& inputPair); | ||
| 52 | |||
| 53 | QScriptValue inputToScriptValue(QScriptEngine* engine, const UserInputMapper::Input& input) { | ||
| 54 | QScriptValue obj = engine->newObject(); | ||
| 55 | obj.setProperty("device", input.getDevice()); | ||
| 56 | obj.setProperty("channel", input.getChannel()); | ||
| 57 | obj.setProperty("type", (unsigned short) input.getType()); | ||
| 58 | obj.setProperty("id", input.getID()); | ||
| 59 | return obj; | ||
| 60 | } | ||
| 61 | |||
| 62 | void inputFromScriptValue(const QScriptValue& object, UserInputMapper::Input& input) { | ||
| 63 | input.setDevice(object.property("device").toUInt16()); | ||
| 64 | input.setChannel(object.property("channel").toUInt16()); | ||
| 65 | input.setType(object.property("type").toUInt16()); | ||
| 66 | input.setID(object.property("id").toInt32()); | ||
| 67 | } | ||
| 68 | |||
| 69 | QScriptValue inputChannelToScriptValue(QScriptEngine* engine, const UserInputMapper::InputChannel& inputChannel) { | ||
| 70 | QScriptValue obj = engine->newObject(); | ||
| 71 | obj.setProperty("input", inputToScriptValue(engine, inputChannel.getInput())); | ||
| 72 | obj.setProperty("modifier", inputToScriptValue(engine, inputChannel.getModifier())); | ||
| 73 | obj.setProperty("action", inputChannel.getAction()); | ||
| 74 | obj.setProperty("scale", inputChannel.getScale()); | ||
| 75 | return obj; | ||
| 76 | } | ||
| 77 | |||
| 78 | void inputChannelFromScriptValue(const QScriptValue& object, UserInputMapper::InputChannel& inputChannel) { | ||
| 79 | UserInputMapper::Input input; | ||
| 80 | UserInputMapper::Input modifier; | ||
| 81 | inputFromScriptValue(object.property("input"), input); | ||
| 82 | inputChannel.setInput(input); | ||
| 83 | inputFromScriptValue(object.property("modifier"), modifier); | ||
| 84 | inputChannel.setModifier(modifier); | ||
| 85 | inputChannel.setAction(UserInputMapper::Action(object.property("action").toVariant().toInt())); | ||
| 86 | inputChannel.setScale(object.property("scale").toVariant().toFloat()); | ||
| 87 | } | ||
| 88 | |||
| 89 | QScriptValue actionToScriptValue(QScriptEngine* engine, const UserInputMapper::Action& action) { | ||
| 90 | QScriptValue obj = engine->newObject(); | ||
| 91 | auto userInputMapper = DependencyManager::get<UserInputMapper>(); | ||
| 92 | QVector<UserInputMapper::InputChannel> inputChannels = userInputMapper->getInputChannelsForAction(action); | ||
| 93 | QScriptValue _inputChannels = engine->newArray(inputChannels.size()); | ||
| 94 | for (int i = 0; i < inputChannels.size(); i++) { | ||
| 95 | _inputChannels.setProperty(i, inputChannelToScriptValue(engine, inputChannels[i])); | ||
| 96 | } | ||
| 97 | obj.setProperty("action", (int) action); | ||
| 98 | obj.setProperty("actionName", userInputMapper->getActionName(action)); | ||
| 99 | obj.setProperty("inputChannels", _inputChannels); | ||
| 100 | return obj; | ||
| 101 | } | ||
| 102 | |||
| 103 | void actionFromScriptValue(const QScriptValue& object, UserInputMapper::Action& action) { | ||
| 104 | action = UserInputMapper::Action(object.property("action").toVariant().toInt()); | ||
| 105 | } | ||
| 106 | |||
| 107 | QScriptValue inputPairToScriptValue(QScriptEngine* engine, const UserInputMapper::InputPair& inputPair) { | ||
| 108 | QScriptValue obj = engine->newObject(); | ||
| 109 | obj.setProperty("input", inputToScriptValue(engine, inputPair.first)); | ||
| 110 | obj.setProperty("inputName", inputPair.second); | ||
| 111 | return obj; | ||
| 112 | } | ||
| 113 | |||
| 114 | void inputPairFromScriptValue(const QScriptValue& object, UserInputMapper::InputPair& inputPair) { | ||
| 115 | inputFromScriptValue(object.property("input"), inputPair.first); | ||
| 116 | inputPair.second = QString(object.property("inputName").toVariant().toString()); | ||
| 117 | } | ||
| 118 | |||
| 119 | void ControllerScriptingInterface::registerControllerTypes(QScriptEngine* engine) { | ||
| 120 | qScriptRegisterSequenceMetaType<QVector<UserInputMapper::Action> >(engine); | ||
| 121 | qScriptRegisterSequenceMetaType<QVector<UserInputMapper::InputChannel> >(engine); | ||
| 122 | qScriptRegisterSequenceMetaType<QVector<UserInputMapper::InputPair> >(engine); | ||
| 123 | qScriptRegisterMetaType(engine, actionToScriptValue, actionFromScriptValue); | ||
| 124 | qScriptRegisterMetaType(engine, inputChannelToScriptValue, inputChannelFromScriptValue); | ||
| 125 | qScriptRegisterMetaType(engine, inputToScriptValue, inputFromScriptValue); | ||
| 126 | qScriptRegisterMetaType(engine, inputPairToScriptValue, inputPairFromScriptValue); | ||
| 127 | } | ||
| 128 | |||
| 129 | void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) { | 26 | void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) { |
| 130 | if (event->type() == HFActionEvent::startType()) { | 27 | if (event->type() == HFActionEvent::startType()) { |
| 131 | emit actionStartEvent(static_cast<HFActionEvent&>(*event)); | 28 | emit actionStartEvent(static_cast<HFActionEvent&>(*event)); |
| @@ -183,162 +80,6 @@ const PalmData* ControllerScriptingInterface::getActivePalm(int palmIndex) const · 51 unmodified lines | |||
| 183 | return NULL; | 80 | return NULL; |
| 184 | } | 81 | } |
| 185 | 82 | ||
| 186 | /* | ||
| 187 | bool ControllerScriptingInterface::isPrimaryButtonPressed() const { | ||
| 188 | const PalmData* primaryPalm = getPrimaryPalm(); | ||
| 189 | if (primaryPalm) { | ||
| 190 | if (primaryPalm->getControllerButtons() & BUTTON_FWD) { | ||
| 191 | return true; | ||
| 192 | } | ||
| 193 | } | ||
| 194 | |||
| 195 | return false; | ||
| 196 | } | ||
| 197 | |||
| 198 | glm::vec2 ControllerScriptingInterface::getPrimaryJoystickPosition() const { | ||
| 199 | const PalmData* primaryPalm = getPrimaryPalm(); | ||
| 200 | if (primaryPalm) { | ||
| 201 | return glm::vec2(primaryPalm->getJoystickX(), primaryPalm->getJoystickY()); | ||
| 202 | } | ||
| 203 | |||
| 204 | return glm::vec2(0); | ||
| 205 | } | ||
| 206 | |||
| 207 | int ControllerScriptingInterface::getNumberOfButtons() const { | ||
| 208 | return getNumberOfActivePalms() * NUMBER_OF_BUTTONS_PER_PALM; | ||
| 209 | } | ||
| 210 | |||
| 211 | bool ControllerScriptingInterface::isButtonPressed(int buttonIndex) const { | ||
| 212 | int palmIndex = buttonIndex / NUMBER_OF_BUTTONS_PER_PALM; | ||
| 213 | int buttonOnPalm = buttonIndex % NUMBER_OF_BUTTONS_PER_PALM; | ||
| 214 | const PalmData* palmData = getActivePalm(palmIndex); | ||
| 215 | if (palmData) { | ||
| 216 | switch (buttonOnPalm) { | ||
| 217 | case 0: | ||
| 218 | return palmData->getControllerButtons() & BUTTON_0; | ||
| 219 | case 1: | ||
| 220 | return palmData->getControllerButtons() & BUTTON_1; | ||
| 221 | case 2: | ||
| 222 | return palmData->getControllerButtons() & BUTTON_2; | ||
| 223 | case 3: | ||
| 224 | return palmData->getControllerButtons() & BUTTON_3; | ||
| 225 | case 4: | ||
| 226 | return palmData->getControllerButtons() & BUTTON_4; | ||
| 227 | case 5: | ||
| 228 | return palmData->getControllerButtons() & BUTTON_FWD; | ||
| 229 | } | ||
| 230 | } | ||
| 231 | return false; | ||
| 232 | } | ||
| 233 | |||
| 234 | int ControllerScriptingInterface::getNumberOfTriggers() const { | ||
| 235 | return getNumberOfActivePalms() * NUMBER_OF_TRIGGERS_PER_PALM; | ||
| 236 | } | ||
| 237 | |||
| 238 | float ControllerScriptingInterface::getTriggerValue(int triggerIndex) const { | ||
| 239 | // we know there's one trigger per palm, so the triggerIndex is the palm Index | ||
| 240 | int palmIndex = triggerIndex; | ||
| 241 | const PalmData* palmData = getActivePalm(palmIndex); | ||
| 242 | if (palmData) { | ||
| 243 | return palmData->getTrigger(); | ||
| 244 | } | ||
| 245 | return 0.0f; | ||
| 246 | } | ||
| 247 | |||
| 248 | int ControllerScriptingInterface::getNumberOfJoysticks() const { | ||
| 249 | return getNumberOfActivePalms() * NUMBER_OF_JOYSTICKS_PER_PALM; | ||
| 250 | } | ||
| 251 | |||
| 252 | glm::vec2 ControllerScriptingInterface::getJoystickPosition(int joystickIndex) const { | ||
| 253 | // we know there's one joystick per palm, so the joystickIndex is the palm Index | ||
| 254 | int palmIndex = joystickIndex; | ||
| 255 | const PalmData* palmData = getActivePalm(palmIndex); | ||
| 256 | if (palmData) { | ||
| 257 | return glm::vec2(palmData->getJoystickX(), palmData->getJoystickY()); | ||
| 258 | } | ||
| 259 | return glm::vec2(0); | ||
| 260 | } | ||
| 261 | |||
| 262 | int ControllerScriptingInterface::getNumberOfSpatialControls() const { | ||
| 263 | return getNumberOfActivePalms() * NUMBER_OF_SPATIALCONTROLS_PER_PALM; | ||
| 264 | } | ||
| 265 | |||
| 266 | glm::vec3 ControllerScriptingInterface::getSpatialControlPosition(int controlIndex) const { | ||
| 267 | int palmIndex = controlIndex / NUMBER_OF_SPATIALCONTROLS_PER_PALM; | ||
| 268 | int controlOfPalm = controlIndex % NUMBER_OF_SPATIALCONTROLS_PER_PALM; | ||
| 269 | const PalmData* palmData = getActivePalm(palmIndex); | ||
| 270 | if (palmData) { | ||
| 271 | switch (controlOfPalm) { | ||
| 272 | case PALM_SPATIALCONTROL: | ||
| 273 | return palmData->getPosition(); | ||
| 274 | case TIP_SPATIALCONTROL: | ||
| 275 | return palmData->getTipPosition(); | ||
| 276 | } | ||
| 277 | } | ||
| 278 | return glm::vec3(0); // bad index | ||
| 279 | } | ||
| 280 | |||
| 281 | glm::vec3 ControllerScriptingInterface::getSpatialControlVelocity(int controlIndex) const { | ||
| 282 | int palmIndex = controlIndex / NUMBER_OF_SPATIALCONTROLS_PER_PALM; | ||
| 283 | int controlOfPalm = controlIndex % NUMBER_OF_SPATIALCONTROLS_PER_PALM; | ||
| 284 | const PalmData* palmData = getActivePalm(palmIndex); | ||
| 285 | if (palmData) { | ||
| 286 | switch (controlOfPalm) { | ||
| 287 | case PALM_SPATIALCONTROL: | ||
| 288 | return palmData->getVelocity(); | ||
| 289 | case TIP_SPATIALCONTROL: | ||
| 290 | return palmData->getTipVelocity(); | ||
| 291 | } | ||
| 292 | } | ||
| 293 | return glm::vec3(0); // bad index | ||
| 294 | } | ||
| 295 | |||
| 296 | glm::quat ControllerScriptingInterface::getSpatialControlRawRotation(int controlIndex) const { | ||
| 297 | int palmIndex = controlIndex / NUMBER_OF_SPATIALCONTROLS_PER_PALM; | ||
| 298 | int controlOfPalm = controlIndex % NUMBER_OF_SPATIALCONTROLS_PER_PALM; | ||
| 299 | const PalmData* palmData = getActivePalm(palmIndex); | ||
| 300 | if (palmData) { | ||
| 301 | switch (controlOfPalm) { | ||
| 302 | case PALM_SPATIALCONTROL: | ||
| 303 | return palmData->getRawRotation(); | ||
| 304 | case TIP_SPATIALCONTROL: | ||
| 305 | return palmData->getRawRotation(); // currently the tip doesn't have a unique rotation, use the palm rotation | ||
| 306 | } | ||
| 307 | } | ||
| 308 | return glm::quat(); // bad index | ||
| 309 | } | ||
| 310 | |||
| 311 | glm::vec3 ControllerScriptingInterface::getSpatialControlRawAngularVelocity(int controlIndex) const { | ||
| 312 | int palmIndex = controlIndex / NUMBER_OF_SPATIALCONTROLS_PER_PALM; | ||
| 313 | int controlOfPalm = controlIndex % NUMBER_OF_SPATIALCONTROLS_PER_PALM; | ||
| 314 | const PalmData* palmData = getActivePalm(palmIndex); | ||
| 315 | if (palmData) { | ||
| 316 | switch (controlOfPalm) { | ||
| 317 | case PALM_SPATIALCONTROL: | ||
| 318 | return palmData->getRawAngularVelocity(); | ||
| 319 | case TIP_SPATIALCONTROL: | ||
| 320 | return palmData->getRawAngularVelocity(); // Tip = palm angular velocity | ||
| 321 | } | ||
| 322 | } | ||
| 323 | return glm::vec3(0); // bad index | ||
| 324 | } | ||
| 325 | |||
| 326 | glm::vec3 ControllerScriptingInterface::getSpatialControlNormal(int controlIndex) const { | ||
| 327 | int palmIndex = controlIndex / NUMBER_OF_SPATIALCONTROLS_PER_PALM; | ||
| 328 | int controlOfPalm = controlIndex % NUMBER_OF_SPATIALCONTROLS_PER_PALM; | ||
| 329 | const PalmData* palmData = getActivePalm(palmIndex); | ||
| 330 | if (palmData) { | ||
| 331 | switch (controlOfPalm) { | ||
| 332 | case PALM_SPATIALCONTROL: | ||
| 333 | return palmData->getNormal(); | ||
| 334 | case TIP_SPATIALCONTROL: | ||
| 335 | return palmData->getFingerDirection(); | ||
| 336 | } | ||
| 337 | } | ||
| 338 | return glm::vec3(0); // bad index | ||
| 339 | } | ||
| 340 | */ | ||
| 341 | |||
| 342 | bool ControllerScriptingInterface::isKeyCaptured(QKeyEvent* event) const { | 83 | bool ControllerScriptingInterface::isKeyCaptured(QKeyEvent* event) const { |
| 343 | return isKeyCaptured(KeyEvent(*event)); | 84 | return isKeyCaptured(KeyEvent(*event)); |
| 344 | } | 85 | } |
| @@ -448,62 +189,6 @@ void ControllerScriptingInterface::update() { · 103 unmodified lines | |||
| 448 | controller::ScriptingInterface::update(); | 189 | controller::ScriptingInterface::update(); |
| 449 | } | 190 | } |
| 450 | 191 | ||
| 451 | QVector<UserInputMapper::Action> ControllerScriptingInterface::getAllActions() { | ||
| 452 | return DependencyManager::get<UserInputMapper>()->getAllActions(); | ||
| 453 | } | ||
| 454 | |||
| 455 | QVector<UserInputMapper::InputChannel> ControllerScriptingInterface::getInputChannelsForAction(UserInputMapper::Action action) { | ||
| 456 | return DependencyManager::get<UserInputMapper>()->getInputChannelsForAction(action); | ||
| 457 | } | ||
| 458 | |||
| 459 | QString ControllerScriptingInterface::getDeviceName(unsigned int device) { | ||
| 460 | return DependencyManager::get<UserInputMapper>()->getDeviceName((unsigned short)device); | ||
| 461 | } | ||
| 462 | |||
| 463 | QVector<UserInputMapper::InputChannel> ControllerScriptingInterface::getAllInputsForDevice(unsigned int device) { | ||
| 464 | return DependencyManager::get<UserInputMapper>()->getAllInputsForDevice(device); | ||
| 465 | } | ||
| 466 | |||
| 467 | bool ControllerScriptingInterface::addInputChannel(UserInputMapper::InputChannel inputChannel) { | ||
| 468 | return DependencyManager::get<UserInputMapper>()->addInputChannel(inputChannel._action, inputChannel._input, inputChannel._modifier, inputChannel._scale); | ||
| 469 | } | ||
| 470 | |||
| 471 | bool ControllerScriptingInterface::removeInputChannel(UserInputMapper::InputChannel inputChannel) { | ||
| 472 | return DependencyManager::get<UserInputMapper>()->removeInputChannel(inputChannel); | ||
| 473 | } | ||
| 474 | |||
| 475 | QVector<UserInputMapper::InputPair> ControllerScriptingInterface::getAvailableInputs(unsigned int device) { | ||
| 476 | return DependencyManager::get<UserInputMapper>()->getAvailableInputs((unsigned short)device); | ||
| 477 | } | ||
| 478 | |||
| 479 | void ControllerScriptingInterface::resetAllDeviceBindings() { | ||
| 480 | DependencyManager::get<UserInputMapper>()->resetAllDeviceBindings(); | ||
| 481 | } | ||
| 482 | |||
| 483 | void ControllerScriptingInterface::resetDevice(unsigned int device) { | ||
| 484 | DependencyManager::get<UserInputMapper>()->resetDevice(device); | ||
| 485 | } | ||
| 486 | |||
| 487 | int ControllerScriptingInterface::findDevice(QString name) { | ||
| 488 | return DependencyManager::get<UserInputMapper>()->findDevice(name); | ||
| 489 | } | ||
| 490 | |||
| 491 | QVector<QString> ControllerScriptingInterface::getDeviceNames() { | ||
| 492 | return DependencyManager::get<UserInputMapper>()->getDeviceNames(); | ||
| 493 | } | ||
| 494 | |||
| 495 | float ControllerScriptingInterface::getActionValue(int action) { | ||
| 496 | return DependencyManager::get<UserInputMapper>()->getActionState(UserInputMapper::Action(action)); | ||
| 497 | } | ||
| 498 | |||
| 499 | int ControllerScriptingInterface::findAction(QString actionName) { | ||
| 500 | return DependencyManager::get<UserInputMapper>()->findAction(actionName); | ||
| 501 | } | ||
| 502 | |||
| 503 | QVector<QString> ControllerScriptingInterface::getActionNames() const { | ||
| 504 | return DependencyManager::get<UserInputMapper>()->getActionNames(); | ||
| 505 | } | ||
| 506 | |||
| 507 | InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) : | 192 | InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) : |
| 508 | _deviceTrackerId(deviceTrackerId), | 193 | _deviceTrackerId(deviceTrackerId), |
| 509 | _subTrackerId(subTrackerId), | 194 | _subTrackerId(subTrackerId), |