oculusVRSensorDevice.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 _OCULUSVRSENSORDEVICE_H_
  23. #define _OCULUSVRSENSORDEVICE_H_
  24. #include "core/util/str.h"
  25. #include "math/mQuat.h"
  26. #include "math/mPoint2.h"
  27. #include "math/mPoint3.h"
  28. #include "math/mPoint4.h"
  29. #include "platform/input/oculusVR/oculusVRConstants.h"
  30. #include "platform/types.h"
  31. #include "OVR_CAPI_0_5_0.h"
  32. struct OculusVRSensorData;
  33. class OculusVRSensorDevice
  34. {
  35. public:
  36. // Action codes
  37. static U32 OVR_SENSORROT[OculusVRConstants::MaxSensors]; // SI_ROT
  38. static U32 OVR_SENSORROTANG[OculusVRConstants::MaxSensors]; // SI_POS but is EulerF
  39. static U32 OVR_SENSORROTAXISX[OculusVRConstants::MaxSensors]; // SI_AXIS
  40. static U32 OVR_SENSORROTAXISY[OculusVRConstants::MaxSensors];
  41. static U32 OVR_SENSORACCELERATION[OculusVRConstants::MaxSensors]; // SI_POS
  42. static U32 OVR_SENSORANGVEL[OculusVRConstants::MaxSensors]; // SI_POS but is EulerF
  43. static U32 OVR_SENSORMAGNETOMETER[OculusVRConstants::MaxSensors]; // SI_POS
  44. static U32 OVR_SENSORPOSITION[OculusVRConstants::MaxSensors];
  45. protected:
  46. bool mIsValid;
  47. ovrHmd mDevice;
  48. U32 mCurrentTrackingCaps;
  49. U32 mSupportedTrackingCaps;
  50. // From OVR::DeviceInfo
  51. String mProductName;
  52. String mManufacturer;
  53. U32 mVersion;
  54. // From OVR::SensorInfo
  55. U16 mVendorId;
  56. U16 mProductId;
  57. String mSerialNumber;
  58. // Has yaw correction been disabled by the control panel
  59. bool mYawCorrectionDisabled;
  60. // Has position tracking been disabled
  61. bool mPositionTrackingDisabled;
  62. // Last tracking status
  63. U32 mLastStatus;
  64. // Assigned by the OculusVRDevice
  65. S32 mActionCodeIndex;
  66. // Buffers to store data for sensor
  67. OculusVRSensorData* mDataBuffer[2];
  68. // Points to the buffer that holds the previously collected data
  69. // for the sensor
  70. OculusVRSensorData* mPrevData;
  71. public:
  72. OculusVRSensorDevice();
  73. virtual ~OculusVRSensorDevice();
  74. static void buildCodeTable();
  75. void cleanUp();
  76. // Set the sensor properties based on information from the OVR device
  77. void set(ovrHmd sensor, S32 actionCodeIndex);
  78. bool isValid() const {return mIsValid;}
  79. bool process(U32 deviceType, bool generateRotAsAngAxis, bool generateRotAsEuler, bool generateRotationAsAxisEvents, bool generatePositionEvents, F32 maxAxisRadius, bool generateRawSensor);
  80. void reset();
  81. // Has yaw correction been disabled using the control panel
  82. bool getYawCorrectionUserDisabled() const { return mYawCorrectionDisabled; }
  83. // Is yaw correction enabled
  84. bool getYawCorrection() const;
  85. // Position is valid
  86. bool getHasValidPosition() const { return mLastStatus & ovrStatus_PositionTracked; }
  87. // Set the yaw correction. Note: if magnetometer calibration data is not present,
  88. // or user has disabled yaw correction in the control panel, this method will
  89. // not enable it.
  90. void setYawCorrection(bool state);
  91. // Sets position tracking state
  92. void setPositionTracking(bool state);
  93. // Is magnetometer calibration data available for this sensor
  94. bool getMagnetometerCalibrationAvailable() const;
  95. // Is position tracking data available for this sensor
  96. bool getOrientationTrackingAvailable() const;
  97. // Is position tracking data available for this sensor
  98. bool getPositionTrackingAvailable() const;
  99. U32 getLastTrackingStatus() const { return mLastStatus; }
  100. const char* getProductName() { return mProductName.c_str(); }
  101. const char* getManufacturer() { return mManufacturer.c_str(); }
  102. U32 getVersion() { return mVersion; }
  103. U16 getVendorId() { return mVendorId; }
  104. U16 getProductId() { return mProductId; }
  105. const char* getSerialNumber() { return mSerialNumber; }
  106. // Get the current rotation of the sensor. Uses prediction if set.
  107. EulerF getEulerRotation();
  108. // Get the current rotation of the sensor.
  109. EulerF getRawEulerRotation();
  110. // Get the current absolute acceleration reading, in m/s^2
  111. VectorF getAcceleration();
  112. // Get the current angular velocity reading, in rad/s
  113. EulerF getAngularVelocity();
  114. // Get the current position
  115. Point3F getPosition();
  116. void updateTrackingCaps();
  117. };
  118. #endif // _OCULUSVRSENSORDEVICE_H_