leapMotionData.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 _LEAPMOTIONDATA_H_
  23. #define _LEAPMOTIONDATA_H_
  24. #include "console/consoleTypes.h"
  25. #include "math/mMathFn.h"
  26. #include "math/mMatrix.h"
  27. #include "math/mQuat.h"
  28. #include "platform/input/leapMotion/leapMotionConstants.h"
  29. #include "Leap.h"
  30. struct LeapMotionDeviceData
  31. {
  32. enum DataDifferences {
  33. DIFF_NONE = 0,
  34. DIFF_HANDROTAXISX = (1<<1),
  35. DIFF_HANDROTAXISY = (1<<2),
  36. DIFF_HANDROTAXIS = (DIFF_HANDROTAXISX | DIFF_HANDROTAXISY),
  37. };
  38. enum MetaDataDifferences {
  39. METADIFF_NONE = 0,
  40. METADIFF_FRAME_VALID_DATA = (1<<0),
  41. };
  42. protected:
  43. void processPersistentHands(const Leap::HandList& hands, bool keepPointableIndexPersistent, LeapMotionDeviceData* prevData);
  44. void processHands(const Leap::HandList& hands);
  45. void processHand(const Leap::Hand& hand, U32 handIndex, bool keepPointableIndexPersistent, LeapMotionDeviceData* prevData);
  46. void processPersistentHandPointables(const Leap::PointableList& pointables, U32 handIndex, LeapMotionDeviceData* prevData);
  47. void processHandPointables(const Leap::PointableList& pointables, U32 handIndex);
  48. void processHandPointable(const Leap::Pointable& pointable, U32 handIndex, U32 handPointableIndex);
  49. public:
  50. bool mDataSet;
  51. // Frame Data Set
  52. bool mIsValid;
  53. bool mHasTrackingData;
  54. // Hand Data Set
  55. bool mHandValid[LeapMotionConstants::MaxHands];
  56. S32 mHandID[LeapMotionConstants::MaxHands];
  57. // Hand Position
  58. F32 mHandRawPos[LeapMotionConstants::MaxHands][3];
  59. S32 mHandPos[LeapMotionConstants::MaxHands][3];
  60. Point3F mHandPosPoint[LeapMotionConstants::MaxHands];
  61. // Hand Rotation
  62. MatrixF mHandRot[LeapMotionConstants::MaxHands];
  63. QuatF mHandRotQuat[LeapMotionConstants::MaxHands];
  64. // Hand rotation as axis x, y
  65. F32 mHandRotAxis[2];
  66. // Pointable Data Set
  67. bool mPointableValid[LeapMotionConstants::MaxHands][LeapMotionConstants::MaxPointablesPerHand];
  68. S32 mPointableID[LeapMotionConstants::MaxHands][LeapMotionConstants::MaxPointablesPerHand];
  69. F32 mPointableLength[LeapMotionConstants::MaxHands][LeapMotionConstants::MaxPointablesPerHand];
  70. F32 mPointableWidth[LeapMotionConstants::MaxHands][LeapMotionConstants::MaxPointablesPerHand];
  71. // Pointable Position
  72. F32 mPointableRawPos[LeapMotionConstants::MaxHands][LeapMotionConstants::MaxPointablesPerHand][3];
  73. S32 mPointablePos[LeapMotionConstants::MaxHands][LeapMotionConstants::MaxPointablesPerHand][3];
  74. Point3F mPointablePosPoint[LeapMotionConstants::MaxHands][LeapMotionConstants::MaxPointablesPerHand];
  75. // Pointable Rotation
  76. MatrixF mPointableRot[LeapMotionConstants::MaxHands][LeapMotionConstants::MaxPointablesPerHand];
  77. QuatF mPointableRotQuat[LeapMotionConstants::MaxHands][LeapMotionConstants::MaxPointablesPerHand];
  78. // Sequence number from device
  79. U64 mSequenceNum;
  80. LeapMotionDeviceData();
  81. /// Reset device data
  82. void reset();
  83. /// Set data based on Leap Motion device data
  84. void setData(const Leap::Frame& frame, LeapMotionDeviceData* prevData, bool keepHandIndexPersistent, bool keepPointableIndexPersistent, const F32& maxHandAxisRadius);
  85. /// Compare this data and given and return differences
  86. U32 compare(LeapMotionDeviceData* other);
  87. /// Compare meta data between this and given and return differences
  88. U32 compareMeta(LeapMotionDeviceData* other);
  89. };
  90. #endif // _LEAPMOTIONDATA_H_