- Introduce the DeviceTracker class to abstract all the possible devices - Introduce the MotionTracker ( a DeviceTracker ) that contains a transform tree of joints - Add Leapmotion class as a MotionTracker and the support for the Leapmotion sdk in external - Add InputController as the abstraction of a MotionTracker/Joint for Javascript
Showing the changes to interface/src/scripting/ControllerScriptingInterface.cpp (1 of 33 files). Show all
Unified · Split
| @@ -13,6 +13,7 @@ · 12 unmodified lines | ||
| 13 | 13 | #include "Application.h" |
| 14 | 14 | #include "devices/SixenseManager.h" |
| 15 | 15 | #include "ControllerScriptingInterface.h" |
| 16 | +#include "devices/MotionTracker.h" | |
| 16 | 17 | |
| 17 | 18 | ControllerScriptingInterface::ControllerScriptingInterface() : |
| 18 | 19 | _mouseCaptured(false), |
| @@ -258,3 +259,73 @@ glm::vec2 ControllerScriptingInterface::getViewportDimensions() const { · 239 unmodified lines | ||
| 258 | 259 | QGLWidget* widget = Application::getInstance()->getGLWidget(); |
| 259 | 260 | return glm::vec2(widget->width(), widget->height()); |
| 260 | 261 | } |
| 262 | + | |
| 263 | +AbstractInputController* ControllerScriptingInterface::createInputController( const QString& category, const QString& tracker ) | |
| 264 | +{ | |
| 265 | + // 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() ) { | |
| 268 | + return (*icIt).second; | |
| 269 | + } else { | |
| 270 | + | |
| 271 | + // Look for matching category | |
| 272 | + int categoryID = 0; | |
| 273 | + MotionTracker* motionTracker = dynamic_cast< MotionTracker* > ( DeviceTracker::getDevice( categoryID ) ); | |
| 274 | + if ( motionTracker ) | |
| 275 | + { | |
| 276 | + int trackerID = motionTracker->findJointIndex( tracker.toStdString() ); | |
| 277 | + if ( trackerID > 0 ) | |
| 278 | + { | |
| 279 | + AbstractInputController* inputController = new InputController(categoryID,trackerID, this ); | |
| 280 | + | |
| 281 | + _inputControllers.insert( InputControllerMap::value_type( inputController->getKey(), inputController ) ); | |
| 282 | + | |
| 283 | + return inputController; | |
| 284 | + } | |
| 285 | + } | |
| 286 | + return 0; | |
| 287 | + } | |
| 288 | +} | |
| 289 | + | |
| 290 | +void ControllerScriptingInterface::updateInputControllers() | |
| 291 | +{ | |
| 292 | + for ( auto it = _inputControllers.begin(); it != _inputControllers.end(); it++ ) { | |
| 293 | + (*it).second->update(); | |
| 294 | + } | |
| 295 | + | |
| 296 | +} | |
| 297 | + | |
| 298 | + | |
| 299 | +InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) : | |
| 300 | + AbstractInputController(), | |
| 301 | + _deviceTrackerId( deviceTrackerId ), | |
| 302 | + _subTrackerId( subTrackerId ) | |
| 303 | +{ | |
| 304 | +} | |
| 305 | + | |
| 306 | +void InputController::update() | |
| 307 | +{ | |
| 308 | + _isActive = false; | |
| 309 | + | |
| 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 ); | |
| 314 | + | |
| 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 ); | |
| 320 | + | |
| 321 | + _isActive = true; | |
| 322 | + emit spatialEvent(_eventCache); | |
| 323 | + } | |
| 324 | + } | |
| 325 | + } | |
| 326 | +} | |
| 327 | + | |
| 328 | + | |
| 329 | +InputController::Key InputController::getKey() const { | |
| 330 | + return (_deviceTrackerId * 10000) + _subTrackerId; | |
| 331 | +} | |