oculusVRHMDDevice.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 _OCULUSVRHMDDEVICE_H_
  23. #define _OCULUSVRHMDDEVICE_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. class OculusVRHMDDevice
  33. {
  34. public:
  35. enum SimulationTypes {
  36. ST_RIFT_PREVIEW,
  37. };
  38. protected:
  39. bool mIsValid;
  40. bool mIsSimulation;
  41. OVR::HMDDevice* mDevice;
  42. // From OVR::DeviceInfo
  43. String mProductName;
  44. String mManufacturer;
  45. U32 mVersion;
  46. // Windows display device name used in EnumDisplaySettings/CreateDC
  47. String mDisplayDeviceName;
  48. // MacOS display ID
  49. S32 mDisplayId;
  50. // Desktop coordinate position of the screen (can be negative; may not be present on all platforms)
  51. Point2I mDesktopPosition;
  52. // Whole screen resolution
  53. Point2I mResolution;
  54. // Physical screen size in meters
  55. Point2F mScreenSize;
  56. // Physical offset from the top of the screen to the center of the
  57. // eye, in meters. Usually half of the vertical physical screen size
  58. F32 mVerticalEyeCenter;
  59. // Physical distance from the eye to the screen
  60. F32 mEyeToScreen;
  61. // Physical distance between lens centers, in meters
  62. F32 mLensSeparation;
  63. // Physical distance between the user's eye centers as defined in the current profile
  64. F32 mProfileInterpupillaryDistance;
  65. // Physical distance between the user's eye centers
  66. F32 mInterpupillaryDistance;
  67. // The eye IPD as a Point3F
  68. Point3F mEyeWorldOffset;
  69. // Radial distortion correction coefficients used by the barrel distortion shader
  70. Point4F mKDistortion;
  71. // Chromatic aberration correction coefficients
  72. Point4F mChromaticAbCorrection;
  73. // Calculated values of eye x offset from center in normalized (uv) coordinates
  74. // where each eye is 0..1. Used for the mono to stereo postFX to simulate an
  75. // eye offset of the camera. The x component is the left eye, the y component
  76. // is the right eye.
  77. Point2F mEyeUVOffset;
  78. // Used to adjust where an eye's view is rendered to account for the lenses not
  79. // being in the center of the physical screen half.
  80. F32 mXCenterOffset;
  81. // When calculating the distortion scale to use to increase the size of the input texture
  82. // this determines how we should attempt to fit the distorted view into the backbuffer.
  83. Point2F mDistortionFit;
  84. // Is the factor by which the input texture size is increased to make post-distortion
  85. // result distortion fit the viewport. If the input texture is the same size as the
  86. // backbuffer, then this should be 1.0.
  87. F32 mDistortionScale;
  88. // Aspect ratio for a single eye
  89. F32 mAspectRatio;
  90. // Vertical field of view
  91. F32 mYFOV;
  92. // The amount to offset the projection matrix to account for the eye not being in the
  93. // center of the screen.
  94. Point2F mProjectionCenterOffset;
  95. protected:
  96. F32 calcScale(F32 fitRadius);
  97. void calculateValues(bool calculateDistortionScale);
  98. void createSimulatedPreviewRift(bool calculateDistortionScale);
  99. public:
  100. OculusVRHMDDevice();
  101. ~OculusVRHMDDevice();
  102. void cleanUp();
  103. // Set the HMD properties based on information from the OVR device
  104. void set(OVR::HMDDevice* hmd, OVR::HMDInfo& info, bool calculateDistortionScale);
  105. // Set the HMD properties based on a simulation of the given type
  106. void createSimulation(SimulationTypes simulationType, bool calculateDistortionScale);
  107. bool isValid() const {return mIsValid;}
  108. bool isSimulated() const {return mIsSimulation;}
  109. const char* getProductName() const { return mProductName.c_str(); }
  110. const char* getManufacturer() const { return mManufacturer.c_str(); }
  111. U32 getVersion() const { return mVersion; }
  112. // Windows display device name used in EnumDisplaySettings/CreateDC
  113. const char* getDisplayDeviceName() const { return mDisplayDeviceName.c_str(); }
  114. // MacOS display ID
  115. S32 getDisplayDeviceId() const { return mDisplayId; }
  116. // Desktop coordinate position of the screen (can be negative; may not be present on all platforms)
  117. const Point2I& getDesktopPosition() const { return mDesktopPosition; }
  118. // Whole screen resolution
  119. const Point2I& getResolution() const { return mResolution; }
  120. // Physical screen size in meters
  121. const Point2F& getScreenSize() const { return mScreenSize; }
  122. // Physical offset from the top of the screen to the center of the
  123. // eye, in meters. Usually half of the vertical physical screen size
  124. F32 getVerticalEyeCenter() const { return mVerticalEyeCenter; }
  125. // Physical distance from the eye to the screen
  126. F32 getEyeToScreen() const { return mEyeToScreen; }
  127. // Physical distance between lens centers, in meters
  128. F32 getLensSeparation() const { return mLensSeparation; }
  129. // Physical distance between the user's eye centers as defined by the current profile
  130. F32 getProfileIPD() const { return mProfileInterpupillaryDistance; }
  131. // Physical distance between the user's eye centers
  132. F32 getIPD() const { return mInterpupillaryDistance; }
  133. // Set a new physical distance between the user's eye centers
  134. void setIPD(F32 ipd, bool calculateDistortionScale);
  135. // Provides the IPD of one eye as a Point3F
  136. const Point3F& getEyeWorldOffset() const { return mEyeWorldOffset; }
  137. // Radial distortion correction coefficients used by the barrel distortion shader
  138. const Point4F& getKDistortion() const { return mKDistortion; }
  139. // Chromatic aberration correction coefficients used by the barrel distortion shader
  140. const Point4F& getChromaticAbCorrection() const { return mChromaticAbCorrection; }
  141. // Calculated values of eye x offset from center in normalized (uv) coordinates.
  142. const Point2F& getEyeUVOffset() const { return mEyeUVOffset; }
  143. // Used to adjust where an eye's view is rendered to account for the lenses not
  144. // being in the center of the physical screen half.
  145. F32 getCenterOffset() const { return mXCenterOffset; }
  146. // Is the factor by which the input texture size is increased to make post-distortion
  147. // result distortion fit the viewport.
  148. F32 getDistortionScale() const { return mDistortionScale; }
  149. // Aspect ration for a single eye
  150. F32 getAspectRation() const { return mAspectRatio; }
  151. // Vertical field of view
  152. F32 getYFOV() const { return mYFOV; }
  153. // The amount to offset the projection matrix to account for the eye not being in the
  154. // center of the screen.
  155. const Point2F& getProjectionCenterOffset() const { return mProjectionCenterOffset; }
  156. };
  157. #endif // _OCULUSVRHMDDEVICE_H_