razerHydraData.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. #include "platform/input/razerHydra/razerHydraData.h"
  23. #include "platform/input/razerHydra/razerHydraUtil.h"
  24. RazerHyrdaControllerData::RazerHyrdaControllerData()
  25. {
  26. reset();
  27. }
  28. void RazerHyrdaControllerData::reset()
  29. {
  30. mDataSet = false;
  31. mShoulder = false;
  32. mThumb = false;
  33. mStart = false;
  34. mButton1 = false;
  35. mButton2 = false;
  36. mButton3 = false;
  37. mButton4 = false;
  38. mIsDocked = false;
  39. }
  40. void RazerHyrdaControllerData::setData(const sixenseControllerData& data, const F32& maxAxisRadius)
  41. {
  42. // Controller position
  43. RazerHydraUtil::convertPosition(data.pos, mRawPos[0], mRawPos[1], mRawPos[2]);
  44. mPos[0] = (S32)mFloor(mRawPos[0]);
  45. mPos[1] = (S32)mFloor(mRawPos[1]);
  46. mPos[2] = (S32)mFloor(mRawPos[2]);
  47. mPosPoint.set(mPos[0], mPos[1], mPos[2]);
  48. // Controller rotation
  49. RazerHydraUtil::convertRotation(data.rot_mat, mRot);
  50. mRotQuat.set(mRot);
  51. // Controller rotation as axis, but only if not docked
  52. if(!data.is_docked)
  53. {
  54. RazerHydraUtil::calculateAxisRotation(mRot, maxAxisRadius, mRotAxis);
  55. }
  56. else
  57. {
  58. mRotAxis.x = 0.0f;
  59. mRotAxis.y = 0.0f;
  60. }
  61. // Thumb stick
  62. mThumbStick[0] = data.joystick_x;
  63. mThumbStick[1] = data.joystick_y;
  64. // Trigger
  65. mTrigger = data.trigger;
  66. //Buttons
  67. mShoulder = data.buttons & SIXENSE_BUTTON_BUMPER;
  68. mThumb = data.buttons & SIXENSE_BUTTON_JOYSTICK;
  69. mStart = data.buttons & SIXENSE_BUTTON_START;
  70. mButton1 = data.buttons & SIXENSE_BUTTON_1;
  71. mButton2 = data.buttons & SIXENSE_BUTTON_2;
  72. mButton3 = data.buttons & SIXENSE_BUTTON_3;
  73. mButton4 = data.buttons & SIXENSE_BUTTON_4;
  74. // Other data
  75. mIsDocked = data.is_docked;
  76. // Store the current sequence number
  77. mSequenceNum = data.sequence_number;
  78. mDataSet = true;
  79. }
  80. U32 RazerHyrdaControllerData::compare(RazerHyrdaControllerData* other)
  81. {
  82. S32 result = DIFF_NONE;
  83. // Check position
  84. if(mDataSet)
  85. {
  86. if(mPos[0] != other->mPos[0])
  87. result |= DIFF_POSX;
  88. if(mPos[1] != other->mPos[1])
  89. result |= DIFF_POSY;
  90. if(mPos[2] != other->mPos[2])
  91. result |= DIFF_POSZ;
  92. }
  93. else
  94. {
  95. result |= DIFF_POS;
  96. }
  97. // Check rotation
  98. if(mRotQuat != other->mRotQuat || !mDataSet)
  99. {
  100. result |= DIFF_ROT;
  101. }
  102. // Check rotation as axis
  103. if(mRotAxis.x != other->mRotAxis.x || !mDataSet)
  104. {
  105. result |= DIFF_ROTAXISX;
  106. }
  107. if(mRotAxis.y != other->mRotAxis.y || !mDataSet)
  108. {
  109. result |= DIFF_ROTAXISY;
  110. }
  111. // Check thumb stick
  112. if(mThumbStick[0] != other->mThumbStick[0] || !mDataSet)
  113. {
  114. result |= DIFF_AXISX;
  115. }
  116. if(mThumbStick[1] != other->mThumbStick[1] || !mDataSet)
  117. {
  118. result |= DIFF_AXISY;
  119. }
  120. // Check trigger
  121. if(mTrigger != other->mTrigger || !mDataSet)
  122. {
  123. result |= DIFF_TRIGGER;
  124. }
  125. // Check buttons
  126. if(mShoulder != other->mShoulder)
  127. {
  128. result |= DIFF_BUTTON_SHOULDER;
  129. }
  130. if(mThumb != other->mThumb)
  131. {
  132. result |= DIFF_BUTTON_THUMB;
  133. }
  134. if(mStart != other->mStart)
  135. {
  136. result |= DIFF_BUTTON_START;
  137. }
  138. if(mButton1 != other->mButton1)
  139. {
  140. result |= DIFF_BUTTON1;
  141. }
  142. if(mButton2 != other->mButton2)
  143. {
  144. result |= DIFF_BUTTON2;
  145. }
  146. if(mButton3 != other->mButton3)
  147. {
  148. result |= DIFF_BUTTON3;
  149. }
  150. if(mButton4 != other->mButton4)
  151. {
  152. result |= DIFF_BUTTON4;
  153. }
  154. return result;
  155. }
  156. U32 RazerHyrdaControllerData::compareMeta(RazerHyrdaControllerData* other)
  157. {
  158. S32 result = DIFF_NONE;
  159. if(mIsDocked != other->mIsDocked || !mDataSet)
  160. {
  161. result |= METADIFF_DOCKED;
  162. }
  163. return result;
  164. }