razerHydraUtil.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/razerHydraUtil.h"
  23. namespace RazerHydraUtil
  24. {
  25. enum Components
  26. {
  27. X = 0,
  28. Y = 1,
  29. Z = 2,
  30. };
  31. void convertPosition(const F32 inPosition[3], F32& x, F32& y, F32& z)
  32. {
  33. // Convert to Torque coordinates. The conversion is:
  34. //
  35. // Motion Torque
  36. // x y z --> x -z y
  37. x = inPosition[X]; // x = x
  38. y = -inPosition[Z]; // y = -z
  39. z = inPosition[Y]; // z = y;
  40. }
  41. void convertPosition(const F32 inPosition[3], Point3F& outPosition)
  42. {
  43. // Convert to Torque coordinates. The conversion is:
  44. //
  45. // Motion Torque
  46. // x y z --> x -z y
  47. outPosition.x = inPosition[X]; // x = x
  48. outPosition.y = -inPosition[Z]; // y = -z
  49. outPosition.z = inPosition[Y]; // z = y;
  50. }
  51. void convertRotation(const F32 inRotMat[3][3], MatrixF& outRotation)
  52. {
  53. // Set rotation. We need to convert from sixense coordinates to
  54. // Torque coordinates. The conversion is:
  55. //
  56. // Sixense Torque
  57. // a b c a b c a -c b
  58. // d e f --> -g -h -i --> -g i -h
  59. // g h i d e f d -f e
  60. outRotation.setColumn(0, Point4F( inRotMat[0][0], -inRotMat[0][2], inRotMat[0][1], 0.0f));
  61. outRotation.setColumn(1, Point4F(-inRotMat[2][0], inRotMat[2][2], -inRotMat[2][1], 0.0f));
  62. outRotation.setColumn(2, Point4F( inRotMat[1][0], -inRotMat[1][2], inRotMat[1][1], 0.0f));
  63. outRotation.setPosition(Point3F::Zero);
  64. }
  65. void calculateAxisRotation(const MatrixF& inRotation, const F32& maxAxisRadius, Point2F& outRotation)
  66. {
  67. const VectorF& controllerUp = inRotation.getUpVector();
  68. Point2F axis(0,0);
  69. axis.x = controllerUp.x;
  70. axis.y = controllerUp.y;
  71. // Limit the axis angle to that given to us
  72. if(axis.len() > maxAxisRadius)
  73. {
  74. axis.normalize(maxAxisRadius);
  75. }
  76. // Renormalize to the range of 0..1
  77. if(maxAxisRadius != 0.0f)
  78. {
  79. axis /= maxAxisRadius;
  80. }
  81. outRotation.x = axis.x;
  82. outRotation.y = axis.y;
  83. }
  84. }