2
0

oculusVRSensorDevice.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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.h"
  32. struct OculusVRSensorData;
  33. class OculusVRSensorDevice
  34. {
  35. public:
  36. enum SimulationTypes {
  37. ST_RIFT_PREVIEW,
  38. };
  39. public:
  40. // Action codes
  41. static U32 OVR_SENSORROT[OculusVRConstants::MaxSensors]; // SI_ROT
  42. static U32 OVR_SENSORROTANG[OculusVRConstants::MaxSensors]; // SI_POS but is EulerF
  43. static U32 OVR_SENSORROTAXISX[OculusVRConstants::MaxSensors]; // SI_AXIS
  44. static U32 OVR_SENSORROTAXISY[OculusVRConstants::MaxSensors];
  45. static U32 OVR_SENSORACCELERATION[OculusVRConstants::MaxSensors]; // SI_POS
  46. static U32 OVR_SENSORANGVEL[OculusVRConstants::MaxSensors]; // SI_POS but is EulerF
  47. static U32 OVR_SENSORMAGNETOMETER[OculusVRConstants::MaxSensors]; // SI_POS
  48. protected:
  49. bool mIsValid;
  50. bool mIsSimulation;
  51. OVR::SensorDevice* mDevice;
  52. OVR::SensorFusion mSensorFusion;
  53. // From OVR::DeviceInfo
  54. String mProductName;
  55. String mManufacturer;
  56. U32 mVersion;
  57. // From OVR::SensorInfo
  58. U16 mVendorId;
  59. U16 mProductId;
  60. String mSerialNumber;
  61. // Has yaw correction been disabled by the control panel
  62. bool mYawCorrectionDisabled;
  63. // Assigned by the OculusVRDevice
  64. S32 mActionCodeIndex;
  65. // Buffers to store data for sensor
  66. OculusVRSensorData* mDataBuffer[2];
  67. // Points to the buffer that holds the previously collected data
  68. // for the sensor
  69. OculusVRSensorData* mPrevData;
  70. protected:
  71. void createSimulatedPreviewRift(S32 actionCodeIndex);
  72. public:
  73. OculusVRSensorDevice();
  74. virtual ~OculusVRSensorDevice();
  75. static void buildCodeTable();
  76. void cleanUp();
  77. // Set the sensor properties based on information from the OVR device
  78. void set(OVR::SensorDevice* sensor, OVR::SensorInfo& info, S32 actionCodeIndex);
  79. // Set the sensor properties based on a simulation of the given type
  80. void createSimulation(SimulationTypes simulationType, S32 actionCodeIndex);
  81. bool isValid() const {return mIsValid;}
  82. bool isSimulated() {return mIsSimulation;}
  83. bool process(U32 deviceType, bool generateRotAsAngAxis, bool generateRotAsEuler, bool generateRotationAsAxisEvents, F32 maxAxisRadius, bool generateRawSensor);
  84. void reset();
  85. // Get the prediction time for the sensor fusion. The time is in seconds.
  86. F32 getPredictionTime() const;
  87. // Set the prediction time for the sensor fusion. The time is in seconds.
  88. void setPredictionTime(F32 dt);
  89. // Is gravity correction enabled for pitch and roll
  90. bool getGravityCorrection() const;
  91. // Set the pitch and roll gravity correction
  92. void setGravityCorrection(bool state);
  93. // Has yaw correction been disabled using the control panel
  94. bool getYawCorrectionUserDisabled() const { return mYawCorrectionDisabled; }
  95. // Is yaw correction enabled
  96. bool getYawCorrection() const;
  97. // Set the yaw correction. Note: if magnetometer calibration data is not present,
  98. // or user has disabled yaw correction in the control panel, this method will
  99. // not enable it.
  100. void setYawCorrection(bool state);
  101. // Is magnetometer calibration data available for this sensor
  102. bool getMagnetometerCalibrationAvailable() const;
  103. const char* getProductName() { return mProductName.c_str(); }
  104. const char* getManufacturer() { return mManufacturer.c_str(); }
  105. U32 getVersion() { return mVersion; }
  106. U16 getVendorId() { return mVendorId; }
  107. U16 getProductId() { return mProductId; }
  108. const char* getSerialNumber() { return mSerialNumber; }
  109. // Get the current rotation of the sensor. Uses prediction if set.
  110. EulerF getEulerRotation();
  111. // Get the current rotation of the sensor.
  112. EulerF getRawEulerRotation();
  113. // Get the current absolute acceleration reading, in m/s^2
  114. VectorF getAcceleration();
  115. // Get the current angular velocity reading, in rad/s
  116. EulerF getAngularVelocity();
  117. // Get the current magnetometer reading (direction and field strength), in Gauss.
  118. // Uses magnetometer calibration if set.
  119. VectorF getMagnetometer();
  120. // Get the current raw magnetometer reading (direction and field strength), in Gauss
  121. VectorF getRawMagnetometer();
  122. };
  123. #endif // _OCULUSVRSENSORDEVICE_H_