razerHydraFrame.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 _RAZERHYDRAFRAME_H_
  23. #define _RAZERHYDRAFRAME_H_
  24. #include "platform/input/razerHydra/razerHydraConstants.h"
  25. #include "console/simObject.h"
  26. #include "math/mPoint3.h"
  27. #include "math/mMatrix.h"
  28. #include "math/mQuat.h"
  29. #include "sixense.h"
  30. class RazerHydraFrame : public SimObject
  31. {
  32. typedef SimObject Parent;
  33. protected:
  34. struct ControllerData
  35. {
  36. // Position
  37. Point3F mRawPos;
  38. Point3I mPos;
  39. // Rotation
  40. MatrixF mRot;
  41. QuatF mRotQuat;
  42. // Controller rotation as axis x, y
  43. Point2F mRotAxis;
  44. // Thumb stick x, y and trigger
  45. Point2F mThumbStick;
  46. F32 mTrigger;
  47. // Buttons
  48. bool mShoulder;
  49. bool mThumb;
  50. bool mStart;
  51. bool mButton1;
  52. bool mButton2;
  53. bool mButton3;
  54. bool mButton4;
  55. // Other data
  56. U8 mSequenceNum;
  57. bool mEnabled;
  58. bool mIsDocked;
  59. };
  60. static U32 smNextInternalFrameId;
  61. // Sixense Frame
  62. bool mFrameValid;
  63. // Torque 3D frame information
  64. U32 mFrameInternalId;
  65. S32 mFrameSimTime;
  66. S32 mFrameRealTime;
  67. // Controller data for the frame
  68. ControllerData mControllerData[RazerHydraConstants::MaxControllers];
  69. public:
  70. RazerHydraFrame();
  71. virtual ~RazerHydraFrame();
  72. static void initPersistFields();
  73. virtual bool onAdd();
  74. virtual void onRemove();
  75. void clear();
  76. /// Copy a Leap Frame into our data structures
  77. void copyFromFrame(const sixenseAllControllerData& frame, const F32& maxAxisRadius);
  78. // Frame
  79. bool isFrameValid() const { return mFrameValid; }
  80. U32 getFrameInternalId() const { return mFrameInternalId; }
  81. S32 getFrameSimTime() const { return mFrameSimTime; }
  82. S32 getFrameRealTime() const { return mFrameRealTime; }
  83. // Controller
  84. const Point3F& getRawPos(U32 index) const;
  85. const Point3I& getPos(U32 index) const;
  86. const MatrixF& getRot(U32 index) const;
  87. const QuatF& getRotQuat(U32 index) const;
  88. const Point2F& getRotAxis(U32 index) const;
  89. // Controller variable controls
  90. const Point2F& getThumbStick(U32 Index) const;
  91. F32 getTrigger(U32 index) const;
  92. // Controller buttons
  93. bool getShoulder(U32 index) const;
  94. bool getThumb(U32 index) const;
  95. bool getStart(U32 index) const;
  96. bool getButton1(U32 index) const;
  97. bool getButton2(U32 index) const;
  98. bool getButton3(U32 index) const;
  99. bool getButton4(U32 index) const;
  100. // Controller other
  101. bool getEnabled(U32 index) const;
  102. bool getDocked(U32 index) const;
  103. S32 getSequenceNum(U32 index) const;
  104. DECLARE_CONOBJECT(RazerHydraFrame);
  105. };
  106. //-----------------------------------------------------------------------------
  107. inline const Point3F& RazerHydraFrame::getRawPos(U32 index) const
  108. {
  109. return (index >= RazerHydraConstants::MaxControllers) ? Point3F::Zero : mControllerData[index].mRawPos;
  110. }
  111. inline const Point3I& RazerHydraFrame::getPos(U32 index) const
  112. {
  113. return (index >= RazerHydraConstants::MaxControllers) ? Point3I::Zero : mControllerData[index].mPos;
  114. }
  115. inline const MatrixF& RazerHydraFrame::getRot(U32 index) const
  116. {
  117. return (index >= RazerHydraConstants::MaxControllers) ? MatrixF::Identity : mControllerData[index].mRot;
  118. }
  119. inline const QuatF& RazerHydraFrame::getRotQuat(U32 index) const
  120. {
  121. return (index >= RazerHydraConstants::MaxControllers) ? QuatF::Identity : mControllerData[index].mRotQuat;
  122. }
  123. inline const Point2F& RazerHydraFrame::getRotAxis(U32 index) const
  124. {
  125. return (index >= RazerHydraConstants::MaxControllers) ? Point2F::Zero : mControllerData[index].mRotAxis;
  126. }
  127. inline const Point2F& RazerHydraFrame::getThumbStick(U32 index) const
  128. {
  129. return (index >= RazerHydraConstants::MaxControllers) ? Point2F::Zero : mControllerData[index].mThumbStick;
  130. }
  131. inline F32 RazerHydraFrame::getTrigger(U32 index) const
  132. {
  133. return (index >= RazerHydraConstants::MaxControllers) ? 0.0f : mControllerData[index].mTrigger;
  134. }
  135. inline bool RazerHydraFrame::getShoulder(U32 index) const
  136. {
  137. return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mShoulder;
  138. }
  139. inline bool RazerHydraFrame::getThumb(U32 index) const
  140. {
  141. return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mThumb;
  142. }
  143. inline bool RazerHydraFrame::getStart(U32 index) const
  144. {
  145. return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mStart;
  146. }
  147. inline bool RazerHydraFrame::getButton1(U32 index) const
  148. {
  149. return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mButton1;
  150. }
  151. inline bool RazerHydraFrame::getButton2(U32 index) const
  152. {
  153. return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mButton2;
  154. }
  155. inline bool RazerHydraFrame::getButton3(U32 index) const
  156. {
  157. return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mButton3;
  158. }
  159. inline bool RazerHydraFrame::getButton4(U32 index) const
  160. {
  161. return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mButton4;
  162. }
  163. inline bool RazerHydraFrame::getEnabled(U32 index) const
  164. {
  165. return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mEnabled;
  166. }
  167. inline bool RazerHydraFrame::getDocked(U32 index) const
  168. {
  169. return (index >= RazerHydraConstants::MaxControllers) ? false : mControllerData[index].mIsDocked;
  170. }
  171. inline S32 RazerHydraFrame::getSequenceNum(U32 index) const
  172. {
  173. return (index >= RazerHydraConstants::MaxControllers) ? -1 : mControllerData[index].mSequenceNum;
  174. }
  175. #endif // _RAZERHYDRAFRAME_H_