Showing the changes to interface/src/scripting/ControllerScriptingInterface.cpp (1 of 12 files). Show all
Unified · Split
| @@ -17,7 +17,6 @@ · 16 unmodified lines | |||
| 17 | #include <plugins/PluginManager.h> | 17 | #include <plugins/PluginManager.h> |
| 18 | 18 | ||
| 19 | #include "Application.h" | 19 | #include "Application.h" |
| 20 | #include <trackers/MotionTracker.h> | ||
| 21 | 20 | ||
| 22 | void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) { | 21 | void ControllerScriptingInterface::handleMetaEvent(HFMetaEvent* event) { |
| 23 | if (event->type() == HFActionEvent::startType()) { | 22 | if (event->type() == HFActionEvent::startType()) { |
| @@ -97,86 +96,6 @@ QVariant ControllerScriptingInterface::getRecommendedOverlayRect() const { · 73 unmodified lines | |||
| 97 | return qRectToVariant(rect); | 96 | return qRectToVariant(rect); |
| 98 | } | 97 | } |
| 99 | 98 | ||
| 100 | controller::InputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) { | ||
| 101 | // This is where we retrieve the Device Tracker category and then the sub tracker within it | ||
| 102 | auto icIt = _inputControllers.find(0); | ||
| 103 | if (icIt != _inputControllers.end()) { | ||
| 104 | return (*icIt).second.get(); | ||
| 105 | } | ||
| 106 | |||
| 107 | // Look for device | ||
| 108 | DeviceTracker::ID deviceID = DeviceTracker::getDeviceID(deviceName.toStdString()); | ||
| 109 | if (deviceID < 0) { | ||
| 110 | deviceID = 0; | ||
| 111 | } | ||
| 112 | // TODO in this current implementation, we just pick the device assuming there is one (normally the Leapmotion) | ||
| 113 | // in the near future we need to change that to a real mapping between the devices and the deviceName | ||
| 114 | // ALso we need to expand the spec so we can fall back on the "default" controller per categories | ||
| 115 | |||
| 116 | if (deviceID >= 0) { | ||
| 117 | // TODO here again the assumption it's the LeapMotion and so it's a MOtionTracker, this would need to be changed to support different types of devices | ||
| 118 | MotionTracker* motionTracker = dynamic_cast< MotionTracker* > (DeviceTracker::getDevice(deviceID)); | ||
| 119 | if (motionTracker) { | ||
| 120 | MotionTracker::Index trackerID = motionTracker->findJointIndex(tracker.toStdString()); | ||
| 121 | if (trackerID >= 0) { | ||
| 122 | controller::InputController::Pointer inputController = std::make_shared<InputController>(deviceID, trackerID, this); | ||
| 123 | controller::InputController::Key key = inputController->getKey(); | ||
| 124 | _inputControllers.insert(InputControllerMap::value_type(key, inputController)); | ||
| 125 | return inputController.get(); | ||
| 126 | } | ||
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | return nullptr; | ||
| 131 | } | ||
| 132 | |||
| 133 | void ControllerScriptingInterface::releaseInputController(controller::InputController* input) { | ||
| 134 | _inputControllers.erase(input->getKey()); | ||
| 135 | } | ||
| 136 | |||
| 137 | void ControllerScriptingInterface::updateInputControllers() { | ||
| 138 | for (auto it = _inputControllers.begin(); it != _inputControllers.end(); it++) { | ||
| 139 | (*it).second->update(); | ||
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) : | ||
| 144 | _deviceTrackerId(deviceTrackerId), | ||
| 145 | _subTrackerId(subTrackerId), | ||
| 146 | _isActive(false) | ||
| 147 | { | ||
| 148 | } | ||
| 149 | |||
| 150 | void InputController::update() { | ||
| 151 | _isActive = false; | ||
| 152 | |||
| 153 | // TODO for now the InputController is only supporting a JointTracker from a MotionTracker | ||
| 154 | MotionTracker* motionTracker = dynamic_cast< MotionTracker*> (DeviceTracker::getDevice(_deviceTrackerId)); | ||
| 155 | if (motionTracker) { | ||
| 156 | if ((int)_subTrackerId < motionTracker->numJointTrackers()) { | ||
| 157 | const MotionTracker::JointTracker* joint = motionTracker->getJointTracker(_subTrackerId); | ||
| 158 | |||
| 159 | if (joint->isActive()) { | ||
| 160 | joint->getAbsFrame().getTranslation(_eventCache.absTranslation); | ||
| 161 | joint->getAbsFrame().getRotation(_eventCache.absRotation); | ||
| 162 | joint->getLocFrame().getTranslation(_eventCache.locTranslation); | ||
| 163 | joint->getLocFrame().getRotation(_eventCache.locRotation); | ||
| 164 | |||
| 165 | _isActive = true; | ||
| 166 | //emit spatialEvent(_eventCache); | ||
| 167 | } | ||
| 168 | } | ||
| 169 | } | ||
| 170 | } | ||
| 171 | |||
| 172 | const unsigned int INPUTCONTROLLER_KEY_DEVICE_OFFSET = 16; | ||
| 173 | const unsigned int INPUTCONTROLLER_KEY_DEVICE_MASK = 16; | ||
| 174 | |||
| 175 | InputController::Key InputController::getKey() const { | ||
| 176 | return (((_deviceTrackerId & INPUTCONTROLLER_KEY_DEVICE_MASK) << INPUTCONTROLLER_KEY_DEVICE_OFFSET) | _subTrackerId); | ||
| 177 | } | ||
| 178 | |||
| 179 | |||
| 180 | void ControllerScriptingInterface::emitKeyPressEvent(QKeyEvent* event) { emit keyPressEvent(KeyEvent(*event)); } | 99 | void ControllerScriptingInterface::emitKeyPressEvent(QKeyEvent* event) { emit keyPressEvent(KeyEvent(*event)); } |
| 181 | void ControllerScriptingInterface::emitKeyReleaseEvent(QKeyEvent* event) { emit keyReleaseEvent(KeyEvent(*event)); } | 100 | void ControllerScriptingInterface::emitKeyReleaseEvent(QKeyEvent* event) { emit keyReleaseEvent(KeyEvent(*event)); } |
| 182 | 101 | ||