History

fixes after first review

- 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

samcake committed 12 years ago

Commit c6e308b1 parent d6104e510 files · +344 −636Browse files

Showing the changes to interface/src/scripting/ControllerScriptingInterface.cpp (1 of 10 files). Show all

Unified · Split

interface/src/scripting/ControllerScriptingInterface.cpp+43−35
@@ -260,63 +260,69 @@ glm::vec2 ControllerScriptingInterface::getViewportDimensions() const { · 259 unmodified lines
260260 return glm::vec2(widget->width(), widget->height());
261261 }
262262
263−AbstractInputController* ControllerScriptingInterface::createInputController( const QString& category, const QString& tracker )
264−{
263+AbstractInputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) {
265264 // 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()) {
268267 return (*icIt).second;
269268 } else {
270269
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+ }
284291 }
285292 }
293+
286294 return 0;
287295 }
288296 }
289297
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++) {
293300 (*it).second->update();
294301 }
295−
296302 }
297303
298304
299305 InputController::InputController(int deviceTrackerId, int subTrackerId, QObject* parent) :
300306 AbstractInputController(),
301− _deviceTrackerId( deviceTrackerId ),
302− _subTrackerId( subTrackerId )
307+ _deviceTrackerId(deviceTrackerId),
308+ _subTrackerId(subTrackerId)
303309 {
304310 }
305311
306−void InputController::update()
307−{
312+void InputController::update() {
308313 _isActive = false;
309314
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);
314320
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);
320326
321327 _isActive = true;
322328 emit spatialEvent(_eventCache);
@@ -325,7 +331,9 @@ void InputController::update() · 2 unmodified lines
325331 }
326332 }
327333
334+const unsigned int INPUTCONTROLLER_KEY_DEVICE_OFFSET = 16;
335+const unsigned int INPUTCONTROLLER_KEY_DEVICE_MASK = 16;
328336
329337 InputController::Key InputController::getKey() const {
330− return (_deviceTrackerId * 10000) + _subTrackerId;
338+ return (((_deviceTrackerId & INPUTCONTROLLER_KEY_DEVICE_MASK) << INPUTCONTROLLER_KEY_DEVICE_OFFSET) | _subTrackerId);
331339 }