oculusVRSensorData.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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/oculusVR/oculusVRSensorData.h"
  23. #include "platform/input/oculusVR/oculusVRUtil.h"
  24. #include "console/console.h"
  25. OculusVRSensorData::OculusVRSensorData()
  26. {
  27. reset();
  28. }
  29. void OculusVRSensorData::reset()
  30. {
  31. mDataSet = false;
  32. }
  33. void OculusVRSensorData::setData(OVR::SensorFusion& data, const F32& maxAxisRadius)
  34. {
  35. // Sensor rotation
  36. OVR::Quatf orientation;
  37. if(data.GetPredictionDelta() > 0)
  38. {
  39. orientation = data.GetPredictedOrientation();
  40. }
  41. else
  42. {
  43. orientation = data.GetOrientation();
  44. }
  45. OVR::Matrix4f orientMat(orientation);
  46. OculusVRUtil::convertRotation(orientMat.M, mRot);
  47. mRotQuat.set(mRot);
  48. // Sensor rotation in Euler format
  49. OculusVRUtil::convertRotation(orientation, mRotEuler);
  50. // Sensor rotation as axis
  51. OculusVRUtil::calculateAxisRotation(mRot, maxAxisRadius, mRotAxis);
  52. mDataSet = true;
  53. }
  54. void OculusVRSensorData::simulateData(const F32& maxAxisRadius)
  55. {
  56. // Sensor rotation
  57. mRot.identity();
  58. mRotQuat.identity();
  59. mRotEuler.zero();
  60. // Sensor rotation as axis
  61. OculusVRUtil::calculateAxisRotation(mRot, maxAxisRadius, mRotAxis);
  62. mDataSet = true;
  63. }
  64. U32 OculusVRSensorData::compare(OculusVRSensorData* other)
  65. {
  66. S32 result = DIFF_NONE;
  67. // Check rotation
  68. if(mRotEuler.x != other->mRotEuler.x || mRotEuler.y != other->mRotEuler.y || mRotEuler.z != other->mRotEuler.z || !mDataSet)
  69. {
  70. result |= DIFF_ROT;
  71. }
  72. // Check rotation as axis
  73. if(mRotAxis.x != other->mRotAxis.x || !mDataSet)
  74. {
  75. result |= DIFF_ROTAXISX;
  76. }
  77. if(mRotAxis.y != other->mRotAxis.y || !mDataSet)
  78. {
  79. result |= DIFF_ROTAXISY;
  80. }
  81. return result;
  82. }