leapMotionDevice.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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 _LEAPMOTIONDEVICE_H_
  23. #define _LEAPMOTIONDEVICE_H_
  24. #include "platform/input/IInputDevice.h"
  25. #include "platform/input/event.h"
  26. #include "platformWin32/platformWin32.h"
  27. #include "core/util/tSingleton.h"
  28. #include "math/mQuat.h"
  29. #include "platform/input/leapMotion/leapMotionConstants.h"
  30. #include "Leap.h"
  31. #define DEFAULT_MOTION_UNIT 0
  32. struct LeapMotionDeviceData;
  33. class LeapMotionDevice : public IInputDevice
  34. {
  35. protected:
  36. class MotionListener : public Leap::Listener
  37. {
  38. public:
  39. MotionListener() {}
  40. virtual ~MotionListener() {}
  41. virtual void onConnect (const Leap::Controller &controller);
  42. virtual void onDisconnect (const Leap::Controller &controller);
  43. };
  44. /// The connection to the Leap Motion
  45. Leap::Controller* mController;
  46. /// Our Leap Motion listener class
  47. MotionListener* mListener;
  48. /// Used with the LM listener object
  49. void* mActiveMutex;
  50. /// Is the Leap Motion active
  51. bool mActive;
  52. /// Buffer to store data Leap Motion data in a Torque friendly way
  53. LeapMotionDeviceData* mDataBuffer[2];
  54. /// Points to the buffers that holds the previously collected data
  55. LeapMotionDeviceData* mPrevData;
  56. protected:
  57. /// Build out the codes used for controller actions with the
  58. /// Input Event Manager
  59. void buildCodeTable();
  60. public:
  61. static bool smEnableDevice;
  62. // Indicates that events for each hand and pointable will be created
  63. static bool smGenerateIndividualEvents;
  64. // Indicates that we track hand IDs and will ensure that the same hand
  65. // will remain at the same index between frames.
  66. static bool smKeepHandIndexPersistent;
  67. // Indicates that we track pointable IDs and will ensure that the same
  68. // pointable will remain at the same index between frames.
  69. static bool smKeepPointableIndexPersistent;
  70. // Broadcast single hand rotation as axis
  71. static bool smGenerateSingleHandRotationAsAxisEvents;
  72. // The maximum hand angle when used as an axis event
  73. // as measured from a vector pointing straight up (in degrees)
  74. static F32 smMaximumHandAxisAngle;
  75. // Indicates that a whole frame event should be generated and frames
  76. // should be buffered.
  77. static bool smGenerateWholeFrameEvents;
  78. // Frame action codes
  79. static U32 LM_FRAMEVALIDDATA; // SI_BUTTON
  80. // Hand action codes
  81. static U32 LM_HAND[LeapMotionConstants::MaxHands]; // SI_POS
  82. static U32 LM_HANDROT[LeapMotionConstants::MaxHands]; // SI_ROT
  83. static U32 LM_HANDAXISX; // SI_AXIS
  84. static U32 LM_HANDAXISY;
  85. // Pointables action codes
  86. static U32 LM_HANDPOINTABLE[LeapMotionConstants::MaxHands][LeapMotionConstants::MaxPointablesPerHand]; // SI_POS
  87. static U32 LM_HANDPOINTABLEROT[LeapMotionConstants::MaxHands][LeapMotionConstants::MaxPointablesPerHand]; // SI_ROT
  88. // Whole frame
  89. static U32 LM_FRAME; // SI_INT
  90. public:
  91. LeapMotionDevice();
  92. ~LeapMotionDevice();
  93. static void staticInit();
  94. bool enable();
  95. void disable();
  96. bool getActive();
  97. void setActive(bool state);
  98. bool process();
  99. public:
  100. // For ManagedSingleton.
  101. static const char* getSingletonName() { return "LeapMotionDevice"; }
  102. };
  103. /// Returns the LeapMotionDevice singleton.
  104. #define LEAPMOTIONDEV ManagedSingleton<LeapMotionDevice>::instance()
  105. #endif // _LEAPMOTIONDEVICE_H_