oculusVRSensorDevice.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. protected:
  46. bool mIsValid;
  47. bool mIsSimulation;
  48. OVR::SensorDevice* mDevice;
  49. OVR::SensorFusion mSensorFusion;
  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. // Assigned by the OculusVRDevice
  59. S32 mActionCodeIndex;
  60. // Buffers to store data for sensor
  61. OculusVRSensorData* mDataBuffer[2];
  62. // Points to the buffer that holds the previously collected data
  63. // for the sensor
  64. OculusVRSensorData* mPrevData;
  65. protected:
  66. void createSimulatedPreviewRift(S32 actionCodeIndex);
  67. public:
  68. OculusVRSensorDevice();
  69. virtual ~OculusVRSensorDevice();
  70. static void buildCodeTable();
  71. void cleanUp();
  72. // Set the sensor properties based on information from the OVR device
  73. void set(OVR::SensorDevice* sensor, OVR::SensorInfo& info, S32 actionCodeIndex);
  74. // Set the sensor properties based on a simulation of the given type
  75. void createSimulation(SimulationTypes simulationType, S32 actionCodeIndex);
  76. bool isValid() const {return mIsValid;}
  77. bool isSimulated() {return mIsSimulation;}
  78. bool process(U32 deviceType, bool generateRotAsAngAxis, bool generateRotAsEuler, bool generateRotationAsAxisEvents, F32 maxAxisRadius);
  79. void reset();
  80. // Get the prediction time for the sensor fusion. The time is in seconds.
  81. F32 getPredictionTime() const;
  82. // Set the prediction time for the sensor fusion. The time is in seconds.
  83. void setPredictionTime(F32 dt);
  84. const char* getProductName() { return mProductName.c_str(); }
  85. const char* getManufacturer() { return mManufacturer.c_str(); }
  86. U32 getVersion() { return mVersion; }
  87. U16 getVendorId() { return mVendorId; }
  88. U16 getProductId() { return mProductId; }
  89. const char* getSerialNumber() { return mSerialNumber; }
  90. EulerF getEulerRotation();
  91. };
  92. #endif // _OCULUSVRSENSORDEVICE_H_