LeapMotionManager_ScriptBinding.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. ConsoleFunction(initLeapMotionManager, void, 1, 1, "() Initialize the LeapMotionManager")
  23. {
  24. if (gLeapMotionManager != NULL)
  25. {
  26. Con::printf("LeapMotionManager already initialized");
  27. }
  28. else
  29. {
  30. gLeapMotionManager = new LeapMotionManager();
  31. }
  32. }
  33. //-----------------------------------------------------------------------------
  34. ConsoleFunction(enableLeapMotionManager, void, 2, 2, "(bool enabledState) Run or pause the LeapMotionManager.\n"
  35. "@param enabledState True to turn it on, false otherwise")
  36. {
  37. if (gLeapMotionManager == NULL)
  38. {
  39. Con::printf("LeapMotionManager not initialized. Call initLeapMotionManager() first");
  40. }
  41. else
  42. {
  43. gLeapMotionManager->enable(dAtob(argv[1]));
  44. }
  45. }
  46. //-----------------------------------------------------------------------------
  47. ConsoleFunction(isLeapMotionManagerEnabled, bool, 1, 1, "() Checks the LeapMotionManager to see if it is enabled.\n"
  48. "@return True if it's running, false otherwise")
  49. {
  50. if (gLeapMotionManager == NULL)
  51. {
  52. Con::printf("LeapMotionManager not initialized. Call initLeapMotionManager() first");
  53. return false;
  54. }
  55. else
  56. {
  57. return gLeapMotionManager->getEnabled();
  58. }
  59. }
  60. //-----------------------------------------------------------------------------
  61. ConsoleFunction(enableLeapCursorControl, void, 2, 2, "(bool enabledState) Toggles the manager to act like a mouse.\n"
  62. "@param enabledState True to act like a mouse, false otherwise")
  63. {
  64. if (gLeapMotionManager == NULL)
  65. {
  66. Con::printf("LeapMotionManager not initialized. Call initLeapMotionManager() first");
  67. }
  68. else
  69. {
  70. return gLeapMotionManager->toggleMouseControl(dAtob(argv[1]));
  71. }
  72. }
  73. //-----------------------------------------------------------------------------
  74. ConsoleFunction(isLeapCursorControlled, bool, 1, 1, "() Checks the LeapMotionManager to see if it is controlling the mouse.\n"
  75. "@return True if it's acting as a mouse, false otherwise")
  76. {
  77. if (gLeapMotionManager == NULL)
  78. {
  79. Con::printf("LeapMotionManager not initialized. Call initLeapMotionManager() first");
  80. return false;
  81. }
  82. else
  83. {
  84. return gLeapMotionManager->getMouseControlToggle();
  85. }
  86. }
  87. //-----------------------------------------------------------------------------
  88. ConsoleFunction(configureLeapGesture, bool, 3, 3, "(gestureString, value) Modified a Config string on the main "
  89. "Controller, via the LeapMotionManager. The following strings are allowed:\n"
  90. "Gesture.Circle.MinProgress\n"
  91. "Gesture.Circle.MinRadius\n"
  92. "Gesture.Circle.MinArc\n"
  93. "Gesture.Swipe.MinLength\n"
  94. "Gesture.Swipe.MinVelocity\n"
  95. "Gesture.KeyTap.MinDownVelocity\n"
  96. "Gesture.KeyTap.HistorySeconds\n"
  97. "Gesture.KeyTap.MinDistance\n"
  98. "Gesture.ScreenTap.MinForwardVelocity\n"
  99. "Gesture.ScreenTap.HistorySeconds\n"
  100. "Gesture.ScreenTap.MinDistance\n"
  101. "@param gestureString The Config string to be set\n"
  102. "@param value The new value for the Config string\n"
  103. "@return True if string was successfully set, false otherwise")
  104. {
  105. if (gLeapMotionManager == NULL)
  106. {
  107. Con::printf("LeapMotionManager not initialized. Call initLeapMotionManager() first");
  108. return false;
  109. }
  110. else
  111. {
  112. if (!dStrcmp("Gesture.Circle.MinProgress", argv[1]))
  113. {
  114. return gLeapMotionManager->setMinCircleProgress(dAtof(argv[2]));
  115. }
  116. else
  117. {
  118. return gLeapMotionManager->configureLeapGesture(argv[1], dAtof(argv[2]));
  119. }
  120. }
  121. }
  122. ConsoleFunction(getPointFromProjection, const char*, 2, 4, "(x, y, z) - Gets the closest point on the screen to a point in space using Leap::Screen::project().\n"
  123. "@param x The x component of the finger position.\n"
  124. "@param y The y component of the finger position.\n"
  125. "@param z The z component of the finger position.\n\n"
  126. "@return An \"x y\" position of where the finger intersects with the screen.")
  127. {
  128. // The new position.
  129. Point3F pos;
  130. if(argc == 2)
  131. {
  132. dSscanf(argv[1], "%g %g %g", &pos.x, &pos.y, &pos.z);
  133. }
  134. else if (argc == 4)
  135. {
  136. pos.x = dAtof(argv[1]);
  137. pos.y = dAtof(argv[2]);
  138. pos.z = dAtof(argv[3]);
  139. }
  140. else
  141. {
  142. Con::warnf("getPointFromProjection() - Invalid number of parameters!");
  143. return "";
  144. }
  145. return gLeapMotionManager->getPointFromProjection(pos).scriptThis();
  146. }
  147. ConsoleFunction(getPointFromIntersection, const char*, 2, 2, "(fingerID) - Gets the point of intersection between the screen and a ray "
  148. "projected from a Pointable object using the Screen::intersect() function\n"
  149. "@param fingerID The finger ID, which will be grabbed from the last frame.\n\n"
  150. "@return An \"x y\" position of where the finger intersects with the screen.")
  151. {
  152. if(argc < 2)
  153. {
  154. Con::warnf("getPointFromIntersection() - Invalid number of parameters!");
  155. return "";
  156. }
  157. return gLeapMotionManager->getPointFromIntersection(dAtoi(argv[1])).scriptThis();
  158. }