|
| 1 | +/********************************************************************************//** |
| 2 | +\file OVR_CAPI_Util.h |
| 3 | +\brief This header provides LibOVR utility function declarations |
| 4 | +\copyright Copyright 2015-2016 Oculus VR, LLC All Rights reserved. |
| 5 | +*************************************************************************************/ |
| 6 | + |
| 7 | +#ifndef OVR_CAPI_Util_h |
| 8 | +#define OVR_CAPI_Util_h |
| 9 | + |
| 10 | + |
| 11 | +#include "OVR_CAPI.h" |
| 12 | + |
| 13 | + |
| 14 | +#ifdef __cplusplus |
| 15 | +extern "C" { |
| 16 | +#endif |
| 17 | + |
| 18 | + |
| 19 | +/// Enumerates modifications to the projection matrix based on the application's needs. |
| 20 | +/// |
| 21 | +/// \see ovrMatrix4f_Projection |
| 22 | +/// |
| 23 | +typedef enum ovrProjectionModifier_ |
| 24 | +{ |
| 25 | + /// Use for generating a default projection matrix that is: |
| 26 | + /// * Right-handed. |
| 27 | + /// * Near depth values stored in the depth buffer are smaller than far depth values. |
| 28 | + /// * Both near and far are explicitly defined. |
| 29 | + /// * With a clipping range that is (0 to w). |
| 30 | + ovrProjection_None = 0x00, |
| 31 | + |
| 32 | + /// Enable if using left-handed transformations in your application. |
| 33 | + ovrProjection_LeftHanded = 0x01, |
| 34 | + |
| 35 | + /// After the projection transform is applied, far values stored in the depth buffer will be less than closer depth values. |
| 36 | + /// NOTE: Enable only if the application is using a floating-point depth buffer for proper precision. |
| 37 | + ovrProjection_FarLessThanNear = 0x02, |
| 38 | + |
| 39 | + /// When this flag is used, the zfar value pushed into ovrMatrix4f_Projection() will be ignored |
| 40 | + /// NOTE: Enable only if ovrProjection_FarLessThanNear is also enabled where the far clipping plane will be pushed to infinity. |
| 41 | + ovrProjection_FarClipAtInfinity = 0x04, |
| 42 | + |
| 43 | + /// Enable if the application is rendering with OpenGL and expects a projection matrix with a clipping range of (-w to w). |
| 44 | + /// Ignore this flag if your application already handles the conversion from D3D range (0 to w) to OpenGL. |
| 45 | + ovrProjection_ClipRangeOpenGL = 0x08, |
| 46 | +} ovrProjectionModifier; |
| 47 | + |
| 48 | + |
| 49 | +/// Return values for ovr_Detect. |
| 50 | +/// |
| 51 | +/// \see ovr_Detect |
| 52 | +/// |
| 53 | +typedef struct OVR_ALIGNAS(8) ovrDetectResult_ |
| 54 | +{ |
| 55 | + /// Is ovrFalse when the Oculus Service is not running. |
| 56 | + /// This means that the Oculus Service is either uninstalled or stopped. |
| 57 | + /// IsOculusHMDConnected will be ovrFalse in this case. |
| 58 | + /// Is ovrTrue when the Oculus Service is running. |
| 59 | + /// This means that the Oculus Service is installed and running. |
| 60 | + /// IsOculusHMDConnected will reflect the state of the HMD. |
| 61 | + ovrBool IsOculusServiceRunning; |
| 62 | + |
| 63 | + /// Is ovrFalse when an Oculus HMD is not detected. |
| 64 | + /// If the Oculus Service is not running, this will be ovrFalse. |
| 65 | + /// Is ovrTrue when an Oculus HMD is detected. |
| 66 | + /// This implies that the Oculus Service is also installed and running. |
| 67 | + ovrBool IsOculusHMDConnected; |
| 68 | + |
| 69 | + OVR_UNUSED_STRUCT_PAD(pad0, 6) ///< \internal struct padding |
| 70 | + |
| 71 | +} ovrDetectResult; |
| 72 | + |
| 73 | +OVR_STATIC_ASSERT(sizeof(ovrDetectResult) == 8, "ovrDetectResult size mismatch"); |
| 74 | + |
| 75 | + |
| 76 | +/// Detects Oculus Runtime and Device Status |
| 77 | +/// |
| 78 | +/// Checks for Oculus Runtime and Oculus HMD device status without loading the LibOVRRT |
| 79 | +/// shared library. This may be called before ovr_Initialize() to help decide whether or |
| 80 | +/// not to initialize LibOVR. |
| 81 | +/// |
| 82 | +/// \param[in] timeoutMilliseconds Specifies a timeout to wait for HMD to be attached or 0 to poll. |
| 83 | +/// |
| 84 | +/// \return Returns an ovrDetectResult object indicating the result of detection. |
| 85 | +/// |
| 86 | +/// \see ovrDetectResult |
| 87 | +/// |
| 88 | +OVR_PUBLIC_FUNCTION(ovrDetectResult) ovr_Detect(int timeoutMilliseconds); |
| 89 | + |
| 90 | +// On the Windows platform, |
| 91 | +#ifdef _WIN32 |
| 92 | + /// This is the Windows Named Event name that is used to check for HMD connected state. |
| 93 | + #define OVR_HMD_CONNECTED_EVENT_NAME L"OculusHMDConnected" |
| 94 | +#endif // _WIN32 |
| 95 | + |
| 96 | + |
| 97 | +/// Used to generate projection from ovrEyeDesc::Fov. |
| 98 | +/// |
| 99 | +/// \param[in] fov Specifies the ovrFovPort to use. |
| 100 | +/// \param[in] znear Distance to near Z limit. |
| 101 | +/// \param[in] zfar Distance to far Z limit. |
| 102 | +/// \param[in] projectionModFlags A combination of the ovrProjectionModifier flags. |
| 103 | +/// |
| 104 | +/// \return Returns the calculated projection matrix. |
| 105 | +/// |
| 106 | +/// \see ovrProjectionModifier |
| 107 | +/// |
| 108 | +OVR_PUBLIC_FUNCTION(ovrMatrix4f) ovrMatrix4f_Projection(ovrFovPort fov, float znear, float zfar, unsigned int projectionModFlags); |
| 109 | + |
| 110 | + |
| 111 | +/// Extracts the required data from the result of ovrMatrix4f_Projection. |
| 112 | +/// |
| 113 | +/// \param[in] projection Specifies the project matrix from which to extract ovrTimewarpProjectionDesc. |
| 114 | +/// \param[in] projectionModFlags A combination of the ovrProjectionModifier flags. |
| 115 | +/// \return Returns the extracted ovrTimewarpProjectionDesc. |
| 116 | +/// \see ovrTimewarpProjectionDesc |
| 117 | +/// |
| 118 | +OVR_PUBLIC_FUNCTION(ovrTimewarpProjectionDesc) ovrTimewarpProjectionDesc_FromProjection(ovrMatrix4f projection, unsigned int projectionModFlags); |
| 119 | + |
| 120 | + |
| 121 | +/// Generates an orthographic sub-projection. |
| 122 | +/// |
| 123 | +/// Used for 2D rendering, Y is down. |
| 124 | +/// |
| 125 | +/// \param[in] projection The perspective matrix that the orthographic matrix is derived from. |
| 126 | +/// \param[in] orthoScale Equal to 1.0f / pixelsPerTanAngleAtCenter. |
| 127 | +/// \param[in] orthoDistance Equal to the distance from the camera in meters, such as 0.8m. |
| 128 | +/// \param[in] HmdToEyeOffsetX Specifies the offset of the eye from the center. |
| 129 | +/// |
| 130 | +/// \return Returns the calculated projection matrix. |
| 131 | +/// |
| 132 | +OVR_PUBLIC_FUNCTION(ovrMatrix4f) ovrMatrix4f_OrthoSubProjection(ovrMatrix4f projection, ovrVector2f orthoScale, |
| 133 | + float orthoDistance, float HmdToEyeOffsetX); |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | +/// Computes offset eye poses based on headPose returned by ovrTrackingState. |
| 138 | +/// |
| 139 | +/// \param[in] headPose Indicates the HMD position and orientation to use for the calculation. |
| 140 | +/// \param[in] hmdToEyeOffset Can be ovrEyeRenderDesc.HmdToEyeOffset returned from |
| 141 | +/// ovr_GetRenderDesc. For monoscopic rendering, use a vector that is the average |
| 142 | +/// of the two vectors for both eyes. |
| 143 | +/// \param[out] outEyePoses If outEyePoses are used for rendering, they should be passed to |
| 144 | +/// ovr_SubmitFrame in ovrLayerEyeFov::RenderPose or ovrLayerEyeFovDepth::RenderPose. |
| 145 | +/// |
| 146 | +OVR_PUBLIC_FUNCTION(void) ovr_CalcEyePoses(ovrPosef headPose, |
| 147 | + const ovrVector3f hmdToEyeOffset[2], |
| 148 | + ovrPosef outEyePoses[2]); |
| 149 | + |
| 150 | + |
| 151 | +/// Returns the predicted head pose in outHmdTrackingState and offset eye poses in outEyePoses. |
| 152 | +/// |
| 153 | +/// This is a thread-safe function where caller should increment frameIndex with every frame |
| 154 | +/// and pass that index where applicable to functions called on the rendering thread. |
| 155 | +/// Assuming outEyePoses are used for rendering, it should be passed as a part of ovrLayerEyeFov. |
| 156 | +/// The caller does not need to worry about applying HmdToEyeOffset to the returned outEyePoses variables. |
| 157 | +/// |
| 158 | +/// \param[in] hmd Specifies an ovrSession previously returned by ovr_Create. |
| 159 | +/// \param[in] frameIndex Specifies the targeted frame index, or 0 to refer to one frame after |
| 160 | +/// the last time ovr_SubmitFrame was called. |
| 161 | +/// \param[in] latencyMarker Specifies that this call is the point in time where |
| 162 | +/// the "App-to-Mid-Photon" latency timer starts from. If a given ovrLayer |
| 163 | +/// provides "SensorSampleTimestamp", that will override the value stored here. |
| 164 | +/// \param[in] hmdToEyeOffset Can be ovrEyeRenderDesc.HmdToEyeOffset returned from |
| 165 | +/// ovr_GetRenderDesc. For monoscopic rendering, use a vector that is the average |
| 166 | +/// of the two vectors for both eyes. |
| 167 | +/// \param[out] outEyePoses The predicted eye poses. |
| 168 | +/// \param[out] outSensorSampleTime The time when this function was called. May be NULL, in which case it is ignored. |
| 169 | +/// |
| 170 | +OVR_PUBLIC_FUNCTION(void) ovr_GetEyePoses(ovrSession session, long long frameIndex, ovrBool latencyMarker, |
| 171 | + const ovrVector3f hmdToEyeOffset[2], |
| 172 | + ovrPosef outEyePoses[2], |
| 173 | + double* outSensorSampleTime); |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | +/// Tracking poses provided by the SDK come in a right-handed coordinate system. If an application |
| 178 | +/// is passing in ovrProjection_LeftHanded into ovrMatrix4f_Projection, then it should also use |
| 179 | +/// this function to flip the HMD tracking poses to be left-handed. |
| 180 | +/// |
| 181 | +/// While this utility function is intended to convert a left-handed ovrPosef into a right-handed |
| 182 | +/// coordinate system, it will also work for converting right-handed to left-handed since the |
| 183 | +/// flip operation is the same for both cases. |
| 184 | +/// |
| 185 | +/// \param[in] inPose that is right-handed |
| 186 | +/// \param[out] outPose that is requested to be left-handed (can be the same pointer to inPose) |
| 187 | +/// |
| 188 | +OVR_PUBLIC_FUNCTION(void) ovrPosef_FlipHandedness(const ovrPosef* inPose, ovrPosef* outPose); |
| 189 | + |
| 190 | + |
| 191 | +#ifdef __cplusplus |
| 192 | +} /* extern "C" */ |
| 193 | +#endif |
| 194 | + |
| 195 | + |
| 196 | +#endif // Header include guard |
0 commit comments