oculusVRDevice.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 _OCULUSVRDEVICE_H_
  23. #define _OCULUSVRDEVICE_H_
  24. #include "platform/input/oculusVR/oculusVRConstants.h"
  25. #include "platform/input/oculusVR/oculusVRHMDDevice.h"
  26. #include "platform/input/oculusVR/oculusVRSensorDevice.h"
  27. #include "platform/input/IInputDevice.h"
  28. #include "platform/input/event.h"
  29. #include "platform/output/IDisplayDevice.h"
  30. #include "core/util/tSingleton.h"
  31. #include "math/mQuat.h"
  32. #include "math/mPoint4.h"
  33. #include "OVR.h"
  34. #define DEFAULT_RIFT_UNIT 0
  35. class OculusVRDevice : public IInputDevice, public IDisplayDevice
  36. {
  37. public:
  38. static bool smEnableDevice;
  39. // If no HMD is present simulate it being available
  40. static bool smSimulateHMD;
  41. // Use the chromatic aberration correction version of the barrel
  42. // distortion shader.
  43. static bool smUseChromaticAberrationCorrection;
  44. // Type of rotation events to broadcast
  45. static bool smGenerateAngleAxisRotationEvents;
  46. static bool smGenerateEulerRotationEvents;
  47. // Broadcast sensor rotation as axis
  48. static bool smGenerateRotationAsAxisEvents;
  49. // The maximum sensor angle when used as an axis event
  50. // as measured from a vector pointing straight up (in degrees)
  51. static F32 smMaximumAxisAngle;
  52. // Broadcast sensor raw data: acceleration, angular velocity, magnetometer reading
  53. static bool smGenerateSensorRawEvents;
  54. // Indicates that a whole frame event should be generated and frames
  55. // should be buffered.
  56. static bool smGenerateWholeFrameEvents;
  57. protected:
  58. class DeviceListener : public OVR::MessageHandler
  59. {
  60. protected:
  61. OculusVRDevice* mOwner;
  62. public:
  63. DeviceListener(OculusVRDevice* owner) { mOwner = owner; }
  64. virtual ~DeviceListener() { mOwner = NULL; }
  65. virtual void OnMessage(const OVR::Message&);
  66. };
  67. // Our OVR SDK device listener class
  68. DeviceListener* mListener;
  69. // The OVR SDK device manager
  70. OVR::DeviceManager* mDeviceManager;
  71. // Discovered HMD devices
  72. Vector<OculusVRHMDDevice*> mHMDDevices;
  73. // Discovered sensor devices
  74. Vector<OculusVRSensorDevice*> mSensorDevices;
  75. /// Is the device active
  76. bool mActive;
  77. // Should the input texture into the HMD (the render target that the scene has been
  78. // rendered to) be scaled according to the HMD's distortion calculation?
  79. bool mScaleInputTexture;
  80. protected:
  81. void cleanUp();
  82. /// Build out the codes used for controller actions with the
  83. /// Input Event Manager
  84. void buildCodeTable();
  85. void addHMDDevice(OVR::HMDDevice* hmd);
  86. void createSimulatedHMD();
  87. void addSensorDevice(OVR::SensorDevice* sensor);
  88. void createSimulatedSensor();
  89. public:
  90. OculusVRDevice();
  91. ~OculusVRDevice();
  92. static void staticInit();
  93. bool enable();
  94. void disable();
  95. bool getActive() { return mActive; }
  96. void setActive(bool state) { mActive = state; }
  97. bool process();
  98. // IDisplayDevice
  99. virtual bool providesYFOV() const;
  100. virtual F32 getYFOV() const;
  101. virtual bool providesEyeOffset() const;
  102. virtual const Point3F& getEyeOffset() const;
  103. virtual bool providesProjectionOffset() const;
  104. virtual const Point2F& getProjectionOffset() const;
  105. // HMDs
  106. U32 getHMDCount() const { return mHMDDevices.size(); }
  107. const OculusVRHMDDevice* getHMDDevice(U32 index) const;
  108. F32 getHMDCurrentIPD(U32 index);
  109. void setHMDCurrentIPD(U32 index, F32 ipd);
  110. // Sensors
  111. U32 getSensorCount() const { return mSensorDevices.size(); }
  112. const OculusVRSensorDevice* getSensorDevice(U32 index) const;
  113. EulerF getSensorEulerRotation(U32 index);
  114. VectorF getSensorAcceleration(U32 index);
  115. EulerF getSensorAngularVelocity(U32 index);
  116. VectorF getSensorMagnetometer(U32 index);
  117. F32 getSensorPredictionTime(U32 index);
  118. void setSensorPredictionTime(U32 index, F32 dt);
  119. void setAllSensorPredictionTime(F32 dt);
  120. bool getSensorGravityCorrection(U32 index);
  121. void setSensorGravityCorrection(U32 index, bool state);
  122. bool getSensorYawCorrection(U32 index);
  123. void setSensorYawCorrection(U32 index, bool state);
  124. bool getSensorMagnetometerCalibrated(U32 index);
  125. void resetAllSensors();
  126. public:
  127. // For ManagedSingleton.
  128. static const char* getSingletonName() { return "OculusVRDevice"; }
  129. };
  130. /// Returns the OculusVRDevice singleton.
  131. #define OCULUSVRDEV ManagedSingleton<OculusVRDevice>::instance()
  132. #endif // _OCULUSVRDEVICE_H_