- lots of cleaning of the syntax to respect the coding standard - Fixed the device tracker singleton for clean destruction - introduced the Factory for the Leapmotion itstead of a naked constructor
Showing the changes to interface/src/scripting/ControllerScriptingInterface.cpp (1 of 10 files). Show all
Unified · Split
| @@ -260,63 +260,69 @@ glm::vec2 ControllerScriptingInterface::getViewportDimensions() const { · 259 unmodified lines | |||
| 260 | return glm::vec2(widget->width(), widget->height()); | 260 | return glm::vec2(widget->width(), widget->height()); |
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | AbstractInputController* ControllerScriptingInterface::createInputController( const QString& category, const QString& tracker ) | 263 | AbstractInputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) { |
| 264 | { | ||
| 265 | // This is where we retreive the Device Tracker category and then the sub tracker within it | 264 | // This is where we retreive the Device Tracker category and then the sub tracker within it |
| 266 | auto icIt = _inputControllers.find( 0 ); | 265 | auto icIt = _inputControllers.find(0); |
| 267 | if ( icIt != _inputControllers.end() ) { | 266 | if (icIt != _inputControllers.end()) { |
| 268 | return (*icIt).second; | 267 | return (*icIt).second; |
| 269 | } else { | 268 | } else { |
| 270 | 269 | ||
| 271 | // Look for matching category | 270 | // Look for device |
| 272 | // TODO in this current implementation, we just pick the first device assuming there is one ( normally the LeapMotion) | 271 | DeviceTracker::ID deviceID = DeviceTracker::getDeviceID(deviceName.toStdString()); |
| 273 | // in the near future we need to change that to a real mapping between the device names and the cateory | 272 | if (deviceID < 0) { |
| 274 | int categoryID = 0; | 273 | deviceID = 0; |
| 275 | MotionTracker* motionTracker = dynamic_cast< MotionTracker* > ( DeviceTracker::getDevice( categoryID ) ); | 274 | } |
| 276 | if ( motionTracker ) { | 275 | // TODO in this current implementation, we just pick the device assuming there is one (normally the Leapmotion) |
| 277 | int trackerID = motionTracker->findJointIndex( tracker.toStdString() ); | 276 | // in the near future we need to change that to a real mapping between the devices and the deviceName |
| 278 | if ( trackerID > 0 ) { | 277 | // ALso we need to expand the spec so we can fall back on the "default" controller per categories |
| 279 | AbstractInputController* inputController = new InputController(categoryID,trackerID, this ); | 278 | |
| 280 | 279 | if (deviceID >= 0) { | |
| 281 | _inputControllers.insert( InputControllerMap::value_type( inputController->getKey(), inputController ) ); | 280 | // 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 |
| 282 | 281 | MotionTracker* motionTracker = dynamic_cast< MotionTracker* > (DeviceTracker::getDevice(deviceID)); | |
| 283 | return inputController; | 282 | if (motionTracker) { |
| 283 | MotionTracker::Index trackerID = motionTracker->findJointIndex(tracker.toStdString()); | ||
| 284 | if (trackerID > 0) { | ||
| 285 | AbstractInputController* inputController = new InputController(deviceID, trackerID, this); | ||
| 286 | |||
| 287 | _inputControllers.insert(InputControllerMap::value_type(inputController->getKey(), inputController)); | ||
| 288 | |||
| 289 | return inputController; | ||
| 290 | } | ||
| 284 | } | 291 | } |
| 285 | } | 292 | } |
| 293 | |||
| 286 | return 0; | 294 | return 0; |
| 287 | } | 295 | } |
| 288 | } | 296 | } |
| 289 | 297 | ||
| 290 | void ControllerScriptingInterface::updateInputControllers() | 298 | void ControllerScriptingInterface::updateInputControllers() { |
| 291 | { | 299 | for (auto it = _inputControllers.begin(); it != _inputControllers.end(); it++) { |
| 292 | for ( auto it = _inputControllers.begin(); it != _inputControllers.end(); it++ ) { | ||
| 293 | (*it).second->update(); | 300 | (*it).second->update(); |
| 294 | } | 301 | } |
| 295 | |||
| 296 | } | 302 | } |
| 297 | 303 | ||
| 298 | 304 | ||
| 299 | InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) : | 305 | InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) : |
| 300 | AbstractInputController(), | 306 | AbstractInputController(), |
| 301 | _deviceTrackerId( deviceTrackerId ), | 307 | _deviceTrackerId(deviceTrackerId), |
| 302 | _subTrackerId( subTrackerId ) | 308 | _subTrackerId(subTrackerId) |
| 303 | { | 309 | { |
| 304 | } | 310 | } |
| 305 | 311 | ||
| 306 | void InputController::update() | 312 | void InputController::update() { |
| 307 | { | ||
| 308 | _isActive = false; | 313 | _isActive = false; |
| 309 | 314 | ||
| 310 | MotionTracker* motionTracker = dynamic_cast< MotionTracker*> ( DeviceTracker::getDevice( _deviceTrackerId ) ); | 315 | // TODO for now the InputController is only supporting a JointTracker from a MotionTracker |
| 311 | if ( motionTracker ) { | 316 | MotionTracker* motionTracker = dynamic_cast< MotionTracker*> (DeviceTracker::getDevice(_deviceTrackerId)); |
| 312 | if ( _subTrackerId < motionTracker->numJointTrackers() ) { | 317 | if (motionTracker) { |
| 313 | const MotionTracker::JointTracker* joint = motionTracker->getJointTracker( _subTrackerId ); | 318 | if (_subTrackerId < motionTracker->numJointTrackers()) { |
| 319 | const MotionTracker::JointTracker* joint = motionTracker->getJointTracker(_subTrackerId); | ||
| 314 | 320 | ||
| 315 | if ( joint->isActive() ) { | 321 | if (joint->isActive()) { |
| 316 | joint->getAbsFrame().getTranslation( _eventCache.absTranslation ); | 322 | joint->getAbsFrame().getTranslation(_eventCache.absTranslation); |
| 317 | joint->getAbsFrame().getRotation( _eventCache.absRotation ); | 323 | joint->getAbsFrame().getRotation(_eventCache.absRotation); |
| 318 | joint->getLocFrame().getTranslation( _eventCache.locTranslation ); | 324 | joint->getLocFrame().getTranslation(_eventCache.locTranslation); |
| 319 | joint->getLocFrame().getRotation( _eventCache.locRotation ); | 325 | joint->getLocFrame().getRotation(_eventCache.locRotation); |
| 320 | 326 | ||
| 321 | _isActive = true; | 327 | _isActive = true; |
| 322 | emit spatialEvent(_eventCache); | 328 | emit spatialEvent(_eventCache); |
| @@ -325,7 +331,9 @@ void InputController::update() · 2 unmodified lines | |||
| 325 | } | 331 | } |
| 326 | } | 332 | } |
| 327 | 333 | ||
| 334 | const unsigned int INPUTCONTROLLER_KEY_DEVICE_OFFSET = 16; | ||
| 335 | const unsigned int INPUTCONTROLLER_KEY_DEVICE_MASK = 16; | ||
| 328 | 336 | ||
| 329 | InputController::Key InputController::getKey() const { | 337 | InputController::Key InputController::getKey() const { |
| 330 | return (_deviceTrackerId * 10000) + _subTrackerId; | 338 | return (((_deviceTrackerId & INPUTCONTROLLER_KEY_DEVICE_MASK) << INPUTCONTROLLER_KEY_DEVICE_OFFSET) | _subTrackerId); |
| 331 | } | 339 | } |