- 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 | 260 | return glm::vec2(widget->width(), widget->height()); |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | −AbstractInputController* ControllerScriptingInterface::createInputController( const QString& category, const QString& tracker ) | |
| 264 | −{ | |
| 263 | +AbstractInputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) { | |
| 265 | 264 | // This is where we retreive the Device Tracker category and then the sub tracker within it |
| 266 | − auto icIt = _inputControllers.find( 0 ); | |
| 267 | − if ( icIt != _inputControllers.end() ) { | |
| 265 | + auto icIt = _inputControllers.find(0); | |
| 266 | + if (icIt != _inputControllers.end()) { | |
| 268 | 267 | return (*icIt).second; |
| 269 | 268 | } else { |
| 270 | 269 | |
| 271 | − // Look for matching category | |
| 272 | − // TODO in this current implementation, we just pick the first device assuming there is one ( normally the LeapMotion) | |
| 273 | − // in the near future we need to change that to a real mapping between the device names and the cateory | |
| 274 | − int categoryID = 0; | |
| 275 | − MotionTracker* motionTracker = dynamic_cast< MotionTracker* > ( DeviceTracker::getDevice( categoryID ) ); | |
| 276 | − if ( motionTracker ) { | |
| 277 | − int trackerID = motionTracker->findJointIndex( tracker.toStdString() ); | |
| 278 | − if ( trackerID > 0 ) { | |
| 279 | − AbstractInputController* inputController = new InputController(categoryID,trackerID, this ); | |
| 280 | − | |
| 281 | − _inputControllers.insert( InputControllerMap::value_type( inputController->getKey(), inputController ) ); | |
| 282 | − | |
| 283 | − return inputController; | |
| 270 | + // Look for device | |
| 271 | + DeviceTracker::ID deviceID = DeviceTracker::getDeviceID(deviceName.toStdString()); | |
| 272 | + if (deviceID < 0) { | |
| 273 | + deviceID = 0; | |
| 274 | + } | |
| 275 | + // TODO in this current implementation, we just pick the device assuming there is one (normally the Leapmotion) | |
| 276 | + // in the near future we need to change that to a real mapping between the devices and the deviceName | |
| 277 | + // ALso we need to expand the spec so we can fall back on the "default" controller per categories | |
| 278 | + | |
| 279 | + if (deviceID >= 0) { | |
| 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 | |
| 281 | + MotionTracker* motionTracker = dynamic_cast< MotionTracker* > (DeviceTracker::getDevice(deviceID)); | |
| 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 | 294 | return 0; |
| 287 | 295 | } |
| 288 | 296 | } |
| 289 | 297 | |
| 290 | −void ControllerScriptingInterface::updateInputControllers() | |
| 291 | −{ | |
| 292 | − for ( auto it = _inputControllers.begin(); it != _inputControllers.end(); it++ ) { | |
| 298 | +void ControllerScriptingInterface::updateInputControllers() { | |
| 299 | + for (auto it = _inputControllers.begin(); it != _inputControllers.end(); it++) { | |
| 293 | 300 | (*it).second->update(); |
| 294 | 301 | } |
| 295 | − | |
| 296 | 302 | } |
| 297 | 303 | |
| 298 | 304 | |
| 299 | 305 | InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) : |
| 300 | 306 | AbstractInputController(), |
| 301 | − _deviceTrackerId( deviceTrackerId ), | |
| 302 | − _subTrackerId( subTrackerId ) | |
| 307 | + _deviceTrackerId(deviceTrackerId), | |
| 308 | + _subTrackerId(subTrackerId) | |
| 303 | 309 | { |
| 304 | 310 | } |
| 305 | 311 | |
| 306 | −void InputController::update() | |
| 307 | −{ | |
| 312 | +void InputController::update() { | |
| 308 | 313 | _isActive = false; |
| 309 | 314 | |
| 310 | − MotionTracker* motionTracker = dynamic_cast< MotionTracker*> ( DeviceTracker::getDevice( _deviceTrackerId ) ); | |
| 311 | − if ( motionTracker ) { | |
| 312 | − if ( _subTrackerId < motionTracker->numJointTrackers() ) { | |
| 313 | − const MotionTracker::JointTracker* joint = motionTracker->getJointTracker( _subTrackerId ); | |
| 315 | + // TODO for now the InputController is only supporting a JointTracker from a MotionTracker | |
| 316 | + MotionTracker* motionTracker = dynamic_cast< MotionTracker*> (DeviceTracker::getDevice(_deviceTrackerId)); | |
| 317 | + if (motionTracker) { | |
| 318 | + if (_subTrackerId < motionTracker->numJointTrackers()) { | |
| 319 | + const MotionTracker::JointTracker* joint = motionTracker->getJointTracker(_subTrackerId); | |
| 314 | 320 | |
| 315 | − if ( joint->isActive() ) { | |
| 316 | − joint->getAbsFrame().getTranslation( _eventCache.absTranslation ); | |
| 317 | − joint->getAbsFrame().getRotation( _eventCache.absRotation ); | |
| 318 | − joint->getLocFrame().getTranslation( _eventCache.locTranslation ); | |
| 319 | − joint->getLocFrame().getRotation( _eventCache.locRotation ); | |
| 321 | + if (joint->isActive()) { | |
| 322 | + joint->getAbsFrame().getTranslation(_eventCache.absTranslation); | |
| 323 | + joint->getAbsFrame().getRotation(_eventCache.absRotation); | |
| 324 | + joint->getLocFrame().getTranslation(_eventCache.locTranslation); | |
| 325 | + joint->getLocFrame().getRotation(_eventCache.locRotation); | |
| 320 | 326 | |
| 321 | 327 | _isActive = true; |
| 322 | 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 | 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 | } |