void OculusInterface::initOculus(float _devicePixelAspect) { m_devicePixelAspect=_devicePixelAspect; std::cout<<"setting device aspect "<<m_devicePixelAspect<<"\n"; m_hmd = ovrHmd_Create(0); if (!m_hmd) { std::cerr<<"Unable to create HMD: "<< ovrHmd_GetLastError(NULL)<<std::endl; std::cerr<<"Attempting to run without HMD\n"; // If we didn't detect an Hmd, create a simulated one for debugging. m_hmd = ovrHmd_CreateDebug(ovrHmd_DK1); if (!m_hmd) { // Failed Hmd creation. exit(EXIT_FAILURE); } } m_windowWidth=m_hmd->Resolution.w; m_windowHeight=m_hmd->Resolution.h; oculusDebug(); // Start the sensor which provides the Rift’s pose and motion. ovrHmd_ConfigureTracking(m_hmd, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position, 0); // let's fill in some info about oculus m_eyeres[0] = ovrHmd_GetFovTextureSize(m_hmd, ovrEye_Left, m_hmd->DefaultEyeFov[0], 1.0); m_eyeres[1] = ovrHmd_GetFovTextureSize(m_hmd, ovrEye_Right, m_hmd->DefaultEyeFov[1],1.0); /* and create a single render target texture to encompass both eyes */ //m_fbWidth = m_eyeres[0].w + m_eyeres[1].w; //m_fbHeight = m_eyeres[0].h > m_eyeres[1].h ? m_eyeres[0].h : m_eyeres[1].h; ovrSizei recommenedTex0Size = ovrHmd_GetFovTextureSize(m_hmd, ovrEye_Left,m_hmd->DefaultEyeFov[0], m_devicePixelAspect); ovrSizei recommenedTex1Size = ovrHmd_GetFovTextureSize(m_hmd, ovrEye_Right,m_hmd->DefaultEyeFov[1], m_devicePixelAspect); // Determine dimensions to fit into a single render target. ovrSizei renderTargetSize; m_fbWidth = recommenedTex0Size.w + recommenedTex1Size.w; m_fbHeight = std::max ( recommenedTex0Size.h, recommenedTex1Size.h ); createRenderTarget(); createOVRGLConfig(); createOVRTextureBuffers(); /* enable low-persistence display and dynamic prediction for lattency compensation */ ovrHmd_SetEnabledCaps(m_hmd, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction); /* configure SDK-rendering and enable chromatic abberation correction, vignetting, and * timewrap, which shifts the image before drawing to counter any lattency between the call * to ovrHmd_GetEyePose and ovrHmd_EndFrame. */ unsigned int dcaps = ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette | ovrDistortionCap_TimeWarp | ovrDistortionCap_Overdrive; if(!ovrHmd_ConfigureRendering(m_hmd, &m_glcfg.Config, dcaps, m_hmd->DefaultEyeFov, m_eyeRdesc)) { fprintf(stderr, "failed to configure distortion renderer\n"); } }
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ static void _oculus_raise_python_exception(ovrHmd device, PyObject *exception, const char *prefix, const char *suffix) { /* Create string buffer for error messages */ char error_buffer[ERROR_BUFFER_SIZE]; strncpy(error_buffer, prefix, ERROR_BUFFER_SIZE); strncat(error_buffer, ovrHmd_GetLastError(device), ERROR_BUFFER_SIZE); strncat(error_buffer, suffix, ERROR_BUFFER_SIZE); PyErr_SetString(exception, error_buffer); }
std::string HeadMountedDisplay::lastError() { return std::string( ovrHmd_GetLastError( m_handler ) ); }