oculusVRDevice.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 "gfx/gfxDevice.h"
  34. #include "OVR_CAPI_0_5_0.h"
  35. #define DEFAULT_RIFT_UNIT 0
  36. class OculusVRDevice : public IInputDevice, public IDisplayDevice
  37. {
  38. public:
  39. static bool smEnableDevice;
  40. // If no HMD is present simulate it being available
  41. static bool smSimulateHMD;
  42. // Type of rotation events to broadcast
  43. static bool smGenerateAngleAxisRotationEvents;
  44. static bool smGenerateEulerRotationEvents;
  45. static bool smGeneratePositionEvents;
  46. // Broadcast sensor rotation as axis
  47. static bool smGenerateRotationAsAxisEvents;
  48. // The maximum sensor angle when used as an axis event
  49. // as measured from a vector pointing straight up (in degrees)
  50. static F32 smMaximumAxisAngle;
  51. // Broadcast sensor raw data: acceleration, angular velocity, magnetometer reading
  52. static bool smGenerateSensorRawEvents;
  53. // Indicates that a whole frame event should be generated and frames
  54. // should be buffered.
  55. static bool smGenerateWholeFrameEvents;
  56. /// Determines desired pixel density for render target
  57. static F32 smDesiredPixelDensity;
  58. /// Determined if the window is moved to the oculus display
  59. static bool smWindowDebug;
  60. static F32 smPositionTrackingScale;
  61. protected:
  62. // Discovered HMD devices
  63. Vector<OculusVRHMDDevice*> mHMDDevices;
  64. /// Is the device active
  65. bool mActive;
  66. /// Which HMD is the active one
  67. U32 mActiveDeviceId;
  68. protected:
  69. void cleanUp();
  70. /// Build out the codes used for controller actions with the
  71. /// Input Event Manager
  72. void buildCodeTable();
  73. void addHMDDevice(ovrHmd hmd);
  74. void createSimulatedHMD();
  75. public:
  76. OculusVRDevice();
  77. ~OculusVRDevice();
  78. static void staticInit();
  79. bool enable();
  80. void disable();
  81. bool getActive() { return mActive; }
  82. void setActive(bool state) { mActive = state; }
  83. bool process();
  84. // IDisplayDevice
  85. virtual bool providesFrameEyePose() const;
  86. virtual void getFrameEyePose(DisplayPose *outPose, U32 eyeId) const;
  87. virtual bool providesEyeOffsets() const;
  88. virtual void getEyeOffsets(Point3F *dest) const;
  89. virtual bool providesFovPorts() const;
  90. virtual void getFovPorts(FovPort *out) const;
  91. virtual bool providesProjectionOffset() const;
  92. virtual const Point2F& getProjectionOffset() const;
  93. virtual void getStereoViewports(RectI *out) const;
  94. virtual void getStereoTargets(GFXTextureTarget **out) const;
  95. virtual void onStartFrame();
  96. // HMDs
  97. U32 getHMDCount() const { return mHMDDevices.size(); }
  98. OculusVRHMDDevice* getHMDDevice(U32 index) const;
  99. F32 getHMDCurrentIPD(U32 index);
  100. void setHMDCurrentIPD(U32 index, F32 ipd);
  101. // Sensors
  102. U32 getSensorCount() const { return mHMDDevices.size(); }
  103. const OculusVRSensorDevice* getSensorDevice(U32 index) const;
  104. EulerF getSensorEulerRotation(U32 index);
  105. VectorF getSensorAcceleration(U32 index);
  106. EulerF getSensorAngularVelocity(U32 index);
  107. bool getSensorYawCorrection(U32 index);
  108. void setSensorYawCorrection(U32 index, bool state);
  109. bool getSensorMagnetometerCalibrated(U32 index);
  110. void setOptimalDisplaySize(U32 idx, GuiCanvas *canvas);
  111. void resetAllSensors();
  112. bool isDiplayingWarning();
  113. void dismissWarning();
  114. String dumpMetrics(U32 idx);
  115. void setDrawCanvas(GuiCanvas *canvas);
  116. virtual void setCurrentConnection(GameConnection *connection);
  117. virtual GameConnection* getCurrentConnection();
  118. bool _handleDeviceEvent( GFXDevice::GFXDeviceEventType evt );
  119. public:
  120. // For ManagedSingleton.
  121. static const char* getSingletonName() { return "OculusVRDevice"; }
  122. };
  123. /// Returns the OculusVRDevice singleton.
  124. #define OCULUSVRDEV ManagedSingleton<OculusVRDevice>::instance()
  125. #endif // _OCULUSVRDEVICE_H_