leapMotionManager.cc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _LEAPMOTIONMANAGER_H_
  23. #include "input/leapMotion/leapMotionManager.h"
  24. #endif
  25. #ifndef _PLATFORM_MEMORY_H_
  26. #include "platform/platformMemory.h"
  27. #endif
  28. #ifndef _CONSOLETYPES_H_
  29. #include "console/consoleTypes.h"
  30. #endif
  31. #ifndef _EVENT_H_
  32. #include "platform/event.h"
  33. #endif
  34. #ifndef _GAMEINTERFACE_H_
  35. #include "game/gameInterface.h"
  36. #endif
  37. #ifndef _GUICANVAS_H_
  38. #include "gui/guiCanvas.h"
  39. #endif
  40. #ifndef _LEAPMOTIONUTIL_H_
  41. #include "leapMotionUtil.h"
  42. #endif
  43. #ifndef _VECTOR2_H_
  44. #include "2d/core/Vector2.h"
  45. #endif
  46. #include "input/leapMotion/LeapMotionManager_ScriptBinding.h"
  47. //-----------------------------------------------------------------------------
  48. bool LeapMotionManager::smEnableDevice = true;
  49. bool LeapMotionManager::smGenerateIndividualEvents = true;
  50. bool LeapMotionManager::smKeepHandIndexPersistent = false;
  51. bool LeapMotionManager::smKeepPointableIndexPersistent = false;
  52. bool LeapMotionManager::smGenerateSingleHandRotationAsAxisEvents = false;
  53. F32 LeapMotionManager::smMaximumHandAxisAngle = 25.0f;
  54. bool LeapMotionManager::smGenerateWholeFrameEvents = false;
  55. U32 LeapMotionManager::LM_FRAMEVALIDDATA = 0;
  56. U32 LeapMotionManager::LM_HAND[LeapMotionConstants::MaxHands] = {0};
  57. //U32 LeapMotionManager::LM_HANDROT[LeapMotionConstants::MaxHands] = {0};
  58. U32 LeapMotionManager::LM_HANDAXISX = 0;
  59. U32 LeapMotionManager::LM_HANDAXISY = 0;
  60. U32 LeapMotionManager::LM_HANDPOINTABLE[LeapMotionConstants::MaxHands][LeapMotionConstants::MaxPointablesPerHand] = {0};
  61. U32 LeapMotionManager::LM_HANDPOINTABLEROT[LeapMotionConstants::MaxHands][LeapMotionConstants::MaxPointablesPerHand] = {0};
  62. U32 LeapMotionManager::LM_FRAME = 0;
  63. //-----------------------------------------------------------------------------
  64. LeapMotionManager::LeapMotionManager()
  65. {
  66. // Initialize the console variables
  67. staticInit();
  68. // Create our controller and listener
  69. mListener = new MotionListener();
  70. mController = new Leap::Controller();
  71. mController->addListener(*mListener);
  72. // Allocate a mutex to use later
  73. mActiveMutex = Mutex::createMutex();
  74. // Nothing is ready yet
  75. mEnabled = false;
  76. mActive = false;
  77. mMouseControl = false;
  78. mMinCircleProgress = 0.0;
  79. }
  80. //-----------------------------------------------------------------------------
  81. LeapMotionManager::~LeapMotionManager()
  82. {
  83. // Disable and delete internal members
  84. disable();
  85. // Get rid of the mutex
  86. Mutex::destroyMutex(mActiveMutex);
  87. }
  88. //-----------------------------------------------------------------------------
  89. void LeapMotionManager::staticInit()
  90. {
  91. // If true, the Leap Motion device will be enabled, if present
  92. Con::addVariable("pref::LeapMotion::EnableDevice", TypeBool, &smEnableDevice);
  93. // Indicates that events for each hand and pointable will be created.
  94. Con::addVariable("LeapMotion::GenerateIndividualEvents", TypeBool, &smGenerateIndividualEvents);
  95. // Indicates that we track hand IDs and will ensure that the same hand will remain at the same index between frames.
  96. Con::addVariable("LeapMotion::KeepHandIndexPersistent", TypeBool, &smKeepHandIndexPersistent);
  97. // Indicates that we track pointable IDs and will ensure that the same pointable will remain at the same index between frames.
  98. Con::addVariable("LeapMotion::KeepPointableIndexPersistent", TypeBool, &smKeepPointableIndexPersistent);
  99. // If true, broadcast single hand rotation as axis events.
  100. Con::addVariable("LeapMotion::GenerateSingleHandRotationAsAxisEvents", TypeBool, &smGenerateSingleHandRotationAsAxisEvents);
  101. // The maximum hand angle when used as an axis event as measured from a vector pointing straight up (in degrees).
  102. // Shoud range from 0 to 90 degrees.
  103. Con::addVariable("LeapMotion::MaximumHandAxisAngle", TypeF32, &smMaximumHandAxisAngle);
  104. // Indicates that a whole frame event should be generated and frames should be buffered.
  105. Con::addVariable("LeapMotion::GenerateWholeFrameEvents", TypeBool, &smGenerateWholeFrameEvents);
  106. }
  107. //-----------------------------------------------------------------------------
  108. void LeapMotionManager::enable(bool enabledState)
  109. {
  110. Mutex::lockMutex(mActiveMutex);
  111. mEnabled = enabledState;
  112. Mutex::unlockMutex(mActiveMutex);
  113. }
  114. //-----------------------------------------------------------------------------
  115. void LeapMotionManager::disable()
  116. {
  117. if (mController)
  118. {
  119. delete mController;
  120. mController = NULL;
  121. if (mListener)
  122. {
  123. delete mListener;
  124. mListener = NULL;
  125. }
  126. }
  127. setActive(false);
  128. mEnabled = false;
  129. }
  130. //-----------------------------------------------------------------------------
  131. bool LeapMotionManager::getActive()
  132. {
  133. Mutex::lockMutex(mActiveMutex);
  134. bool active = mActive;
  135. Mutex::unlockMutex(mActiveMutex);
  136. return active;
  137. }
  138. //-----------------------------------------------------------------------------
  139. void LeapMotionManager::setActive(bool state)
  140. {
  141. Mutex::lockMutex(mActiveMutex);
  142. mActive = state;
  143. Mutex::unlockMutex(mActiveMutex);
  144. }
  145. //-----------------------------------------------------------------------------
  146. void LeapMotionManager::toggleMouseControl(bool enabledState)
  147. {
  148. Mutex::lockMutex(mActiveMutex);
  149. mMouseControl = enabledState;
  150. Mutex::unlockMutex(mActiveMutex);
  151. }
  152. //-----------------------------------------------------------------------------
  153. bool LeapMotionManager::getMouseControlToggle()
  154. {
  155. Mutex::lockMutex(mActiveMutex);
  156. bool mouseControlled = mMouseControl;
  157. Mutex::unlockMutex(mActiveMutex);
  158. return mouseControlled;
  159. }
  160. //-----------------------------------------------------------------------------
  161. // You can get and set gesture configuration parameters using the Config object
  162. // obtained from a connected Controller object. The key strings required to
  163. // * identify a configuration parameter include:
  164. //*
  165. //* Key string | Value type | Default value | Units
  166. //* -----------|------------|---------------|------
  167. //* Gesture.Circle.MinRadius | float | 5.0 | mm
  168. //* Gesture.Circle.MinArc | float | 1.5 | radians
  169. //* Gesture.Swipe.MinLength | float | 150 | mm
  170. //* Gesture.Swipe.MinVelocity | float | 1000 | mm/s
  171. //* Gesture.KeyTap.MinDownVelocity | float | 50 | mm/s
  172. //* Gesture.KeyTap.HistorySeconds | float | 0.1 | s
  173. //* Gesture.KeyTap.MinDistance | float | 3.0 | mm
  174. //* Gesture.ScreenTap.MinForwardVelocity | float | 50 | mm/s
  175. //* Gesture.ScreenTap.HistorySeconds | float | 0.1 | s
  176. //* Gesture.ScreenTap.MinDistance | float | 5.0 | mm
  177. bool LeapMotionManager::configureLeapGesture(const char* configString, const F32 value)
  178. {
  179. // Get this controller's config.
  180. Leap::Config config = mController->config();
  181. // Convert and pass the key, along with the value.
  182. std::string *keyString = new std::string(configString);
  183. bool success = config.setFloat(*keyString, value);
  184. // Free memory and return the result.
  185. delete keyString;
  186. return success;
  187. }
  188. //-----------------------------------------------------------------------------
  189. bool LeapMotionManager::setMinCircleProgress(const F32 value)
  190. {
  191. mMinCircleProgress = value;
  192. return true;
  193. }
  194. //-----------------------------------------------------------------------------
  195. void LeapMotionManager::processHand(const Leap::Hand& hand, S32 id)
  196. {
  197. // Get hand (palm) position
  198. /*Point3F rawHandPosition;
  199. Point3I convertedHandPosition;
  200. LeapMotionUtil::convertPosition(hand.palmPosition(), rawHandPosition);
  201. convertedHandPosition.x = (S32)mFloor(rawHandPosition.x);
  202. convertedHandPosition.y = (S32)mFloor(rawHandPosition.y);
  203. convertedHandPosition.z = (S32)mFloor(rawHandPosition.z);*/
  204. // Get the hand's normal vector and direction
  205. const Leap::Vector normal = hand.palmNormal();
  206. const Leap::Vector direction = hand.direction();
  207. F32 pitch = direction.pitch() * Leap::RAD_TO_DEG;
  208. F32 roll = normal.roll() * Leap::RAD_TO_DEG;
  209. F32 yaw = direction.yaw() * Leap::RAD_TO_DEG;
  210. // Position Event
  211. InputEvent handPosEvent;
  212. handPosEvent.deviceInst = 0;
  213. handPosEvent.iValue = id;
  214. handPosEvent.fValues[0] = hand.palmPosition().x;
  215. handPosEvent.fValues[1] = hand.palmPosition().y;
  216. handPosEvent.fValues[2] = hand.palmPosition().z;
  217. handPosEvent.deviceType = LeapMotionDeviceType;
  218. handPosEvent.objType = LM_HANDPOS;
  219. handPosEvent.objInst = 0;
  220. handPosEvent.action = SI_LEAP;
  221. handPosEvent.modifier = 0;
  222. InputEvent handRotEvent;
  223. handRotEvent.deviceInst = 0;
  224. handRotEvent.iValue = id;
  225. handRotEvent.fValues[0] = yaw;
  226. handRotEvent.fValues[1] = pitch;
  227. handRotEvent.fValues[2] = roll;
  228. handRotEvent.objType = LM_HANDROT;
  229. handRotEvent.deviceType = LeapMotionDeviceType;
  230. handRotEvent.objInst = 0;
  231. handRotEvent.action = SI_LEAP;
  232. handRotEvent.modifier = 0;
  233. Game->postEvent(handPosEvent);
  234. Game->postEvent(handRotEvent);
  235. }
  236. //-----------------------------------------------------------------------------
  237. void LeapMotionManager::processHandPointables(const Leap::PointableList& pointables)
  238. {
  239. InputEvent pointablePositionEvent;
  240. pointablePositionEvent.deviceInst = 0;
  241. pointablePositionEvent.objInst = 0;
  242. pointablePositionEvent.modifier = 0;
  243. pointablePositionEvent.deviceType = LeapMotionDeviceType;
  244. pointablePositionEvent.objType = LM_FINGERPOS;
  245. pointablePositionEvent.action = SI_LEAP;
  246. for (int f = 0; f < pointables.count(); ++f)
  247. {
  248. Leap::Pointable pointable = pointables[f];
  249. char charHolder[10];
  250. Leap::Vector tipPosition = pointables[f].tipPosition();
  251. dItoa((S32)tipPosition.x, charHolder);
  252. dStrcat(pointablePositionEvent.fingersX, charHolder);
  253. dStrcat(pointablePositionEvent.fingersX, " ");
  254. dItoa((S32)tipPosition.y, charHolder);
  255. dStrcat(pointablePositionEvent.fingersY, charHolder);
  256. dStrcat(pointablePositionEvent.fingersY, " ");
  257. dItoa((S32)tipPosition.z, charHolder);
  258. dStrcat(pointablePositionEvent.fingersZ, charHolder);
  259. dStrcat(pointablePositionEvent.fingersZ, " ");
  260. dItoa(pointables[f].id(), charHolder);
  261. dStrcat(pointablePositionEvent.fingerIDs, charHolder);
  262. dStrcat(pointablePositionEvent.fingerIDs, " ");
  263. }
  264. // Post
  265. Game->postEvent(pointablePositionEvent);
  266. }
  267. //-----------------------------------------------------------------------------
  268. void LeapMotionManager::processGestures(const Leap::GestureList& gestures)
  269. {
  270. for (int g = 0; g < gestures.count(); ++g)
  271. {
  272. Leap::Gesture gesture = gestures[g];
  273. switch (gesture.type())
  274. {
  275. case Leap::Gesture::TYPE_CIRCLE:
  276. {
  277. Leap::CircleGesture circle = gesture;
  278. if (circle.progress() < mMinCircleProgress)
  279. break;
  280. bool clockWise;
  281. if (circle.pointable().direction().angleTo(circle.normal()) <= Leap::PI/4)
  282. clockWise = true;
  283. else
  284. clockWise = false;
  285. InputEvent event;
  286. event.deviceInst = 0;
  287. event.iValue = g;
  288. event.fValues[0] = circle.progress();
  289. event.fValues[1] = circle.radius();
  290. event.fValues[2] = clockWise;
  291. event.fValues[3] = (F32)circle.state();
  292. event.deviceType = LeapMotionDeviceType;
  293. event.objType = SI_CIRCLE_GESTURE;
  294. event.objInst = 0;
  295. event.action = SI_GESTURE;
  296. event.modifier = 0;
  297. Game->postEvent(event);
  298. break;
  299. }
  300. case Leap::Gesture::TYPE_SWIPE:
  301. {
  302. Leap::SwipeGesture swipe = gesture;
  303. // Comment to post begin and update swipes
  304. if (swipe.state() != Leap::Gesture::STATE_STOP)
  305. {
  306. break;
  307. }
  308. InputEvent event;
  309. event.deviceInst = 0;
  310. event.iValue = g;
  311. event.fValues[0] = (F32)swipe.state();
  312. event.fValues[1] = swipe.direction().x;
  313. event.fValues[2] = swipe.direction().y;
  314. event.fValues[3] = swipe.direction().z;
  315. event.fValues[4] = swipe.speed();
  316. event.deviceType = LeapMotionDeviceType;
  317. event.objType = SI_SWIPE_GESTURE;
  318. event.objInst = 0;
  319. event.action = SI_GESTURE;
  320. event.modifier = 0;
  321. Game->postEvent(event);
  322. break;
  323. }
  324. case Leap::Gesture::TYPE_KEY_TAP:
  325. {
  326. Leap::KeyTapGesture tap = gesture;
  327. InputEvent event;
  328. event.deviceInst = 0;
  329. event.iValue = g;
  330. event.fValues[0] = tap.position().x;
  331. event.fValues[1] = tap.position().y;
  332. event.fValues[2] = tap.position().z;
  333. event.fValues[3] = tap.direction().x;
  334. event.fValues[4] = tap.direction().y;
  335. event.fValues[5] = tap.direction().z;
  336. event.deviceType = LeapMotionDeviceType;
  337. event.objType = SI_KEYTAP_GESTURE;
  338. event.objInst = 0;
  339. event.action = SI_GESTURE;
  340. event.modifier = 0;
  341. Game->postEvent(event);
  342. break;
  343. }
  344. case Leap::Gesture::TYPE_SCREEN_TAP:
  345. {
  346. Leap::ScreenTapGesture screentap = gesture;
  347. InputEvent event;
  348. event.deviceInst = 0;
  349. event.iValue = g;
  350. event.fValues[0] = screentap.position().x;
  351. event.fValues[1] = screentap.position().y;
  352. event.fValues[2] = screentap.position().z;
  353. event.fValues[3] = screentap.direction().x;
  354. event.fValues[4] = screentap.direction().y;
  355. event.fValues[5] = screentap.direction().z;
  356. event.deviceType = LeapMotionDeviceType;
  357. event.objType = SI_SCREENTAP_GESTURE;
  358. event.objInst = 0;
  359. event.action = SI_GESTURE;
  360. event.modifier = 0;
  361. Game->postEvent(event);
  362. break;
  363. }
  364. default:
  365. Con::warnf("LeapMotionManager::process() - Unknown gesture detected");
  366. break;
  367. }
  368. }
  369. }
  370. //-----------------------------------------------------------------------------
  371. void LeapMotionManager::process(const Leap::Controller& controller)
  372. {
  373. // Is the manager enabled?
  374. if (!mEnabled)
  375. return;
  376. // Was the leap device activated
  377. if (!getActive())
  378. return;
  379. // Get the current frame
  380. const Leap::Frame frame = controller.frame();
  381. if (!frame.isValid())
  382. return;
  383. mLastFrame = frame;
  384. // Get gestures
  385. const Leap::GestureList gestures = frame.gestures();
  386. if (!gestures.isEmpty())
  387. processGestures(gestures);
  388. if (getMouseControlToggle())
  389. {
  390. generateMouseEvent(controller);
  391. return;
  392. }
  393. // Is a hand present?
  394. if ( !frame.hands().isEmpty() )
  395. {
  396. for (int h = 0; h < frame.hands().count(); ++h)
  397. {
  398. const Leap::Hand hand = frame.hands()[h];
  399. processHand(hand, h);
  400. }
  401. }
  402. if (frame.pointables().count())
  403. {
  404. const Leap::PointableList pointables = frame.pointables();
  405. if (pointables.count())
  406. processHandPointables(pointables);
  407. }
  408. }
  409. //-----------------------------------------------------------------------------
  410. void LeapMotionManager::generateMouseEvent(Leap::Controller const & controller)
  411. {
  412. const Leap::ScreenList screens = controller.locatedScreens();
  413. // make sure we have a detected screen
  414. if (screens.isEmpty())
  415. return;
  416. const Leap::Screen screen = screens[0];
  417. // find the first finger or tool
  418. const Leap::Frame frame = controller.frame();
  419. const Leap::HandList hands = frame.hands();
  420. if (hands.isEmpty())
  421. return;
  422. const Leap::PointableList pointables = hands[0].pointables();
  423. if (pointables.isEmpty())
  424. return;
  425. const Leap::Pointable firstPointable = pointables[0];
  426. // get x, y coordinates on the first screen
  427. const Leap::Vector intersection = screen.intersect( firstPointable, true, 1.0f );
  428. // if the user is not pointing at the screen all components of
  429. // the returned vector will be Not A Number (NaN)
  430. // isValid() returns true only if all components are finite
  431. if (!intersection.isValid())
  432. return;
  433. F32 x = screen.widthPixels() * intersection.x;
  434. // flip y coordinate to standard top-left origin
  435. F32 y = screen.heightPixels() * (1.0f - intersection.y);
  436. // Move the cursor
  437. Point2I location((S32)x, (S32)y);
  438. Canvas->setCursorPos(location);
  439. // Build and postthe mouse event
  440. MouseMoveEvent TorqueEvent;
  441. TorqueEvent.xPos = (S32) location.x;
  442. TorqueEvent.yPos = (S32) location.y;
  443. Game->postEvent(TorqueEvent);
  444. }
  445. //-----------------------------------------------------------------------------
  446. Vector2 LeapMotionManager::getPointFromProjection(Point3F position)
  447. {
  448. // Get the screen and projection
  449. const Leap::Vector pointablePosition(position.x, position.y, position.z);
  450. const Leap::Screen screen = mController->locatedScreens()[0];
  451. const Leap::Vector projectedPosition = screen.project(pointablePosition, true, 1.0f);
  452. // if the user is not pointing at the screen all components of
  453. // the returned vector will be Not A Number (NaN)
  454. // isValid() returns true only if all components are finite
  455. if (!projectedPosition.isValid())
  456. return Vector2("");
  457. // Get the screen coordinates
  458. F32 x = screen.widthPixels() * projectedPosition.x;
  459. // flip y coordinate to standard top-left origin
  460. F32 y = screen.heightPixels() * (1.0f - projectedPosition.y);
  461. // Build the screenPosition and return it
  462. Vector2 screenPosition;
  463. screenPosition.x = x;
  464. screenPosition.y = y;
  465. return screenPosition;
  466. }
  467. //-----------------------------------------------------------------------------
  468. Vector2 LeapMotionManager::getPointFromIntersection(S32 pointableID)
  469. {
  470. // Get the finger via ID and check for validity
  471. Leap::Pointable lastPointable = mLastFrame.pointable(pointableID);
  472. if (!lastPointable.isValid())
  473. return Vector2("");
  474. // Get the screen and intersection
  475. const Leap::Screen screen = mController->locatedScreens()[0];
  476. const Leap::Vector intersection = screen.intersect( lastPointable, true, 1.0f );
  477. // if the user is not pointing at the screen all components of
  478. // the returned vector will be Not A Number (NaN)
  479. // isValid() returns true only if all components are finite
  480. if (!intersection.isValid())
  481. return Vector2("");
  482. // Get the screen coordinates
  483. F32 x = screen.widthPixels() * intersection.x;
  484. // flip y coordinate to standard top-left origin
  485. F32 y = screen.heightPixels() * (1.0f - intersection.y);
  486. // Build the screenPosition and return it
  487. Vector2 screenPosition;
  488. screenPosition.x = x;
  489. screenPosition.y = y;
  490. return screenPosition;
  491. }
  492. //-----------------------------------------------------------------------------
  493. void LeapMotionManager::MotionListener::onInit(const Leap::Controller& controller)
  494. {
  495. //Con::printf("MotionListener::onInit()");
  496. }
  497. //-----------------------------------------------------------------------------
  498. void LeapMotionManager::MotionListener::onFrame(const Leap::Controller& controller)
  499. {
  500. gLeapMotionManager->process(controller);
  501. }
  502. //-----------------------------------------------------------------------------
  503. void LeapMotionManager::MotionListener::onConnect(const Leap::Controller& controller)
  504. {
  505. gLeapMotionManager->setActive(true);
  506. controller.enableGesture(Leap::Gesture::TYPE_CIRCLE);
  507. controller.enableGesture(Leap::Gesture::TYPE_KEY_TAP);
  508. controller.enableGesture(Leap::Gesture::TYPE_SCREEN_TAP);
  509. controller.enableGesture(Leap::Gesture::TYPE_SWIPE);
  510. }
  511. //-----------------------------------------------------------------------------
  512. void LeapMotionManager::MotionListener::onDisconnect (const Leap::Controller& controller)
  513. {
  514. gLeapMotionManager->setActive(false);
  515. }
  516. //-----------------------------------------------------------------------------
  517. void LeapMotionManager::MotionListener::onFocusGained(const Leap::Controller& controller)
  518. {
  519. gLeapMotionManager->setActive(true);
  520. }
  521. //-----------------------------------------------------------------------------
  522. void LeapMotionManager::MotionListener::onFocusLost(const Leap::Controller& controller)
  523. {
  524. gLeapMotionManager->setActive(false);
  525. }